void TestBencodeDictWontGetNextIfEmpty( CuTest * tc ) { bencode_t ben, ben2; char *str = strdup("de"); const char *ren; int len, ret; bencode_init(&ben, str, strlen(str)); ret = bencode_dict_get_next(&ben, &ben2, &ren, &len); CuAssertTrue(tc, 0 == ret); free(str); }
void testCuFree(CuTest_t* tc){ int *iVar = (int*)CuAlloc(sizeof(int)); CuSize_t freecount = CuAlloc_getFreeCount(); CuSize_t alloccount = CuAlloc_getAllocCount(); bool freeResult = CuFree(iVar); // CuAssertTrue(tc, !CuAlloc_getBufferValidity(iVar)); CuAssertIntEquals(tc, true, freeResult); CuAssertIntEquals(tc, alloccount, CuAlloc_getAllocCount()); CuAssertIntEquals(tc, freecount+1, CuAlloc_getFreeCount()); freeResult = CuFree(iVar); //CuAssertTrue(tc, !CuAlloc_getBufferValidity(iVar)); CuAssertTrue(tc, !freeResult); }
void TestBencodeStringValue2( CuTest * tc ) { bencode_t ben; char *str = strdup("12:flyinganimal"); const char *ren; int len; bencode_init(&ben, str, strlen(str)); bencode_string_value(&ben, &ren, &len); CuAssertTrue(tc, !strncmp("flyinganimal", ren, len)); free(str); }
/** * The string value function errors when the string is of insufficient length * */ void TestBencodeStringInvalid( CuTest * tc ) { bencode_t ben; char *str = strdup("5:test"); const char *ren; int len; bencode_init(&ben, str, strlen(str)); bencode_string_value(&ben, &ren, &len); CuAssertTrue(tc, !ren); free(str); }
static void alloc_bytes(CuTest *tc) { int i; char *alloc; alloc = apr_palloc(pmain, ALLOC_BYTES); CuAssertPtrNotNull(tc, alloc); for (i=0;i<ALLOC_BYTES;i++) { char *ptr = alloc + i; *ptr = 0xa; } /* This is just added to get the positive. If this test fails, the * suite will seg fault. */ CuAssertTrue(tc, 1); }
void TestRaft_follower_becomes_candidate_when_election_timeout_occurs( CuTest * tc) { void *r = raft_new(); /* 1 second election timeout */ raft_set_election_timeout(r, 1000); raft_add_node(r, (void*)1, 1); raft_add_node(r, (void*)2, 0); /* 1.001 seconds have passed */ raft_periodic(r, 1001); /* is a candidate now */ CuAssertTrue(tc, 1 == raft_is_candidate(r)); }
static void test_entries_as_list ( CuTest* tc ) { const char *index = "_1.cfs"; lcn_compound_file_reader_t *cfr; lcn_directory_t *cf_dir; lcn_list_t *entries; apr_pool_t *pool; apr_pool_create( &pool, NULL ); LCN_TEST( lcn_fs_directory_create(&cf_dir, cf_static, LCN_FALSE, pool ) ); LCN_TEST( lcn_compound_file_reader_create(&cfr, cf_dir, index, pool) ); LCN_TEST( lcn_compound_file_reader_entries_as_list(cfr, &entries, pool) ); CuAssertTrue( tc, lcn_list_size(entries) == 7); }
static void testCall0StackAlignment1(CuTest* tc) { // The first 6 ptr/int values are passed in registers. We need to push // at least 7 ptrs to start using the stack. CallInfo* ci = CALL0_ALLOCATE_CALL_INFO(NULL, stackPointer, 7, 0, 0, 0, 0); CuAssertPtrNotNull(tc, ci); call0AddPtr(ci, (void*) 1); call0AddPtr(ci, (void*) 2); call0AddPtr(ci, (void*) 3); call0AddPtr(ci, (void*) 4); call0AddPtr(ci, (void*) 5); call0AddPtr(ci, (void*) 6); call0AddPtr(ci, (void*) 7); void* (*f)(CallInfo*) = (void* (*)(CallInfo*)) _call0; void* result = f(ci); CuAssertTrue(tc, (((ptrdiff_t) result) & 0xf) == 8); }
void testBlock_getInstance(CuTest* testCase) { cactusBlockTestSetup(); CuAssertTrue(testCase, block_getInstance(block, segment_getName(rootSegment)) == segment_getReverse(rootSegment)); CuAssertTrue(testCase, block_getInstance(block, segment_getName(leaf1Segment)) == leaf1Segment); CuAssertTrue(testCase, block_getInstance(block, segment_getName(leaf2Segment)) == segment_getReverse(leaf2Segment)); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(rootSegment)) == rootSegment); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(leaf1Segment)) == segment_getReverse(leaf1Segment)); CuAssertTrue(testCase, block_getInstance(block_getReverse(block), segment_getName(leaf2Segment)) == leaf2Segment); cactusBlockTestTeardown(); }
void testCap_getSegment(CuTest* testCase) { cactusCapTestSetup(); Block *block = block_construct(2, flower); Segment *segment = segment_construct(block, rootEvent); CuAssertTrue(testCase, cap_getSegment(segment_get5Cap(segment)) == segment); CuAssertTrue(testCase, cap_getSegment(segment_get3Cap(segment)) == segment); CuAssertTrue(testCase, cap_getOrientation(segment_get5Cap(segment)) == segment_getOrientation(segment)); CuAssertTrue(testCase, cap_getOrientation(segment_get3Cap(segment)) == segment_getOrientation(segment)); CuAssertTrue(testCase, cap_getSegment(cap_getReverse(segment_get5Cap(segment))) == segment_getReverse(segment)); CuAssertTrue(testCase, cap_getSegment(cap_getReverse(segment_get3Cap(segment))) == segment_getReverse(segment)); cactusCapTestTeardown(); }
int TestSetLockDetect(CuTest *ct) { DB_ENV *dbenv; u_int32_t v; dbenv = NULL; /* lk_detect: NOT reset at run-time. */ ENV CuAssertTrue(ct, dbenv->set_lk_detect(dbenv, DB_LOCK_MAXLOCKS) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_CREATE | DB_INIT_LOCK, 0666) == 0); CuAssertTrue(ct, dbenv->get_lk_detect(dbenv, &v) == 0); CuAssertTrue(ct, v == DB_LOCK_MAXLOCKS); ENV CuAssertTrue(ct, dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0); CuAssertTrue(ct, dbenv->get_lk_detect(dbenv, &v) == 0); CuAssertTrue(ct, v == DB_LOCK_MAXLOCKS); return (0); }
int TestSetLogRegionSize(CuTest *ct) { DB_ENV *dbenv; u_int32_t v; dbenv = NULL; /* lg_regionmax: NOT reset at run-time. */ ENV CuAssertTrue(ct, dbenv->set_lg_regionmax(dbenv, 137 * 1024) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_CREATE | DB_INIT_LOG, 0666) == 0); CuAssertTrue(ct, dbenv->get_lg_regionmax(dbenv, &v) == 0); CuAssertTrue(ct, v == 137 * 1024); ENV CuAssertTrue(ct, dbenv->set_lg_regionmax(dbenv, 163 * 1024) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0); CuAssertTrue(ct, dbenv->get_lg_regionmax(dbenv, &v) == 0); CuAssertTrue(ct, v == 137 * 1024); return (0); }
int TestSetLockMaxObjects(CuTest *ct) { DB_ENV *dbenv; u_int32_t v; dbenv = NULL; /* lk_max_objects: NOT reset at run-time. */ ENV CuAssertTrue(ct, dbenv->set_lk_max_objects(dbenv, 1037) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_CREATE | DB_INIT_LOCK, 0666) == 0); CuAssertTrue(ct, dbenv->get_lk_max_objects(dbenv, &v) == 0); CuAssertTrue(ct, v == 1037); ENV CuAssertTrue(ct, dbenv->set_lk_max_objects(dbenv, 1063) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0); CuAssertTrue(ct, dbenv->get_lk_max_objects(dbenv, &v) == 0); CuAssertTrue(ct, v == 1037); return (0); }
static void test_stSortedSetUnion(CuTest* testCase) { sonLibSortedSetTestSetup(); //Check intersection of empty sets is okay.. stSortedSet *sortedSet3 = stSortedSet_getUnion(sortedSet, sortedSet2); CuAssertTrue(testCase, stSortedSet_size(sortedSet3) == 0); stSortedSet_destruct(sortedSet3); int32_t i; for(i=0; i<size; i++) { stSortedSet_insert(sortedSet, stIntTuple_construct(1, input[i])); } //Check intersection of empty and non-empty set is equal to the non-empty set. sortedSet3 = stSortedSet_getUnion(sortedSet, sortedSet2); CuAssertTrue(testCase, stSortedSet_equals(sortedSet, sortedSet3)); stSortedSet_destruct(sortedSet3); //Check intersection of two non-empty, overlapping sets in correct. stSortedSet_insert(sortedSet2, stIntTuple_construct(1, 0)); stSortedSet_insert(sortedSet2, stIntTuple_construct(1, 1)); stSortedSet_insert(sortedSet2, stIntTuple_construct(1, 5)); sortedSet3 = stSortedSet_getUnion(sortedSet, sortedSet2); CuAssertTrue(testCase, stSortedSet_size(sortedSet3) == stSortedSet_size(sortedSet) + 1); CuAssertTrue(testCase, !stSortedSet_equals(sortedSet, sortedSet3)); stSortedSet_insert(sortedSet, stIntTuple_construct(1, 0)); CuAssertTrue(testCase, stSortedSet_size(sortedSet3) == stSortedSet_size(sortedSet)); CuAssertTrue(testCase, stSortedSet_equals(sortedSet, sortedSet3)); stSortedSet_destruct(sortedSet3); //Check we get an exception with sorted sets with different comparators. stSortedSet *sortedSet4 = stSortedSet_construct(); stTry { stSortedSet_getUnion(sortedSet, sortedSet4); CuAssertTrue(testCase, 0); } stCatch(except) { CuAssertTrue(testCase, stExcept_getId(except) == SORTED_SET_EXCEPTION_ID); } stTryEnd stSortedSet_destruct(sortedSet4); sonLibSortedSetTestTeardown(); }
void testEnd_getBlock(CuTest* testCase) { cactusEndTestSetup(); Block *block = block_construct(10, flower); End *leftEnd = block_get5End(block); End *rightEnd = block_get3End(block); CuAssertTrue(testCase, end_getBlock(end) == NULL); CuAssertTrue(testCase, end_getBlock(end_getReverse(end)) == NULL); CuAssertTrue(testCase, end_getBlock(leftEnd) == block); CuAssertTrue(testCase, end_getBlock(end_getReverse(leftEnd)) == block_getReverse(block)); CuAssertTrue(testCase, block_getOrientation(block) == end_getOrientation(leftEnd)); CuAssertTrue(testCase, end_getBlock(rightEnd) == block); CuAssertTrue(testCase, end_getBlock(end_getReverse(rightEnd)) == block_getReverse(block)); CuAssertTrue(testCase, block_getOrientation(block) == end_getOrientation(rightEnd)); cactusEndTestTeardown(); }
int TestSetTxMax(CuTest *ct) { DB_ENV *dbenv; u_int32_t v; dbenv = NULL; /* tx_max: NOT reset at run-time. */ ENV CuAssertTrue(ct, dbenv->set_tx_max(dbenv, 37) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_CREATE | DB_INIT_TXN, 0666) == 0); CuAssertTrue(ct, dbenv->get_tx_max(dbenv, &v) == 0); CuAssertTrue(ct, v == 37); ENV CuAssertTrue(ct, dbenv->set_tx_max(dbenv, 63) == 0); CuAssertTrue(ct, dbenv->open(dbenv, TEST_ENV, DB_JOINENV, 0666) == 0); CuAssertTrue(ct, dbenv->get_tx_max(dbenv, &v) == 0); CuAssertTrue(ct, v == 37); return (0); }
void test_stList_filter(CuTest *testCase) { setup(); stSortedSet *set = stSortedSet_construct(); stSortedSet_insert(set, strings[0]); stSortedSet_insert(set, strings[4]); stList *list2 = stList_filterToExclude(list, set); stList *list3 = stList_filterToInclude(list, set); CuAssertTrue(testCase,stList_length(list2) == 3); CuAssertTrue(testCase,stList_length(list3) == 2); CuAssertTrue(testCase,stList_get(list2, 0) == strings[1]); CuAssertTrue(testCase,stList_get(list2, 1) == strings[2]); CuAssertTrue(testCase,stList_get(list2, 2) == strings[3]); CuAssertTrue(testCase,stList_get(list3, 0) == strings[0]); CuAssertTrue(testCase,stList_get(list3, 1) == strings[4]); teardown(); }
void TestRaft_server_apply_entry_increments_last_applied_idx(CuTest* tc) { raft_entry_t ety; char *str = "aaa"; ety.term = 1; void *r = raft_new(); raft_set_commit_idx(r, 1); raft_set_last_applied_idx(r, 0); ety.id = 1; ety.data.buf = str; ety.data.len = 3; raft_append_entry(r, &ety); raft_apply_entry(r); CuAssertTrue(tc, 1 == raft_get_last_applied_idx(r)); }
static void testNonExistentLens(CuTest *tc) { int r; r = aug_rm(aug, "/augeas/load/*"); CuAssertTrue(tc, r >= 0); r = aug_set(aug, "/augeas/load/Fake/lens", "Fake.lns"); CuAssertIntEquals(tc, 0, r); r = aug_set(aug, "/augeas/load/Fake/incl", "/fake"); CuAssertIntEquals(tc, 0, r); r = aug_set(aug, "/files/fake/entry", "value"); CuAssertIntEquals(tc, 0, r); r = aug_save(aug); CuAssertIntEquals(tc, -1, r); r = aug_error(aug); CuAssertIntEquals(tc, AUG_ENOLENS, r); }
void testRBtree_massive_delete(CuTest *tc){ RB_tree tree; tree.nil = (RB_node*)malloc(sizeof(RB_node)); tree.nil->color = BLACK; tree.nil->key = -10; tree.root = tree.nil; int i; for(i = 32000; i >= 0; --i){ insert_node(&tree, i); } for(i = 0; i <= 32000; ++i){ delete_node(&tree, i); } CuAssertTrue(tc, tree.root == tree.nil); free(tree.nil); }
void test_write_file_failed_with_wrong_flag(CuTest *tc) { int64_t write_size = 0; oss_media_file_t *file = NULL; char *content = NULL; content = "hello oss media file\n"; // open file file = oss_media_file_open(TEST_BUCKET_NAME, "oss_media_file", "r", auth_func); CuAssertTrue(tc, NULL != file); // write file write_size = oss_media_file_write(file, content, strlen(content)); CuAssertIntEquals(tc, -1, write_size); // close file oss_media_file_close(file); }
_LUCENE_THREAD_FUNC(indexDocs, _data) { ThreadData * data = (ThreadData *)_data; int cnt = 0; TCHAR * text; for (int j=1; j<docsPerThread; j++) { Document doc; text = English::IntToEnglish(data->num*docsPerThread+j); doc.add(*new Field(_T("sizeContent"), text, Field::STORE_YES | Field::INDEX_UNTOKENIZED)); data->writer->addDocument(&doc); _CLDELETE_ARRAY(text); { SCOPED_LOCK_MUTEX(data->dir->THIS_LOCK); CuAssertTrue(data->tc, data->dir->sizeInBytes == data->dir->getRecomputedSizeInBytes()); } } _LUCENE_THREAD_FUNC_RETURN( 0 ); }
void testEnd_isBlockOrStubEnd(CuTest* testCase) { cactusEndTestSetup(); CuAssertTrue(testCase, end_isStubEnd(end)); CuAssertTrue(testCase, !end_isBlockEnd(end)); Block *block = block_construct(2, flower); End *leftEnd = block_get5End(block); End *rightEnd = block_get3End(block); CuAssertTrue(testCase, end_isBlockEnd(leftEnd)); CuAssertTrue(testCase, end_isBlockEnd(rightEnd)); CuAssertTrue(testCase, !end_isStubEnd(leftEnd)); CuAssertTrue(testCase, !end_isStubEnd(rightEnd)); cactusEndTestTeardown(); }
void testEventTree_copyConstruct(CuTest* testCase) { cactusEventTreeTestSetup(); Flower *flower2 = flower_construct(cactusDisk); EventTree *eventTree2 = eventTree_copyConstruct(eventTree, flower2, unaryEventFunction); CuAssertIntEquals(testCase, eventTree_getEventNumber(eventTree), eventTree_getEventNumber(eventTree2)); CuAssertTrue(testCase, event_getName(eventTree_getEvent(eventTree2, event_getName(rootEvent))) == event_getName(rootEvent)); CuAssertTrue(testCase, event_getName(eventTree_getEvent(eventTree2, event_getName(internalEvent))) == event_getName(internalEvent)); CuAssertTrue(testCase, event_getName(eventTree_getEvent(eventTree2, event_getName(leafEvent1))) == event_getName(leafEvent1)); CuAssertTrue(testCase, event_getName(eventTree_getEvent(eventTree2, event_getName(leafEvent2))) == event_getName(leafEvent2)); CuAssertTrue(testCase, event_isOutgroup(eventTree_getEvent(eventTree2, event_getName(leafEvent1)))); CuAssertTrue(testCase, !event_isOutgroup(eventTree_getEvent(eventTree2, event_getName(leafEvent2)))); cactusEventTreeTestTeardown(); }
void test_stList_iterator(CuTest *testCase) { setup(); stListIterator *it = stList_getIterator(list); int64_t i; for(i=0; i<stringNumber; i++) { CuAssertTrue(testCase, stList_getNext(it) == strings[i]); } CuAssertTrue(testCase, stList_getNext(it) == NULL); CuAssertTrue(testCase, stList_getNext(it) == NULL); stListIterator *it2 = stList_copyIterator(it); for(i=0; i<stringNumber; i++) { CuAssertTrue(testCase, stList_getPrevious(it) == strings[stringNumber-1-i]); CuAssertTrue(testCase, stList_getPrevious(it2) == strings[stringNumber-1-i]); } CuAssertTrue(testCase, stList_getPrevious(it) == NULL); CuAssertTrue(testCase, stList_getPrevious(it) == NULL); CuAssertTrue(testCase, stList_getPrevious(it2) == NULL); stList_destructIterator(it); teardown(); }
void testGroup_endIterator(CuTest* testCase) { cactusGroupTestSetup(); Group_EndIterator *iterator = group_getEndIterator(group); CuAssertTrue(testCase, group_getNextEnd(iterator) == end1); CuAssertTrue(testCase, group_getNextEnd(iterator) == end2); CuAssertTrue(testCase, group_getNextEnd(iterator) == NULL); Group_EndIterator *iterator2 = group_copyEndIterator(iterator); CuAssertTrue(testCase, group_getPreviousEnd(iterator) == end2); CuAssertTrue(testCase, group_getPreviousEnd(iterator) == end1); CuAssertTrue(testCase, group_getPreviousEnd(iterator) == NULL); group_destructEndIterator(iterator); CuAssertTrue(testCase, group_getPreviousEnd(iterator2) == end2); CuAssertTrue(testCase, group_getPreviousEnd(iterator2) == end1); CuAssertTrue(testCase, group_getPreviousEnd(iterator2) == NULL); group_destructEndIterator(iterator2); cactusGroupTestTeardown(); }
void TestParseExpr_7(CuTest *tc) { /* Lexer data. */ char sqlexpr[] = "- - -(-(-(-6)));"; db_eetnode_t *expr; db_lexer_t lexer; lexer_init(&lexer, sqlexpr); /* Memory management data. */ db_int segment_size = 1000; unsigned char segment[segment_size]; db_query_mm_t mm; init_query_mm(&mm, segment, sizeof(segment)); /* Do the whole process. */ parseexpression(&expr, &lexer, 0, strlen(sqlexpr), &mm, 0); db_eetnode_t *np = expr; CuAssertTrue(tc, (db_uint8)DB_EETNODE_CONST_DBINT == ((db_eetnode_dbint_t*)np)->base.type); CuAssertTrue(tc, 6 == ((db_eetnode_dbint_t*)np)->integer); MOVEPOINTERNBYTES(np, np, sizeof(db_eetnode_dbint_t), db_eetnode_t*); CuAssertTrue(tc, (db_uint8)DB_EETNODE_OP_UNARYNEG == np->type); MOVEPOINTERNBYTES(np, np, sizeof(db_eetnode_t), db_eetnode_t*); CuAssertTrue(tc, (db_uint8)DB_EETNODE_OP_UNARYNEG == np->type); MOVEPOINTERNBYTES(np, np, sizeof(db_eetnode_t), db_eetnode_t*); CuAssertTrue(tc, (db_uint8)DB_EETNODE_OP_UNARYNEG == np->type); MOVEPOINTERNBYTES(np, np, sizeof(db_eetnode_t), db_eetnode_t*); CuAssertTrue(tc, (db_uint8)DB_EETNODE_OP_UNARYNEG == np->type); MOVEPOINTERNBYTES(np, np, sizeof(db_eetnode_t), db_eetnode_t*); CuAssertTrue(tc, (db_uint8)DB_EETNODE_OP_UNARYNEG == np->type); MOVEPOINTERNBYTES(np, np, sizeof(db_eetnode_t), db_eetnode_t*); CuAssertTrue(tc, (db_uint8)DB_EETNODE_OP_UNARYNEG == np->type); MOVEPOINTERNBYTES(np, np, sizeof(db_eetnode_t), db_eetnode_t*); }
void TestHashmaplinked_Get2( CuTest * tc ) { hashmap_t *hm; unsigned long val; hm = hashmap_new(__uint_hash, __uint_compare, 11); hashmap_put(hm, (void *) 50, (void *) 92); hashmap_put(hm, (void *) 49, (void *) 91); hashmap_put(hm, (void *) 48, (void *) 90); hashmap_put(hm, (void *) 47, (void *) 89); hashmap_put(hm, (void *) 46, (void *) 88); hashmap_put(hm, (void *) 45, (void *) 87); val = (unsigned long) hashmap_get(hm, (void *) 48); CuAssertTrue(tc, val == 90); hashmap_freeall(hm); }
void Test_matrix_from_items_example4(CuTest *tc) { // All fit double items[] = { 0.111, 0.100, 0.05 }; uint_matrix *A = matrix_from_items(items, 3, 3); CuAssertIntEquals(tc, 1, A->height); { unsigned int combination[] = {3, 3, 3}; CuAssertTrue(tc, matrix_contains_exact_row(A, combination)); } free_uint_matrix(A); }
static void string_error(CuTest *tc) { char buf[128], *rv; apr_status_t n; buf[0] = '\0'; rv = apr_strerror(APR_ENOENT, buf, sizeof buf); CuAssertPtrEquals(tc, buf, rv); CuAssertTrue(tc, strlen(buf) > 0); rv = apr_strerror(APR_TIMEUP, buf, sizeof buf); CuAssertPtrEquals(tc, buf, rv); CuAssertStrEquals(tc, "The timeout specified has expired", buf); /* throw some randomish numbers at it to check for robustness */ for (n = 1; n < 1000000; n *= 2) { apr_strerror(n, buf, sizeof buf); } }