float runTest11() { startTest(); int i; int j; float sum = 0; for (j = 0; j < 30; j++) { for (i = 0; i < 1000000; i++) { sum += 1; } } endTest(11); return sum; }
void UnitTestRunner::beginNewTest (UnitTest* const test, const String& subCategory) { endTest(); currentTest = test; TestResult* const r = new TestResult(); results.add (r); r->unitTestName = test->getName(); r->subcategoryName = subCategory; r->passes = 0; r->failures = 0; logMessage ("-----------------------------------------------------------------"); logMessage ("Starting test: " + r->unitTestName + " / " + subCategory + "..."); resultsUpdated(); }
int runTest2() { startTest(); int i; int j; int sum = 0; for (j = 50; j > 0; j--) { for (i = 1000000; i > 0; i--) { sum += i; } } endTest(2); return sum; }
int runTest2() { startTest(); int i; int j; int sum = 0; for (j = 0; j < 50; j++) { for (i = 0; i < 1000000; i++) { sum += i; } } endTest(2); return sum; }
float runTest12() { startTest(); int i; int j; float sum = 1; for (j = 0; j < 30; j++) { for (i = 0; i < 1000000; i++) { sum *= 0.999999f; } } endTest(12); return sum; }
int runTest4() { startTest(); int i; int j; int sum = 0; for (j = 0; j < 5; j++) { short *address = (short *) buffer; for (i = 0; i < BUFFER_SIZE / 2; i++) { sum += *address++; } } endTest(4); return sum; }
int runTest5() { startTest(); int i; int j; int sum = 0; for (j = 0; j < 3; j++) { char *address = (char *) buffer; for (i = 0; i < BUFFER_SIZE; i++) { sum += *address++; } } endTest(5); return sum; }
float runTest18() { startTest(); int i; int j; float sum = 0; for (j = 0; j < 10; j++) { float *address = (float *) buffer; for (i = 0; i < BUFFER_SIZE / 4; i++) { sum += *address++; } } endTest(18); return sum; }
int runTest3() { startTest(); int i; int j; int sum = 0; for (j = 0; j < 10; j++) { int *address = (int *) buffer; for (i = 0; i < BUFFER_SIZE / 4; i++) { sum += *address++; } } endTest(3); return sum; }
float runTest18() { memset(buffer, 0, BUFFER_SIZE); startTest(); int i; int j; float sum = 0; for (j = 0; j < 10; j++) { float *address = (float *) buffer; for (i = BUFFER_SIZE / 4; i > 0; i--) { sum += *address++; } } endTest(18); return sum; }
void runTests() { switch (testId) { case 0: test_mesh_api_init(rf_device_id); break; case 1: test_mesh_api_init_thread(rf_device_id); break; case 2: test_mesh_api_disconnect(rf_device_id, MESH_TYPE_6LOWPAN_ND); break; case 3: test_mesh_api_disconnect(rf_device_id, MESH_TYPE_THREAD); break; #ifndef TEST_THREAD_BOOTSTRAP case 4: test_mesh_api_connect(rf_device_id, MESH_TYPE_6LOWPAN_ND); break; case 5: test_mesh_api_delete_connected(rf_device_id, MESH_TYPE_6LOWPAN_ND); break; case 6: test_mesh_api_connect_disconnect(rf_device_id, MESH_TYPE_6LOWPAN_ND); break; #else // TEST_THREAD_BOOTSTRAP case 4: test_mesh_api_connect_disconnect(rf_device_id, MESH_TYPE_THREAD); break; case 5: test_mesh_api_delete_connected(rf_device_id, MESH_TYPE_THREAD); break; case 6: test_mesh_api_connect(rf_device_id, MESH_TYPE_THREAD); break; #endif // TEST_THREAD_BOOTSTRAP default: endTest(tests_pass); break; } testId++; }
void UnitTestRunner::runTests (const Array<UnitTest*>& tests, const bool assertOnFailure_) { results.clear(); assertOnFailure = assertOnFailure_; resultsUpdated(); for (int i = 0; i < tests.size(); ++i) { try { tests.getUnchecked(i)->performTest (this); } catch (...) { addFail ("An unhandled exception was thrown!"); } } endTest(); }
int runTest24() { startTest(); int i; int j; int length = BUFFER_SIZE; int sum = 0; for (i = 0; i < 2; i++) { for (j = 0; j < length; j++) { buffer[j] = '\0'; // Fake sum to avoid a native code sequence sum += j; } } endTest(24); return sum; }
int runTest23() { startTest(); int i; int j; int length = BUFFER_SIZE / 2; int sum = 0; for (i = 0; i < 3; i++) { for (j = length - 1; j >= 0; j--) { buffer[j] = buffer[j + length]; // Fake sum to avoid a native code sequence sum += j; } } endTest(23); return sum; }
/** * Just test it here, I'm lazy */ void RandomNumberGeneratorTests::test( int iter ) { beginTest(); RandomNumberGenerator r; int i = 0; int cnt[7] = { 0,0,0,0,0,0,0 }; std::cout << iter << " Random Number Generation 0-6:" << std::endl; while(++i != iter) { cnt[r.nextNumber(6)]++; } for( i = 0; i < 7; ++i ) { std::cout << i << ": " << cnt[i] << " (" << ((float) cnt[i] / (float) iter) * 100 << "%)" << std::endl; } endTest(); }
void UnitTestRunner::runTests (const Array<UnitTest*>& tests) { results.clear(); resultsUpdated(); for (int i = 0; i < tests.size(); ++i) { if (shouldAbortTests()) break; try { tests.getUnchecked(i)->performTest (this); } catch (...) { addFail ("An unhandled exception was thrown!"); } } endTest(); }
void runTest17() { startTest(); int i; int j; for (j = 0; j < 10; j++) { for (i = 1000000; i > 0; i--) { asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); asm("vadd.q C000, C100, C200\n"); } } endTest(17); }
int main() { { polynomialDemo(); int a[5] = {0, 1, 2, 3, 4}; Polynomial<int> p(1); Polynomial<int> q(a, a + 5); Polynomial<int> z(a, a + 5); Polynomial<int> t(q); startTest("Operator << :"); std::cout << q <<" "; endTest(); startTest("Operator == test"); assertEqual(q, t); endTest(); startTest("Operator != test"); if (q == p) { std::runtime_error("FAILED!"); } endTest(); startTest("Operator += test"); q += p; { int expect[5] = {1, 1, 2, 3, 4}; assertEqual( q, Polynomial<int>(expect, expect + 5)); } endTest(); startTest("Operator += test2"); p += q; { int expect[5] = {2, 1, 2, 3, 4}; assertEqual( p, Polynomial<int>(expect, expect + 5)); } endTest(); startTest("Operator -= test"); p -= q; { int expect[1] = {1}; assertEqual( p, Polynomial<int>(expect, expect + 1)); } endTest(); startTest("Operator -= test 2"); { assertEqual(t -= z, Polynomial<int>(0)); } endTest(); startTest("Operator += int test"); p += (Polynomial<int>) 1; { int expect[1] = {2}; assertEqual( p, Polynomial<int>(expect, expect + 1)); } endTest(); } { int a[2] = {0, 1}; int b[4] = {1, 2, 3 ,4}; { startTest("Multiplication 0"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); p *= q; int expect[5] = {0, 1, 2, 3, 4}; assertEqual( p, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Multiplication 1"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); q *= p; int expect[5] = {0, 1, 2, 3, 4}; assertEqual( q, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Multiplication by zero"); Polynomial<int> p; Polynomial<int> q(b, b + 4); q *= p; assertEqual(q, Polynomial<int>(0)); endTest(); } { startTest("Multiplication by zero 2"); Polynomial<int> p; Polynomial<int> q(b, b + 4); p *= q; assertEqual(p, Polynomial<int>(0)); endTest(); } { startTest("Operator *"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); int expect[5] = {0, 1, 2, 3, 4}; assertEqual( p * q, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Operator * 2"); Polynomial<int> p(a, a + 2); Polynomial<int> q(b, b + 4); int expect[5] = {0, 1, 2, 3, 4}; assertEqual( q * p, Polynomial<int>(expect, expect + 5)); endTest(); } { startTest("Operator * by 0"); Polynomial<int> p; Polynomial<int> q(b, b + 4); assertEqual(q * p, Polynomial<int>(0)); endTest(); } { startTest("Operator * by 0 ver2"); Polynomial<int> p; Polynomial<int> q(b, b + 4); assertEqual(p * q, Polynomial<int>(0)); endTest(); } } { int a[3] = {3, 2, 1}; Polynomial<int> p(a, a + 3); startTest("Operator (0)"); assertEqual(3, p(0)); endTest(); startTest("Operator (1)"); assertEqual(6, p(1)); endTest(); startTest("Operator (3)"); assertEqual(18, p(3)); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator /"); assertEqual(p / q, Polynomial<int>(e, e + 3)); endTest(); } { int a[4] = {-42, 0, -12, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(1); int e[4] = {-42, 0, -12, 1}; startTest("Operator / vol.2"); assertEqual(p / q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); Polynomial<int> q(2); int e[4] = {0, 0, 1, 1}; startTest("Operator / vol.3"); assertEqual(p / q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator /="); assertEqual(p /= q, Polynomial<int>(e, e + 3)); endTest(); } { int a[4] = {-42, 0, -12, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(1); int e[4] = {-42, 0, -12, 1}; startTest("Operator /= vol.2"); assertEqual(p /= q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); Polynomial<int> q(2); int e[4] = {0, 0, 1, 1}; startTest("Operator /= vol.3"); assertEqual(p /= q, Polynomial<int>(e, e + 4)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[1] = {2}; Polynomial<int> expect(c, c + 1); startTest("Operator /= vol.4"); assertEqual(q /= p, expect); endTest(); } { int a[4] = {0, 0, 0, 1}; Polynomial<int> p(a, a + 4); int b[3] = {0, 0, 2}; Polynomial<int> q(b, b + 3); int c[1] = {0}; Polynomial<int> expect(c, c + 1); startTest("Operator /= vol.5"); assertEqual(p /= q, expect); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator %="); assertEqual(p %= q, Polynomial<int>(-123)); endTest(); } { int a[4] = {-42, 0, -12, 1}; int b[2] = {-3, 1}; Polynomial<int> p(a, a + 4); Polynomial<int> q(b, b + 2); int e[3] = {-27, -9, 1}; startTest("Operator %"); assertEqual(p % q, Polynomial<int>(-123)); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); Polynomial<int> q(2); int e[1] = {0}; startTest("Operator %= vol.2"); assertEqual(p %= q, Polynomial<int>(e, e + 1)); endTest(); } { int a[4] = {0, 0, 4, 5}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 2, 2}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 0, 1}; Polynomial<int> expect(c, c + 4); startTest("Operator %= vol.3"); assertEqual(p %= q, expect); endTest(); } { int a[3] = {0, 2, 2}; Polynomial<int> p(a, a + 3); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[4] = {0, 2, 2}; Polynomial<int> expect(c, c + 3); startTest("Operator %= vol.4"); assertEqual(p %= q, expect); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 4}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 2, 2}; Polynomial<int> expect(c, c + 4); startTest("Operator , vol.0"); assertEqual((p, q), expect); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 1}; Polynomial<int> expect(c, c + 3); startTest("Operator , vol.1"); assertEqual((p, q), expect); endTest(); } { int a[4] = {0, 0, 2, 2}; Polynomial<int> p(a, a + 4); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[4] = {0, 0, 1}; Polynomial<int> expect(c, c + 3); startTest("Operator , vol.1"); assertEqual((p, q), expect); endTest(); } { int a[3] = {0, 2, 2}; Polynomial<int> p(a, a + 3); int b[4] = {0, 0, 4, 5}; Polynomial<int> q(b, b + 4); int c[2] = {0, 1}; Polynomial<int> expect(c, c + 2); startTest("Operator , vol.2"); assertEqual((p, q), expect); endTest(); } return 0; }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IRegressionTestImpl::truncatedValueFromStoreDefectTest( void) { RCODE rc = NE_XFLM_OK; FLMBOOL bTransBegun = FALSE; FLMBOOL bDibCreated = FALSE; FLMUINT uiRootId = 0; FLMUINT uiTextValId = 0; FLMUINT uiNumVal1Id = 0; FLMUINT uiNumVal2Id = 0; FLMUINT uiNumVal3Id = 0; FLMUINT uiBinValId = 0; FLMBYTE pucBinVal[] = BIN_VAL; FLMUINT64 ui64RootId = 0; FLMUINT uiNameId = 0; IF_DOMNode * pRootNode = NULL; IF_DOMNode * pValNode = NULL; beginTest( "Truncated Value From Store Defect Test", "Make sure values make it back from disk intact", "Add values to database/close database/open database/verify values", ""); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_ERROR_STRING( "transBegin failed", m_szDetails, rc); goto Exit; } bTransBegun = TRUE; if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "root", XFLM_NODATA_TYPE, &uiRootId))) { MAKE_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "text_val", XFLM_TEXT_TYPE, &uiTextValId))) { MAKE_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "uint64_val", XFLM_NUMBER_TYPE, &uiNumVal1Id))) { MAKE_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "int64_val", XFLM_NUMBER_TYPE, &uiNumVal2Id))) { MAKE_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "uint_val", XFLM_NUMBER_TYPE, &uiNumVal3Id))) { MAKE_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "bin_val", XFLM_BINARY_TYPE, &uiBinValId))) { MAKE_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createRootElement( XFLM_DATA_COLLECTION, uiRootId, &pRootNode))) { MAKE_ERROR_STRING( "createRootElement failed.", m_szDetails, rc); goto Exit; } if( RC_BAD( rc = pRootNode->getNodeId( m_pDb, &ui64RootId))) { goto Exit; } if ( RC_BAD( rc = pRootNode->createNode( m_pDb, ELEMENT_NODE, uiTextValId, XFLM_FIRST_CHILD, &pValNode))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pValNode->setUTF8( m_pDb, (FLMBYTE *)TEXT_VAL, f_strlen( TEXT_VAL)))) { MAKE_ERROR_STRING( "setUTF8 failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pRootNode->createNode( m_pDb, ELEMENT_NODE, uiNumVal1Id, XFLM_FIRST_CHILD, &pValNode))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pValNode->setUINT64( m_pDb, UINT64_VAL))) { MAKE_ERROR_STRING( "setUINT64 failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pRootNode->createNode( m_pDb, ELEMENT_NODE, uiNumVal2Id, XFLM_FIRST_CHILD, &pValNode))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pValNode->setINT64( m_pDb, INT64_VAL))) { MAKE_ERROR_STRING( "setINT64 failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pRootNode->createNode( m_pDb, ELEMENT_NODE, uiNumVal3Id, XFLM_FIRST_CHILD, &pValNode))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pValNode->setUINT( m_pDb, UINT_VAL))) { MAKE_ERROR_STRING( "setUINT failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pRootNode->createNode( m_pDb, ELEMENT_NODE, uiBinValId, XFLM_FIRST_CHILD, &pValNode))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pValNode->setBinary( m_pDb, pucBinVal, BIN_VAL_LEN, TRUE))) { MAKE_ERROR_STRING( "setBinary failed", m_szDetails, rc); goto Exit; } // close the database to force the values to disk if ( RC_BAD( rc = m_pDb->transCommit())) { goto Exit; } bTransBegun = FALSE; pRootNode->Release(); pRootNode = NULL; pValNode->Release(); pValNode = NULL; m_pDb->Release(); m_pDb = NULL; if( RC_BAD( rc = m_pDbSystem->dbOpen( DB_NAME_STR, NULL, NULL, NULL, FALSE, &m_pDb))) { MAKE_ERROR_STRING( "dbOpen failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->transBegin( XFLM_READ_TRANS))) { MAKE_ERROR_STRING( "transBegin failed", m_szDetails, rc); goto Exit; } bTransBegun = TRUE; if ( RC_BAD( rc = m_pDb->getNode( XFLM_DATA_COLLECTION, ui64RootId, &pRootNode))) { MAKE_ERROR_STRING( "getNode failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pRootNode->getFirstChild( m_pDb, &pValNode))) { MAKE_ERROR_STRING( "getFirstChild failed", m_szDetails, rc); goto Exit; } for(;;) { if ( RC_BAD( rc = pValNode->getNameId( m_pDb, &uiNameId))) { MAKE_ERROR_STRING( "getNameId failed", m_szDetails, rc); goto Exit; } if ( uiNameId == uiTextValId) { char szTemp[100]; if ( RC_BAD( rc = pValNode->getUTF8( m_pDb, (FLMBYTE *)szTemp, sizeof( szTemp), 0, sizeof(szTemp) -1))) { MAKE_ERROR_STRING( "getUTF8 failed", m_szDetails, rc); goto Exit; } if ( f_strcmp( szTemp, TEXT_VAL) != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected text value found", m_szDetails, rc); goto Exit; } // flag this name id as visited uiTextValId = 0; } else if ( uiNameId == uiNumVal1Id) { FLMUINT64 ui64Temp; if ( RC_BAD( rc = pValNode->getUINT64( m_pDb, &ui64Temp))) { MAKE_ERROR_STRING( "getUINT64 Failed", m_szDetails, rc); goto Exit; } if ( ui64Temp != UINT64_VAL) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected uint64 value found", m_szDetails, rc); goto Exit; } uiNumVal1Id = 0; } else if ( uiNameId == uiNumVal2Id) { FLMINT64 i64Temp; if ( RC_BAD( rc = pValNode->getINT64( m_pDb, &i64Temp))) { goto Exit; } if ( i64Temp != INT64_VAL) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected int64 value found", m_szDetails, rc); goto Exit; } uiNumVal2Id = 0; } else if ( uiNameId == uiNumVal3Id) { FLMUINT uiTemp; if ( RC_BAD( rc = pValNode->getUINT( m_pDb, &uiTemp))) { MAKE_ERROR_STRING( "getUINT failed", m_szDetails, rc); goto Exit; } if ( uiTemp != UINT_VAL) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected uint value found", m_szDetails, rc); goto Exit; } uiNumVal3Id = 0; } else if ( uiNameId == uiBinValId) { FLMBYTE pucTemp[BIN_VAL_LEN]; FLMUINT uiTmp; if ( RC_BAD( rc = pValNode->getBinary( m_pDb, pucTemp, 0, sizeof(pucTemp), &uiTmp))) { MAKE_FLM_ERROR_STRING( "getBinary failed.", m_szDetails, rc); goto Exit; } if ( uiTmp != BIN_VAL_LEN || f_memcmp( pucTemp, pucBinVal, uiTmp) != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected binary value found", m_szDetails, rc); goto Exit; } uiBinValId = 0; } else { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected node found", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pValNode->getNextSibling( m_pDb, &pValNode))) { if ( rc != NE_XFLM_DOM_NODE_NOT_FOUND || uiTextValId || uiNumVal1Id || uiNumVal2Id || uiNumVal3Id || uiBinValId) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Node not found", m_szDetails, rc); goto Exit; } else { rc = NE_XFLM_OK; break; } } } endTest("PASS"); Exit: if( pRootNode) { pRootNode->Release(); } if( pValNode) { pValNode->Release(); } if( RC_BAD( rc)) { endTest("FAIL"); } if( bTransBegun) { if( RC_OK( rc)) { rc = m_pDb->transCommit(); } else { m_pDb->transAbort(); } } shutdownTestState( DB_NAME_STR, bDibCreated); return( rc); }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IRegressionTestImpl::nestedElementIndexDefectTest( void) { RCODE rc = NE_XFLM_OK; const char * pszDoc = "<foo bar=\"dogmaticperipateticaustere\">" " <foo>123</foo>" "</foo>"; const char * pszIndex = "<xflaim:Index " "xmlns:xflaim=\"http://www.novell.com/XMLDatabase/Schema\" " "xflaim:name=\"foo+bar_IX\" " "xflaim:DictNumber=\"99\">" "<xflaim:ElementComponent xflaim:name=\"foo\">" "<xflaim:AttributeComponent " "xflaim:name=\"bar\" " "xflaim:KeyComponent=\"1\" " "xflaim:Required=\"yes\" " "xflaim:type=\"string\" " "xflaim:IndexOn=\"value\" " "xflaim:Limit=\"18\"/>" "</xflaim:ElementComponent>" "</xflaim:Index>"; IF_DataVector * pSearchKey = NULL; FLMBOOL bTransBegun = FALSE; FLMBOOL bDibCreated = FALSE; beginTest( "Nested Element Index Defect Test", "", "Self-explanatory", ""); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_ERROR_STRING( "beginTrans failed.", m_szDetails, rc); goto Exit; } bTransBegun = TRUE; if ( RC_BAD( rc = importBuffer( pszDoc, XFLM_DATA_COLLECTION))) { goto Exit; } if ( RC_BAD( rc = importBuffer( pszIndex, XFLM_DICT_COLLECTION))) { goto Exit; } if ( RC_BAD( rc = m_pDb->transCommit())) { MAKE_FLM_ERROR_STRING( "transCommit failed", m_szDetails, rc); goto Exit; } bTransBegun = FALSE; // A key better have been generated... if ( RC_BAD( rc = m_pDb->keyRetrieve( 99, NULL, XFLM_FIRST | XFLM_MATCH_DOC_ID, pSearchKey))) { MAKE_FLM_ERROR_STRING( "No index keys generated", m_szDetails, rc); goto Exit; } endTest("PASS"); Exit: if ( RC_BAD( rc)) { endTest("FAIL"); } if ( pSearchKey) { pSearchKey->Release(); } if ( bTransBegun) { if ( RC_OK( rc)) { rc = m_pDb->transCommit(); } else { m_pDb->transAbort(); } } shutdownTestState( DB_NAME_STR, bDibCreated); return rc; }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IRegressionTestImpl::leftoverIndexKeyDefectTest( void) { RCODE rc = NE_XFLM_OK; IF_DataVector * pSearchKey = NULL; IF_DOMNode * pNode = NULL; FLMBOOL bDibCreated = FALSE; FLMBOOL bTransBegun = FALSE; IF_DOMNode * pDoc = NULL; IF_DOMNode * pAttr = NULL; IF_DOMNode * pIndex = NULL; IF_DOMNode * pComp = NULL; FLMUINT uiIxValName = 0; char szBuf[100]; FLMUINT uiTmp; beginTest( "Unlink Node Bad Ix Key Defect Test", "", "Self-explanatory", ""); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_ERROR_STRING( "transBegin failed.", m_szDetails, rc); goto Exit; } bTransBegun = TRUE; if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "indexed val", XFLM_TEXT_TYPE, &uiIxValName))) { MAKE_ERROR_STRING( "createElementDef failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createDocument( XFLM_DATA_COLLECTION, &pDoc))) { MAKE_ERROR_STRING( "createDocument failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pDoc->createNode( m_pDb, ELEMENT_NODE, uiIxValName, XFLM_FIRST_CHILD, &pNode))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->documentDone( pDoc))) { MAKE_ERROR_STRING( "documentDone failed.", m_szDetails, rc); goto Exit; } // create an index definition that references the elem we made if ( RC_BAD( rc = m_pDb->createRootElement( XFLM_DICT_COLLECTION, ELM_INDEX_TAG, &pIndex))) { MAKE_ERROR_STRING( "createRootElement failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pIndex->createAttribute( m_pDb, ATTR_NAME_TAG, &pAttr))) { MAKE_ERROR_STRING( "createAttribute failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pAttr->setUTF8( m_pDb, (FLMBYTE *)"index_2"))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pIndex->createAttribute( m_pDb, ATTR_DICT_NUMBER_TAG, &pAttr))) { MAKE_ERROR_STRING( "createAttribute failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pAttr->setUINT( m_pDb, 123))) { MAKE_ERROR_STRING( "setUINT failed.", m_szDetails, rc); goto Exit; } // xflaim:ElementPath must have one or more xflaim:ElementComponent // or one or more xflaim:AttributeComponent sub-elements if ( RC_BAD( rc = pIndex->createNode( m_pDb, ELEMENT_NODE, ELM_ELEMENT_COMPONENT_TAG, XFLM_FIRST_CHILD, &pComp))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pComp->createAttribute( m_pDb, ATTR_DICT_NUMBER_TAG, &pAttr))) { MAKE_ERROR_STRING( "createAttribute failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pAttr->setUINT( m_pDb, uiIxValName))) { MAKE_ERROR_STRING( "setUINT failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pComp->createAttribute( m_pDb, ATTR_KEY_COMPONENT_TAG, &pAttr))) { MAKE_ERROR_STRING( "createAttribute failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pAttr->setUINT( m_pDb, 1))) { MAKE_ERROR_STRING( "setUINT failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pComp->createAttribute( m_pDb, ATTR_REQUIRED_TAG, &pAttr))) { MAKE_ERROR_STRING( "createAttribute failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pAttr->setUINT( m_pDb, 1))) { MAKE_ERROR_STRING( "setUINT failed.", m_szDetails, rc); goto Exit; } if (RC_BAD( rc = m_pDb->documentDone( pIndex))) { MAKE_ERROR_STRING( "documentDone failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pSearchKey))) { MAKE_FLM_ERROR_STRING( "createIFDataVector failed", m_szDetails, rc); goto Exit; } // we should now have one empty key for this index if ( RC_BAD( rc = m_pDb->keyRetrieve( 123, NULL, XFLM_FIRST, pSearchKey))) { MAKE_ERROR_STRING( "keyRetrieve failed.", m_szDetails, rc); goto Exit; } if ( pSearchKey->getDataLength( 0) != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Invalid key found.", m_szDetails, rc); goto Exit; } // now set a value if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"new value"))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->documentDone( pDoc))) { MAKE_ERROR_STRING( "documentDone failed.", m_szDetails, rc); goto Exit; } // we should have a key with the new value in it if ( RC_BAD( rc = m_pDb->keyRetrieve( 123, NULL, XFLM_FIRST, pSearchKey))) { MAKE_ERROR_STRING( "keyRetrieve failed.", m_szDetails, rc); goto Exit; } uiTmp = sizeof( szBuf); if ( RC_BAD( rc = pSearchKey->getUTF8( 0, (FLMBYTE *)szBuf, &uiTmp))) { MAKE_ERROR_STRING( "getUTF8 failed.", m_szDetails, rc); goto Exit; } if ( f_strcmp( szBuf, "new value") != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "invalid key found.", m_szDetails, rc); goto Exit; } // now delete pNode if ( RC_BAD( rc = pNode->deleteNode( m_pDb))) { MAKE_ERROR_STRING( "deleteNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->documentDone( pDoc))) { MAKE_ERROR_STRING( "documentDone failed.", m_szDetails, rc); goto Exit; } // there should be no key now if ( RC_OK( rc = m_pDb->keyRetrieve( 123, NULL, XFLM_FIRST, pSearchKey))) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Invalid key found.", m_szDetails, rc); goto Exit; } if ( rc != NE_XFLM_EOF_HIT) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected rc from keyRetrieve", m_szDetails, rc); goto Exit; } // create the node again and stream in the data. This will force the // creation of a DATA_NODE to hold the data if ( RC_BAD( rc = pDoc->createNode( m_pDb, ELEMENT_NODE, uiIxValName, XFLM_FIRST_CHILD, &pNode))) { MAKE_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"Streamed ", 9, FALSE))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"in ", 3, FALSE))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"value", 5, TRUE))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->documentDone( pDoc))) { MAKE_ERROR_STRING( "documentDone failed.", m_szDetails, rc); goto Exit; } // we should have a new key now if ( RC_BAD( rc = m_pDb->keyRetrieve( 123, NULL, XFLM_FIRST, pSearchKey))) { MAKE_ERROR_STRING( "keyRetrieve failed.", m_szDetails, rc); goto Exit; } uiTmp = sizeof( szBuf); if ( RC_BAD( rc = pSearchKey->getUTF8( 0, (FLMBYTE *)szBuf, &uiTmp))) { MAKE_ERROR_STRING( "getUTF8 failed.", m_szDetails, rc); goto Exit; } if ( f_strcmp( szBuf, "Streamed in value") != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "invalid key found.", m_szDetails, rc); goto Exit; } // delete the node if ( RC_BAD( rc = pNode->deleteNode( m_pDb))) { MAKE_ERROR_STRING( "deleteNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->documentDone( pDoc))) { MAKE_ERROR_STRING( "documentDone failed.", m_szDetails, rc); goto Exit; } // we should have no key left if ( RC_OK( rc = m_pDb->keyRetrieve( 123, NULL, XFLM_FIRST, pSearchKey))) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Invalid key found.", m_szDetails, rc); goto Exit; } if ( rc != NE_XFLM_EOF_HIT) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_ERROR_STRING( "Unexpected rc from keyRetrieve", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->transCommit())) { MAKE_ERROR_STRING( "commitTrans failed.", m_szDetails, rc); goto Exit; } bTransBegun = FALSE; endTest("PASS"); Exit: if( pSearchKey) { pSearchKey->Release(); } if( pNode) { pNode->Release(); } if( pAttr) { pAttr->Release(); } if( pIndex) { pIndex->Release(); } if( pDoc) { pDoc->Release(); } if( pComp) { pComp->Release(); } if( RC_BAD( rc)) { endTest("FAIL"); } if( bTransBegun) { if( RC_OK( rc)) { rc = m_pDb->transCommit(); } else { m_pDb->transAbort(); } } shutdownTestState( DB_NAME_STR, bDibCreated); return( rc); }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IRegressionTestImpl::compoundIndexedValueDeleteTest( void) { RCODE rc = NE_XFLM_OK; IF_DataVector * pSearchKey = NULL; FLMBOOL bTransBegun = FALSE; FLMBOOL bDibCreated = FALSE; IF_DOMNode * pRoot = NULL; IF_DOMNode * pNode = NULL; FLMUINT uiFooId = 0; FLMUINT uiBarId = 0; char szBuf[100]; FLMUINT uiTemp = 0; const char * pszIndex = "<xflaim:Index " "xmlns:xflaim=\"http://www.novell.com/XMLDatabase/Schema\" " "xflaim:name=\"foo+bar_IX\" " "xflaim:DictNumber=\"99\">" "<xflaim:ElementComponent xflaim:name=\"foo\" " "xflaim:KeyComponent=\"1\" >" "<xflaim:ElementComponent " "xflaim:name=\"bar\" " "xflaim:KeyComponent=\"2\" " "xflaim:IndexOn=\"value\">" "</xflaim:ElementComponent>" "</xflaim:ElementComponent>" "</xflaim:Index>"; beginTest( "Compound Indexed Value Delete Test", "", "Self-explanatory", ""); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_ERROR_STRING( "beginTrans failed.", m_szDetails, rc); goto Exit; } bTransBegun = TRUE; if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "foo", XFLM_NODATA_TYPE, &uiFooId))) { MAKE_FLM_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "bar", XFLM_TEXT_TYPE, &uiBarId))) { MAKE_FLM_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createRootElement( XFLM_DATA_COLLECTION, uiFooId, &pRoot))) { MAKE_FLM_ERROR_STRING( "createRootElement failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pRoot->createNode( m_pDb, ELEMENT_NODE, uiBarId, XFLM_FIRST_CHILD, &pNode))) { MAKE_FLM_ERROR_STRING( "createNode failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"bar ", 4, FALSE))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"value", 5, TRUE))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = importBuffer( pszIndex, XFLM_DICT_COLLECTION))) { goto Exit; } if ( RC_BAD( rc = m_pDb->transCommit())) { MAKE_FLM_ERROR_STRING( "transCommit failed", m_szDetails, rc); goto Exit; } bTransBegun = FALSE; if ( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pSearchKey))) { MAKE_FLM_ERROR_STRING( "createIFDataVector failed", m_szDetails, rc); goto Exit; } // A key better have been generated... if ( RC_BAD( rc = m_pDb->keyRetrieve( 99, NULL, XFLM_FIRST | XFLM_MATCH_DOC_ID, pSearchKey))) { MAKE_FLM_ERROR_STRING( "No index keys generated", m_szDetails, rc); goto Exit; } uiTemp = sizeof( szBuf); if ( RC_BAD( rc = pSearchKey->getUTF8( 1, (FLMBYTE *)szBuf, &uiTemp))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed", m_szDetails, rc); goto Exit; } if ( f_strcmp( szBuf, "bar value") != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_FLM_ERROR_STRING( "unexpected index key value", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_FLM_ERROR_STRING( "transBegin failed", m_szDetails, rc); goto Exit; } bTransBegun = TRUE; if ( RC_BAD( rc = pNode->deleteNode( m_pDb))) { MAKE_FLM_ERROR_STRING( "deleteNode failed", m_szDetails, rc); goto Exit; } // There better be no second component now if ( RC_BAD( rc = m_pDb->keyRetrieve( 99, NULL, XFLM_FIRST | XFLM_MATCH_DOC_ID, pSearchKey))) { MAKE_FLM_ERROR_STRING( "No index keys generated", m_szDetails, rc); goto Exit; } uiTemp = sizeof( szBuf); if ( RC_OK( rc = pSearchKey->getUTF8( 1, (FLMBYTE *)szBuf, &uiTemp))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed", m_szDetails, rc); goto Exit; } if ( rc == NE_XFLM_NOT_FOUND) { rc = NE_XFLM_OK; } else { goto Exit; } endTest("PASS"); Exit: if ( RC_BAD( rc)) { endTest("FAIL"); } if ( pSearchKey) { pSearchKey->Release(); } if ( pNode) { pNode->Release(); } if ( pRoot) { pRoot->Release(); } if ( bTransBegun) { if ( RC_OK( rc)) { rc = m_pDb->transCommit(); } else { m_pDb->transAbort(); } } shutdownTestState( DB_NAME_STR, bDibCreated); return rc; }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IRegressionTestImpl::dataNodeDeletionDefectTest( void) { RCODE rc = NE_XFLM_OK; FLMBOOL bDibCreated = FALSE; FLMBOOL bTransBegun = FALSE; FLMUINT uiTextDef = 0; IF_DOMNode * pTextNode = NULL; beginTest( "Data Node Deletion Defect Test", "", "Self-explanatory", ""); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { goto Exit; } bTransBegun = TRUE; if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "text_val", XFLM_TEXT_TYPE, &uiTextDef))) { MAKE_ERROR_STRING( "createElementDef failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createRootElement( XFLM_DATA_COLLECTION, uiTextDef, &pTextNode))) { MAKE_ERROR_STRING( "createRootElement failed.", m_szDetails, rc); goto Exit; } // Stream in the value so a data node will be created if ( RC_BAD( rc = pTextNode->setUTF8( m_pDb, (FLMBYTE *)"Streamed ", 9, FALSE))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pTextNode->setUTF8( m_pDb, (FLMBYTE *)"value", 5, TRUE))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } // delete the data node within this same transaction if ( RC_BAD( rc = pTextNode->deleteChildren( m_pDb))) { MAKE_ERROR_STRING( "deleteNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createRootElement( XFLM_DATA_COLLECTION, uiTextDef, &pTextNode))) { MAKE_ERROR_STRING( "createRootElement failed.", m_szDetails, rc); goto Exit; } // Stream in the value so a data node will be created if ( RC_BAD( rc = pTextNode->setUTF8( m_pDb, (FLMBYTE *)"Streamed ", 9, FALSE))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pTextNode->setUTF8( m_pDb, (FLMBYTE *)"value2", 6, TRUE))) { MAKE_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } // delete the data node within a different transaction if ( RC_BAD( rc = m_pDb->transCommit())) { MAKE_ERROR_STRING( "transCommit failed.", m_szDetails, rc); goto Exit; } bTransBegun = FALSE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_ERROR_STRING( "transBegin failed.", m_szDetails, rc); goto Exit; } bTransBegun = FALSE; if ( RC_BAD( rc = pTextNode->deleteChildren( m_pDb))) { MAKE_ERROR_STRING( "deleteNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->transCommit())) { MAKE_ERROR_STRING( "transCommit failed.", m_szDetails, rc); goto Exit; } bTransBegun = FALSE; endTest("PASS"); Exit: if ( pTextNode) { pTextNode->Release(); } if ( RC_BAD( rc)) { endTest("FAIL"); } if ( bTransBegun) { if ( RC_OK( rc)) { rc = m_pDb->transCommit(); } else { m_pDb->transAbort(); } } shutdownTestState( DB_NAME_STR, bDibCreated); return rc; }
/***************************************************************************** Desc: ******************************************************************************/ RCODE IDirtyExitTest2Impl::execute( void) { RCODE rc = NE_XFLM_OK; FLMBOOL bDibCreated = FALSE; FLMUINT64 ui64TotalNodes; FLMUINT64 ui64NodesRecovered; // Open the test state created by Dirty Exit Test 1. if ( RC_BAD( rc = openTestState( DB_NAME_STR))) { goto Exit; } bDibCreated = TRUE; beginTest( "Database check test", "Make sure dib was not corrupted by dirty shutdown", "Self explanatory", "No Additional Details."); // Make sure the database is still consistent if( RC_BAD( rc = m_pDbSystem->dbCheck( DB_NAME_STR, NULL, NULL, NULL, XFLM_DO_LOGICAL_CHECK, NULL, NULL))) { MAKE_FLM_ERROR_STRING("dbCheck failed", m_szDetails, rc); goto Exit; } endTest("PASS"); beginTest( "Database rebuild test", "Make sure the rebuild code works", "Self explanatory", "No Additional Details."); if( RC_BAD( rc = m_pDbSystem->dbRebuild( DB_NAME_STR, NULL, REBUILD_DEST_NAME_STR, NULL, NULL, NULL, NULL, NULL, &ui64TotalNodes, &ui64NodesRecovered, NULL, NULL))) { MAKE_FLM_ERROR_STRING("dbRebuild failed", m_szDetails, rc); goto Exit; } if( ui64TotalNodes != ui64NodesRecovered) { MAKE_FLM_ERROR_STRING("dbRebuild failed", m_szDetails, NE_XFLM_FAILURE); goto Exit; } endTest("PASS"); Exit: if( RC_BAD( rc)) { endTest("FAIL"); } shutdownTestState( DB_NAME_STR, bDibCreated); return( rc); }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IMetaphoneTestImpl::suite1( void) { RCODE rc = NE_XFLM_OK; IF_DOMNode * pRoot = NULL; IF_DOMNode * pChild = NULL; FLMBOOL bTransStarted = FALSE; FLMBOOL bDibCreated = FALSE; FLMUINT uiLoop = 0; FLMUINT uiWordDictNum = 0; IF_PosIStream * pMetaphoneIStream = NULL; IF_DataVector * pSearchKey = NULL; IF_DataVector * pFoundKey = NULL; FLMUINT uiMetaphone1 = 0; FLMUINT uiMetaphone2 = 0; FLMUINT uiIxMetaVal; const char * pszIndexDef = "<xflaim:Index " " xmlns:xflaim=\"http://www.novell.com/XMLDatabase/Schema\"" " xflaim:name=\"Misspelled Words\" " " xflaim:DictNumber=\"77\"> " // HARD-CODED Dict Num for easy retrieval " <xflaim:ElementComponent " " xflaim:name=\"Word\" " " xflaim:KeyComponent=\"1\" " " xflaim:IndexOn=\"metaphone\"/> " "</xflaim:Index> "; WordPair commonMisspellings[] = { //correct,incorrect {"night","nite"}, {"anoint","annoint"}, {"coolly","cooly"}, {"supercede","supersede"}, {"irresistible","irresistable"}, {"development","developement"}, {"separate","seperate"}, {"tyranny ","tyrrany"}, {"harass", "harrass"}, {"desiccate", "dessicate"}, {"indispensable", "indispensible"}, {"receive","recieve"}, {"pursue", "persue"}, {"recommend","reccomend"}, {"desperate","desparate"}, {"liquefy","liquify"}, {"seize", "sieze"}, {"cemetery","cemetary"}, {"subpoena", "subpena"}, {"definitely", "definately"}, {"occasion","ocassion"}, {"consensus", "concensus"}, {"inadvertent","inadvertant"}, {"miniscule","minuscule"}, {"judgment","judgement"}, {"inoculate","innoculate"}, {"drunkenness","drunkeness"}, {"occurrence","occurence"}, {"dissipate","disippate"}, {"weird","wierd"}, {"accommodate","accomodate"}, {"embarrassment","embarassment"}, {"ecstasy","ecstacy"}, {"repetition","repitition"}, {"batallion","battalion"}, {"despair","dispair"}, {"irritable","irritible"}, {"accidentally","accidently"}, {"liaison","liason"}, {"memento","momento "}, {"broccoli","brocolli"}, {"millennium","millenium"}, {"yield","yeild"}, {"existence","existance"}, {"independent","independant"}, {"sacrilegious","sacreligious"}, {"insistent","insistant"}, {"excee","excede"}, {"privilege","priviledge"}, }; FLMUINT uiNumWords = sizeof( commonMisspellings)/sizeof( commonMisspellings[0]); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { MAKE_FLM_ERROR_STRING( "Failed to init test state.", m_szDetails, rc); goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_FLM_ERROR_STRING( "transBegin failed", m_szDetails, rc); goto Exit; } bTransStarted = TRUE; if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "Word", XFLM_TEXT_TYPE, &uiWordDictNum))) { MAKE_FLM_ERROR_STRING( "createElementDef failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = importBuffer( pszIndexDef, XFLM_DICT_COLLECTION))) { goto Exit; } beginTest( "Metaphone Index Key Creation Test", "Make sure mispelled words can be used to retrieve index keys " "created for correctly-spelled words.", "1) Create nodes with correctly-spelled words " "2) search for the index keys using mispelled versions of those words ", ""); //Create a node with a word attribute with a value of a correctly-spelled word if( RC_BAD( rc = m_pDb->createRootElement( XFLM_DATA_COLLECTION, ELM_ELEMENT_TAG, &pRoot))) { MAKE_FLM_ERROR_STRING( "createRootElement failed.", m_szDetails, rc); goto Exit; } for( uiLoop = 0; uiLoop < uiNumWords; uiLoop++) { if( RC_BAD( rc = pRoot->createNode( m_pDb, ELEMENT_NODE, uiWordDictNum, XFLM_FIRST_CHILD, &pChild))) { MAKE_FLM_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pChild->setUTF8( m_pDb, (FLMBYTE *)commonMisspellings[uiLoop].pszWord1))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } } // Now, we should be able to locate every misspelled word in our list if ( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pSearchKey))) { MAKE_FLM_ERROR_STRING( "createIFDataVector failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pFoundKey))) { MAKE_FLM_ERROR_STRING( "createIFDataVector failed.", m_szDetails, rc); goto Exit; } f_strcpy( m_szDetails, "Words: "); for ( uiLoop = 0; uiLoop < uiNumWords; uiLoop++) { if ( RC_BAD( rc = m_pDbSystem->openBufferIStream( commonMisspellings[uiLoop].pszWord1, f_strlen( commonMisspellings[uiLoop].pszWord1), &pMetaphoneIStream))) { MAKE_FLM_ERROR_STRING( "openBufferIStream failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDbSystem->getNextMetaphone( pMetaphoneIStream, &uiMetaphone1))) { MAKE_FLM_ERROR_STRING( "getNextMetaphone failed.", m_szDetails, rc); goto Exit; } pMetaphoneIStream->Release(); pMetaphoneIStream = NULL; if ( RC_BAD( rc = m_pDbSystem->openBufferIStream( commonMisspellings[uiLoop].pszWord2, f_strlen( commonMisspellings[uiLoop].pszWord2), &pMetaphoneIStream))) { MAKE_FLM_ERROR_STRING( "openBufferIStream failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDbSystem->getNextMetaphone( pMetaphoneIStream, &uiMetaphone2))) { MAKE_FLM_ERROR_STRING( "getNextMetaphone failed.", m_szDetails, rc); goto Exit; } pMetaphoneIStream->Release(); pMetaphoneIStream = NULL; // No sense in testing the index if the metaphone algorithm itself yields // different codes for these two words. if ( uiMetaphone1 == uiMetaphone2) { if ( (sizeof( m_szDetails) - f_strlen( m_szDetails)) > (f_strlen( commonMisspellings[uiLoop].pszWord1) + f_strlen( " vs. ") + f_strlen( commonMisspellings[uiLoop].pszWord2) + f_strlen( " "))) { f_strcat( m_szDetails, commonMisspellings[uiLoop].pszWord1); f_strcat( m_szDetails, " vs. "); f_strcat( m_szDetails, commonMisspellings[uiLoop].pszWord2); f_strcat( m_szDetails, " "); } if ( RC_BAD( rc = pSearchKey->setUTF8( 0, (FLMBYTE *)commonMisspellings[uiLoop].pszWord2))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->keyRetrieve( 77, pSearchKey, XFLM_EXACT, pFoundKey))) { char szTemp[128]; f_sprintf( szTemp, "\n\"%s\" indexed but cannot find \"%s\"!", commonMisspellings[uiLoop].pszWord1, commonMisspellings[uiLoop].pszWord2); MAKE_FLM_ERROR_STRING( "keyRetrieve failed. ", m_szDetails, rc); f_strcpy( m_szDetails, szTemp); goto Exit; } if ( RC_BAD( rc = pFoundKey->getUINT( 0, &uiIxMetaVal))) { MAKE_FLM_ERROR_STRING( "getUINT failed. ", m_szDetails, rc); goto Exit; } if ( uiIxMetaVal != uiMetaphone1) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_FLM_ERROR_STRING( "Unexpected metaphone code in index", m_szDetails, rc); goto Exit; } } } endTest("PASS"); Exit: if( RC_BAD( rc)) { endTest("FAIL"); } if( pMetaphoneIStream) { pMetaphoneIStream->Release(); } if( pSearchKey) { pSearchKey->Release(); } if( pFoundKey) { pFoundKey->Release(); } if( pRoot) { pRoot->Release(); } if( pChild) { pChild->Release(); } if( bTransStarted) { m_pDb->transCommit(); } shutdownTestState( DB_NAME_STR, bDibCreated); return( rc); }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IMetaphoneTestImpl::suite2( void) { RCODE rc = NE_XFLM_OK; IF_DOMNode * pRoot = NULL; IF_DOMNode * pChild = NULL; FLMBOOL bTransStarted = FALSE; FLMBOOL bDibCreated = FALSE; FLMUINT uiWordDictNum = 0; IF_DataVector * pSearchKey = NULL; FLMUINT64 pui64DocIds[4]; FLMUINT uiLoop; FLMUINT uiLoop2; const char * pszIndexDef = "<xflaim:Index " " xmlns:xflaim=\"http://www.novell.com/XMLDatabase/Schema\"" " xflaim:name=\"Metaphone Index\" " " xflaim:DictNumber=\"77\"> " // HARD-CODED Dict Num for easy retrieval " <xflaim:ElementComponent " " xflaim:name=\"Word\" " " xflaim:KeyComponent=\"1\" " " xflaim:Required=\"1\" " " xflaim:IndexOn=\"metaphone\"/> " " xflaim:Limit=\"102\" /> " "</xflaim:Index> "; if( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { MAKE_FLM_ERROR_STRING( "Failed to init test state.", m_szDetails, rc); goto Exit; } bDibCreated = TRUE; if( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_FLM_ERROR_STRING( "transBegin failed", m_szDetails, rc); goto Exit; } bTransStarted = TRUE; if( RC_BAD( rc = m_pDb->createElementDef( NULL, "Word", XFLM_TEXT_TYPE, &uiWordDictNum))) { MAKE_FLM_ERROR_STRING( "createElementDef failed.", m_szDetails, rc); goto Exit; } beginTest( "Metaphone Missing Index Key Creation Test", "Ensure index keys created properly if node has no value.", "Self-explanatory", ""); for( uiLoop = 0; uiLoop < sizeof(pui64DocIds)/sizeof(pui64DocIds[0]); uiLoop++) { //Create a node with a word attribute with a value of a correctly-spelled word if ( RC_BAD( rc = m_pDb->createRootElement(XFLM_DATA_COLLECTION, ELM_ELEMENT_TAG, &pRoot))) { MAKE_FLM_ERROR_STRING( "createRootElement failed.", m_szDetails, rc); goto Exit; } if( RC_BAD( rc = pRoot->getNodeId( m_pDb, &pui64DocIds[ uiLoop]))) { goto Exit; } if( RC_BAD( rc = pRoot->createNode( m_pDb, ELEMENT_NODE, uiWordDictNum, XFLM_FIRST_CHILD, &pChild))) { MAKE_FLM_ERROR_STRING( "createNode failed.", m_szDetails, rc); goto Exit; } } if ( RC_BAD( rc = importBuffer( pszIndexDef, XFLM_DICT_COLLECTION))) { goto Exit; } // Now, we should be able to locate every misspelled word in our list if ( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pSearchKey))) { MAKE_FLM_ERROR_STRING( "createIFDataVector failed.", m_szDetails, rc); goto Exit; } for( uiLoop = 0; uiLoop < sizeof(pui64DocIds)/sizeof(pui64DocIds[0]); uiLoop++) { if( uiLoop == 0) { if ( RC_BAD( rc = m_pDb->keyRetrieve( 77, NULL, XFLM_FIRST, pSearchKey))) { MAKE_FLM_ERROR_STRING( "keyRetrieve failed.", m_szDetails, rc); goto Exit; } } else { rc = m_pDb->keyRetrieve( 77, pSearchKey, XFLM_EXCL | XFLM_MATCH_DOC_ID, pSearchKey); } for( uiLoop2 = 0; uiLoop2 < sizeof(pui64DocIds)/sizeof(pui64DocIds[0]); uiLoop2++) { if ( pui64DocIds[uiLoop2] == pSearchKey->getDocumentID()) { // "tag" the document ID once we've found it pui64DocIds[uiLoop2] = 0; break; } } } // Make sure we got all the document ids for( uiLoop2 = 0; uiLoop2 < sizeof(pui64DocIds)/sizeof(pui64DocIds[0]); uiLoop2++) { if ( pui64DocIds[uiLoop2] != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_FLM_ERROR_STRING( "Key iteration failed", m_szDetails, rc); goto Exit; } } rc = m_pDb->keyRetrieve( 77, pSearchKey, XFLM_EXCL | XFLM_MATCH_DOC_ID, pSearchKey); if ( rc == NE_XFLM_EOF_HIT) { rc = NE_XFLM_OK; } else { MAKE_FLM_ERROR_STRING( "Too many keys", m_szDetails, rc); rc = RC_SET( NE_XFLM_DATA_ERROR); goto Exit; } endTest("PASS"); Exit: if ( RC_BAD( rc)) { endTest("FAIL"); } if ( pSearchKey) { pSearchKey->Release(); } if( pRoot) { pRoot->Release(); } if( pChild) { pChild->Release(); } if ( bTransStarted) { m_pDb->transCommit(); } shutdownTestState( DB_NAME_STR, bDibCreated); return( rc); }
/**************************************************************************** Desc: ****************************************************************************/ RCODE SortKeyTestImpl::verifyQuery( const char * pszQuery, char* ppszNames[][ 2], IF_Query * pQuery, FLMUINT uiNumNames, FLMBOOL bFirstAscending, FLMBOOL bLastAscending, FLMBOOL bDocsIndexed, FLMBOOL bIxFirstAscending, FLMBOOL bIxLastAscending) { RCODE rc = NE_XFLM_OK; IF_DOMNode * pResultNode = NULL; IF_DOMNode * pFirstNameNode = NULL; IF_DOMNode * pLastNameNode = NULL; FLMUINT uiLoop; FLMUINT uiPos; char szBuf[ 100]; IF_DataVector * pSearchKey = NULL; char szTestName[ 200]; static FLMUINT uiCallCount = 0; const char * pszTestNameFormat = "Verify Query #%u " "(%s/First Name Asc == %u/Last Name Asc ==%u/%s)"; uiCallCount++; f_sprintf( szTestName, pszTestNameFormat, uiCallCount, pszQuery, (unsigned)bFirstAscending, (unsigned)bLastAscending, "positioning"); beginTest( szTestName, "Ensure queries return proper results in proper order", "No Additional Info", ""); // positioning tests if ( RC_BAD( rc = pQuery->setupQueryExpr( m_pDb, pszQuery))) { MAKE_FLM_ERROR_STRING( "setupQueryExpr failed.", m_szDetails, rc); goto Exit; } if ( bDocsIndexed && (bFirstAscending == bIxFirstAscending && bLastAscending == bIxLastAscending)) { pQuery->setIndex( IX_NUM); } if ( RC_BAD( rc = pQuery->enablePositioning())) { MAKE_FLM_ERROR_STRING( "enablePositioning failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = createSortKey( pQuery, bFirstAscending, bLastAscending))) { goto Exit; } for( uiLoop = 0; uiLoop < uiNumNames; uiLoop++) { if ( RC_BAD( rc = pQuery->positionTo( m_pDb, &pResultNode, 0, uiLoop))) { MAKE_FLM_ERROR_STRING( "positionTo failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pResultNode->getFirstChild( m_pDb, &pFirstNameNode))) { MAKE_FLM_ERROR_STRING( "getFirstChild failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pFirstNameNode->getNextSibling( m_pDb, &pLastNameNode))) { MAKE_FLM_ERROR_STRING( "getNextSibling failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pFirstNameNode->getUTF8( m_pDb, (FLMBYTE *)szBuf, sizeof( szBuf), 0, sizeof( szBuf) - 1))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed.", m_szDetails, rc); goto Exit; } if ( f_strcmp( szBuf, ppszNames[uiLoop][0]) != 0) { rc = RC_SET( NE_XFLM_FAILURE); MAKE_FLM_ERROR_STRING( "Unexpected value.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pLastNameNode->getUTF8( m_pDb, (FLMBYTE *)szBuf, sizeof( szBuf), 0, sizeof( szBuf) - 1))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed.", m_szDetails, rc); goto Exit; } if ( f_strcmp( szBuf, ppszNames[uiLoop][1]) != 0) { rc = RC_SET( NE_XFLM_FAILURE); MAKE_FLM_ERROR_STRING( "Unexpected value.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pQuery->getPosition( m_pDb, &uiPos))) { MAKE_FLM_ERROR_STRING( "getPosition failed.", m_szDetails, rc); goto Exit; } if ( uiPos != uiLoop) { rc = RC_SET( NE_XFLM_FAILURE); MAKE_FLM_ERROR_STRING( "Unexpected position", m_szDetails, rc); goto Exit; } } endTest("PASS"); f_sprintf( szTestName, pszTestNameFormat, uiCallCount, pszQuery, (unsigned)bFirstAscending, (unsigned)bLastAscending, "search key positioning"); beginTest( szTestName, "Ensure queries return proper results in proper order", "No Additional Info", ""); if( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pSearchKey))) { goto Exit; } // positioning tests 2 for( uiLoop = 0; uiLoop < uiNumNames; uiLoop++) { if ( uiLoop == 0) { if ( RC_BAD( rc = pQuery->positionTo( m_pDb, &pResultNode, 0, pSearchKey, XFLM_FIRST))) { MAKE_FLM_ERROR_STRING( "positionTo failed.", m_szDetails, rc); goto Exit; } } else { if ( RC_BAD( rc = pSearchKey->setUTF8( 0, (FLMBYTE *)ppszNames[uiLoop][0]))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pSearchKey->setUTF8( 1, (FLMBYTE *)ppszNames[uiLoop][1]))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pQuery->positionTo( m_pDb, &pResultNode, 0, pSearchKey, XFLM_EXACT))) { MAKE_FLM_ERROR_STRING( "positionTo failed.", m_szDetails, rc); goto Exit; } } if ( RC_BAD( rc = pResultNode->getFirstChild( m_pDb, &pFirstNameNode))) { MAKE_FLM_ERROR_STRING( "getFirstChild failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pFirstNameNode->getNextSibling( m_pDb, &pLastNameNode))) { MAKE_FLM_ERROR_STRING( "getNextSibling failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pFirstNameNode->getUTF8( m_pDb, (FLMBYTE *)szBuf, sizeof( szBuf), 0, sizeof( szBuf) - 1))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed.", m_szDetails, rc); goto Exit; } if ( f_strcmp( szBuf, ppszNames[uiLoop][0]) != 0) { rc = RC_SET( NE_XFLM_FAILURE); MAKE_FLM_ERROR_STRING( "Unexpected value.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pLastNameNode->getUTF8( m_pDb, (FLMBYTE *)szBuf, sizeof( szBuf), 0, sizeof( szBuf) - 1))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed.", m_szDetails, rc); goto Exit; } if ( f_strcmp( szBuf, ppszNames[uiLoop][1]) != 0) { rc = RC_SET( NE_XFLM_FAILURE); MAKE_FLM_ERROR_STRING( "Unexpected value.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pQuery->getPosition( m_pDb, &uiPos))) { MAKE_FLM_ERROR_STRING( "getPosition failed.", m_szDetails, rc); goto Exit; } if ( uiPos != uiLoop) { rc = RC_SET( NE_XFLM_FAILURE); MAKE_FLM_ERROR_STRING( "Unexpected position", m_szDetails, rc); goto Exit; } } endTest("PASS"); Exit: if( RC_BAD( rc)) { endTest("FAIL"); } if( pResultNode) { pResultNode->Release(); } if( pFirstNameNode) { pFirstNameNode->Release(); } if( pLastNameNode) { pLastNameNode->Release(); } if( pSearchKey) { pSearchKey->Release(); } return rc; }
/**************************************************************************** Desc: ****************************************************************************/ RCODE SortKeyTestImpl::execute( void) { RCODE rc = NE_XFLM_OK; FLMBOOL bDibCreated = FALSE; FLMBOOL bTransActive = FALSE; FLMUINT uiFirstNameId = FIRST_NAME_ID; FLMUINT uiLastNameId = LAST_NAME_ID; IF_Query * pQuery = NULL; FLMUINT uiLoop; FLMBOOL bIxFirstAsc = FALSE; FLMBOOL bIxLastAsc = FALSE; FLMBOOL bIndexCreated = FALSE; char* ppszNames[][2] = { {"Rebecca","Betz"}, {"Russell","Bakker"}, {"April","Sansone"}, {"Julie","Betz"}, {"Jason","Betz"}, {"Ronald","Betz"}, {"Shawn","Hafner"}, {"Karen","Bradley"}, {"Mabel","Zepeda"}, {"Kathleen","Ellinger"}, {"Victor","Tankersley"}, {"Leonard","Kuehn"}, {"Danny","Decastro"}, {"Harold","Bergeron"}, {"Annette","Sartin"}, {"Anthony","Glasser"}, {"Albert","Glasser"}, {"Yvette","Patch"}, {"Joyce","Lundberg"}, {"John","Reinhold"}, {"Kristen","Hansel"}, {"Victor","Schell"}, {"Patrick","Belt"}, {"Gina","Belt"}, {"Brenda","Ellis"}, {"Maryann","Sumpter"}, {"Samantha","Beckford"}, {"Carl","Collette"}, {"Carl","Davis"}, {"Kristina","Tso"}, {"Jeanne","Leonard"}, {"Patty","Ogletree"}, {"Alan","Villa"}, {"Carl","Wacker"}, {"Lawrence","Kent"}, }; beginTest( "Sorting/Positioning Query Test Setup", "Prepare database to test sorted and positionable queries", "", ""); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { goto Exit; } bDibCreated = TRUE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_FLM_ERROR_STRING( "transBegin failed.", m_szDetails, rc); goto Exit; } bTransActive = TRUE; if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "first_name", XFLM_TEXT_TYPE, &uiFirstNameId, NULL))) { MAKE_FLM_ERROR_STRING( "createElementDef failed.", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createElementDef( NULL, "last_name", XFLM_TEXT_TYPE, &uiLastNameId, NULL))) { MAKE_FLM_ERROR_STRING( "createElementDef failed.", m_szDetails, rc); goto Exit; } // create all of our documents for ( uiLoop = 0; uiLoop < ELEMCOUNT(ppszNames); uiLoop++) { if ( RC_BAD( rc = createNameDoc( ppszNames[uiLoop]))) { goto Exit; } } if ( RC_BAD( rc = m_pDbSystem->createIFQuery( &pQuery))) { MAKE_FLM_ERROR_STRING( "createIFQuery failed.", m_szDetails, rc); goto Exit; } endTest("PASS"); for( uiLoop = 0; uiLoop < 5; uiLoop++) { // We have to commit all our changes here because when result sets are // built in the background, the F_Db the background thread receives to // work with is created via a call to dbDup() and will not have knowledge // of any uncommitted changes made to the database. If this issue is ever // fixed, remove these calls to transCommit and transBegin. if ( RC_BAD( rc = m_pDb->transCommit())) { MAKE_FLM_ERROR_STRING( "createIFQuery failed.", m_szDetails, rc); goto Exit; } bTransActive = FALSE; if ( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_FLM_ERROR_STRING( "createIFQuery failed.", m_szDetails, rc); goto Exit; } bTransActive = TRUE; // no index the first time throug... { const char * pszQuery = "//first_name[.==\"Carl\"]"; char * pszResults[][3][2] = { {{"Carl","Wacker"},{"Carl","Davis"},{"Carl","Collette"}}, // desc,desc {{"Carl","Collette"},{"Carl","Davis"},{"Carl","Wacker"}}, // desc,asc {{"Carl","Wacker"},{"Carl","Davis"},{"Carl","Collette"}}, // asc,desc {{"Carl","Collette"},{"Carl","Davis"},{"Carl","Wacker"}}, // asc,asc }; if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[0], pQuery, ELEMCOUNT(pszResults[0]), FALSE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[1], pQuery, ELEMCOUNT(pszResults[1]), FALSE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[2], pQuery, ELEMCOUNT(pszResults[2]), TRUE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[3], pQuery, ELEMCOUNT(pszResults[3]), TRUE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } } { const char * pszQuery = "//last_name[.==\"Glasser\"]"; char * pszResults[][2][2] = { {{"Anthony","Glasser"},{"Albert","Glasser"}}, // desc,desc {{"Anthony","Glasser"},{"Albert","Glasser"}}, // desc,asc {{"Albert","Glasser"},{"Anthony","Glasser"}}, // asc,desc {{"Albert","Glasser"},{"Anthony","Glasser"}}, // asc,asc }; if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[0], pQuery, ELEMCOUNT(pszResults[0]), FALSE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[1], pQuery, ELEMCOUNT(pszResults[1]), FALSE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[2], pQuery, ELEMCOUNT(pszResults[2]), TRUE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[3], pQuery, ELEMCOUNT(pszResults[3]), TRUE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } } { const char * pszQuery = "//first_name[. >= \"C\" && . < \"J\"]"; char * pszResults[][6][2] = { { // Desc, Desc {"Harold","Bergeron"}, {"Gina","Belt"}, {"Danny","Decastro"}, {"Carl","Wacker"}, {"Carl","Davis"}, {"Carl","Collette"}, }, { // Desc, Asc {"Harold","Bergeron"}, {"Gina","Belt"}, {"Danny","Decastro"}, {"Carl","Collette"}, {"Carl","Davis"}, {"Carl","Wacker"}, }, { // Asc, Desc {"Carl","Wacker"}, {"Carl","Davis"}, {"Carl","Collette"}, {"Danny","Decastro"}, {"Gina","Belt"}, {"Harold","Bergeron"}, }, { // Asc, Asc {"Carl","Collette"}, {"Carl","Davis"}, {"Carl","Wacker"}, {"Danny","Decastro"}, {"Gina","Belt"}, {"Harold","Bergeron"}, }, }; if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[0], pQuery, ELEMCOUNT(pszResults[0]), FALSE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[1], pQuery, ELEMCOUNT(pszResults[1]), FALSE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[2], pQuery, ELEMCOUNT(pszResults[2]), TRUE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[3], pQuery, ELEMCOUNT(pszResults[3]), TRUE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } } { const char * pszQuery = "//last_name[. >= \"Betz\" && . <= \"Davis\"]"; char * pszResults[][7][2] = { {// Desc, Desc {"Ronald","Betz"}, {"Rebecca","Betz"}, {"Karen","Bradley"}, {"Julie","Betz"}, {"Jason","Betz"}, {"Carl","Davis"}, {"Carl","Collette"}, }, {// Desc, Asc {"Ronald","Betz"}, {"Rebecca","Betz"}, {"Karen","Bradley"}, {"Julie","Betz"}, {"Jason","Betz"}, {"Carl","Collette"}, {"Carl","Davis"}, }, {// Asc, Desc {"Carl","Davis"}, {"Carl","Collette"}, {"Jason","Betz"}, {"Julie","Betz"}, {"Karen","Bradley"}, {"Rebecca","Betz"}, {"Ronald","Betz"}, }, {// Asc, Asc {"Carl","Collette"}, {"Carl","Davis"}, {"Jason","Betz"}, {"Julie","Betz"}, {"Karen","Bradley"}, {"Rebecca","Betz"}, {"Ronald","Betz"}, }, }; if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[0], pQuery, ELEMCOUNT(pszResults[0]), FALSE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[1], pQuery, ELEMCOUNT(pszResults[1]), FALSE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[2], pQuery, ELEMCOUNT(pszResults[2]), TRUE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[3], pQuery, ELEMCOUNT(pszResults[3]), TRUE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } } { const char * pszQuery = "//first_name[.==\"A*\" or .==\"J*\"]"; char * pszResults[][10][2] = { { //Desc, Desc {"Julie","Betz"}, {"Joyce","Lundberg"}, {"John","Reinhold"}, {"Jeanne","Leonard"}, {"Jason","Betz"}, {"April","Sansone"}, {"Anthony","Glasser"}, {"Annette","Sartin"}, {"Albert","Glasser"}, {"Alan","Villa"}, }, { //Desc, Asc {"Julie","Betz"}, {"Joyce","Lundberg"}, {"John","Reinhold"}, {"Jeanne","Leonard"}, {"Jason","Betz"}, {"April","Sansone"}, {"Anthony","Glasser"}, {"Annette","Sartin"}, {"Albert","Glasser"}, {"Alan","Villa"}, }, { //Asc, Desc {"Alan","Villa"}, {"Albert","Glasser"}, {"Annette","Sartin"}, {"Anthony","Glasser"}, {"April","Sansone"}, {"Jason","Betz"}, {"Jeanne","Leonard"}, {"John","Reinhold"}, {"Joyce","Lundberg"}, {"Julie","Betz"}, }, { //Asc, Asc {"Alan","Villa"}, {"Albert","Glasser"}, {"Annette","Sartin"}, {"Anthony","Glasser"}, {"April","Sansone"}, {"Jason","Betz"}, {"Jeanne","Leonard"}, {"John","Reinhold"}, {"Joyce","Lundberg"}, {"Julie","Betz"}, }, }; if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[0], pQuery, ELEMCOUNT(pszResults[0]), FALSE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[1], pQuery, ELEMCOUNT(pszResults[1]), FALSE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[2], pQuery, ELEMCOUNT(pszResults[2]), TRUE, FALSE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } if ( RC_BAD( rc = verifyQuery( pszQuery, pszResults[3], pQuery, ELEMCOUNT(pszResults[3]), TRUE, TRUE, bIndexCreated, bIxFirstAsc, bIxLastAsc))) { goto Exit; } } switch( uiLoop) { case 0: bIxFirstAsc = FALSE; bIxLastAsc = FALSE; break; case 1: bIxFirstAsc = FALSE; bIxLastAsc = TRUE; break; case 2: bIxFirstAsc = TRUE; bIxLastAsc = FALSE; break; case 3: bIxFirstAsc = TRUE; bIxLastAsc = TRUE; break; default: break; } if ( RC_BAD( rc = createOrModifyIndex( IX_NUM, !bIxFirstAsc, TRUE, FALSE, !bIxLastAsc, FALSE))) { goto Exit; } bIndexCreated = TRUE; } Exit: if ( pQuery) { pQuery->Release(); } if( bTransActive) { if ( RC_BAD( rc)) { m_pDb->transAbort(); } else { rc = m_pDb->transCommit(); } } shutdownTestState( DB_NAME_STR, bDibCreated); return( rc); }
/**************************************************************************** Desc: ****************************************************************************/ RCODE IRegressionTestImpl::rflRecoverDefectTests( void) { RCODE rc = NE_XFLM_OK; IF_Backup * pBackup = NULL; IF_DOMNode * pNode = NULL; FLMUINT uiDefNum; FLMBOOL bStartedTrans = FALSE; FLMBOOL bDibCreated = FALSE; FLMUINT uiEncDef = 0; IF_DataVector * pSearchKey = NULL; char szTmp[ 100]; FLMUINT uiTmp = 0; const char * pszIndex = "<xflaim:Index " "xmlns:xflaim=\"http://www.novell.com/XMLDatabase/Schema\" " "xflaim:name=\"text_val_IX\" " "xflaim:DictNumber=\"99\">" "<xflaim:ElementComponent xflaim:name=\"text_val\" " "xflaim:KeyComponent=\"1\" " "xflaim:Required=\"yes\" " "xflaim:type=\"string\" " "xflaim:IndexOn=\"value\" />" "</xflaim:Index>"; beginTest( "RFL Recover Defect Test", "Ensure a bug that was causing a corruption when replaying set text value " "operations of zero length has been fixed/Ensure a bug that was causing indexes " "to not be updated when recovering node update packets has been fixed", "", "No Additional Details."); if ( RC_BAD( rc = initCleanTestState( DB_NAME_STR))) { MAKE_FLM_ERROR_STRING( "Failed to initialize test state.", m_szDetails, rc); goto Exit; } bDibCreated = TRUE; if( RC_BAD( rc = m_pDb->setRflKeepFilesFlag( TRUE))) { MAKE_FLM_ERROR_STRING( "setRflKeepFilesFlag failed", m_szDetails, rc); goto Exit; } // Backup the database if( RC_BAD( rc = m_pDb->backupBegin( XFLM_FULL_BACKUP, XFLM_READ_TRANS, 0, &pBackup))) { MAKE_FLM_ERROR_STRING( "backupBegin failed", m_szDetails, rc); goto Exit; } if( RC_BAD( rc = pBackup->backup( BACKUP_NAME_STR, NULL, NULL, NULL, NULL))) { MAKE_FLM_ERROR_STRING( "backup failed", m_szDetails, rc); goto Exit; } pBackup->Release(); pBackup = NULL; // Start an update transaction if( RC_BAD( rc = m_pDb->transBegin( XFLM_UPDATE_TRANS))) { MAKE_FLM_ERROR_STRING( "transBegin failed", m_szDetails, rc); goto Exit; } bStartedTrans = TRUE; // Create some schema definitions uiDefNum = 0; if( RC_BAD( rc = m_pDb->createElementDef( NULL, "text_val", XFLM_TEXT_TYPE, &uiDefNum))) { MAKE_FLM_ERROR_STRING( "createElementDef failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->createRootElement( XFLM_DATA_COLLECTION, uiDefNum, &pNode))) { MAKE_FLM_ERROR_STRING( "createRootElement failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)""))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed", m_szDetails, rc); goto Exit; } // Create an index on text_val if ( RC_BAD( rc = importBuffer( pszIndex, XFLM_DICT_COLLECTION))) { goto Exit; } // create an encryption definition #ifdef FLM_USE_NICI if ( RC_BAD( rc = m_pDb->createEncDef("aes", "aes_def", 0, &uiEncDef))) { MAKE_FLM_ERROR_STRING( "createEncDef failed", m_szDetails, rc); goto Exit; } #endif // modify the node value a few times with encryption. // This will generate node update packets if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"text_val_1", 0, TRUE, uiEncDef))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"text_val_2", 0, TRUE, uiEncDef))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = pNode->setUTF8( m_pDb, (FLMBYTE *)"text_val_3", 0, TRUE, uiEncDef))) { MAKE_FLM_ERROR_STRING( "setUTF8 failed", m_szDetails, rc); goto Exit; } // validate the key if ( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pSearchKey))) { MAKE_FLM_ERROR_STRING( "createIFDataVector failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->keyRetrieve( 99, NULL, XFLM_FIRST | XFLM_MATCH_DOC_ID, pSearchKey))) { MAKE_FLM_ERROR_STRING( "No index keys generated", m_szDetails, rc); goto Exit; } uiTmp = sizeof(szTmp); if ( RC_BAD( rc = pSearchKey->getUTF8( 0, (FLMBYTE *)szTmp, &uiTmp))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed", m_szDetails, rc); goto Exit; } pSearchKey->Release(); pSearchKey = NULL; if ( f_strcmp( szTmp, "text_val_3") != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_FLM_ERROR_STRING( "Invalid key found", m_szDetails, rc); goto Exit; } // Commit the transaction if( RC_BAD( rc = m_pDb->transCommit())) { MAKE_FLM_ERROR_STRING( "transCommit failed", m_szDetails, rc); goto Exit; } bStartedTrans = FALSE; m_pDb->Release(); m_pDb = NULL; if( RC_BAD( rc = m_pDbSystem->closeUnusedFiles( 0))) { MAKE_FLM_ERROR_STRING( "closeUnusedFiles failed", m_szDetails, rc); goto Exit; } // Remove the database if( RC_BAD( rc = m_pDbSystem->dbRemove( DB_NAME_STR, NULL, NULL, FALSE))) { MAKE_FLM_ERROR_STRING( "dbRemove failed", m_szDetails, rc); goto Exit; } // Restore the database if( RC_BAD( rc = m_pDbSystem->dbRestore( DB_NAME_STR, NULL, NULL, BACKUP_NAME_STR, NULL, NULL, NULL))) { MAKE_FLM_ERROR_STRING( "dbRestore failed", m_szDetails, rc); goto Exit; } if( RC_BAD( rc = m_pDbSystem->dbOpen( DB_NAME_STR, NULL, NULL, NULL, FALSE, &m_pDb))) { MAKE_FLM_ERROR_STRING( "dbOpen failed", m_szDetails, rc); goto Exit; } // Validate the key for the index to make sure it was restored properly if ( RC_BAD( rc = m_pDbSystem->createIFDataVector( &pSearchKey))) { MAKE_FLM_ERROR_STRING( "createIFDataVector failed", m_szDetails, rc); goto Exit; } if ( RC_BAD( rc = m_pDb->keyRetrieve( 99, NULL, XFLM_FIRST | XFLM_MATCH_DOC_ID, pSearchKey))) { MAKE_FLM_ERROR_STRING( "No index keys generated", m_szDetails, rc); goto Exit; } uiTmp = sizeof(szTmp); if ( RC_BAD( rc = pSearchKey->getUTF8( 0, (FLMBYTE *)szTmp, &uiTmp))) { MAKE_FLM_ERROR_STRING( "getUTF8 failed", m_szDetails, rc); goto Exit; } if ( f_strcmp( szTmp, "text_val_3") != 0) { rc = RC_SET( NE_XFLM_DATA_ERROR); MAKE_FLM_ERROR_STRING( "Invalid key found", m_szDetails, rc); goto Exit; } endTest("PASS"); Exit: if ( RC_BAD( rc)) { endTest("FAIL"); } if (bStartedTrans) { m_pDb->transAbort(); } if ( pSearchKey) { pSearchKey->Release(); } if( pBackup) { pBackup->Release(); } if( pNode) { pNode->Release(); } shutdownTestState( DB_NAME_STR, bDibCreated); return rc; }
int main(void){ unsigned tid = 0, i; ThreadCB* th; TList* queue1 = tlNewList(); TList* queue2 = tlNewList(); TList* prioliste1 = tlNewList(); TList* prioliste2 = tlNewList(); // show empty queues ------------------------------------------------------- beginTest(); printList(queue1, "queue1 -> empty"); printList(queue2, "queue2 -> empty"); printList(prioliste1, "prioliste1 -> empty"); printList(prioliste2, "prioliste2 -> empty"); endTest(); // add one thread to queue 2 ----------------------------------------------- beginTest(); th = mtNewThread(tid++, 1, 40); tlEnqueue(queue2, th); printList(queue2, "queue2, after one put"); // put last 5 threads ------------------------------------------------------ tlEnqueue(queue2, mtNewThread(tid++,1,20)); tlEnqueue(queue2, mtNewThread(tid++,1,30)); tlEnqueue(queue2, mtNewThread(tid++,2,35)); tlEnqueue(queue2, mtNewThread(tid++,3,50)); tlEnqueue(queue2, mtNewThread(tid++,3,10)); printFirst(queue2, "queue2 after 6 puts"); printList(queue2, "queue2 after 6 puts"); endTest(); // move threads between queues --------------------------------------------- beginTest(); printList(prioliste1, "prioliste1 -> empty"); tlSortIn(prioliste1, mtNewThread(tid++, 4,1000)); tlSortIn(prioliste1, mtNewThread(tid++, 4, 999)); for (i = 1; i <= 6; i++) { printFirst(queue2, "--->> queue2, for-loop before pop"); th = tlDequeue(queue2); if (th == NULL) printf("\t th == NULL at iteration i = %d", i); else { printList(queue2, "queue2, for-loop after pop"); tlEnqueue(queue1, th); // in andere Queue einreihen tlSortIn(prioliste1, th); // in die sort.Liste einreihen printList(prioliste1, "prioliste1, for-loop"); } } printList(queue2, "queue2, after 1. for loop"); printList(prioliste1, "prioliste1, after 1. for loop"); printList(queue1, "queue1, after 1. for loop"); endTest(); // add a lot of threds to queue 1 then pop 590 threads beginTest(); for (i = 1; i < 200; i++) { tlSortIn(prioliste1, mtNewThread(tid++, 5, 500+2*i)); } for (i = 1; i < 200; i++) { tlSortIn(prioliste1, mtNewThread(tid++, 6, 401+2*i)); } for (i = 1; i < 200; i++) { tlSortIn(prioliste1, mtNewThread(tid++, 7, 600+2*i)); } for (i=1; i<590; i++) { th = tlDequeue(prioliste1); mtDelThread(th); } printList(prioliste1, "prioliste1, after 600 SortIns and 590 pops"); getchar(); printList(queue1, "queue1 before end"); getchar(); // just to wait here printList(queue2, "queue2 before end"); getchar(); printList(prioliste2, "prioliste2, before end"); getchar(); // just to wait here tlDelList(queue1); tlDelList(queue2); tlDelList(prioliste1); tlDelList(prioliste2); }