persistentstorage/sql/TEST/t_sqldefect2.cpp
changeset 41 3256212fc81f
parent 0 08ec8eefde2f
child 40 b8bdbc8f59c7
equal deleted inserted replaced
35:0d6db0a14001 41:3256212fc81f
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 //
    14 //
    15 
    15 
    16 #include <e32test.h>
    16 #include <e32test.h>
    17 #include <f32file.h>
    17 #include <f32file.h>
    18 #include <sqldb.h>
    18 #include <sqldb.h>
    19 
    19 #include <f32file.h>
    20 ///////////////////////////////////////////////////////////////////////////////////////
    20 ///////////////////////////////////////////////////////////////////////////////////////
    21 
    21 
    22 static RFs TheFs;
    22 static RFs TheFs;
    23 static RTest TheTest(_L("t_sqldefect2 test"));
    23 static RTest TheTest(_L("t_sqldefect2 test"));
    24 static RSqlDatabase TheDb1;
    24 static RSqlDatabase TheDb1;
   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(KServerTempDir, "c:\\private\\10281e17\\temp\\");
       
   308     _LIT(KTempFile1, "TMP00052.$$$");
       
   309     _LIT(KTempFile2, "TMP00044.$$$");
       
   310     
       
   311     KillProcess(KSqlSrvName);
       
   312  
       
   313     //Create two temp file in c:\\private\\10281e17\\temp\\ folder
       
   314     TInt err = TheFs.MkDir(KServerTempDir);
       
   315     TEST(err == KErrNone || err == KErrAlreadyExists);
       
   316     RFile file;
       
   317     TFileName filename1(KServerTempDir);
       
   318     TFileName filename2(KServerTempDir);
       
   319     filename1.Append(KTempFile1);
       
   320     filename2.Append(KTempFile2);
       
   321     err = file.Replace(TheFs, filename1, 0);
       
   322     file.Close();
       
   323     TEST2(err, KErrNone);
       
   324     err = file.Replace(TheFs, filename2, 0);
       
   325     file.Close();
       
   326     TEST2(err, KErrNone);
       
   327     
       
   328     //Create a database that should start sql server
       
   329     err = TheDb1.Create(KTestDatabase1);
       
   330     TEST(err == KErrNone || err == KErrAlreadyExists);
       
   331     //Test that the temp files have been deleted during server's start-up
       
   332     TUint dummy;
       
   333     err = TheFs.Att(filename1, dummy);
       
   334     TEST2(err, KErrNotFound);
       
   335     err = TheFs.Att(filename2, dummy);
       
   336     TEST2(err, KErrNotFound);
       
   337     
       
   338     TheDb1.Close();
       
   339     err = RSqlDatabase::Delete(KTestDatabase1);
       
   340     TEST2(err, KErrNone);
       
   341     }
       
   342 
       
   343 TInt TempFilesCount()
       
   344 	{
       
   345     _LIT(KServerTempDirMask, "c:\\private\\10281e17\\temp\\*.*");
       
   346 	CDir* dir = NULL;
       
   347 	TInt err = TheFs.GetDir(KServerTempDirMask, KEntryAttNormal, ESortNone, dir);
       
   348 	TEST2(err, KErrNone);
       
   349 	TInt tmpFileCount = dir->Count();
       
   350 	delete dir;
       
   351 	return tmpFileCount;
       
   352 	}
       
   353 
       
   354 /**
       
   355 @SYMTestCaseID          PDS-SQL-CT-4211
       
   356 @SYMTestCaseDesc        Test for the change "Temp files created during sql operations are not deleted after rebooting the phone" 
       
   357 @SYMTestPriority        High
       
   358 @SYMTestActions         The test creates a database and runs a set of statements that
       
   359 						will lead to a delayed creation of a temp file.
       
   360 						At the end the test checks that the temp file was created.
       
   361 @SYMTestExpectedResults Test must not fail
       
   362 */
       
   363 void TempFileTest()
       
   364 	{
       
   365     (void)RSqlDatabase::Delete(KTestDatabase1);
       
   366     TInt err = TheDb1.Create(KTestDatabase1);
       
   367     TEST2(err, KErrNone);
       
   368     //Get the number of the files in the SQL temp directory 
       
   369 	TInt tmpFileCount = TempFilesCount();
       
   370     //    
       
   371     err = TheDb1.Exec(_L("CREATE TABLE t1(x UNIQUE); INSERT INTO t1 VALUES(1)"));
       
   372     TEST(err >= 0);
       
   373     err = TheDb1.Exec(_L("BEGIN; UPDATE t1 SET x = 2; UPDATE t1 SET x = 3; COMMIT"));
       
   374     TEST(err >= 0);
       
   375     //Check that a temp file really was created
       
   376 	TInt tmpFileCount2 = TempFilesCount();
       
   377 	TEST(tmpFileCount2 > tmpFileCount);
       
   378     //
       
   379     TheDb1.Close();
       
   380     err = RSqlDatabase::Delete(KTestDatabase1);
       
   381     TEST2(err, KErrNone);
       
   382 	}
       
   383 
   262 void DoTestsL()
   384 void DoTestsL()
   263 	{
   385 	{
   264 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4154 DEF143062: SQL, \"CREATE INDEX\" sql crashes SQL server"));
   386 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4154 DEF143062: SQL, \"CREATE INDEX\" sql crashes SQL server"));
   265 	DEF143062();
   387 	DEF143062();
   266 
   388 
   267     TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4155 DEF143061: SQL, SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT value is too big"));
   389     TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4155 DEF143061: SQL, SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT value is too big"));
   268     DEF143061();
   390     DEF143061();
   269 
   391 
   270     TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4156 DEF143150: SQL, strftime() returns incorrect result"));
   392     TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4156 DEF143150: SQL, strftime() returns incorrect result"));
   271     DEF143150();
   393     DEF143150();
       
   394     
       
   395     TheTest.Next(_L(" @SYMTestCaseDesc Temp files created during sql operations are not deleted after rebooting the phone - 1"));
       
   396     DeleteTempFile();
       
   397     
       
   398     TheTest.Next(_L(" @SYMTestCaseDesc Temp files created during sql operations are not deleted after rebooting the phone - 2"));
       
   399     TempFileTest();
   272 	}
   400 	}
   273 
   401 
   274 TInt E32Main()
   402 TInt E32Main()
   275 	{
   403 	{
   276 	TheTest.Title();
   404 	TheTest.Title();