diff -r cce6680bbf1c -r ba1c4f4a893f persistentstorage/sql/TEST/t_sqldefect2.cpp --- a/persistentstorage/sql/TEST/t_sqldefect2.cpp Thu Jul 01 17:02:22 2010 +0100 +++ b/persistentstorage/sql/TEST/t_sqldefect2.cpp Tue Jul 06 11:54:49 2010 +0100 @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +// Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). // All rights reserved. // This component and the accompanying materials are made available // under the terms of "Eclipse Public License v1.0" @@ -16,7 +16,7 @@ #include #include #include - +#include /////////////////////////////////////////////////////////////////////////////////////// static RFs TheFs; @@ -259,6 +259,128 @@ TEST(diff.Int() <= 1); } +static TInt KillProcess(const TDesC& aProcessName) + { + TFullName name; + TBuf<64> pattern(aProcessName); + TInt length = pattern.Length(); + pattern += _L("*"); + TFindProcess procFinder(pattern); + + while (procFinder.Next(name) == KErrNone) + { + if (name.Length() > length) + {//If found name is a string containing aProcessName string. + TChar c(name[length]); + if (c.IsAlphaDigit() || + c == TChar('_') || + c == TChar('-')) + { + // If the found name is other valid application name + // starting with aProcessName string. + continue; + } + } + RProcess proc; + if (proc.Open(name) == KErrNone) + { + proc.Kill(0); + } + proc.Close(); + } + return KErrNone; + } + +/** +@SYMTestCaseID PDS-SQL-CT-4210 +@SYMTestCaseDesc Test for the change "Temp files created during sql operations are not deleted after rebooting the phone" +@SYMTestPriority High +@SYMTestActions Kill the sql server + Create two temp files in sql server's private directory + Start the sql server + Test that the temp files do not exist. +@SYMTestExpectedResults Test must not fail +*/ +void DeleteTempFile() + { + _LIT(KSqlSrvName, "sqlsrv.exe"); + _LIT(KServerTempDir, "c:\\private\\10281e17\\temp\\"); + _LIT(KTempFile1, "TMP00052.$$$"); + _LIT(KTempFile2, "TMP00044.$$$"); + + KillProcess(KSqlSrvName); + + //Create two temp file in c:\\private\\10281e17\\temp\\ folder + TInt err = TheFs.MkDir(KServerTempDir); + TEST(err == KErrNone || err == KErrAlreadyExists); + RFile file; + TFileName filename1(KServerTempDir); + TFileName filename2(KServerTempDir); + filename1.Append(KTempFile1); + filename2.Append(KTempFile2); + err = file.Replace(TheFs, filename1, 0); + file.Close(); + TEST2(err, KErrNone); + err = file.Replace(TheFs, filename2, 0); + file.Close(); + TEST2(err, KErrNone); + + //Create a database that should start sql server + err = TheDb1.Create(KTestDatabase1); + TEST(err == KErrNone || err == KErrAlreadyExists); + //Test that the temp files have been deleted during server's start-up + TUint dummy; + err = TheFs.Att(filename1, dummy); + TEST2(err, KErrNotFound); + err = TheFs.Att(filename2, dummy); + TEST2(err, KErrNotFound); + + TheDb1.Close(); + err = RSqlDatabase::Delete(KTestDatabase1); + TEST2(err, KErrNone); + } + +TInt TempFilesCount() + { + _LIT(KServerTempDirMask, "c:\\private\\10281e17\\temp\\*.*"); + CDir* dir = NULL; + TInt err = TheFs.GetDir(KServerTempDirMask, KEntryAttNormal, ESortNone, dir); + TEST2(err, KErrNone); + TInt tmpFileCount = dir->Count(); + delete dir; + return tmpFileCount; + } + +/** +@SYMTestCaseID PDS-SQL-CT-4211 +@SYMTestCaseDesc Test for the change "Temp files created during sql operations are not deleted after rebooting the phone" +@SYMTestPriority High +@SYMTestActions The test creates a database and runs a set of statements that + will lead to a delayed creation of a temp file. + At the end the test checks that the temp file was created. +@SYMTestExpectedResults Test must not fail +*/ +void TempFileTest() + { + (void)RSqlDatabase::Delete(KTestDatabase1); + TInt err = TheDb1.Create(KTestDatabase1); + TEST2(err, KErrNone); + //Get the number of the files in the SQL temp directory + TInt tmpFileCount = TempFilesCount(); + // + err = TheDb1.Exec(_L("CREATE TABLE t1(x UNIQUE); INSERT INTO t1 VALUES(1)")); + TEST(err >= 0); + err = TheDb1.Exec(_L("BEGIN; UPDATE t1 SET x = 2; UPDATE t1 SET x = 3; COMMIT")); + TEST(err >= 0); + //Check that a temp file really was created + TInt tmpFileCount2 = TempFilesCount(); + TEST(tmpFileCount2 > tmpFileCount); + // + TheDb1.Close(); + err = RSqlDatabase::Delete(KTestDatabase1); + TEST2(err, KErrNone); + } + void DoTestsL() { TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4154 DEF143062: SQL, \"CREATE INDEX\" sql crashes SQL server")); @@ -269,6 +391,12 @@ TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SQL-CT-4156 DEF143150: SQL, strftime() returns incorrect result")); DEF143150(); + + TheTest.Next(_L(" @SYMTestCaseDesc Temp files created during sql operations are not deleted after rebooting the phone - 1")); + DeleteTempFile(); + + TheTest.Next(_L(" @SYMTestCaseDesc Temp files created during sql operations are not deleted after rebooting the phone - 2")); + TempFileTest(); } TInt E32Main()