// ************************************************************ void testOperators (void) { Value *result; testName = "test value comparison and boolean operators"; MAKE_VALUE(result, DT_INT, 0); // equality OP_TRUE(stringToValue("i10"),stringToValue("i10"), valueEquals, "10 = 10"); OP_FALSE(stringToValue("i9"),stringToValue("i10"), valueEquals, "9 != 10"); OP_TRUE(stringToValue("sHello World"),stringToValue("sHello World"), valueEquals, "Hello World = Hello World"); OP_FALSE(stringToValue("sHello Worl"),stringToValue("sHello World"), valueEquals, "Hello Worl != Hello World"); OP_FALSE(stringToValue("sHello Worl"),stringToValue("sHello Wor"), valueEquals, "Hello Worl != Hello Wor"); // smaller OP_TRUE(stringToValue("i3"),stringToValue("i10"), valueSmaller, "3 < 10"); OP_TRUE(stringToValue("f5.0"),stringToValue("f6.5"), valueSmaller, "5.0 < 6.5"); // boolean OP_TRUE(stringToValue("bt"),stringToValue("bt"), boolAnd, "t AND t = t"); OP_FALSE(stringToValue("bt"),stringToValue("bf"), boolAnd, "t AND f = f"); OP_TRUE(stringToValue("bt"),stringToValue("bf"), boolOr, "t OR f = t"); OP_FALSE(stringToValue("bf"),stringToValue("bf"), boolOr, "f OR f = f"); TEST_CHECK(boolNot(stringToValue("bf"), result)); ASSERT_TRUE(result->v.boolV, "!f = t"); TEST_DONE(); }
// ************************************************************ void testExpressions (void) { Expr *op, *l, *r; Value *res; testName = "test complex expressions"; MAKE_CONS(l, stringToValue("i10")); evalExpr(NULL, NULL, l, &res); OP_TRUE(stringToValue("i10"), res, valueEquals, "Const 10"); MAKE_CONS(r, stringToValue("i20")); evalExpr(NULL, NULL, r, &res); OP_TRUE(stringToValue("i20"), res, valueEquals, "Const 20"); MAKE_BINOP_EXPR(op, l, r, OP_COMP_SMALLER); evalExpr(NULL, NULL, op, &res); OP_TRUE(stringToValue("bt"), res, valueEquals, "Const 10 < Const 20"); MAKE_CONS(l, stringToValue("bt")); evalExpr(NULL, NULL, l, &res); OP_TRUE(stringToValue("bt"), res, valueEquals, "Const true"); r = op; MAKE_BINOP_EXPR(op, r, l, OP_BOOL_AND); evalExpr(NULL, NULL, op, &res); OP_TRUE(stringToValue("bt"), res, valueEquals, "(Const 10 < Const 20) AND true"); TEST_DONE(); }
void tests(void) { char *loc; TEST_START("utf8_setlocale"); loc = setlocale(LC_CTYPE, "en_US.UTF-8"); ASSERT_PTR_NE(loc, NULL); TEST_DONE(); badarg(); one("null", NULL, 8, 6, 6, "(null)"); one("empty", "", 2, 0, 0, ""); one("ascii", "x", -2, -2, -2, "x"); one("newline", "a\nb", -2, -2, -2, "a\nb"); one("cr", "a\rb", -2, -2, -2, "a\rb"); one("tab", "a\tb", -2, -2, -2, "a\tb"); one("esc", "\033x", -2, -2, -2, "\\033x"); one("inv_badbyte", "\377x", -2, -2, -2, "\\377x"); one("inv_nocont", "\341x", -2, -2, -2, "\\341x"); one("inv_nolead", "a\200b", -2, -2, -2, "a\\200b"); one("sz_ascii", "1234567890123456", -2, -2, 16, "123456789012345"); one("sz_esc", "123456789012\033", -2, -2, 16, "123456789012"); one("width_ascii", "123", 2, 2, -1, "12"); one("width_double", "a\343\201\201", 2, 1, -1, "a"); one("double_fit", "a\343\201\201", 3, 3, 4, "a\343\201\201"); one("double_spc", "a\343\201\201", 4, 3, 4, "a\343\201\201"); }
// ************************************************************ void testCreateTableAndInsert (void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2} }; int numInserts = 9, i; Record *r; RID *rids; Schema *schema; testName = "test creating a new table and inserting tuples"; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); //printf("\n Testing create table"); TEST_CHECK(createTable("test_table_r.txt",schema)); //printf("\n Testing open Table"); TEST_CHECK(openTable(table, "test_table_r.txt")); printf("\n Opened "); // insert rows into table for(i = 0; i < numInserts; i++) { printf("\n Inserting"); r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_r.txt")); printf("\n Opened successsfully"); // randomly retrieve records from the table and compare to inserted ones for(i = 0; i < 1000; i++) { int pos = rand() % numInserts; RID rid = rids[pos]; printf("\n getting records"); TEST_CHECK(getRecord(table, rid, r)); ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[pos]), r, schema, "compare records"); } TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r.txt")); TEST_CHECK(shutdownRecordManager()); free(rids); free(table); TEST_DONE(); }
void test_s2k(void) { TEST_START("s2k"); static unsigned char salt[S2K_SALT_BYTES] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }; const char * pphrase = "ImGumbyAndYouAreNot"; static unsigned char expected_key1[AES128_KEY_BYTES] = { 0x0e, 0xa5, 0x00, 0x1c, 0xce, 0xad, 0x7e, 0xa8, 0xa0, 0x81, 0x38, 0xae, 0xaf, 0x4e, 0x28, 0xd5 }; unsigned char s2k_key1[AES128_KEY_BYTES]; compute_gpg_s2k_key(pphrase, sizeof(s2k_key1), salt, S2K_ITER_BYTE_COUNT, s2k_key1); ASSERT_INT_EQ(memcmp(s2k_key1, expected_key1, sizeof(s2k_key1)), 0); // Second test to handle the case where we need to run multiple hashes to generate enough bits // Note that the first 16 bytes are the same as the previous test - this is to be expected, since the // salt and passphrase are the same, so the first hash is executed identically. static unsigned char expected_key2[48] = { 0x0e, 0xa5, 0x00, 0x1c, 0xce, 0xad, 0x7e, 0xa8, 0xa0, 0x81, 0x38, 0xae, 0xaf, 0x4e, 0x28, 0xd5, 0x21, 0xf1, 0xee, 0x4b, 0x02, 0xc0, 0x0f, 0x63, 0x6a, 0x17, 0xbf, 0x62, 0x34, 0x10, 0x26, 0x48, 0x7b, 0xc6, 0x3f, 0x08, 0x9d, 0xb5, 0x6b, 0x34, 0x70, 0x3b, 0x71, 0xdb, 0x67, 0x92, 0x6f, 0x5f }; unsigned char s2k_key2[48]; compute_gpg_s2k_key(pphrase, sizeof(s2k_key2), salt, S2K_ITER_BYTE_COUNT, s2k_key2); ASSERT_INT_EQ(memcmp(s2k_key2, expected_key2, sizeof(s2k_key2)), 0); TEST_DONE(); }
void testReadPage () { BM_BufferPool *bm = MAKE_POOL(); BM_PageHandle *h = MAKE_PAGE_HANDLE(); testName = "Reading a page"; CHECK(createPageFile("testbuffer.bin")); CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); CHECK(pinPage(bm, h, 0)); CHECK(pinPage(bm, h, 0)); CHECK(markDirty(bm, h)); CHECK(unpinPage(bm,h)); CHECK(unpinPage(bm,h)); CHECK(forcePage(bm, h)); CHECK(shutdownBufferPool(bm)); CHECK(destroyPageFile("testbuffer.bin")); free(bm); free(h); TEST_DONE(); }
int Test::Main() { TEST_INIT("false_test"); EXPECT_TRUE(false); TEST_DONE(); }
// create pages 100 with content "Page X" and perform 10000 random reads of these pages and check that the correct pages are read void testCreatingAndRandomReadingDummyPages (void) { int i; BM_BufferPool *bm = MAKE_POOL(); testName = "Creating and Dummy Pages and reading them in random order"; CHECK(createPageFile("testbuffer.bin")); createDummyPages(bm, 100); CHECK(initBufferPool(bm, "testbuffer.bin", 10, RS_FIFO, NULL)); srand(time(0)); for(i = 0; i < 10000; i++) { int page = rand() % NUM_DUMMY_PAGES; readAndCheckDummyPage(bm, page); } CHECK(shutdownBufferPool(bm)); CHECK(destroyPageFile("testbuffer.bin")); free(bm); TEST_DONE(); }
void main() { Schema *temp; char *s = (char *)malloc(100), **c = (char *)malloc(100 * 10); temp = testSchema(); char *res = (char *)malloc(1000); RM_TABLE_INFO *newTable = (RM_TABLE_INFO *)malloc(sizeof(RM_TABLE_INFO)), *outPutTable = (RM_TABLE_INFO *)malloc(sizeof(RM_TABLE_INFO)); RID *newRID = (RID *)malloc(sizeof(RID)); newRID->page = 1; newRID->slot = 1; newTable->s = temp; newTable->firstFreeRec = newRID; serializeTableInformation("testTable", newTable, res); printf("%s\n", res); deSerializeTableInformation(res, outPutTable); if (checkEqual(newTable, outPutTable) == TRUE) printf("successful serialization and deserialization\n"); else printf("unsuccessful serialization and deserialization\n"); free(res); free(newRID); free(newTable); if (testTombstone() == RC_OK) { printf("successful implementation of tombstone\n"); } TEST_DONE(); }
int Test::Main() { TEST_INIT("printabletest"); testSimple(); testAsciiVariant(); TEST_DONE(); }
void testClock(void) { // expected results const char *poolContents[]= { "[3x0],[-1 0],[-1 0],[-1 0]", "[3x0],[2 0],[-1 0],[-1 0]", "[3x0],[2 0],[0 0],[-1 0]", "[3x0],[2 0],[0 0],[8 0]", "[4 0],[2 0],[0 0],[8 0]", "[4 0],[2 0],[0 0],[8 0]", "[4 0],[2 0],[5 0],[8 0]", "[4 0],[2 0],[5 0],[0 0]", "[9 0],[2 0],[5 0],[0 0]", "[9 0],[8 0],[5 0],[0 0]", "[9 0],[8 0],[3x0],[0 0]", "[9 0],[8 0],[3x0],[2 0]" }; const int orderRequests[]= {3,2,0,8,4,2,5,0,9,8,3,2}; int i; int snapshot = 0; BM_BufferPool *bm = MAKE_POOL(); BM_PageHandle *h = MAKE_PAGE_HANDLE(); testName = "Testing CLOCK page replacement"; CHECK(createPageFile("testbuffer.bin")); createDummyPages(bm, 100); CHECK(initBufferPool(bm, "testbuffer.bin", 4, RS_CLOCK, NULL)); for (i=0;i<11;i++) { pinPage(bm,h,orderRequests[i]); if(orderRequests[i] == 3) markDirty(bm,h); unpinPage(bm,h); ASSERT_EQUALS_POOL(poolContents[snapshot++], bm, "check pool content using pages"); } forceFlushPool(bm); // check number of write IOs ASSERT_EQUALS_INT(2, getNumWriteIO(bm), "check number of write I/Os"); ASSERT_EQUALS_INT(10, getNumReadIO(bm), "check number of read I/Os"); CHECK(shutdownBufferPool(bm)); CHECK(destroyPageFile("testbuffer.bin")); free(bm); free(h); TEST_DONE(); }
int Test::Main() { TEST_INIT("generationhandler_test"); TEST_DO(requireThatGenerationCanBeIncreased()); TEST_DO(requireThatReadersCanTakeGuards()); TEST_DO(requireThatGuardsCanBeCopied()); TEST_DO(requireThatTheFirstUsedGenerationIsCorrect()); TEST_DO(requireThatGenerationCanGrowLarge()); TEST_DONE(); }
// ************************************************************ void testValueSerialize (void) { testName = "test value serialization and deserialization"; ASSERT_EQUALS_STRING(serializeValue(stringToValue("i10")), "10", "create Value 10"); ASSERT_EQUALS_STRING(serializeValue(stringToValue("f5.3")), "5.300000", "create Value 5.3"); ASSERT_EQUALS_STRING(serializeValue(stringToValue("sHello World")), "Hello World", "create Value Hello World"); ASSERT_EQUALS_STRING(serializeValue(stringToValue("bt")), "true", "create Value true"); ASSERT_EQUALS_STRING(serializeValue(stringToValue("btrue")), "true", "create Value true"); TEST_DONE(); }
void testPrintTree(void) { RID insert[] = { {1,1}, {2,3}, {1,2}, {3,5}, {4,4}, {3,2}, }; int numInserts = 6; Value **keys; char *stringKeys[] = { "i1", "i11", "i13", "i17", "i23", "i52" }; testName = "test b-tree print"; int i, testint; BTreeHandle *tree = NULL; keys = createValues(stringKeys, numInserts); // init TEST_CHECK(initIndexManager(NULL)); TEST_CHECK(createBtree("testidx", DT_INT, 2)); TEST_CHECK(openBtree(&tree, "testidx")); printf("0"); // remove it later // insert keys for(i = 0; i < numInserts; i++) TEST_CHECK(insertKey(tree, keys[i], insert[i])); char * expected = "(0)[1,13,2,23,3]\n(1)[1.1,1,2.3,11,2]\n(2)[1.2,13,3.5,17,3]\n(3)[4.4,23,3.2,52]\n"; //test printTree function ASSERT_EQUALS_STRING(expected,printTree(tree),"checking b-tree shape"); \ // cleanup TEST_CHECK(closeBtree(tree)); TEST_CHECK(deleteBtree("testidx")); TEST_CHECK(shutdownIndexManager()); freeValues(keys, numInserts); TEST_DONE(); }
int Test::Main() { TEST_INIT("programoptions_test"); srandom(1); testSyntaxPage(); testNormalUsage(); testFailures(); testVectorArgument(); testAllHiddenOption(); // Currently not supported // testOptionsAfterArguments(); TEST_DONE(); }
void badarg(void) { char buf[16]; int len, width; width = 1; TEST_START("utf8_badarg"); len = snmprintf(buf, sizeof(buf), &width, "\377"); ASSERT_INT_EQ(len, -1); ASSERT_STRING_EQ(buf, ""); ASSERT_INT_EQ(width, 0); TEST_DONE(); }
void sshbuf_getput_fuzz_tests(void) { u_char blob[] = { /* u8 */ 0xd0, /* u16 */ 0xc0, 0xde, /* u32 */ 0xfa, 0xce, 0xde, 0xad, /* u64 */ 0xfe, 0xed, 0xac, 0x1d, 0x1f, 0x1c, 0xbe, 0xef, /* string */ 0x00, 0x00, 0x00, 0x09, 'O', ' ', 'G', 'o', 'r', 'g', 'o', 'n', '!', /* bignum1 */ 0x79, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, /* bignum2 */ 0x00, 0x00, 0x00, 0x14, 0x00, 0xf0, 0xe0, 0xd0, 0xc0, 0xb0, 0xa0, 0x90, 0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00, 0x7f, 0xff, 0x11, /* EC point (NIST-256 curve) */ 0x00, 0x00, 0x00, 0x41, 0x04, 0x0c, 0x82, 0x80, 0x04, 0x83, 0x9d, 0x01, 0x06, 0xaa, 0x59, 0x57, 0x52, 0x16, 0x19, 0x13, 0x57, 0x34, 0xb4, 0x51, 0x45, 0x9d, 0xad, 0xb5, 0x86, 0x67, 0x7e, 0xf9, 0xdf, 0x55, 0x78, 0x49, 0x99, 0x4d, 0x19, 0x6b, 0x50, 0xf0, 0xb4, 0xe9, 0x4b, 0x3c, 0x73, 0xe3, 0xa9, 0xd4, 0xcd, 0x9d, 0xf2, 0xc8, 0xf9, 0xa3, 0x5e, 0x42, 0xbd, 0xd0, 0x47, 0x55, 0x0f, 0x69, 0xd8, 0x0e, 0xc2, 0x3c, 0xd4, }; struct fuzz *fuzz; TEST_START("fuzz blob parsing"); fuzz = fuzz_begin(FUZZ_1_BIT_FLIP | FUZZ_2_BIT_FLIP | FUZZ_1_BYTE_FLIP | FUZZ_2_BYTE_FLIP | FUZZ_TRUNCATE_START | FUZZ_TRUNCATE_END, blob, sizeof(blob)); TEST_ONERROR(onerror, fuzz); for(; !fuzz_done(fuzz); fuzz_next(fuzz)) attempt_parse_blob(blob, sizeof(blob)); fuzz_cleanup(fuzz); TEST_DONE(); TEST_ONERROR(NULL, NULL); }
// test error cases void testError (void) { BM_BufferPool *bm = MAKE_POOL(); BM_PageHandle *h = MAKE_PAGE_HANDLE(); testName = "ERROR TEST"; CHECK(createPageFile("testbuffer.bin")); // pinpage until buffer pool is full and then request additional page. CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); CHECK(pinPage(bm, h, 0)); CHECK(pinPage(bm, h, 1)); CHECK(pinPage(bm, h, 2)); ASSERT_ERROR(pinPage(bm, h, 3), "try to pin page when pool is full of pinned pages with fix-count > 0"); CHECK(shutdownBufferPool(bm)); // try to pin page with negative page number. CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); ASSERT_ERROR(pinPage(bm, h, -10), "try to pin page with negative page number"); CHECK(shutdownBufferPool(bm)); // try to use uninitialized buffer pool ASSERT_ERROR(initBufferPool(bm, "unavailable.bin", 3, RS_FIFO, NULL), "try to init buffer pool for non existing page file"); ASSERT_ERROR(shutdownBufferPool(bm), "shutdown buffer pool that is not open"); ASSERT_ERROR(forceFlushPool(bm), "flush buffer pool that is not open"); ASSERT_ERROR(pinPage(bm, h, 1), "pin page in buffer pool that is not open"); // try to unpin, mark, or force page that is not in pool CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); ASSERT_ERROR(unpinPage(bm, h), "Try to unpin a page which is not available in framelist."); ASSERT_ERROR(forcePage(bm, h), "Try to forceflush a page which is not available in framelist."); ASSERT_ERROR(markDirty(bm, h), "Try to markdirty a page which is not available in framelist."); CHECK(shutdownBufferPool(bm)); // done remove page file CHECK(destroyPageFile("testbuffer.bin")); free(bm); free(h); TEST_DONE(); }
int TestErrors::Main() { if (_argc != 2) { fprintf(stderr, "usage: %s spec", _argv[0]); return 1; } TEST_INIT("test_errors"); init(_argv[1]); testNoError(); testNoSuchMethod(); testWrongParameters(); testWrongReturnValues(); testMethodFailed(); fini(); TEST_DONE(); }
// create n pages with content "Page X" and read them back to check whether the content is right void testCreatingAndReadingDummyPages(void) { BM_BufferPool *bm = MAKE_POOL(); testName = "Creating and Reading Back Dummy Pages"; CHECK(createPageFile("testbuffer.bin")); createDummyPages(bm, 22); checkDummyPages(bm, 20); createDummyPages(bm, 10000); checkDummyPages(bm, 10000); CHECK(destroyPageFile("testbuffer.bin")); free(bm); TEST_DONE() ; }
// test error cases void testError (void) { int i; BM_BufferPool *bm = MAKE_POOL(); BM_PageHandle *h = MAKE_PAGE_HANDLE(); testName = "Testing LRU page replacement"; CHECK(createPageFile("testbuffer.bin")); // pin until buffer pool is full and request additional page CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); CHECK(pinPage(bm, h, 0)); CHECK(pinPage(bm, h, 1)); CHECK(pinPage(bm, h, 2)); ASSERT_ERROR(pinPage(bm, h, 3), "try to pin page when pool is full of pinned pages"); CHECK(shutdownBufferPool(bm)); // try to ready page with negative page number CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); ASSERT_ERROR(pinPage(bm, h, -1), "try to pin page with negative page number"); CHECK(shutdownBufferPool(bm)); // try to use uninitialized buffer pool ASSERT_ERROR(shutdownBufferPool(bm), "shutdown buffer pool that is not open"); ASSERT_ERROR(forceFlushPool(bm), "flush buffer pool that is not open"); ASSERT_ERROR(pinPage(bm, h, 1), "pin page in buffer pool that is not open"); ASSERT_ERROR(initBufferPool(bm, "xxx.bin", 3, RS_FIFO, NULL), "try to init buffer pool for non existing page file"); // try to unpin, mark, or force page that is not in pool CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); ASSERT_ERROR(unpinPage(bm, h), "unpin page not in buffer pool"); ASSERT_ERROR(forcePage(bm, h), "unpin page not in buffer pool"); ASSERT_ERROR(markDirty(bm, h), "mark page dirty that is not in buffer pool"); CHECK(shutdownBufferPool(bm)); // done remove page file CHECK(destroyPageFile("testbuffer.bin")); free(bm); free(h); TEST_DONE(); }
/* Try to create, open, and close a page file */ void testSinglePageContent(void) { SM_FileHandle fh; SM_PageHandle ph; int i; testName = "test single page content"; ph = (SM_PageHandle) malloc(PAGE_SIZE); // create a new page file TEST_CHECK(createPageFile (TESTPF)); TEST_CHECK(openPageFile (TESTPF, &fh)); printf("created and opened file\n"); // read first page into handle TEST_CHECK(readFirstBlock (&fh, ph)); // the page should be empty (zero bytes) for (i=0; i < PAGE_SIZE; i++) ASSERT_TRUE((ph[i] == 0), "expected zero byte in first page of freshly initialized page"); printf("first block was empty\n"); // change ph to be a string and write that one to disk for (i=0; i < PAGE_SIZE; i++) ph[i] = (i % 10) + '0'; TEST_CHECK(writeBlock (0, &fh, ph)); printf("writing first block\n"); // read back the page containing the string and check that it is correct TEST_CHECK(readFirstBlock (&fh, ph)); for (i=0; i < PAGE_SIZE; i++) ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected."); printf("reading first block\n"); // destroy new page file TEST_CHECK(destroyPageFile (TESTPF)); free(ph); ph=NULL; TEST_DONE(); }
/* Try to create, open, and close a page file */ void testCreateOpenClose(void) { SM_FileHandle fh; testName = "test create open and close methods"; TEST_CHECK(createPageFile (TESTPF)); TEST_CHECK(openPageFile (TESTPF, &fh)); ASSERT_TRUE(strcmp(fh.fileName, TESTPF) == 0, "filename correct"); ASSERT_TRUE((fh.totalNumPages == 1), "expect 1 page in new file"); ASSERT_TRUE((fh.curPagePos == 0), "freshly opened file's page position should be 0"); TEST_CHECK(closePageFile (&fh)); TEST_CHECK(destroyPageFile (TESTPF)); // after destruction trying to open the file should cause an error ASSERT_TRUE((openPageFile(TESTPF, &fh) != RC_OK), "opening non-existing file should return an error."); TEST_DONE(); }
void one(const char *name, const char *mbs, int width, int wantwidth, int wantlen, const char *wants) { char buf[16]; int *wp; int len; if (wantlen == -2) wantlen = strlen(wants); (void)strlcpy(buf, "utf8_", sizeof(buf)); (void)strlcat(buf, name, sizeof(buf)); TEST_START(buf); wp = wantwidth == -2 ? NULL : &width; len = snmprintf(buf, sizeof(buf), wp, "%s", mbs); ASSERT_INT_EQ(len, wantlen); ASSERT_STRING_EQ(buf, wants); ASSERT_INT_EQ(width, wantwidth); TEST_DONE(); }
void testsimpleFIFO () { printf("FIFO Execution in new thread : \n " ); // expected results const char *poolContents[] = { "[0 0],[-1 0],[-1 0]" , "[0 0],[1 0],[-1 0]", "[0 0],[1 0],[2 0]", "[3 0],[1 0],[2 0]" }; const int requests[] = {0,1,2,3,4,4,5,6,0}; const int numLinRequests = 4; int i; BM_BufferPool *bm = MAKE_POOL(); BM_PageHandle *h = MAKE_PAGE_HANDLE(); testName = "Testing FIFO page replacement"; CHECK(createPageFile("testbuffer.bin")); createDummyPages(bm, 100); CHECK(initBufferPool(bm, "testbuffer.bin", 3, RS_FIFO, NULL)); // reading some pages linearly with direct unpin and no modifications for(i = 0; i < numLinRequests; i++) { pinPage(bm, h, requests[i]); unpinPage(bm, h); ASSERT_EQUALS_POOL(poolContents[i], bm, "check pool content"); } CHECK(shutdownBufferPool(bm)); CHECK(destroyPageFile("testbuffer.bin")); free(bm); free(h); TEST_DONE(); }
/* Try to create, open, and close a page file */ void testWrite(void) { SM_FileHandle fh; SM_PageHandle ph; int i; testName = "test single page content"; ph = (SM_PageHandle) malloc(PAGE_SIZE); // create a new page file TEST_CHECK(createPageFile (TESTPF)); TEST_CHECK(openPageFile (TESTPF, &fh)); printf("created and opened file\n"); TEST_CHECK(ensureCapacity(5,&fh)); for (i=0; i < PAGE_SIZE; i++) ph[i] = (i % 10) + '0'; ASSERT_TRUE((fh.totalNumPages == 5), "expect 5 pages in new file"); TEST_CHECK(writeBlock (5, &fh, ph)); // read back the page containing the string and check that it is correct TEST_CHECK(readBlock (5,&fh, ph)); printf("\nreading :"); for (i=0; i < PAGE_SIZE; i++) ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected."); // destroy new page file TEST_CHECK(destroyPageFile (TESTPF)); TEST_DONE(); }
void testRecords (void) { TestRecord expected[] = { {1, "aaaa", 3}, }; Schema *schema; Record *r; Value *value; testName = "test creating records and manipulating attributes"; // check attributes of created record schema = testSchema(); r = fromTestRecord(schema, expected[0]); getAttr(r, schema, 0, &value); printf("\n Value is %d",value->v.intV); OP_TRUE(stringToValue("i1"), value, valueEquals, "first attr"); freeVal(value); getAttr(r, schema, 1, &value); OP_TRUE(stringToValue("saaaa"), value, valueEquals, "second attr"); freeVal(value); getAttr(r, schema, 2, &value); OP_TRUE(stringToValue("i3"), value, valueEquals, "third attr"); freeVal(value); //modify attrs setAttr(r, schema, 2, stringToValue("i4")); getAttr(r, schema, 2, &value); OP_TRUE(stringToValue("i4"), value, valueEquals, "third attr after setting"); freeVal(value); freeRecord(r); TEST_DONE(); }
// ************************************************************ void testInsertAndFind (void) { RID insert[] = { {1,1}, {2,3}, {1,2}, {3,5}, {4,4}, {3,2}, }; int numInserts = 6; Value **keys; char *stringKeys[] = { "i1", "i11", "i13", "i17", "i23", "i52" }; testName = "test b-tree inserting and search"; int i, testint; BTreeHandle *tree = NULL; keys = createValues(stringKeys, numInserts); // init TEST_CHECK(initIndexManager(NULL)); printf("\n Init"); TEST_CHECK(createBtree("testidx", DT_INT, 2)); printf("\n Created"); TEST_CHECK(openBtree(&tree, "testidx")); // insert keys for(i = 0; i < numInserts; i++) TEST_CHECK(insertKey(tree, keys[i], insert[i])); // check index stats TEST_CHECK(getNumNodes(tree, &testint)); ASSERT_EQUALS_INT(testint,4, "number of nodes in btree"); TEST_CHECK(getNumEntries(tree, &testint)); ASSERT_EQUALS_INT(testint, numInserts, "number of entries in btree"); // search for keys for(i = 0; i < 1000; i++) { int pos = rand() % numInserts; RID rid; Value *key = keys[pos]; TEST_CHECK(findKey(tree, key, &rid)); ASSERT_EQUALS_RID(insert[pos], rid, "did we find the correct RID?"); } // cleanup TEST_CHECK(closeBtree(tree)); TEST_CHECK(deleteBtree("testidx")); TEST_CHECK(shutdownIndexManager()); freeValues(keys, numInserts); TEST_DONE(); }
// ************************************************************ void testIndexScan (void) { RID insert[] = { {1,1}, {2,3}, {1,2}, {3,5}, {4,4}, {3,2}, }; int numInserts = 6; Value **keys; char *stringKeys[] = { "i1", "i11", "i13", "i17", "i23", "i52" }; testName = "random insertion order and scan"; int i, testint, iter, rc; BTreeHandle *tree = NULL; BT_ScanHandle *sc = NULL; RID rid; keys = createValues(stringKeys, numInserts); // init TEST_CHECK(initIndexManager(NULL)); for(iter = 0; iter < 50; iter++) { int *permute; // create permutation permute = createPermutation(numInserts); // create B-tree TEST_CHECK(createBtree("testidx", DT_INT, 2)); TEST_CHECK(openBtree(&tree, "testidx")); // insert keys for(i = 0; i < numInserts; i++) TEST_CHECK(insertKey(tree, keys[permute[i]], insert[permute[i]])); // check index stats TEST_CHECK(getNumEntries(tree, &testint)); ASSERT_EQUALS_INT(testint, numInserts, "number of entries in btree"); // execute scan, we should see tuples in sort order openTreeScan(tree, &sc); i = 0; while((rc = nextEntry(sc, &rid)) == RC_OK) { RID expRid = insert[i++]; ASSERT_EQUALS_RID(expRid, rid, "did we find the correct RID?"); } ASSERT_EQUALS_INT(RC_IM_NO_MORE_ENTRIES, rc, "no error returned by scan"); ASSERT_EQUALS_INT(numInserts, i, "have seen all entries"); closeTreeScan(sc); // cleanup TEST_CHECK(closeBtree(tree)); TEST_CHECK(deleteBtree("testidx")); free(permute); } TEST_CHECK(shutdownIndexManager()); freeValues(keys, numInserts); TEST_DONE(); }
// ************************************************************ void testDelete (void) { RID insert[] = { {1,1}, {2,3}, {1,2}, {3,5}, {4,4}, {3,2}, }; int numInserts = 6; Value **keys; char *stringKeys[] = { "i1", "i11", "i13", "i17", "i23", "i52" }; testName = "test b-tree inserting and search"; int i, iter; BTreeHandle *tree = NULL; int numDeletes = 3; bool *deletes = (bool *) malloc(numInserts * sizeof(bool)); keys = createValues(stringKeys, numInserts); // init TEST_CHECK(initIndexManager(NULL)); // create test b-tree and randomly remove entries for(iter = 0; iter < 50; iter++) { // randomly select entries for deletion (may select the same on twice) for(i = 0; i < numInserts; i++) deletes[i] = FALSE; for(i = 0; i < numDeletes; i++) deletes[rand() % numInserts] = TRUE; // init B-tree TEST_CHECK(createBtree("testidx", DT_INT, 2)); TEST_CHECK(openBtree(&tree, "testidx")); // insert keys for(i = 0; i < numInserts; i++) TEST_CHECK(insertKey(tree, keys[i], insert[i])); // delete entries for(i = 0; i < numInserts; i++) { if (deletes[i]) TEST_CHECK(deleteKey(tree, keys[i])); } // search for keys for(i = 0; i < 1000; i++) { int pos = rand() % numInserts; RID rid; Value *key = keys[pos]; if (deletes[pos]) { int rc = findKey(tree, key, &rid); ASSERT_TRUE((rc == RC_IM_KEY_NOT_FOUND), "entry was deleted, should not find it"); } else { TEST_CHECK(findKey(tree, key, &rid)); ASSERT_EQUALS_RID(insert[pos], rid, "did we find the correct RID?"); } } // cleanup TEST_CHECK(closeBtree(tree)); TEST_CHECK(deleteBtree("testidx")); } TEST_CHECK(shutdownIndexManager()); freeValues(keys, numInserts); free(deletes); TEST_DONE(); }