65 }; |
65 }; |
66 ////////////////////////////////////////////////////////////////////////////////////// |
66 ////////////////////////////////////////////////////////////////////////////////////// |
67 |
67 |
68 _LIT(KPanicCategory, "SrvTerm"); |
68 _LIT(KPanicCategory, "SrvTerm"); |
69 _LIT(KPanicCategory2, "InvArg"); |
69 _LIT(KPanicCategory2, "InvArg"); |
|
70 _LIT(KPanicCategory3, "SessConn"); |
|
71 _LIT(KPanicCategory4, "TcNull"); |
|
72 _LIT(KPanicCategory5, "ThrDNull"); |
70 const TInt KPanicCode = 1111; |
73 const TInt KPanicCode = 1111; |
71 const TInt KPanicCode2 = 2222; |
74 const TInt KPanicCode2 = 2222; |
72 |
75 |
73 /////////////////////////////////////////////////////////////////////////////////////// |
76 /////////////////////////////////////////////////////////////////////////////////////// |
74 |
77 |
79 } |
82 } |
80 |
83 |
81 /////////////////////////////////////////////////////////////////////////////////////// |
84 /////////////////////////////////////////////////////////////////////////////////////// |
82 /////////////////////////////////////////////////////////////////////////////////////// |
85 /////////////////////////////////////////////////////////////////////////////////////// |
83 //Test macros and functions |
86 //Test macros and functions |
84 void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse) |
87 void Check1(TInt aValue, TInt aLine) |
85 { |
88 { |
86 if(!aValue) |
89 if(!aValue) |
87 { |
90 { |
88 DeleteTestFiles(); |
91 DeleteTestFiles(); |
89 if(aPrintThreadName) |
92 TheTest.Printf(_L("*** Line %d. Expression evaluated to false.\r\n"), aLine); |
90 { |
|
91 RThread th; |
|
92 TName name = th.Name(); |
|
93 RDebug::Print(_L("*** Thread %S, Line %d\r\n"), &name, aLine); |
|
94 } |
|
95 else |
|
96 { |
|
97 RDebug::Print(_L("*** Line %d\r\n"), aLine); |
|
98 } |
|
99 TheTest(EFalse, aLine); |
93 TheTest(EFalse, aLine); |
100 } |
94 } |
101 } |
95 } |
102 void Check2(TInt aValue, TInt aExpected, TInt aLine, TBool aPrintThreadName = EFalse) |
96 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
103 { |
97 { |
104 if(aValue != aExpected) |
98 if(aValue != aExpected) |
105 { |
99 { |
106 DeleteTestFiles(); |
100 DeleteTestFiles(); |
107 if(aPrintThreadName) |
101 TheTest.Printf(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
108 { |
|
109 RThread th; |
|
110 TName name = th.Name(); |
|
111 RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue); |
|
112 } |
|
113 else |
|
114 { |
|
115 RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
|
116 } |
|
117 TheTest(EFalse, aLine); |
102 TheTest(EFalse, aLine); |
118 } |
103 } |
119 } |
104 } |
120 #define TEST(arg) ::Check1((arg), __LINE__) |
105 #define TEST(arg) ::Check1((arg), __LINE__) |
121 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
106 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
122 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue) |
|
123 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue) |
|
124 |
107 |
125 /////////////////////////////////////////////////////////////////////////////////////// |
108 /////////////////////////////////////////////////////////////////////////////////////// |
126 |
109 |
127 //Creates file session instance and the test directory |
110 //Creates file session instance and the test directory |
128 void CreateTestEnv() |
111 void CreateTestEnv() |
253 return aSession.SendReceive(aFunction, aArgs); |
236 return aSession.SendReceive(aFunction, aArgs); |
254 } |
237 } |
255 |
238 |
256 void PrintIterationCount(TInt aIteration) |
239 void PrintIterationCount(TInt aIteration) |
257 { |
240 { |
258 if((aIteration % 100) == 0) |
241 static TInt lastIteration = 0; |
259 { |
242 if((aIteration - lastIteration) >= 100) |
|
243 { |
|
244 lastIteration = aIteration; |
260 TTime time; |
245 TTime time; |
261 time.HomeTime(); |
246 time.HomeTime(); |
262 TDateTime dt = time.DateTime(); |
247 TDateTime dt = time.DateTime(); |
263 TBuf<16> tbuf; |
248 TBuf<16> tbuf; |
264 tbuf.Format(_L("%02d:%02d:%02d.%06d"), dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond()); |
249 tbuf.Format(_L("%02d:%02d:%02d.%06d"), dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond()); |
265 RDebug::Print(_L("-----[%S] Test iterations: %d\r\n"), &tbuf, aIteration); |
250 TheTest.Printf(_L("-----[%S] Test iterations: %d\r\n"), &tbuf, aIteration); |
266 } |
251 } |
267 } |
252 } |
268 |
253 |
269 //Worker thread function. |
254 //Worker thread function. |
270 //It behaves as a malicious client. Connects to the SQL server. In each test iteration generates some random values |
255 //It behaves as a malicious client. Connects to the SQL server. In each test iteration generates some random values |
275 TInt ThreadFunc1(void* aData) |
260 TInt ThreadFunc1(void* aData) |
276 { |
261 { |
277 __UHEAP_MARK; |
262 __UHEAP_MARK; |
278 |
263 |
279 CTrapCleanup* tc = CTrapCleanup::New(); |
264 CTrapCleanup* tc = CTrapCleanup::New(); |
280 TTEST(tc != NULL); |
265 if(!tc) |
|
266 { |
|
267 User::Panic(KPanicCategory4, KErrNoMemory); |
|
268 } |
281 |
269 |
282 TThreadData* p = static_cast <TThreadData*> (aData); |
270 TThreadData* p = static_cast <TThreadData*> (aData); |
283 TTEST(p != NULL); |
271 if(!p) |
|
272 { |
|
273 User::Panic(KPanicCategory5, KErrArgument); |
|
274 } |
284 TThreadData& data = *p; |
275 TThreadData& data = *p; |
285 |
276 |
286 TVersion sqlSoftwareVersion(KSqlMajorVer, KSqlMinorVer, KSqlBuildVer); |
277 TVersion sqlSoftwareVersion(KSqlMajorVer, KSqlMinorVer, KSqlBuildVer); |
287 RTestSqlDbSession sess; |
278 RTestSqlDbSession sess; |
288 TInt err = sess.Connect(sqlSoftwareVersion); |
279 TInt err = sess.Connect(sqlSoftwareVersion); |
289 TTEST2(err, KErrNone); |
280 if(err != KErrNone) |
|
281 { |
|
282 User::Panic(KPanicCategory3, err); |
|
283 } |
290 |
284 |
291 while(++data.iIteration <= KTestIterCount) |
285 while(++data.iIteration <= KTestIterCount) |
292 { |
286 { |
293 PrintIterationCount(data.iIteration); |
|
294 TIpcArgs args; |
287 TIpcArgs args; |
295 do |
288 do |
296 { |
289 { |
297 data.iFunction = Math::Rand(data.iSeed) % (ESqlSrvStreamClose + 1);//ESqlSrvStreamClose - the last server message number) |
290 data.iFunction = Math::Rand(data.iSeed) % (ESqlSrvStreamClose + 1);//ESqlSrvStreamClose - the last server message number) |
298 } |
291 } |