// // $Id: rmtest.cc 2025 2007-10-18 00:07:22Z chenli $ // // Make file for the testing scripts for project 1 for CS222, fall, 2007. // // Copyright (C) 2007 by The Regents of the University of California // // Redistribution of this file is permitted under the terms of the GNU // Public License (GPL). // // Date: 10/16/2007 // Author: Chen Li // #include #include #include #include #include "ix.h" #include #include //for the performance tests using namespace std; #define IX_SUCCESS 0 //to check RC functions #define NUM_ITERATIONS 9999 // no: of iterations, for testing performance #define TIME_THRESH 100 // time limit (in seconds), for testing performance in case 1 #define TIME_THRESH2 100 // time limit (in seconds), for testing performance in case 2 //Global Inits RM *rm = new RM("disk1"); RID rid; RC rc; IX_Manager *ixManager = new IX_Manager("disk1"); // check syntax IX_IndexHandle ixHandle = IX_IndexHandle(); // check syntax // TEST PLAN // We have 2 sections of 5 test cases each. We can probably release part 1. Part 2 will be secret. void myCreateTable(const char* tablename) { // Functions tested // 1. Create Table ** -- made separate. vector v_name; v_name.push_back("Emp_Name"); v_name.push_back("Age"); v_name.push_back("Height"); v_name.push_back("SSN"); printf("calling secA-1\n"); vector v_type; v_type.push_back(TypeChar); v_type.push_back(TypeInt); v_type.push_back(TypeReal); v_type.push_back(TypeInt); printf("calling secA-2\n"); vector v_length; v_length.push_back((AttrLength)30); v_length.push_back(4); v_length.push_back(4); v_length.push_back(4); rm->createTable(tablename, 200, 200, v_name, v_type, v_length); printf("TABLE CREATED: %s\n", tablename); } int testCase_1() { // Functions tested // 1. Create Index ** // 2. OpenIndex ** // 3. OpenIndex -- when index is already made on that key ** // 4. CloseIndex ** // NOTE: "**" signifies the new functions being tested in this test case. int returner=1; rc = ixManager->CreateIndex("MyTable", "Emp_Name"); cout<OpenIndex("MyTable", "Emp_Name", ixHandle); if(rc == IX_SUCCESS) cout << "Index Opened Successfully" << endl; else { cout << "FAILED TEST1b " << rc << endl; returner=0; } // should fail coz index is already present rc = ixManager->CreateIndex("MyTable", "Emp_Name"); cout<CloseIndex(ixHandle); if(rc == IX_SUCCESS) cout << "Index Destroyed Successfully" << endl; else { cout << "FAILED TEST1d " << rc << endl; returner=0; } if (returner==1) { cout << "*** PASSED TEST 1 *** " << endl; } else { cout << "*** FAILED TEST 1 *** " << endl; } return returner; } int testCase_2() { // Functions tested // 1. Create Index // 2. OpenIndex // 3. Insert entry ** // 4. Scan entries NO_OP -- open** // 5. Scan close ** // 6. CloseIndex ** // NOTE: "**" signifies the new functions being tested in this test case. int returner=1; rc = ixManager->CreateIndex("MyTable", "SSN"); if(rc == IX_SUCCESS) cout << "Index created" << endl; else { cout << "FAILED TEST 2.1 " << rc << endl; returner=0; } //getchar(); rc = ixManager->OpenIndex("MyTable", "SSN", ixHandle); if(rc == IX_SUCCESS) cout << "Index Opened Successfully" << endl; else { cout << "FAILED TEST 2.2 " << rc << endl; returner=0; } //getchar(); unsigned numberInserts = 100; unsigned maxValue = 500; unsigned insertMe = (rand() % (maxValue-1))+1;//just in case somebody starts pageNum and recordId from 1 for(unsigned i = 0; i <= numberInserts; i++) { RID rid; rid.pageNum = insertMe; rid.slotNum = insertMe; rc = ixHandle.InsertEntry((void*)&insertMe, rid); if(rc != IX_SUCCESS) { cout << "FAILED TEST 2.3 " << rc << endl; returner=0; } insertMe++;//added on dec 06 -vks } //getchar(); // get everything IX_IndexScan* ixScan = new IX_IndexScan(); rc= ixScan->OpenScan(ixHandle, NO_OP, NULL); if(rc == IX_SUCCESS) cout << "Scan Opened Successfully" << endl; else { cout << "FAILED TEST 2.4 " << rc << endl; returner=0; } //getchar(); while(ixScan->GetNextEntry(rid) == IX_SUCCESS) { cout << rid.pageNum << " " << rid.slotNum ;//lets just see the output } cout<CloseScan(); if(rc == IX_SUCCESS) cout << "Scan Closed Successfully" << endl; else { cout << "FAILED TEST 2.5 " << rc << endl; returner=0; } rc = ixManager->CloseIndex(ixHandle); if(rc == IX_SUCCESS) cout << "Index Closed Successfully" << endl; else { cout << "FAILED TEST 2.6 " << rc << endl; returner=0; } if (returner==1) { cout << "*** PASSED TEST 2 *** " << endl; } else { cout << "*** FAILED TEST 2 *** " << endl; } return returner; } int testCase_3() { // Functions tested // 1. OpenIndex // 2. Insert entry // 3. Delete entry ** // 4. Delete entry -- when the value is not there ** // 5. Close Index // NOTE: "**" signifies the new functions being tested in this test case. int returner=1; rc = ixManager->OpenIndex("MyTable", "Emp_Name", ixHandle); if(rc == IX_SUCCESS) cout << "Index Opened Successfully" << endl; else { cout << "FAILED TEST 3.1 " << rc << endl; returner=0; } //getchar(); cout<<"------------"<CloseIndex(ixHandle); if(rc == IX_SUCCESS) cout << "Index Closed Successfully" << endl; else { cout << "FAILED TEST 3.5 " << rc << endl; returner=0; } if (returner==1) { cout << "*** PASSED TEST 3 *** " << endl; } else { cout << "*** FAILED TEST 3 *** " << endl; } return returner; } int testCase_4() { // Functions tested // 1. Destroy Index ** // 2. OpenIndex -- should fail // 3. Scan -- should fail // NOTE: "**" signifies the new functions being tested in this test case. int returner=1; rc = ixManager->DestroyIndex("MyTable", "SSN"); if(rc != IX_SUCCESS) { cout << "FAILED TEST 4.1 " << rc << endl; returner=0; } rc = ixManager->OpenIndex("MyTable", "SSN", ixHandle); if(rc == IX_SUCCESS) //should not work now { cout << "FAILED TEST 4.2 " << rc << endl; returner=0; } IX_IndexScan* ixScan = new IX_IndexScan(); rc= ixScan->OpenScan(ixHandle, NO_OP, NULL); if(rc == IX_SUCCESS) { cout << "FAILED TEST 4.3 " << rc << endl; returner=0; } if (returner==1) { cout << "*** PASSED TEST 4 *** " << endl; } else { cout << "*** FAILED TEST 4 *** " << endl; } return returner; } int testCase_5() { // Functions tested // 1. Create Index // 2. OpenIndex // 3. Insert entry // 4. Scan entries using GT_OP operator and checking if the values returned are correct. ** // 5. Scan close // 6. CloseIndex // 7. DestroyIndex // NOTE: "**" signifies the new functions being tested in this test case. int returner=1; rc = ixManager->CreateIndex("MyTable", "SSN"); if(rc == IX_SUCCESS) cout << "Index created" << endl; else { cout << "FAILED TEST 5.1 " << rc << endl; returner=0; } rc = ixManager->OpenIndex("MyTable", "SSN", ixHandle); if(rc == IX_SUCCESS) cout << "Index Opened Successfully" << endl; else { cout << "FAILED TEST 5.2 " << rc << endl; returner=0; } cout<<"-----------"<display(); // getchar(); IX_IndexScan* ixScan = new IX_IndexScan(); int compVal=501; rc= ixScan->OpenScan(ixHandle, GE_OP, &compVal); if(rc == IX_SUCCESS) cout << "Scan Opened Successfully" << endl; else { cout << "FAILED TEST 5.4.1 " << rc << endl; returner=0; } cout<<"end of 5.4.1"<lastLeafNodeAccessed<GetNextEntry(rid) == IX_SUCCESS) { cout << ":::"<< rid.pageNum << " " << rid.slotNum <CloseScan(); if(rc == IX_SUCCESS) cout << "Scan Closed Successfully" << endl; else { cout << "FAILED TEST 5.5 " << rc << endl; returner=0; } cout<<"end of 5.5"<CloseIndex(ixHandle); if(rc == IX_SUCCESS) cout << "Index Closed Successfully" << endl; else { cout << "FAILED TEST 5.6 " << rc << endl; returner=0; } cout<<"end of 5.6"<DestroyIndex("MyTable", "SSN"); if(rc != IX_SUCCESS) { cout << "FAILED TEST 5.7 " << rc << endl; returner=0; } cout<<"end of 5.7"<setRM(*rm); num_correct +=testCase_1(); num_correct +=testCase_2(); num_correct +=testCase_3(); num_correct +=testCase_4(); num_correct +=testCase_5(); /* num_correct +=testCase_6(); num_correct +=testCase_7(); num_correct +=testCase_8(); num_correct +=testCase_9(); num_correct +=testCase_10(); */ //score=WT_SEC1*(secA_correct_count/10) + WT_SEC2*(secB_correct_count/2); printf("Your got %d testcases correct", num_correct); //cout << "OK" << endl; }