Update contrib.
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
25 #undef __UHEAP_MARKEND
27 #define __UHEAP_MARKEND
29 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
31 #ifndef __linux__ //No CRC test on LINUX
33 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_DEFECT.CRC");
35 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_DEFECT.CRC");
40 LOCAL_D RTest TheTest (_L ("t_defect.exe"));
41 LOCAL_D CTrapCleanup* TheTrapCleanup = NULL;
43 LOCAL_D RSemaphore TheWaitToStartSem;
44 LOCAL_D RSemaphore TheWaitForThreadsReadySem;
47 LOCAL_D RDbs TheDbs1, TheDbs2;
48 LOCAL_D RDbNamedDatabase TheDb1, TheDb2;
50 _LIT (KName, "ConnectTestThread_");
51 _LIT (KStart, "Starting thread %x.\n");
52 _LIT (KConnect, "Thread %x: Waiting to connect...\n");
53 _LIT (KConSuccess, "Thread %x: Connection succeeded.\n");
54 _LIT (KConFailed, "Thread %x: Connection failed. Error %d.\n");
55 _LIT (KStatus, "Status of thread %x is %d.\n");
58 _LIT(KTable, "TABLE");
59 _LIT(KColName, "Fld");
60 _LIT(KCol2Name, "Fld2");
63 const TPtrC KDbName=_L("C:\\dbms-tst\\TESTDB22.DB");
65 const TPtrC KDbName=_L(".\\dbms-tst\\TESTDB22.DB");
68 _LIT(KSQLInsert1, "INSERT INTO TABLE (Fld, Fld2) VALUES ('ACDC\\','BLAH')");
69 _LIT(KSQLInsert2, "INSERT INTO TABLE (Fld) VALUES ('ABCDEFGH')");
70 _LIT(KSQLInsert3, "INSERT INTO TABLE (Fld) VALUES ('A?CDEFGH')");
71 _LIT(KSQLInsert4, "INSERT INTO TABLE (Fld) VALUES ('A?*?CDEFGH')");
72 _LIT(KSQLInsert5, "INSERT INTO TABLE (Fld) VALUES ('A*CDEFGH')");
73 _LIT(KSQLInsert6, "INSERT INTO TABLE (Fld, Fld2) VALUES ('ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP','ADCB')");
74 _LIT(KSQLInsert7, "INSERT INTO TABLE (Fld) VALUES ('XZD\\FZX')");
76 _LIT(KSqlRequestGranularity, "SELECT Fld FROM test WHERE (Fld LIKE '1' AND Fld LIKE '2') AND Fld LIKE '3' AND Fld LIKE '4' AND Fld LIKE '5' AND Fld LIKE '6'");
78 _LIT(KText16Name, "text16");
79 _LIT(KTableName, "test");
80 _LIT(KIndexName, "test_index");
81 _LIT(KMaxStringFormat, "%0256d");
91 (void)TheFs.Delete(KDbName);
93 TheCrcChecker.GenerateCrcL(KDbName);
96 //-----------------------------------------------------------------------------
98 // Test macros and functions.
100 //-----------------------------------------------------------------------------
101 // If (!aValue) then the test will be panicked, the test data files will be
103 LOCAL_C void Check(TInt aValue, TInt aLine)
108 TheTest(EFalse, aLine);
113 // If (aValue != aExpected) then the test will be panicked, the test data files
115 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
117 if(aValue != aExpected)
119 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
121 TheTest(EFalse, aLine);
126 //Use these to test conditions.
127 #define TEST(arg) ::Check((arg), __LINE__)
128 #define TEST2(aValue, aExpected) ::Check((aValue), (aExpected), __LINE__)
129 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
138 const TTest KQuery[]=
140 {_S("ACDC\\"),_S("SELECT Fld FROM TABLE WHERE Fld LIKE 'ACDC\\' AND Fld2 LIKE '*BL*'")},
141 {_S("A*CDEFGH"),_S("SELECT * FROM TABLE WHERE Fld LIKE '*A\\*C*' ESCAPE '\\'")},
142 {_S("A?CDEFGH"),_S("SELECT * FROM TABLE WHERE Fld LIKE '*A\\?C*' ESCAPE '\\'")},
143 {_S("A?*?CDEFGH"),_S("SELECT * FROM TABLE WHERE Fld LIKE '*A\\?\\*\\?C*' ESCAPE '\\'")},
144 {_S("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"),_S("SELECT * FROM TABLE WHERE Fld LIKE '*1234*'")},
145 {_S("BLAH"),_S("SELECT Fld2 FROM TABLE WHERE Fld LIKE '*AC*' AND Fld2 LIKE '?LA?'")},
146 {_S("BLAH"),_S("SELECT Fld2 FROM TABLE WHERE Fld LIKE 'NOTINTABLE' OR Fld2 LIKE '?LA?'")},
147 {_S("ADCDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOPQRSTUVWXYZ123456789ACDEFGHIJKLMNOP"),_S("SELECT * FROM TABLE WHERE Fld LIKE '*ADC*' AND Fld2 LIKE 'ADC?'")},
148 {_S("A*CDEFGH"),_S("SELECT Fld FROM TABLE WHERE Fld LIKE '*\\*C*' ESCAPE '\\'")},
149 {_S("XZD\\FZX"),_S("SELECT Fld FROM TABLE WHERE Fld LIKE '*D\\\\*' ESCAPE '\\'")}
152 const TTest KBadQuery[]=
154 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE 'A?C' ESCAPE '\\'")},
155 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE 'A*C' ESCAPE '\\'")},
156 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE '?A\\?C' ESCAPE '\\'")},
157 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE '?A\\?C?' ESCAPE '\\'")},
158 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE '*A\\??\\?C*' ESCAPE '\\'")},
159 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE '*A*\\*C*' ESCAPE '\\'")},
160 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE 'ABC' ESCAPE '\\'")},
161 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE 'ABC*' ESCAPE '\\'")},
162 {_S(""),_S("SELECT * FROM TABLE WHERE Fld LIKE '*ABC' ESCAPE '\\'")}
165 const TInt KNumQueries = 10;
166 const TInt KNumBadQueries = 9;
167 const TInt KThreadCount = 3;
168 const TInt KOneSecond = 1000000;
169 const TInt KDbNameLen = 255;
170 const TInt KMaxColName = 32;
173 static void DoDbmsConnectThreadSubFunctionL (TInt aThreadNumber)
177 CleanupClosePushL (TheDbSession);
179 RDebug::Print (KStart (), aThreadNumber);
180 RDebug::Print (KConnect (), aThreadNumber);
182 // Signal the main thread to continue
183 TheWaitForThreadsReadySem.Signal (1);
185 // Wait until we are signalled
186 TheWaitToStartSem.Wait ();
189 TInt r = TheDbSession.Connect ();
193 RDebug::Print (KConSuccess (), aThreadNumber);
194 TheDbSession.Close ();
198 RDebug::Print (KConFailed (), aThreadNumber, r);
202 CleanupStack::PopAndDestroy (1); // session
205 static TInt DoDbmsConnectThread (TAny* aThreadNumber)
209 CTrapCleanup* trapCleanup = CTrapCleanup::New ();
210 __ASSERT_ALWAYS (trapCleanup!=NULL, User::Invariant ());
212 TInt* threadNumber = static_cast <TInt*> (aThreadNumber);
213 TRAPD (err, DoDbmsConnectThreadSubFunctionL (*threadNumber));
223 #ifndef TOOLS2_VARIANT
225 @SYMTestCaseID SYSLIB-DBMS-CT-0644
226 @SYMTestCaseDesc Test for defect no 44697
227 @SYMTestPriority Medium
228 @SYMTestActions Test for defect fixes
229 @SYMTestExpectedResults Test must not fail
232 LOCAL_C void Defect_DEF44697L ()
234 TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-DBMS-CT-0644 Defect_DEF44697L "));
238 // find out the number of open handles
239 TInt startProcessHandleCount;
240 TInt startThreadHandleCount;
241 RThread ().HandleCount (startProcessHandleCount, startThreadHandleCount);
243 /////////////////////
244 // The Test Begins...
247 ::CleanupClosePushL (::TheWaitForThreadsReadySem);
248 User::LeaveIfError (::TheWaitForThreadsReadySem.CreateLocal (0));
250 ::CleanupClosePushL (::TheWaitToStartSem);
251 User::LeaveIfError (::TheWaitToStartSem.CreateLocal (0));
253 // Create the threads.
254 RThread createTestThread_1;
255 RThread createTestThread_2;
256 RThread createTestThread_3;
258 TBuf<100> thread_name;
259 TInt KThreadNumber1 = 1;
260 TInt KThreadNumber2 = 2;
261 TInt KThreadNumber3 = 3;
263 // Create the first test thread______________________________
264 thread_name = KName ();
265 thread_name.AppendNum (KThreadNumber1);
268 createTestThread_1.Create (thread_name,
269 (TThreadFunction) DoDbmsConnectThread,
275 // Default priority of Main thread is EPriorityNormal
276 createTestThread_1.SetPriority(EPriorityMore);
278 TheTest.Printf (_L ("%S thread started\n"), &thread_name);
280 // Request notification when the thread dies.
281 TRequestStatus threadStatus_1;
282 createTestThread_1.Logon (threadStatus_1);
284 //___________________________________________________________
286 // Create the second test thread______________________________
287 thread_name = KName ();
288 thread_name.AppendNum (KThreadNumber2);
291 createTestThread_2.Create (thread_name,
292 (TThreadFunction) DoDbmsConnectThread,
298 // Default priority of Main thread is EPriorityNormal
299 createTestThread_2.SetPriority(EPriorityMore);
301 TheTest.Printf (_L ("%S thread started\n"), &thread_name);
303 // Request notification when the tread dies.
304 TRequestStatus threadStatus_2;
305 createTestThread_2.Logon (threadStatus_2);
307 //___________________________________________________________
309 // Create the third test thread______________________________
310 thread_name = KName ();
311 thread_name.AppendNum (KThreadNumber3);
314 createTestThread_3.Create (thread_name,
315 (TThreadFunction) DoDbmsConnectThread,
321 // Default priority of Main thread is EPriorityNormal
322 createTestThread_3.SetPriority(EPriorityMore);
324 TheTest.Printf (_L ("%S thread started\n"), &thread_name);
326 // Request notification when the tread dies.
327 TRequestStatus threadStatus_3;
328 createTestThread_3.Logon (threadStatus_3);
330 //___________________________________________________________
332 TheTest (threadStatus_1.Int () == KRequestPending);
333 TheTest (threadStatus_2.Int () == KRequestPending);
334 TheTest (threadStatus_3.Int () == KRequestPending);
336 // Make threads eligible for execution
337 createTestThread_1.Resume ();
338 createTestThread_2.Resume ();
339 createTestThread_3.Resume ();
341 // The way this works is that the main thread blocks until all
342 // the test threads are ready (semaphore 1) and then signals them
345 // 1: Main thread Waits for ALL test threads to become ready.
346 // 2: Main thread Signals ALL test threads to run.
348 // 1: Test thread Signals Main thread
349 // 2: Test thread Waits for Main thread
351 // There is still a slight race condition between the
352 // test thread signalling (semaphore 1) and then waiting
353 // (semaphore 2) which is why we use both higher priority test
354 // threads and a timer.
356 // The problems come with the way Time slicing works due to
357 // other threads of higher priority being run.
359 // Higher priority: Ensures the test thread runs before the
362 // Timer: Safeguards when multiple core processors are being used.
364 // The Higher priority fixes the problem on single core processors
365 // and multiple cores processors (SMP) where each core can run a
368 // It should also ensure that if the system is so busy that it
369 // affects the test thread execution, the test thread will still
370 // get to the Wait state before the Main thread can Signal.
372 // However, on multiple cores the Main thread may run at the same
373 // time as the test thread, so we need to make sure that when the
374 // test thread Signals it can acheive its Wait state before the
375 // Main thread Signals. For example, if the timer has elapsed on the
376 // Main thread and the sytem is busy, the test thread should still
377 // run before the Main thread due to it higher priority.
379 // We also have to think about things like priority inheritance
380 // where a thread that has a handle on a Mutex inherits the same
381 // priority as a thread Waiting on it. This shouldn't happen for
382 // Semaphores as there is no one handle, i.e. no critical section.
384 // This higher priority inheritance will take affect when a low
385 // priority thread that has a handle on the Mutex blocks because of
386 // another medium priority running thread. So in effect a high
387 // priority thread Waiting on this Mutex is also blocked.
389 // It is also worth noting that on EKA1 emulator, scheduling is
390 // performed by windows. On EKA2 emulator scheduling is performed
391 // by Symbian so that it is the same as hardware.
393 TheWaitForThreadsReadySem.Wait();
394 TheWaitForThreadsReadySem.Wait();
395 TheWaitForThreadsReadySem.Wait();
397 // Sleep for a while to allow threads to block on the semaphore
398 User::After (KOneSecond<<2); // 4 seconds
400 // Signal all the threads to continue
401 TheWaitToStartSem.Signal (KThreadCount);
403 // Wait for all threads to complete, don't care on the order.
404 User::WaitForRequest (threadStatus_1);
405 User::WaitForRequest (threadStatus_2);
406 User::WaitForRequest (threadStatus_3);
408 TheTest.Printf (KStatus, KThreadNumber1, threadStatus_1.Int ());
409 TheTest.Printf (KStatus, KThreadNumber2, threadStatus_2.Int ());
410 TheTest.Printf (KStatus, KThreadNumber3, threadStatus_3.Int ());
412 TheTest (threadStatus_1.Int () == KErrNone);
413 TheTest (threadStatus_2.Int () == KErrNone);
414 TheTest (threadStatus_3.Int () == KErrNone);
416 CleanupStack::PopAndDestroy (&::TheWaitToStartSem);
417 CleanupStack::PopAndDestroy (&::TheWaitForThreadsReadySem);
420 /////////////////////
422 // check that no handles have leaked
423 TInt endProcessHandleCount;
424 TInt endThreadHandleCount;
425 RThread ().HandleCount (endProcessHandleCount, endThreadHandleCount);
427 TheTest (startThreadHandleCount == endThreadHandleCount);
431 #endif // !TOOLS2_VARIANT
435 // Test for LIKE Predicate for EDbColLongText16
436 LOCAL_C void LikePredicateDbColLongText16TestL()
438 TheTest.Next (_L ("LikePredicateDbColLongText16TestL"));
442 User::LeaveIfError(fsSession.Connect());
443 CleanupClosePushL(fsSession);
444 RDbNamedDatabase database;
445 User::LeaveIfError(database.Replace(fsSession, KDbName));
446 CleanupClosePushL(database);
450 CDbColSet* columns= CDbColSet::NewLC();
452 TDbCol name(KColName,EDbColLongText16,KDbNameLen);
453 name.iAttributes = TDbCol::ENotNull;
455 TDbCol name2(KCol2Name,EDbColLongText16,KDbNameLen);
458 columns->AddL(name2);
459 User::LeaveIfError (database.CreateTable (KTable, *columns));
460 CleanupStack::PopAndDestroy(); // columns
462 // Insert values into table
463 TInt error = database.Execute(KSQLInsert1);
465 error =database.Execute(KSQLInsert2);
467 error =database.Execute(KSQLInsert3);
469 error = database.Execute(KSQLInsert4);
471 error = database.Execute(KSQLInsert5);
473 error = database.Execute(KSQLInsert6);
475 error = database.Execute(KSQLInsert7);
479 TheTest.Next(_L("Test for valid LIKE predicate queries"));
482 for(TInt i =0;i<KNumQueries;++i)
484 RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query));
486 view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly);
489 typedef TBuf<256> TScriptLine;
498 rd.ReadL(text,view.ColLength(1));
499 CleanupStack::PopAndDestroy();
500 RDebug::Print(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&text);
501 TInt err = text.Compare(TPtrC(KQuery[i].result));
509 // test for illegal statements, check they return KErrArgument
510 TheTest.Next(_L("Test that illegal queries return KErrArgument"));
513 for(TInt j =0;j<KNumBadQueries;++j)
515 RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query));
517 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly);
518 TheTest(prepErr==KErrArgument);
522 CleanupStack::PopAndDestroy(&database); // database
523 CleanupStack::PopAndDestroy(&fsSession); // fsSession
528 // for LIKE Predicate for EDbColLongText8
529 LOCAL_C void LikePredicateDbColLongText8TestL()
531 TheTest.Next (_L ("LikePredicate DbColLongText8 TestL"));
536 User::LeaveIfError(fsSession.Connect());
537 CleanupClosePushL(fsSession);
538 RDbNamedDatabase database;
539 User::LeaveIfError(database.Replace(fsSession, KDbName));
540 CleanupClosePushL(database);
544 CDbColSet* columns= CDbColSet::NewLC();
546 TDbCol name(KColName,EDbColLongText8,KDbNameLen);
547 name.iAttributes = TDbCol::ENotNull;
549 TDbCol name2(KCol2Name,EDbColLongText8,KDbNameLen);
552 columns->AddL(name2);
554 User::LeaveIfError (database.CreateTable (KTable, *columns));
555 CleanupStack::PopAndDestroy(); // columns
557 // Insert values into the table
558 TInt error = database.Execute(KSQLInsert1);
560 error =database.Execute(KSQLInsert2);
562 error =database.Execute(KSQLInsert3);
564 error = database.Execute(KSQLInsert4);
566 error = database.Execute(KSQLInsert5);
568 error = database.Execute(KSQLInsert6);
570 error = database.Execute(KSQLInsert7);
573 TheTest.Next(_L("Test for valid LIKE predicate queries"));
576 for(TInt i =0;i<KNumQueries;++i)
578 RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query));
580 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly);
582 TInt evErr = view.EvaluateAll();
586 result.Copy(TPtrC(KQuery[i].result));
594 rd.ReadL(colname,view.ColLength(1));
595 CleanupStack::PopAndDestroy();
596 RDebug::Print(_L("Expected result: %S Actual Result: %S\n"),&result,&colname);
597 TInt err = colname.CompareF(result);
606 // test for illegal statements, check they return KErrArgument
607 TheTest.Next(_L("Test that illegal queries return KErrArgument"));
611 for(TInt j =0;j<KNumBadQueries;++j)
613 RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query));
615 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly);
616 TheTest(prepErr==KErrArgument);
621 CleanupStack::PopAndDestroy(&database); // database
622 CleanupStack::PopAndDestroy(&fsSession); // fsSession
627 // Test for LIKE Predicate for EDbColText
628 LOCAL_C void LikePredicateDbColTextTestL()
630 TheTest.Next (_L ("LikePredicate DbColText TestL"));
634 User::LeaveIfError(fsSession.Connect());
635 CleanupClosePushL(fsSession);
636 RDbNamedDatabase database;
637 User::LeaveIfError(database.Replace(fsSession, KDbName));
638 CleanupClosePushL(database);
642 CDbColSet* columns= CDbColSet::NewLC();
644 TDbCol name(KColName,EDbColText,KDbNameLen);
645 name.iAttributes = TDbCol::ENotNull;
647 TDbCol name2(KCol2Name,EDbColText,KDbNameLen);
650 columns->AddL(name2);
652 User::LeaveIfError (database.CreateTable (KTable, *columns));
653 CleanupStack::PopAndDestroy(); // columns
655 // Insert values into the table
656 TInt error = database.Execute(KSQLInsert1);
658 error =database.Execute(KSQLInsert2);
660 error =database.Execute(KSQLInsert3);
662 error = database.Execute(KSQLInsert4);
664 error = database.Execute(KSQLInsert5);
666 error = database.Execute(KSQLInsert6);
668 error = database.Execute(KSQLInsert7);
672 TheTest.Next(_L("Test for valid LIKE predicate queries"));
675 for(TInt i =0;i<KNumQueries;++i)
677 RDebug::Print(_L("Executing statement: %s \n"),(KQuery[i].query));
679 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KQuery[i].query), EDbCompareFolded), view.EReadOnly);
680 if(TPtrC(KQuery[i].result).Length() == 0)
682 TheTest(prepErr != KErrNone);
693 colname = view.ColDes(1);
694 res= KQuery[i].result;
695 RDebug::Print(_L("Expected result: %s Actual Result: %S\n"),(KQuery[i].result),&colname);
696 TInt err = colname.Compare(TPtrC(KQuery[i].result));
703 // test for illegal statements, check they return KErrArgument
704 TheTest.Next(_L("Test that illegal queries return KErrArgument"));
706 for(TInt j =0;j<KNumBadQueries;++j)
708 RDebug::Print(_L("Executing illegal statement: %s \n"),(KBadQuery[j].query));
710 TInt prepErr = view.Prepare(database, TDbQuery(TPtrC(KBadQuery[j].query), EDbCompareFolded), view.EReadOnly);
711 TheTest(prepErr==KErrArgument);
715 CleanupStack::PopAndDestroy(&database); // database
716 CleanupStack::PopAndDestroy(&fsSession); // fsSession
722 @SYMTestCaseID SYSLIB-DBMS-UT-1592
723 @SYMTestCaseDesc Testing limited-ESCAPE-clause
724 @SYMTestPriority High
725 @SYMTestActions Execute DBMS query with ESCAPE-clause
726 @SYMTestExpectedResults The test should not fail.
729 LOCAL_C void Defect_INC076370 ()
731 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-1592 Defect INC076370 "));
732 LikePredicateDbColTextTestL(); //EDbColText
733 LikePredicateDbColLongText16TestL(); //EDbColLongText16
734 LikePredicateDbColLongText8TestL(); //EDbColLongText8
738 @SYMTestCaseID SYSLIB-DBMS-UT-1667
739 @SYMTestCaseDesc Testing RdbRowSet::DeleteL() with EDbColLongText16 type columns
740 @SYMTestPriority High
741 @SYMTestActions Create a table with a EDbColLongText16 type column and then use
742 RdbRowSet::DeleteL() to delete the current row.
743 @SYMTestExpectedResults The test should not fail.
746 LOCAL_C void Defect_INC083027 ()
748 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-1667 Defect INC083027 "));
750 CleanupClosePushL(fs);
751 User::LeaveIfError(fs.Connect());
754 RDbNamedDatabase database;
755 CleanupClosePushL(database);
756 User::LeaveIfError(database.Replace(fs, _L("c:\\test.db")));
758 CDbColSet* columns = CDbColSet::NewLC();
759 const TInt maxTextLength = 256;
760 TDbCol text16Col(KText16Name, EDbColLongText16, maxTextLength);
761 columns->AddL(text16Col);
763 TBuf<KMaxColName> targetColName;
764 targetColName = KText16Name;
767 User::LeaveIfError(database.CreateTable(KTableName, *columns));
770 CDbKey* key = CDbKey::NewLC();
771 TInt keyLength = 122;
772 TDbKeyCol keyCol(targetColName, keyLength);
774 User::LeaveIfError(database.CreateIndex(KIndexName, KTableName, *key));
775 CleanupStack::PopAndDestroy(2); // key and columns
778 HBufC* sqlQueryBuf = HBufC::NewLC(512);
779 TPtr sqlQuery(sqlQueryBuf->Des());
780 _LIT(KSQLInsertFormat, "SELECT %S FROM %S");
781 sqlQuery.Format(KSQLInsertFormat, &targetColName, &KTableName);
784 User::LeaveIfError(insertview.Prepare(database, TDbQuery(sqlQuery), RDbView::EInsertOnly));
786 HBufC* tmpBuf = HBufC::NewLC(maxTextLength);
787 TPtr maxString(tmpBuf->Des());
788 maxString.Format(KMaxStringFormat, 0);
789 insertview.InsertL();
790 insertview.SetColL(1, maxString);
796 User::LeaveIfError(deleteview.Prepare(database, TDbQuery(sqlQuery), RDbView::EUpdatable));
797 User::LeaveIfError(deleteview.EvaluateAll());
799 while (deleteview.NextL())
802 TRAPD(err , deleteview.DeleteL());
803 TheTest(err==KErrNone);
807 CleanupStack::PopAndDestroy(2); // tmpBuf, sqlQueryBuf
808 CleanupStack::PopAndDestroy(&database); // database
809 CleanupStack::PopAndDestroy(&fs); // fs
813 @SYMTestCaseID SYSLIB-DBMS-UT-1894
814 @SYMTestCaseDesc Testing memory handling in CSqlMultiNode::Concatenate()
815 @SYMTestPriority Medium
816 @SYMTestActions Execute a special request to a database which will trigger CSqlMultiNode::Concatenate(), and the size of one of the SQL nodes will be divisible by the CSqlMultiNode granularity
817 @SYMTestExpectedResults The test should not fail or panic.
820 LOCAL_C void Defect_INC093657L ()
822 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-1894 Defect INC093657 "));
824 CleanupClosePushL(fs);
825 User::LeaveIfError(fs.Connect());
828 RDbNamedDatabase database;
829 CleanupClosePushL(database);
830 User::LeaveIfError(database.Replace(fs, _L("c:\\test.db")));
832 CDbColSet* columns = CDbColSet::NewLC();
833 const TInt maxTextLength = 256;
834 TDbCol column(KColName, EDbColLongText16, maxTextLength);
835 columns->AddL(column);
838 User::LeaveIfError(database.CreateTable(KTableName, *columns));
839 CleanupStack::PopAndDestroy(); // columns
841 //execute a pointless request that is intended to detect subtle memory corruptions in CSqlMultiNode::Concatenate
843 TInt err = view.Prepare(database, TDbQuery(KSqlRequestGranularity));
845 TheTest(err==KErrNone);
850 CleanupStack::PopAndDestroy(&database); // database
851 CleanupStack::PopAndDestroy(&fs); // fs
855 @SYMTestCaseID SYSLIB-DBMS-UT-3467
856 @SYMTestCaseDesc Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
857 The test creates a table with 3 coluumns and a multi-column key (3 columns). The column
858 names length is such that when RDbRowSet::ColSetL() is called for retrieving the column
859 names, the CDbColSet array data member will make just a single memory allocation, where
860 all TDbCol elements will be stored. Then the test repeats 100 times, the following statements:
862 <create a copy of colset's last TDbCol element using TDbCol's copy constructor>;
863 <create a copy of colset's last TDbCol element using TDbCol's "=" operator>;
864 If the test uses the compiler generated TDbCol's copy constructor and "=" operator,
865 the test crashes at some iteration, because an invalid memory region is accessed and
866 the crash is: KERN-EXEC 3.
867 The same test is repeated for TDbKeyCol's copy constructor and "=" operator.
868 @SYMTestPriority High
869 @SYMTestActions Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
870 @SYMTestExpectedResults The test must not fail
875 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3467 DEF105615 DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory"));
877 TInt err = fs.Connect();
878 TheTest(err == KErrNone);
881 err = db.Replace(fs, KDbName);
882 TheTest(err == KErrNone);
884 const TInt KColCnt = 3;
886 err = db.Execute(_L("CREATE TABLE A(A1234567890 INTEGER, B1234567890 INTEGER, C12345 INTEGER)"));
887 TheTest(err == KErrNone);
888 err = db.Execute(_L("CREATE INDEX I1 ON A(A1234567890, B1234567890, C12345)"));
889 TheTest(err == KErrNone);
892 err = tbl.Open(db, _L("A"));
893 TheTest(err == KErrNone);
895 //It is very hard to reproduce the problem, because the memory region after the memory, occupied by
896 //CDbColSet's array, may be valid. That is the reason the test is repeated in a loop KTestCnt times,
897 //where every ColSetL() call will allocate a new block of memory for its array and at some point TDbCol's
898 //copy constructor and "=" operator may try to access an invalid memory area, if the compiler generated
900 const TInt KTestCnt = 100;
902 CDbColSet* colset[KTestCnt];
903 for(i=0;i<KTestCnt;++i)
905 TRAP(err, colset[i] = tbl.ColSetL());
906 TheTest(err == KErrNone);
907 TDbCol lastCol = (*colset[i])[KColCnt]; //copy constructor
908 lastCol = (*colset[i])[KColCnt]; //"=" operator
910 for(i=0;i<KTestCnt;++i)
917 //The same test is repeated for TDbKeyCol's copy constructor and "=" operator
918 CDbKey* key[KTestCnt];
919 for(i=0;i<KTestCnt;++i)
921 TRAP(err, key[i] = db.KeyL(_L("I1"), _L("A")));
922 TheTest(err == KErrNone);
923 TDbKeyCol lastKeyCol = (*key[i])[KColCnt - 1]; //copy constructor
924 lastKeyCol = (*key[i])[KColCnt - 1]; //"=" operator
926 for(i=0;i<KTestCnt;++i)
932 err = fs.Delete(KDbName);
933 TheTest(err == KErrNone);
938 @SYMTestCaseID SYSLIB-DBMS-UT-3469
939 @SYMTestCaseDesc Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
940 The test creates TDbCol and TDbKeyCol objects, creates their copies using copy constructors
941 and "=" operators and checks that the copies were constructed correctly,
942 @SYMTestPriority High
943 @SYMTestActions Test for DEF105615 "DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory".
944 @SYMTestExpectedResults The test must not fail
949 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3469 DEF105615 DBMS, CDbColSet::operator[](TDbColNo) operator may access an invalid memory - 2 "));
951 const TDbColType KColType = EDbColText16;
952 const TInt KMaxColLen = 73;
953 const TUint KColAttributes = TDbCol::ENotNull;
954 _LIT(KColName, "Name");
956 TDbCol srcDbCol(KColName, EDbColText16, KMaxColLen);
957 srcDbCol.iAttributes = KColAttributes;
959 //TDbCol - copy constructor
960 TDbCol dbColCopy1(srcDbCol);
961 TheTest(dbColCopy1.iType == srcDbCol.iType && dbColCopy1.iType == KColType);
962 TheTest(dbColCopy1.iMaxLength == srcDbCol.iMaxLength && dbColCopy1.iMaxLength == KMaxColLen);
963 TheTest(dbColCopy1.iAttributes == srcDbCol.iAttributes && dbColCopy1.iAttributes == KColAttributes);
964 TheTest(dbColCopy1.iName == srcDbCol.iName && dbColCopy1.iName == KColName);
966 //TDbCol - "=" operator
968 dbColCopy2 = srcDbCol;
969 TheTest(dbColCopy2.iType == srcDbCol.iType && dbColCopy2.iType == KColType);
970 TheTest(dbColCopy2.iMaxLength == srcDbCol.iMaxLength && dbColCopy2.iMaxLength == KMaxColLen);
971 TheTest(dbColCopy2.iAttributes == srcDbCol.iAttributes && dbColCopy2.iAttributes == KColAttributes);
972 TheTest(dbColCopy2.iName == srcDbCol.iName && dbColCopy2.iName == KColName);
974 //TDbCol - self assignment
976 TheTest(srcDbCol.iType == KColType);
977 TheTest(srcDbCol.iMaxLength == KMaxColLen);
978 TheTest(srcDbCol.iAttributes == KColAttributes);
979 TheTest(srcDbCol.iName == KColName);
981 const TInt KKeyLen = 29;
982 const TDbKeyCol::TOrder KKeyOrder = TDbKeyCol::EDesc;
983 _LIT(KKeyName, "Name22");
985 TDbKeyCol srcDbKeyCol(KKeyName, KKeyLen, KKeyOrder);
987 //TDbKeyCol - copy constructor
988 TDbKeyCol dbKeyColCopy1(srcDbKeyCol);
989 TheTest(dbKeyColCopy1.iOrder == srcDbKeyCol.iOrder && dbKeyColCopy1.iOrder == KKeyOrder);
990 TheTest(dbKeyColCopy1.iLength == srcDbKeyCol.iLength && dbKeyColCopy1.iLength == KKeyLen);
991 TheTest(dbKeyColCopy1.iName == srcDbKeyCol.iName && dbKeyColCopy1.iName == KKeyName);
993 //TDbKeyCol - "=" operator
994 TDbKeyCol dbKeyColCopy2;
995 dbKeyColCopy2 = srcDbKeyCol;
996 TheTest(dbKeyColCopy2.iOrder == srcDbKeyCol.iOrder && dbKeyColCopy2.iOrder == KKeyOrder);
997 TheTest(dbKeyColCopy2.iLength == srcDbKeyCol.iLength && dbKeyColCopy2.iLength == KKeyLen);
998 TheTest(dbKeyColCopy2.iName == srcDbKeyCol.iName && dbKeyColCopy2.iName == KKeyName);
1000 //TDbKeyCol - self assignment
1001 srcDbKeyCol = srcDbKeyCol;
1002 TheTest(srcDbKeyCol.iOrder == KKeyOrder);
1003 TheTest(srcDbKeyCol.iLength == KKeyLen);
1004 TheTest(srcDbKeyCol.iName == KKeyName);
1008 @SYMTestCaseID SYSLIB-DBMS-UT-3413
1009 @SYMTestCaseDesc Testing that "incremental update" operations running in one connection does not
1010 interfere with database operations executed from a second connection
1011 @SYMTestPriority High
1012 @SYMTestActions Create a test database with one table and insert some records there (> 100).
1013 Create 2 database connections.
1014 Open that database from connection 1 and execute an incremental update operation
1015 in a transaction. At the same time try to open and close the same table from
1016 connection 2, mixing these operations with the RDbUpdate::Next() calls from
1017 connection 1. So the call pattern should be:
1021 while((err = dbUpdate.Next()) > 0) //from "Conenction 1"
1024 err = tbl.Open(TheDb2, _L("A")); //from "Conenction 2"
1028 @SYMTestExpectedResults The test should not fail or panic.
1031 void Defect_INC101720()
1033 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3413 "));
1034 //Create the test database
1035 TInt err = TheDb1.Replace(TheFs, KDbName);
1036 TEST2(err, KErrNone);
1038 TheCrcChecker.GenerateCrcL(KDbName);
1040 //Establish the first database connection
1042 err = TheDbs1.Connect();
1043 TEST2(err, KErrNone);
1045 err = TheDb1.Open(TheDbs1, KDbName);
1046 TEST2(err, KErrNone);
1047 //Create a test table and fill the table with enough test records (> 100)
1048 err = TheDb1.Execute(_L("CREATE TABLE A(Id COUNTER, Id2 INTEGER, Name LONG VARCHAR)"));
1049 TEST2(err, KErrNone);
1050 const TInt KTestRecCount = 200;
1051 err = TheDb1.Begin();
1052 TEST2(err, KErrNone);
1053 for(TInt i=0;i<KTestRecCount;++i)
1055 _LIT(KSqlFmtStr, "INSERT INTO A(Id2, Name) VALUES(%d, 'TestNameString')");
1057 // We can't use this because Math::Random() may return different numbers on
1058 // different platform, which will lead to different output that result in
1059 // CRC test failing.
1060 // TUint32 id = Math::Random() % KTestRecCount;
1061 TUint32 id = (i^0x55555555) % KTestRecCount;
1063 sql.Format(KSqlFmtStr, id + 1);
1064 err = TheDb1.Execute(sql);
1067 err = TheDb1.Commit();
1068 TEST2(err, KErrNone);
1069 //Establish a second connection with the same test database
1071 err = TheDbs2.Connect();
1072 TEST2(err, KErrNone);
1074 err = TheDb2.Open(TheDbs2, KDbName);
1075 TEST2(err, KErrNone);
1076 //The test: Conenction 1 - "incremental update" operation.
1077 // Connection 2 - "open table/close table" operations mixed with the incremental Next-s.
1078 //Expectation: The test must not fail.
1079 err = TheDb1.Begin();
1080 TEST2(err, KErrNone);
1082 err = dbUpdate.Execute(TheDb1, _L("UPDATE A SET Name = 'ModifiedNameString' WHERE Id2 > 10"));
1083 TEST2(err, KErrNone);
1085 while((err = dbUpdate.Next()) > 0)
1089 err = tbl.Open(TheDb2, _L("A"));
1090 TEST2(err, KErrNone);
1093 TEST(step > 1);//just to be sure that the test executes dbUpdate.Next() more than once
1094 TEST2(err, KErrNone);
1096 err = TheDb1.Commit();
1097 TEST2(err, KErrNone);
1107 TheCrcChecker.GenerateCrcL(KDbName);
1111 @SYMTestCaseID SYSLIB-DBMS-UT-3484
1112 @SYMTestCaseDesc DBMS Hindi collation doesn't work on long text fields.
1113 @SYMTestPriority Medium
1114 @SYMTestActions This test is to check that DBMS correctly sorts columns using Collation, when
1115 the columns are of type EDbColLongText16. Previous implementations split the
1116 strings to be compared into chunks, however this could cause it to be sorted
1117 incorrectly if it was split on a combining or accent character. This fault
1118 occurs on the default locale as well as Hindi. Test steps:
1119 * Create a database table and adds several unicode strings to EDbColLongText16
1120 column in table. One set of strings have an ascii character followed by
1121 an accent (e + ') and the other set have the combined equivilant ascii
1122 character (è). These should have the same sort order,however if are split
1123 then will compare differently.
1124 * Sort the columns using EDbCompareCollated
1125 * Check that the columns were sorted in the correct order
1126 @SYMTestExpectedResults The columns should get sorted into ascending order correctly
1129 void Defect_INC107268L()
1131 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3484 Defect INC107268 - DBMS Hindi collation doesn't work on long text fields"));
1133 // some unicode characters
1134 const TChar Ka(0x0061); // a
1135 const TChar Kb(0x0062); // b
1136 const TChar Ke(0x0065); // e
1137 const TChar Kgrave(0x0060); // ' (grave)
1138 const TChar Kegrave(0x00e8); // e with grave
1139 const TChar K1(0x0031); // 1
1140 const TChar K2(0x0032); // 2
1142 // the maximum characters in a EDbColLongText16 string before dbms stops storing
1143 // the string inline, and we need to read it from a stream (see TBlobKey).
1144 const TInt KInlineLimit = 127;
1146 // maximum number of characters buffered in TBlobKey when string stored out of line.
1147 // (see TBlobKey::ETruncSize which is in bytes)
1148 const TInt KTruncLimit = 16;
1150 const TInt KMaxStringSize = 256;
1152 TBuf<KMaxStringSize> inLineBoundryA;
1153 TBuf<KMaxStringSize> inLineBoundryB;
1154 TBuf<KMaxStringSize> truncBoundryA;
1155 TBuf<KMaxStringSize> truncBoundryB;
1156 TBuf<KMaxStringSize> padding;
1158 // this string will be stored inline. It should sort to be < stringB
1159 inLineBoundryA.Fill(Ka, KInlineLimit-2);
1160 inLineBoundryA.Append(Kegrave);
1161 inLineBoundryA.Append(K1);
1163 // this string is just over the break point, so *is* truncated.
1164 // this is expected to get sorted incorrecly as combining character is split off (negative test case)
1165 inLineBoundryB.Fill(Ka, KInlineLimit-2);
1166 inLineBoundryB.Append(Ke);
1167 inLineBoundryB.Append(Kgrave);
1168 inLineBoundryB.Append(K2);
1170 padding.Fill(Kb, KInlineLimit);
1172 // this string is longger that KInlineLimit so is stored out of line
1173 truncBoundryA.Fill(Kb, KTruncLimit-2);
1174 truncBoundryA.Append(Kegrave);
1175 truncBoundryA.Append(K1);
1176 truncBoundryA.Append(padding);
1178 // this string has combining characters that fall on boundry of ETruncSize value (32 bytes)
1179 truncBoundryB.Fill(Kb, KTruncLimit-2);
1180 truncBoundryB.Append(Ke);
1181 truncBoundryB.Append(Kgrave);
1182 truncBoundryB.Append(K2);
1183 truncBoundryB.Append(padding);
1186 // e and '(grave) characters seperately
1188 e_grave.Append( Ke );
1189 e_grave.Append( Kgrave );
1191 // e with grave character - this should sort the same as e_grave
1193 egrave.Append( Kegrave );
1197 e_grave.Append(K2); // make e_grave sort second
1198 egrave.Append(K1); // make egrave sort first
1200 // Check with database
1201 _LIT(KPosLmLandmarkTable, "lmt_landmark");
1202 _LIT(KPosLmLandmarkIdCol, "lmc_lmid");
1203 _LIT(KPosLmNameCol, "lmc_name");
1205 TInt err = TheDb1.Replace( TheFs, KDbName );
1206 TEST2 (err, KErrNone);
1207 CleanupClosePushL(TheDb1);
1209 CDbColSet* columns = CDbColSet::NewLC();
1210 TDbCol idField( KPosLmLandmarkIdCol, EDbColUint32 );
1211 idField.iAttributes |= TDbCol::EAutoIncrement;
1212 columns->AddL( idField );
1213 columns->AddL( TDbCol( KPosLmNameCol, EDbColLongText16 ) ); // Works with EDbColText16. Defect only for EDbColLongText16.
1215 err = TheDb1.CreateTable( KPosLmLandmarkTable, *columns );
1216 TEST2 (err, KErrNone);
1217 CleanupStack::PopAndDestroy(columns);
1220 err = table.Open( TheDb1, KPosLmLandmarkTable );
1221 TEST2 (err, KErrNone);
1222 CleanupClosePushL(table);
1224 // add rows to table
1226 table.SetColL( 2, egrave); // row 0 - sorted 8th
1230 table.SetColL( 2, e_grave ); // row 1 - sorted 9th
1234 table.SetColL( 2, inLineBoundryA ); // row 2 - sorted 3rd (incorrectly - negative test case)
1238 table.SetColL( 2, inLineBoundryB ); // row 3 - sorted 2nd (incorrectly - negative test case)
1242 table.SetColL( 2, nullString ); // row 4 - sorted 1st
1246 table.SetColL( 2, truncBoundryB ); // row 5 - sorted 5th
1250 table.SetColL( 2, truncBoundryA ); // row 6 - sorted 4th
1254 CleanupStack::PopAndDestroy(); // table.close()
1256 // do an sql select with Order By to sort columns
1257 _LIT(KPosLmSqlSelectOrderByString, "SELECT %S, %S FROM %S ORDER BY %S");
1259 sql.Format( KPosLmSqlSelectOrderByString,
1260 &KPosLmLandmarkIdCol,
1262 &KPosLmLandmarkTable,
1266 CleanupClosePushL(view);
1267 err = view.Prepare( TheDb1, TDbQuery( sql, EDbCompareCollated ) );
1268 TEST2 (err, KErrNone);
1269 err = view.EvaluateAll();
1270 TEST2 (err, KErrNone);
1272 // Now check that view is ordered correctly
1273 const TUint32 ExpectedOrder[] = {4,3,2,6,5,0,1};
1275 while (view.NextL())
1278 TEST2(view.ColUint32(1), ExpectedOrder[x]); // check we got the expected order
1281 TEST2(x, 7); // check we got the right number of values
1282 CleanupStack::PopAndDestroy(2); // TheDb1.Close(); view.Close()
1283 TheCrcChecker.GenerateCrcL(KDbName);
1288 LOCAL_C void DoTestsL ()
1291 CleanupClosePushL(TheFs);
1295 // Defect_DEF44697L (); // Use of three RThreads, not possible for tools2.
1297 Defect_INC093657L();
1299 // These two tests don't work on 9.3.
1303 Defect_INC107268L();
1304 CleanupStack::PopAndDestroy(); // TheFs.Close()
1308 GLDEF_C TInt E32Main ()
1312 TheTest.Start (_L ("Verify Defect Fixes"));
1314 TheTrapCleanup = CTrapCleanup::New ();
1315 __ASSERT_ALWAYS (TheTrapCleanup!=NULL, User::Invariant ());
1317 TInt err = TheFs.Connect();
1318 TheTest(err == KErrNone);
1320 TRAP (err,DoTestsL ());
1321 TheTest (err==KErrNone);
1323 //Wait some time, because DBMS server won't be destroyed right after the last DBMS session
1325 TheTest.Printf(_L("Wait DBMS server shutdown...\n"));
1326 User::After(7000000);
1330 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
1331 TheTest(err==KErrNone);
1332 TheTest(lc==KErrNone);
1334 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
1336 TheCrcChecker.ErrorReportL(err, errmsg);
1337 RDebug::Print(errmsg);
1338 TheTest(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
1342 delete TheTrapCleanup;