67 RSqlDatabase::Delete(KTestDbName3); |
67 RSqlDatabase::Delete(KTestDbName3); |
68 RSqlDatabase::Delete(KTestDbName2); |
68 RSqlDatabase::Delete(KTestDbName2); |
69 RSqlDatabase::Delete(KTestDbName1); |
69 RSqlDatabase::Delete(KTestDbName1); |
70 } |
70 } |
71 |
71 |
|
72 void GetHomeTimeAsString(TDes& aStr) |
|
73 { |
|
74 TTime time; |
|
75 time.HomeTime(); |
|
76 TDateTime dt = time.DateTime(); |
|
77 aStr.Format(_L("%02d:%02d:%02d.%06d"), dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond()); |
|
78 } |
|
79 |
72 /////////////////////////////////////////////////////////////////////////////////////// |
80 /////////////////////////////////////////////////////////////////////////////////////// |
73 /////////////////////////////////////////////////////////////////////////////////////// |
81 /////////////////////////////////////////////////////////////////////////////////////// |
74 //Test macros and functions |
82 //Test macros and functions |
75 void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse) |
83 void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse) |
76 { |
84 { |
112 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
120 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
113 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue) |
121 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue) |
114 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue) |
122 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue) |
115 |
123 |
116 /////////////////////////////////////////////////////////////////////////////////////// |
124 /////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
|
126 //StatementMaxNumberTest() timeouts in WDP builds. |
|
127 //This function is used to check whether the time limit is reaqched or not. |
|
128 TBool IsTimeLimitReached() |
|
129 { |
|
130 struct TStartTime |
|
131 { |
|
132 TStartTime() |
|
133 { |
|
134 iTime.HomeTime(); |
|
135 } |
|
136 TTime iTime; |
|
137 }; |
|
138 |
|
139 static TStartTime startTime; |
|
140 const TInt KTestTimeLimit = 250;//seconds |
|
141 |
|
142 TTime currTime; |
|
143 currTime.HomeTime(); |
|
144 |
|
145 TTimeIntervalSeconds s; |
|
146 TInt err = currTime.SecondsFrom(startTime.iTime, s); |
|
147 TEST2(err, KErrNone); |
|
148 return s.Int() > KTestTimeLimit; |
|
149 } |
117 |
150 |
118 void CreateTestDir() |
151 void CreateTestDir() |
119 { |
152 { |
120 RFs fs; |
153 RFs fs; |
121 TInt err = fs.Connect(); |
154 TInt err = fs.Connect(); |
530 User::After(2000000); |
563 User::After(2000000); |
531 |
564 |
532 CloseTestThreads(threads, statuses, KTestThreadCnt); |
565 CloseTestThreads(threads, statuses, KTestThreadCnt); |
533 } |
566 } |
534 |
567 |
|
568 /** |
|
569 @SYMTestCaseID PDS-SQL-CT-4201 |
|
570 @SYMTestCaseDesc Max number of SQL statements test. |
|
571 @SYMTestPriority High |
|
572 @SYMTestActions The test creates a table with couple of records and then |
|
573 creates as many as possible SQL statements. The expected result is |
|
574 that either the statement creation process will fail with KErrNoMemory or |
|
575 the max number of statements to be created is reached (100000). |
|
576 Then the test deletes 1/2 of the created statements objects and |
|
577 after that attempts to execute Next() on the rest of them. |
|
578 Note that the test has a time limit of 500 seconds. Otherwise on some platforms |
|
579 with WDP feature switched on the test may timeout. |
|
580 @SYMTestExpectedResults Test must not fail |
|
581 @SYMDEF DEF145236 |
|
582 */ |
|
583 void StatementMaxNumberTest() |
|
584 { |
|
585 TBuf<30> time; |
|
586 GetHomeTimeAsString(time); |
|
587 TheTest.Printf(_L("=== %S: Create database\r\n"), &time); |
|
588 |
|
589 (void)RSqlDatabase::Delete(KTestDbName1); |
|
590 RSqlDatabase db; |
|
591 TInt err = db.Create(KTestDbName1); |
|
592 TEST2(err, KErrNone); |
|
593 err = db.Exec(_L("CREATE TABLE A(I INTEGER); INSERT INTO A(I) VALUES(1); INSERT INTO A(I) VALUES(2);")); |
|
594 TEST(err >= 0); |
|
595 |
|
596 GetHomeTimeAsString(time); |
|
597 TheTest.Printf(_L("=== %S: Create statements array\r\n"), &time); |
|
598 |
|
599 //Reserve memory for the statement objects |
|
600 const TInt KMaxStmtCount = 100000; |
|
601 RSqlStatement* stmt = new RSqlStatement[KMaxStmtCount]; |
|
602 TEST(stmt != NULL); |
|
603 |
|
604 //Create as many statement objects as possible |
|
605 TInt idx = 0; |
|
606 err = KErrNone; |
|
607 for(;idx<KMaxStmtCount;++idx) |
|
608 { |
|
609 err = stmt[idx].Prepare(db, _L("SELECT * FROM A WHERE I>=0 AND I<10")); |
|
610 if(err != KErrNone) |
|
611 { |
|
612 break; |
|
613 } |
|
614 if((idx % 100) == 0) |
|
615 { |
|
616 GetHomeTimeAsString(time); |
|
617 TheTest.Printf(_L("=== %S: Create % 5d statements\r\n"), &time, idx + 1); |
|
618 if(IsTimeLimitReached()) |
|
619 { |
|
620 TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time); |
|
621 ++idx;//The idx-th statement is valid, the statement count is idx + 1. |
|
622 break; |
|
623 } |
|
624 } |
|
625 } |
|
626 |
|
627 TInt stmtCnt = idx; |
|
628 TheTest.Printf(_L("%d created statement objects. Last error: %d.\r\n"), stmtCnt, err); |
|
629 TEST(err == KErrNone || err == KErrNoMemory); |
|
630 |
|
631 //Close 1/2 of the statements to free some memory |
|
632 idx = 0; |
|
633 for(;idx<(stmtCnt/2);++idx) |
|
634 { |
|
635 stmt[idx].Close(); |
|
636 if((idx % 100) == 0) |
|
637 { |
|
638 GetHomeTimeAsString(time); |
|
639 TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, idx + 1); |
|
640 } |
|
641 } |
|
642 |
|
643 //Now, there should be enough memory to be able to execute Next() on the rest of the statements |
|
644 for(TInt j=0;idx<stmtCnt;++idx,++j) |
|
645 { |
|
646 err = stmt[idx].Next(); |
|
647 TEST2(err, KSqlAtRow); |
|
648 err = stmt[idx].Next(); |
|
649 TEST2(err, KSqlAtRow); |
|
650 err = stmt[idx].Next(); |
|
651 TEST2(err, KSqlAtEnd); |
|
652 if((j % 100) == 0) |
|
653 { |
|
654 GetHomeTimeAsString(time); |
|
655 TheTest.Printf(_L("=== %S: % 5d statements processed\r\n"), &time, j + 1); |
|
656 } |
|
657 if(IsTimeLimitReached()) |
|
658 { |
|
659 TheTest.Printf(_L("=== %S: The time limit reached.\r\n"), &time); |
|
660 break; |
|
661 } |
|
662 } |
|
663 |
|
664 //Cleanup |
|
665 for(idx=0;idx<stmtCnt;++idx) |
|
666 { |
|
667 stmt[idx].Close(); |
|
668 if((idx % 100) == 0) |
|
669 { |
|
670 GetHomeTimeAsString(time); |
|
671 TheTest.Printf(_L("=== %S: % 5d statements closed\r\n"), &time, idx + 1); |
|
672 } |
|
673 } |
|
674 delete [] stmt; |
|
675 db.Close(); |
|
676 (void)RSqlDatabase::Delete(KTestDbName1); |
|
677 GetHomeTimeAsString(time); |
|
678 TheTest.Printf(_L("=== %S: Test case end\r\n"), &time); |
|
679 } |
|
680 |
535 void DoTests() |
681 void DoTests() |
536 { |
682 { |
537 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |
683 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-1627-0001 SQL server load test ")); |
538 SqlLoadTest(); |
684 SqlLoadTest(); |
|
685 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4201 Statement max number test")); |
|
686 StatementMaxNumberTest(); |
539 } |
687 } |
540 |
688 |
541 TInt E32Main() |
689 TInt E32Main() |
542 { |
690 { |
543 TheTest.Title(); |
691 TheTest.Title(); |