257 err = sqltime.SecondsFrom(time, diff); |
257 err = sqltime.SecondsFrom(time, diff); |
258 TEST2(err, KErrNone); |
258 TEST2(err, KErrNone); |
259 TEST(diff.Int() <= 1); |
259 TEST(diff.Int() <= 1); |
260 } |
260 } |
261 |
261 |
|
262 static TInt KillProcess(const TDesC& aProcessName) |
|
263 { |
|
264 TFullName name; |
|
265 TBuf<64> pattern(aProcessName); |
|
266 TInt length = pattern.Length(); |
|
267 pattern += _L("*"); |
|
268 TFindProcess procFinder(pattern); |
|
269 |
|
270 while (procFinder.Next(name) == KErrNone) |
|
271 { |
|
272 if (name.Length() > length) |
|
273 {//If found name is a string containing aProcessName string. |
|
274 TChar c(name[length]); |
|
275 if (c.IsAlphaDigit() || |
|
276 c == TChar('_') || |
|
277 c == TChar('-')) |
|
278 { |
|
279 // If the found name is other valid application name |
|
280 // starting with aProcessName string. |
|
281 continue; |
|
282 } |
|
283 } |
|
284 RProcess proc; |
|
285 if (proc.Open(name) == KErrNone) |
|
286 { |
|
287 proc.Kill(0); |
|
288 } |
|
289 proc.Close(); |
|
290 } |
|
291 return KErrNone; |
|
292 } |
|
293 |
|
294 /** |
|
295 @SYMTestCaseID PDS-SQL-CT-4210 |
|
296 @SYMTestCaseDesc Test for the change "Temp files created during sql operations are not deleted after rebooting the phone" |
|
297 @SYMTestPriority High |
|
298 @SYMTestActions Kill the sql server |
|
299 Create two temp files in sql server's private directory |
|
300 Start the sql server |
|
301 Test that the temp files do not exist. |
|
302 @SYMTestExpectedResults Test must not fail |
|
303 */ |
|
304 void DeleteTempFile() |
|
305 { |
|
306 _LIT(KSqlSrvName, "sqlsrv.exe"); |
|
307 _LIT(KTempFile1, "TMP00052.$$$"); |
|
308 _LIT(KTempFile2, "TMP00044.$$$"); |
|
309 |
|
310 KillProcess(KSqlSrvName); |
|
311 |
|
312 //Create two temp file in c:\\private\\10281e17\\temp\\ folder |
|
313 TInt err = TheFs.MkDir(KServerTempDir); |
|
314 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
315 RFile file; |
|
316 TFileName filename1(KServerTempDir); |
|
317 TFileName filename2(KServerTempDir); |
|
318 filename1.Append(KTempFile1); |
|
319 filename2.Append(KTempFile2); |
|
320 err = file.Replace(TheFs, filename1, 0); |
|
321 file.Close(); |
|
322 TEST2(err, KErrNone); |
|
323 err = file.Replace(TheFs, filename2, 0); |
|
324 file.Close(); |
|
325 TEST2(err, KErrNone); |
|
326 |
|
327 //Create a database that should start sql server |
|
328 err = TheDb1.Create(KTestDatabase1); |
|
329 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
330 //Test that the temp files have been deleted during server's start-up |
|
331 TUint dummy; |
|
332 err = TheFs.Att(filename1, dummy); |
|
333 TEST2(err, KErrNotFound); |
|
334 err = TheFs.Att(filename2, dummy); |
|
335 TEST2(err, KErrNotFound); |
|
336 |
|
337 TheDb1.Close(); |
|
338 err = RSqlDatabase::Delete(KTestDatabase1); |
|
339 TEST2(err, KErrNone); |
|
340 } |
|
341 |
|
342 TInt TempFilesCount() |
|
343 { |
|
344 _LIT(KServerTempDirMask, "c:\\private\\10281e17\\temp\\*.*"); |
|
345 CDir* dir = NULL; |
|
346 TInt err = TheFs.GetDir(KServerTempDirMask, KEntryAttNormal, ESortNone, dir); |
|
347 TEST2(err, KErrNone); |
|
348 TInt tmpFileCount = dir->Count(); |
|
349 delete dir; |
|
350 return tmpFileCount; |
|
351 } |
|
352 |
|
353 /** |
|
354 @SYMTestCaseID PDS-SQL-CT-4211 |
|
355 @SYMTestCaseDesc Test for the change "Temp files created during sql operations are not deleted after rebooting the phone" |
|
356 @SYMTestPriority High |
|
357 @SYMTestActions The test creates a database and runs a set of statements that |
|
358 will lead to a delayed creation of a temp file. |
|
359 At the end the test checks that the temp file was created. |
|
360 @SYMTestExpectedResults Test must not fail |
|
361 */ |
|
362 void TempFileTest() |
|
363 { |
|
364 (void)RSqlDatabase::Delete(KTestDatabase1); |
|
365 TInt err = TheDb1.Create(KTestDatabase1); |
|
366 TEST2(err, KErrNone); |
|
367 //Get the number of the files in the SQL temp directory |
|
368 TInt tmpFileCount = TempFilesCount(); |
|
369 // |
|
370 err = TheDb1.Exec(_L("CREATE TABLE t1(x UNIQUE); INSERT INTO t1 VALUES(1)")); |
|
371 TEST(err >= 0); |
|
372 err = TheDb1.Exec(_L("BEGIN; UPDATE t1 SET x = 2; UPDATE t1 SET x = 3; COMMIT")); |
|
373 TEST(err >= 0); |
|
374 //Check that a temp file really was created |
|
375 TInt tmpFileCount2 = TempFilesCount(); |
|
376 TEST(tmpFileCount2 > tmpFileCount); |
|
377 // |
|
378 TheDb1.Close(); |
|
379 err = RSqlDatabase::Delete(KTestDatabase1); |
|
380 TEST2(err, KErrNone); |
|
381 } |
|
382 |
|
383 /** |
|
384 @SYMTestCaseID PDS-SQL-CT-4214 |
|
385 @SYMTestCaseDesc Test for the change "After *#7370# Java apps are not preinstalled again" |
|
386 @SYMTestPriority High |
|
387 @SYMTestActions The test makes sure there are no issues if the temp folder is removed after the server |
|
388 has already started. The test performs the following actions - |
|
389 1. Delete the 'temp' directory. |
|
390 2. Create a transaction which creates temp files. |
|
391 3. Check 'temp' folder exists at the end |
|
392 @SYMTestExpectedResults Test must not fail |
|
393 */ |
|
394 void DeleteTempFolder() |
|
395 { |
|
396 //1. Delete 'temp' folder |
|
397 TInt err = TheFs.RmDir(KServerTempDir); |
|
398 TEST2(err, KErrNone); |
|
399 |
|
400 //2. Create a transaction which creates temp files. |
|
401 (void)RSqlDatabase::Delete(KTestDatabase1); |
|
402 err = TheDb1.Create(KTestDatabase1); |
|
403 TEST2(err, KErrNone); |
|
404 |
|
405 err = TheDb1.Exec(_L("CREATE TABLE t1(x UNIQUE); INSERT INTO t1 VALUES(1)")); |
|
406 TEST(err >= 0); |
|
407 err = TheDb1.Exec(_L("BEGIN; UPDATE t1 SET x = 2; UPDATE t1 SET x = 3; COMMIT")); |
|
408 TEST(err >= 0); |
|
409 |
|
410 TheDb1.Close(); |
|
411 err = RSqlDatabase::Delete(KTestDatabase1); |
|
412 TEST2(err, KErrNone); |
|
413 |
|
414 //3. Check 'temp' folder exists |
|
415 err = TheFs.MkDir(KServerTempDir); |
|
416 TEST2(err, KErrAlreadyExists); |
|
417 } |
|
418 |
|
419 /** |
|
420 @SYMTestCaseID PDS-SQL-CT-4213 |
|
421 @SYMTestCaseDesc Tests the ability of the SQL server to store empty strings and retrieve them as |
|
422 text column values, not NULLs. |
|
423 Change: ou1cimx1#504388. |
|
424 @SYMTestPriority High |
|
425 @SYMTestActions The test creates a database and a table and stores there empty strings. |
|
426 Then the test retrieves the stored column values and verifies that the column type is |
|
427 "text", not "null". |
|
428 @SYMTestExpectedResults Test must not fail |
|
429 */ |
|
430 void EmptyTextColumnTest() |
|
431 { |
|
432 _LIT8(KEncUtf16, "encoding=\"UTF-16\""); |
|
433 _LIT8(KEncUtf8, "encoding=\"UTF-8\""); |
|
434 TPtrC8 enc[] = {KEncUtf16(), KEncUtf8()}; |
|
435 for(TInt i=0;i<(sizeof(enc)/sizeof(enc[0]));++i) |
|
436 { |
|
437 (void)RSqlDatabase::Delete(KTestDatabase1); |
|
438 TInt err = TheDb1.Create(KTestDatabase1, &enc[i]); |
|
439 TEST2(err, KErrNone); |
|
440 //Insert records with empty text column values using RSqlDatabase::Exec() |
|
441 err = TheDb1.Exec(_L("CREATE TABLE A(ID INTEGER, T TEXT)")); |
|
442 TEST(err >= 0); |
|
443 err = TheDb1.Exec(_L("INSERT INTO A VALUES(1, '')")); |
|
444 TEST2(err, 1); |
|
445 err = TheDb1.Exec(_L8("INSERT INTO A VALUES(2, '')")); |
|
446 TEST2(err, 1); |
|
447 //Insert a record with empty text column value using RSqlParamWriteStream |
|
448 RSqlStatement stmt; |
|
449 err = stmt.Prepare(TheDb1, _L("INSERT INTO A(ID, T) VALUES(:P1, :P2)")); |
|
450 TEST2(err, KErrNone); |
|
451 err = stmt.BindInt(0, 3); |
|
452 TEST2(err, KErrNone); |
|
453 RSqlParamWriteStream strm; |
|
454 err = strm.BindText(stmt, 1); |
|
455 TEST2(err, KErrNone); |
|
456 TRAP(err, strm.WriteL(KNullDesC)); |
|
457 TEST2(err, KErrNone); |
|
458 strm.Close(); |
|
459 err = stmt.Exec(); |
|
460 TEST2(err, 1); |
|
461 stmt.Close(); |
|
462 //Insert records with empty text column values using RSqlStatement::Bind() |
|
463 err = stmt.Prepare(TheDb1, _L("INSERT INTO A(ID, T) VALUES(:P1, :P2)")); |
|
464 TEST2(err, KErrNone); |
|
465 err = stmt.BindInt(0, 4); |
|
466 TEST2(err, KErrNone); |
|
467 err = stmt.BindText(1, KNullDesC); |
|
468 TEST2(err, KErrNone); |
|
469 err = stmt.Exec(); |
|
470 TEST2(err, 1); |
|
471 // |
|
472 err = stmt.Reset(); |
|
473 TEST2(err, KErrNone); |
|
474 err = stmt.BindInt(0, 5); |
|
475 TEST2(err, KErrNone); |
|
476 _LIT(KEmptyStr, ""); |
|
477 err = stmt.BindText(1, KEmptyStr); |
|
478 TEST2(err, KErrNone); |
|
479 err = stmt.Exec(); |
|
480 TEST2(err, 1); |
|
481 stmt.Close(); |
|
482 //Read the empty text column values |
|
483 err = stmt.Prepare(TheDb1, _L("SELECT T FROM A")); |
|
484 TEST2(err, KErrNone); |
|
485 TInt cnt = 0; |
|
486 while((err = stmt.Next()) == KSqlAtRow) |
|
487 { |
|
488 ++cnt; |
|
489 TPtrC val; |
|
490 err = stmt.ColumnText(0, val); |
|
491 TEST2(err, KErrNone); |
|
492 TEST2(val.Length(), 0); |
|
493 TSqlColumnType type = stmt.ColumnType(0); |
|
494 TEST2(type, ESqlText); |
|
495 } |
|
496 stmt.Close(); |
|
497 TEST2(err, KSqlAtEnd); |
|
498 TEST2(cnt, 5); |
|
499 // |
|
500 TheDb1.Close(); |
|
501 err = RSqlDatabase::Delete(KTestDatabase1); |
|
502 TEST2(err, KErrNone); |
|
503 } |
|
504 } |
|
505 |
262 void DoTestsL() |
506 void DoTestsL() |
263 { |
507 { |
264 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4154 DEF143062: SQL, \"CREATE INDEX\" sql crashes SQL server")); |
508 TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4154 DEF143062: SQL, \"CREATE INDEX\" sql crashes SQL server")); |
265 DEF143062(); |
509 DEF143062(); |
266 |
510 |
267 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4155 DEF143061: SQL, SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT value is too big")); |
511 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4155 DEF143061: SQL, SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT value is too big")); |
268 DEF143061(); |
512 DEF143061(); |
269 |
513 |
270 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4156 DEF143150: SQL, strftime() returns incorrect result")); |
514 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4156 DEF143150: SQL, strftime() returns incorrect result")); |
271 DEF143150(); |
515 DEF143150(); |
|
516 |
|
517 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4210 Temp files created during sql operations are not deleted after rebooting the phone - 1")); |
|
518 DeleteTempFile(); |
|
519 |
|
520 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4211 Temp files created during sql operations are not deleted after rebooting the phone - 2")); |
|
521 TempFileTest(); |
|
522 |
|
523 TheTest.Next(_L(" @SYMTestCaseID:PDS-SQL-CT-4213 No support to store an empty string in symbian's sqlite.")); |
|
524 EmptyTextColumnTest(); |
|
525 |
|
526 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4214 After *#7370# Java apps are not preinstalled again")); |
|
527 DeleteTempFolder(); |
272 } |
528 } |
273 |
529 |
274 TInt E32Main() |
530 TInt E32Main() |
275 { |
531 { |
276 TheTest.Title(); |
532 TheTest.Title(); |