Пример #1
0
char *test_findHashElementByKey() {
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));

//simple hash function
	struct hash *symbolTable = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	createHashElement(symbolTable, "blue", symbol);

	mu_assert("Could not find element that should be table.", 
 		findHashElementByKey(symbolTable, "blue") != NULL);

	mu_assert("Found element that should not be table.", 
 		findHashElementByKey(symbolTable, "green") == NULL);

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);	

//normal hash function
	symbolTable = createHash(&getHashedKeyNormal);
	mu_assert("Call to createHash does not seg fault.", 1);	

	createHashElement(symbolTable, "teekkekkke", symbol);

	mu_assert("Could not find element that should be table.", 
 		findHashElementByKey(symbolTable, "teekkekkke") != NULL);

	mu_assert("Found element that should not be table.", 
 		findHashElementByKey(symbolTable, "green") == NULL);

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);

	return NULL;
}
Пример #2
0
static VALUE 
_create_request_hash(struct conn *c, RouteRef route, const char* body, int bodylen) {
  const char *method, *uri, *query;
  VALUE hash_headers;
  struct parsed_header* h;
  int i;

	VALUE hash = createHash();

	addStrToHash(hash, "application", 
    route->_application, strlen(route->_application));

	addStrToHash(hash, "model", 
    route->_model, strlen(route->_model));

	if (route->_action!=NULL) {
		const char* actionName = route->_action;
		addStrToHash(hash, "action", actionName, strlen(actionName));
	}
	
	if (route->_id!=NULL) {
		const char* _id = route->_id;
		addStrToHash(hash, "id", _id, strlen(_id));
	}
	
  method = _shttpd_known_http_methods[c->method].ptr;
	addStrToHash(hash, "request-method", method, strlen(method));
		
	uri = c->uri;
	addStrToHash(hash, "request-uri", uri, strlen(uri));
	
	query = c->query == NULL ? "" : c->query;
	addStrToHash(hash, "request-query", query, strlen(query));
	
	hash_headers = createHash();
  h = &c->ch.cl;
	for (i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) {
		if (h->_name) {
			char* name = trim(_shttpd_strdup(h->_name));
			if (h->_type == HDR_STRING) {
				addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len);
			} else if (h->_type == HDR_INT) {
				addIntToHash(hash_headers, name, h->_v.v_big_int);
			} else if (h->_type == HDR_DATE) {
				addTimeToHash(hash_headers, name, h->_v.v_time);
			}
			free(name);
		}
		h++;
	}
	addHashToHash(hash,"headers",hash_headers);
	
  if (bodylen > 0) {
		addStrToHash(hash, "request-body", body, bodylen);
	}
	
	return hash;
}
Пример #3
0
static VALUE 
_CreateRequestHash(HttpContextRef context, RouteRef route) {
	DBG(("Creating Req Hash\n"));
	
	VALUE hash = createHash();

	const char* applicationName = route->_application;
	addStrToHash(hash, "application", applicationName, strlen(applicationName));

	const char* modelName = route->_model;
	addStrToHash(hash, "model", modelName, strlen(modelName));

	if (route->_action!=NULL) {
		const char* actionName = route->_action;
		addStrToHash(hash, "action", actionName, strlen(actionName));
	}
	
	if (route->_id!=NULL) {
		const char* _id = route->_id;
		addStrToHash(hash, "id", _id, strlen(_id));
	}
	
	const char* method = HTTPGetMethod(context->_request->_method);
	addStrToHash(hash, "request-method", method, strlen(method));
	
	const char* uri = context->_request->_uri;
	addStrToHash(hash, "request-uri", uri, strlen(uri));
	
	const char* query = context->_request->_query == NULL ? "" : context->_request->_query;
	addStrToHash(hash, "request-query", query, strlen(query));
	
	VALUE hash_headers = createHash();
	struct parsed_header* h = &context->_request->_cheaders.cl;
	for (int i = 0; i < sizeof(struct headers)/sizeof(struct parsed_header); i++) {
		if (h->_name) {
			char* name = trim(strdup(h->_name));
			if (h->_type == HDR_STRING) {
				addStrToHash(hash_headers,name,h->_v.v_vec.ptr,h->_v.v_vec.len);
			} else if (h->_type == HDR_INT) {
				addIntToHash(hash_headers, name, h->_v.v_big_int);
			} else if (h->_type == HDR_DATE) {
				addTimeToHash(hash_headers, name, h->_v.v_time);
			}
			free(name);
		}
		h++;
	}
	addHashToHash(hash,"headers",hash_headers);
	
	int buflen = CFDataGetLength(context->_rcvdBytes);
	if (buflen > 0) {
		addStrToHash(hash, "request-body", 
					 (char*)CFDataGetBytePtr(context->_rcvdBytes), buflen);
	}
	
	return hash;
}
Пример #4
0
char *test_createHashElement() {
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));
	symbol->lvl = 14;
//simple hash function
	struct hash *symbolTable = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	mu_assert("Could not created element in empty table.", 
 		createHashElement(symbolTable, "blue", symbol) == 0);

	mu_assert("Could not create element where bucket collison happened.", 
 		createHashElement(symbolTable, "boo", symbol) == 0);

	mu_assert("Level of symbol not same as current lex level.", 
 		createHashElement(symbolTable, "blue", symbol) == 1);	

	setLexLevel(symbolTable, 14);
	mu_assert("Head of symbol linked list hash same lex level as appending symbol.", 
 		createHashElement(symbolTable, "blue", symbol) == 3);

	struct Symbol *symbol2 =  calloc(1, sizeof(struct Symbol));
	symbol2->lvl = 1;
	setLexLevel(symbolTable, 1);
	mu_assert("Appending symbol is at a lower lex level then list head.", 
 		createHashElement(symbolTable, "blue", symbol2) == 4);

	symbol2->lvl = 15;
	setLexLevel(symbolTable, 15);
	mu_assert("Could not append symbol where expected.", 
 		createHashElement(symbolTable, "blue", symbol2) == 0);

	// createHashElement(symbolTable, "green", symbol) ;
	// createHashElement(symbolTable, "red", symbol) ;
	// dumpHash(symbolTable);

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);	

//normal hash function
	symbolTable = createHash(&getHashedKeyNormal);
	mu_assert("Call to createHash does not seg fault.", 1);	

	mu_assert("Could not created element in empty table.", 
 		createHashElement(symbolTable, "blue", symbol) == 0);

	mu_assert("Could not create element where bucket collison happened.", 
 		createHashElement(symbolTable, "boo", symbol) == 0);

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);

	return NULL;
}
Пример #5
0
char *test_deleteHashElement_single() {
// simple hash function	
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));
   	struct hash *hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	createHashElement(hash, "GREEN", symbol);
	createHashElement(hash, "bb", symbol);
	createHashElement(hash, "bbb", symbol);
	createHashElement(hash, "bbbb", symbol);

	int index  = getHashIndex(hash, "G");
	struct hashElement *element = findHashElementByKey(hash, "GREEN");

	mu_assert("unexpected element at in single bucket list.", 
 		hash->elements[index] == element);

	mu_assert("Delete function did not remove single bucket element.", 
 		deleteHashElement(hash, "GREEN") == 0);

	mu_assert("Single element not deleted.", 
 		hash->elements[index] == NULL);

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);

//normal hash function
	hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	createHashElement(hash, "GREEN", symbol);
	createHashElement(hash, "bb", symbol);
	createHashElement(hash, "bbb", symbol);
	createHashElement(hash, "bbbb", symbol);

	index  = getHashIndex(hash, "G");
	element = findHashElementByKey(hash, "GREEN");

	mu_assert("unexpected element at in single bucket list.", 
 		hash->elements[index] == element);

	mu_assert("Delete function did not remove single bucket element.", 
 		deleteHashElement(hash, "GREEN") == 0);

	mu_assert("Single element not deleted.", 
 		hash->elements[index] == NULL);

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);

	return NULL;
}
Пример #6
0
char *test_getSizeOfBucket() {
//simple hash	
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));
   	struct hash *hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	mu_assert("Expected empty bucket.",
		getSizeOfBucket(hash, "blue") == 0);

	createHashElement(hash, "blue", symbol);

	mu_assert("Expected bucket size of 1.",
		getSizeOfBucket(hash, "blue") == 1);

	createHashElement(hash, "red", symbol);
	createHashElement(hash, "ruby", symbol);
	createHashElement(hash, "rouse", symbol);
	createHashElement(hash, "rose", symbol);

	mu_assert("Expected bucket size of 4.",
		getSizeOfBucket(hash, "r") == 4);

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);

//normal hash	
	hash = createHash(&getHashedKeyNormal);
	mu_assert("Call to createHash does not seg fault.", 1);	

	mu_assert("Expected empty bucket.",
		getSizeOfBucket(hash, "blue") == 0);

	createHashElement(hash, "blue", symbol);

	mu_assert("Expected bucket size of 1.",
		getSizeOfBucket(hash, "blue") == 1);

	createHashElement(hash, "red", symbol);
	createHashElement(hash, "rose", symbol);

	mu_assert("Expected bucket size of 0.",
		getSizeOfBucket(hash, "r") == 0);

	mu_assert("Expected bucket size of 4.",
		getSizeOfBucket(hash, "red") == 1);

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);
	return NULL;
}
Пример #7
0
char *test_createHash() {
//simple hash function
	struct hash *symbolTable = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	int index = (*(symbolTable->hashFunction))("b");
	mu_assert("Hash function does not caluculate expected value for key 'b'.",
		index == 98);
	
	index = (*(symbolTable->hashFunction))("a");
	mu_assert("Hash function does not caluculate expected value for key 'a'.",
		index == 97);	

	for (int i = 0; i < TABLE_SIZE; ++i) {
		mu_assert("Empty table bucket does not equal NULL.", 
			symbolTable->elements[i] == NULL);
	}

	mu_assert("Expected initial lex level of 0",
		symbolTable->lexLevel == 0);

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);		

//normal hash function	
	symbolTable = createHash(&getHashedKeyNormal);
	mu_assert("Call to createHash does not seg fault.", 1);	

	index = (*(symbolTable->hashFunction))("A");
	mu_assert("Hash function does not caluculate expected value for key 'A'.",
		index == 638);
	
	index = (*(symbolTable->hashFunction))("aaa");
	mu_assert("Hash function does not caluculate expected value for key 'a'.",
		index == 928);	

	for (int i = 0; i < TABLE_SIZE; ++i) {
		mu_assert("Empty table bucket does not equal NULL.", 
			symbolTable->elements[i] == NULL);
	}

	mu_assert("Expected initial lex level of 0",
		symbolTable->lexLevel == 0);	

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);	
	return NULL;
}
Пример #8
0
//can't test on normal hash function. can't find collisons
char *test_deleteHashElement_begining() {
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));
	struct hash *hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

   	createHashElement(hash, "GREEN", symbol);
	createHashElement(hash, "bb", symbol);
	createHashElement(hash, "bbb", symbol);
	createHashElement(hash, "bbbb", symbol);
	
	struct hashElement *element = findHashElementByKey(hash, "bb");
	struct hashElement *newHead = element->next;

	int index  = getHashIndex(hash, "b");
	mu_assert("unexpected element at head of bucket list.", 
 		hash->elements[index] == element);

	mu_assert("Delete function did not remove begining element.", 
 		deleteHashElement(hash, "bb") == 0);

	mu_assert("Begining element not deleted.", 
 		hash->elements[index] == newHead);

	mu_assert("Did not delete front of list propertly.", 
 		newHead->prev == NULL);

	mu_assert("Resulting bucket should have more than one element.", 
 		newHead->next != NULL);	

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);

	return NULL;
}
Пример #9
0
//can't test on normal hash function. can't find collisons
char *test_deleteHashElement_middle() {
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));
	struct hash *hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

   	createHashElement(hash, "GREEN", symbol);
	createHashElement(hash, "bb", symbol);
	createHashElement(hash, "bbb", symbol);
	createHashElement(hash, "bbbb", symbol);

	struct hashElement *element = findHashElementByKey(hash, "bbb");
	struct hashElement *head = findHashElementByKey(hash, "bb");
	struct hashElement *tail = findHashElementByKey(hash, "bbbb");

	mu_assert("unexpected element after head.", 
 		head->next == element);

	mu_assert("unexpected element before tail.", 
 		tail->prev == element);

	mu_assert("Delete function did not remove middle element.", 
 		deleteHashElement(hash, "bbb") == 0);

	mu_assert("Did not reset next in list propertly.", 
 		head->next == tail);

	mu_assert("Did not reset prev in list propertly", 
 		tail->prev == head);

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);

	return NULL;
}
Пример #10
0
//can't test on normal hash function. can't find collisons
char *test_isKeyInBucket() {
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));
	struct hash *symbolTable = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	createHashElement(symbolTable, "blue", symbol);
	createHashElement(symbolTable, "boo", symbol);
	createHashElement(symbolTable, "bobby", symbol);

	mu_assert("Could not find expected key 'blue' in bucket.", 
		isKeyInBucket(symbolTable, "blue") == 1 );		

	mu_assert("Could not find expected key 'blue' in bucket.", 
		isKeyInBucket(symbolTable, "bobby") == 1 );			

	mu_assert("Could not find expected key 'blue' in bucket.", 
		isKeyInBucket(symbolTable, "gree") == 0 );		

	mu_assert("Could not find expected key 'blue' in bucket.", 
		isKeyInBucket(symbolTable, "boo") == 1 );		
	
	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);	

	return NULL;
}
Пример #11
0
char * test_isOnlySymbolInList() {
	struct hash *hash = createHash(&getHashedKeySimple);

	struct Symbol *symbol0 = createTestSymbol(0, "charley");
	createHashElement(hash, "charley", symbol0);

	struct Symbol *symbol1 = createTestSymbol(0, "cherry");
	createHashElement(hash, "cherry", symbol1);

	struct Symbol *symbol2 = createTestSymbol(1, "cherry");
	setLexLevel(hash, 1);
	createHashElement(hash, "cherry", symbol2);

	struct Symbol *symbol3 = createTestSymbol(2, "cherry");
	setLexLevel(hash, 2);
	createHashElement(hash, "cherry", symbol3);

	struct hashElement *element = findHashElementByKey(hash, "charley");
	struct Symbol *retSymbol = getGlobalSymbol(hash, "charley");
	mu_assert("Unexpected return of isOnlySymbolInList, test 1",
		isOnlySymbolInList(element, retSymbol) == 1);	

	element = findHashElementByKey(hash, "cherry");
	retSymbol = getGlobalSymbol(hash, "cherry");
	mu_assert("Unexpected return of isOnlySymbolInList, test 2",
		isOnlySymbolInList(element, retSymbol) == 0);		

	return NULL;
}
Пример #12
0
int main (int argc, char *argv[])
{
    char benchmarkPath[BUFFERSIZE], auxFile[BUFFERSIZE], placefile[BUFFERSIZE];

    if(argc != 4) {
        printf("Usage: %s <benchmark_dir> <aux_file> <placement_file>\n",
               argv[0]);
        printf("    <benchmark_dir> is the benchmark file directory.\n");
        printf("    <aux_file> is the bookshelf format auxiliary file");
        printf(" (assume in <benchmark_dir>).\n");
        printf("    <placement_file> is the placement file");
        printf(" (assume in current directory).\n");
        exit(1);
    }    

    strcpy(benchmarkPath, argv[1]);
    strcpy(auxFile, argv[2]);
    strcpy(placefile, argv[3]);

    readAuxFile(benchmarkPath, auxFile);
    createHash(benchmarkPath, nodesFile);
    readNodesFile(benchmarkPath, nodesFile);
    readNetsFile(benchmarkPath, netsFile);
    readPlFile(".", placefile);
    freeHash();

    readLUT();

    printf("Half-perimeter wirelength: %.2f\n", HPwl());
    printf("FLUTE wirelength         : %.2f\n", flutewl());
}
Пример #13
0
char *test_decrementLexLevel() {
	struct hash *hash = createHash(&getHashedKeySimple);	

	mu_assert("Unexpected lexical level from decrementLexLevel, test1",
		getCurrentLexLevel(hash) == 0);

	// 
	mu_assert("Unexpected lexical level from decrementLexLevel, test2",
		decrementLexLevel(hash) == 1);		

	incrementLexLevel(hash);
	mu_assert("Unexpected lexical level from decrementLexLevel, test3",
		decrementLexLevel(hash) == 0);	


	incrementLexLevel(hash);
	incrementLexLevel(hash);
	incrementLexLevel(hash);
	decrementLexLevel(hash);
	mu_assert("Unexpected lexical level from decrementLexLevel, test4",
		getCurrentLexLevel(hash) == 2);	

	hash = NULL;
	mu_assert("Unexpected lexical level from incrementLexLevel, test5",
		incrementLexLevel(hash) == 1);		
	
	return NULL;
}
Пример #14
0
// Driver program to test above functions
int main()
{
    // Let cache can hold 4 pages
    Queue* q = createQueue( 4 );

    // Let 10 different pages can be requested (pages to be
    // referenced are numbered from 0 to 9
    Hash* hash = createHash( 10 );

    // Let us refer pages 1, 2, 3, 1, 4, 5
    ReferencePage( q, hash, 1);
    ReferencePage( q, hash, 2);
    ReferencePage( q, hash, 3);
    ReferencePage( q, hash, 1);
    ReferencePage( q, hash, 4);
    ReferencePage( q, hash, 5);

    // Let us print cache frames after the above referenced pages
    printf ("%d ", q->front->pageNumber);
    printf ("%d ", q->front->next->pageNumber);
    printf ("%d ", q->front->next->next->pageNumber);
    printf ("%d ", q->front->next->next->next->pageNumber);

    return 0;
}
Пример #15
0
void CDuplicateFinder::findDuplicatesFileSize(std::vector<CFileEntry>::iterator itr){

    auto itr_end = m_duplicates.end();
    auto itr_dup = std::adjacent_find(itr,
                                      itr_end,
                                      [](const auto& lhs, const auto& rhs) {
          return lhs.m_filesize == rhs.m_filesize;
        });

    if (itr_dup != itr_end) {

      //Found a potential duplicate range

      auto itr_base = itr_dup;

      //Potential duplicates get prepared for a deep comparision
      while (itr_dup != itr_end && itr_base->m_filesize == itr_dup->m_filesize) {
        itr_dup->createHash();
        ++itr_dup;
      }

      //check for more dups
      if (itr_dup != itr_end) {
        findDuplicatesFileSize(itr_dup);
      }
    }
}
Пример #16
0
//can't test on normal hash function. can't find collisons
char *test_deleteHashElement_end() {
	struct Symbol *symbol =  calloc(1, sizeof(struct Symbol));
	struct hash *hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

   	createHashElement(hash, "GREEN", symbol);
	createHashElement(hash, "bb", symbol);
	createHashElement(hash, "bbb", symbol);
	createHashElement(hash, "bbbb", symbol);

	struct hashElement *element = findHashElementByKey(hash, "bbbb");
	struct hashElement *newTail = element->prev;

	mu_assert("unexpected element at end of list.", 
 		element->next == NULL);

	mu_assert("Delete function did not remove end element.", 
 		deleteHashElement(hash, "bbbb") == 0);

	mu_assert("End element not deleted.", 
 		newTail->next == NULL);

	mu_assert("Did not delete end of list propertly.", 
 		newTail->prev != NULL);

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);

	return NULL;
}
Пример #17
0
static VALUE _getRecord(CABRecord* record) {
	if (record) {
		VALUE hash = createHash();
		record->enumValues(_addRecordValue,&hash);
		return hash;
	}
	return rho_ruby_get_NIL();
}
Пример #18
0
WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createHmac(
    WebCryptoAlgorithmId hash,
    unsigned keyLengthBits) {
  if (!WebCryptoAlgorithm::isHash(hash))
    return WebCryptoKeyAlgorithm();
  return WebCryptoKeyAlgorithm(WebCryptoAlgorithmIdHmac,
                               wrapUnique(new WebCryptoHmacKeyAlgorithmParams(
                                   createHash(hash), keyLengthBits)));
}
Пример #19
0
//-----------------------------------------------------------------------------
void UIViewFactory::rememberAttribute (CView* view, IdStringPtr attrName, const std::string& value) const
{
#if ENABLE_UNIT_TESTS
	if (disableRememberAttributes)
		return;
#endif
	size_t hash = createHash (attrName);
	view->setAttribute (hash, static_cast<uint32_t> (value.size () + 1), value.c_str ());
}
Пример #20
0
char *test_popLexLevel(){
	struct hash *hash = createHash(&getHashedKeySimple);	

	mu_assert("Unexpected return of popLexLevel, test1",
		popLexLevel(hash) == 1);

	setLexLevel(hash, 1);
	mu_assert("Unexpected return of popLexLevel, test2",
		popLexLevel(hash) == 0);

	struct Symbol *symbol0 = createTestSymbol(0, "charley");
	createHashElement(hash, "charley", symbol0);

	struct Symbol *symbol1 = createTestSymbol(0, "cherry");
	createHashElement(hash, "cherry", symbol1);

	struct Symbol *symbol2 = createTestSymbol(1, "cherry");
	setLexLevel(hash, 1);
	createHashElement(hash, "cherry", symbol2);

	struct Symbol *symbol3 = createTestSymbol(2, "cherry");
	setLexLevel(hash, 2);
	createHashElement(hash, "cherry", symbol3);

	// dumpHash(hash);

	mu_assert("Unexpected return of popLexLevel, test3",
		popLexLevel(hash) == 0);

	// dumpHash(hash);

	setLexLevel(hash, 0);
	mu_assert("Unexpected return of popLexLevel, test4",
		popLexLevel(hash) == 1);

	// dumpHash(hash);

	setLexLevel(hash, 1);
	struct Symbol *symbol4 = createTestSymbol(1, "yellow");
	createHashElement(hash, "yellow", symbol4);
	symbol4 = createTestSymbol(1, "indigo");
	createHashElement(hash, "indigo", symbol4);	
	symbol4 = createTestSymbol(1, "bobby");
	createHashElement(hash, "bobby", symbol4);

	// dumpHash(hash);	

	mu_assert("Unexpected return of popLexLevel, test5",
		popLexLevel(hash) == 0);	

	mu_assert("popLexLevel did not decrement lex level",
		getCurrentLexLevel(hash) == 0);

	// dumpHash(hash);	

	return NULL;
}
Пример #21
0
char * test_getCurrentLexLevel() {
	struct hash *hash = createHash(&getHashedKeyNormal);
	hash->lexLevel = 23;

	mu_assert("Unexpected value in hash lex level.",
		getCurrentLexLevel(hash) == 23);	

	return NULL;
}
Пример #22
0
char *test_dumpHash() {
	struct hash *hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	dumpHash(hash);
	mu_assert("Hash dump seg faults.", 1);

/*test 2: Copy stdout to to buffer and compare out of empty symbol table.*/
	char buffer[100] = {0};
	int out_pipe[2];
	int saved_stdout = dup(STDOUT_FILENO); /* save stdout for display later */

	pipe(out_pipe);						/* make a pipe */
	dup2(out_pipe[1], STDOUT_FILENO);   /* redirect stdout to the pipe */
	close(out_pipe[1]);

 	dumpHash(hash);		/* anything sent to printf should now go down the pipe */
 	fflush(stdout);

 	read(out_pipe[0], buffer, 100);  //read from pipe into buffer 
 	dup2(saved_stdout, STDOUT_FILENO);  /* reconnect stdout for testing */

 	char expectedOutput[33] = "\n\nDUMPING HASH:\nDUMP COMPLETE.\n\n";

	mu_assert("Hash dumper gives unexpected output on empty hash.", 
 		strcmp(expectedOutput, buffer) == 0);	
	
	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);	

	hash = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	// createHashElement(hash, "blue", 123);
	// createHashElement(hash, "boo", 23456);
	// createHashElement(hash, "bobby", 123);

	// dumpHash(hash);

	destroyHash(&hash);
	mu_assert("Call to destroyHash does not seg fault.", 1);

	return NULL;
}
Пример #23
0
char * test_setLexLevel() {
	struct hash *hash = createHash(&getHashedKeyNormal);

	setLexLevel(hash, 5);
	mu_assert("Call to setLexLevel seg faulted", 1);

	mu_assert("Expected value of getCurrentLexLevel is 5.",
		getCurrentLexLevel(hash) == 5);

	return NULL;
}
Пример #24
0
char * test_getLexLevel() {
	struct hash *hash = createHash(&getHashedKeyNormal);
	hash->lexLevel = 5;

	mu_assert("Expected lexical level of 5",
		getCurrentLexLevel(hash) == 5);
	
	mu_assert("Expected lexical level of 5",
		getCurrentLexLevel(hash) != 1);

	return NULL;
}
Пример #25
0
WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createRsaHashed(
    WebCryptoAlgorithmId id,
    unsigned modulusLengthBits,
    const unsigned char* publicExponent,
    unsigned publicExponentSize,
    WebCryptoAlgorithmId hash) {
  // FIXME: Verify that id is an RSA algorithm which expects a hash
  if (!WebCryptoAlgorithm::isHash(hash))
    return WebCryptoKeyAlgorithm();
  return WebCryptoKeyAlgorithm(
      id, wrapUnique(new WebCryptoRsaHashedKeyAlgorithmParams(
              modulusLengthBits, publicExponent, publicExponentSize,
              createHash(hash))));
}
// FUCNTION COMPRESS
// COMPRESS A FILE
int compress(Tree* tree, unsigned char* charactersArray, unsigned char * fileString) {
    Hash* hash = createHash();
    int i;
    printf("\nComprimindo arquivo.\n");
    for(i = 0; i < strlen(charactersArray); i++) {
        fillTree(tree, charactersArray[i], NULL, hash);
    }
    writeFile(hash, charactersArray, fileString);

   free(hash);

   free(fileString);
   free(tree);
}
Пример #27
0
char *test_destroyHash() {
	struct hash *symbolTable = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	for (int i = 0; i < TABLE_SIZE; ++i) {
		mu_assert("destroyed bucket does not equal NULL.", 
			symbolTable->elements[i] == NULL);
	}	

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);		

	return NULL;
}
Пример #28
0
char *test_getHashIndex() {
//simple hash function	
	struct hash *symbolTable = createHash(&getHashedKeySimple);
	mu_assert("Call to createHash does not seg fault.", 1);	

	int index = getHashIndex(symbolTable, "b");
	mu_assert("getHashIndex does not return expected value on key 'b'", 
		index == 98);

	index = getHashIndex(symbolTable, "W");
	mu_assert("getHashIndex does not return expected value on key 'b'", 
		index == 87);

	index = getHashIndex(symbolTable, "=");
	mu_assert("getHashIndex does not return expected value on key 'b'", 
		index == 61);			

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);	

//normal hash function	
	symbolTable = createHash(&getHashedKeyNormal);
	mu_assert("Call to createHash does not seg fault.", 1);	

	index = getHashIndex(symbolTable, "b");
	mu_assert("getHashIndex does not return expected value on key 'b'", 
		index == 671);

	index = getHashIndex(symbolTable, "W");
	mu_assert("getHashIndex does not return expected value on key 'b'", 
		index == 660);			

	destroyHash(&symbolTable);
	mu_assert("Call to destroyHash does not seg fault.", 1);	

	return NULL;
}
Пример #29
0
bool
ImagePack::parsePack(const char* packFile)
{
    ILOG_TRACE(ILX_IMAGEPACK);
    ILOG_DEBUG(ILX_IMAGEPACK, " -> file: %s\n", packFile);

    std::string cacheFile = PrintF("%s%u.sxml", FileSystem::ilxDirectory().c_str(), createHash(packFile));
    ILOG_DEBUG(ILX_IMAGEPACK, " -> cache file: %s\n", cacheFile.c_str());
    if (difftime(FileSystem::getModificationTime(cacheFile), FileSystem::getModificationTime(packFile)) > 0)
    {
        ILOG_DEBUG(ILX_IMAGEPACK, " -> Parsing cached image pack file.\n");
        std::ifstream ifs(cacheFile.c_str(), std::ios::in);
        ifs >> *this;
        ifs.close();
        ILOG_INFO(ILX_IMAGEPACK, "Parsed cached image pack file: %s\n", cacheFile.c_str());
    } else
Пример #30
0
//-----------------------------------------------------------------------------
bool UIViewFactory::getRememberedAttribute (CView* view, IdStringPtr attrName, std::string& value) const
{
	bool result = false;
	size_t hash = createHash (attrName);
	uint32_t attrSize = 0;
	if (view->getAttributeSize (hash, attrSize))
	{
		char* temp = new char[attrSize];
		if (view->getAttribute (hash, attrSize, temp, attrSize))
		{
			value = temp;
			result = true;
		}
		delete [] temp;
	}
	return result;
}