sl@0: // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // SQL security - copying secure test databases to C: sl@0: // Please, ensure that t_sqlenvcreate test is executed before the other sql tests sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: RTest TheTest(_L("t_sqlenvcreate - copying secure test databases to C:")); sl@0: sl@0: _LIT(KSqlServerPrivateDirC, "c:\\private\\10281e17\\"); sl@0: sl@0: _LIT(KDbZFileName1, "z:\\private\\10281e17\\[21212122]AADb2.db"); sl@0: _LIT(KDbZFileName2, "z:\\private\\10281e17\\[21212122]BBDb2.db"); sl@0: _LIT(KDbZFileName3, "z:\\private\\10281e17\\[21212125]T_AB.db"); sl@0: _LIT(KDbZFileName4, "z:\\private\\10281e17\\[1111CCCC]T_AB.db"); sl@0: _LIT(KDbZFileName5, "z:\\private\\10281e17\\[21212125]T_OneDefPolicy.db"); sl@0: sl@0: _LIT(KDbCFileName1, "c:\\private\\10281e17\\[21212122]AADb2.db"); sl@0: _LIT(KDbCFileName2, "c:\\private\\10281e17\\[21212122]BBDb2.db"); sl@0: _LIT(KDbCFileName3, "c:\\private\\10281e17\\[21212125]T_AB.db"); sl@0: _LIT(KDbCFileName4, "c:\\private\\10281e17\\[1111CCCC]T_AB.db"); sl@0: _LIT(KDbCFileName5, "c:\\private\\10281e17\\[21212125]T_OneDefPolicy.db"); sl@0: sl@0: _LIT(KDb1org, "z:\\private\\10281e17\\[98765432]t_nosettings.db"); sl@0: _LIT(KDb1, "c:\\private\\10281e17\\[98765432]t_nosettings.db"); sl@0: sl@0: _LIT(KDb2org, "z:\\private\\10281e17\\[98765432]t_emptysettings.db"); sl@0: _LIT(KDb2, "c:\\private\\10281e17\\[98765432]t_emptysettings.db"); sl@0: sl@0: _LIT(KDb3org, "z:\\private\\10281e17\\[98765432]t_invversion.db"); sl@0: _LIT(KDb3, "c:\\private\\10281e17\\[98765432]t_invversion.db"); sl@0: sl@0: _LIT(KDb4org, "z:\\private\\10281e17\\[98765432]t_nocollation.db"); sl@0: _LIT(KDb4, "c:\\private\\10281e17\\[98765432]t_nocollation.db"); sl@0: sl@0: _LIT(KDb5org, "z:\\private\\10281e17\\[98765432]t_longcollation.db"); sl@0: _LIT(KDb5, "c:\\private\\10281e17\\[98765432]t_longcollation.db"); sl@0: sl@0: _LIT(KDb6org, "z:\\private\\10281e17\\[98765432]t_nodefaultpolicy.db"); sl@0: _LIT(KDb6, "c:\\private\\10281e17\\[98765432]t_nodefaultpolicy.db"); sl@0: sl@0: _LIT(KDb7org, "z:\\private\\10281e17\\[98765432]t_invobject.db"); sl@0: _LIT(KDb7, "c:\\private\\10281e17\\[98765432]t_invobject.db"); sl@0: sl@0: _LIT(KDb8org, "z:\\private\\10281e17\\[98765432]t_2defaultpolicies.db"); sl@0: _LIT(KDb8, "c:\\private\\10281e17\\[98765432]t_2defaultpolicies.db"); sl@0: sl@0: _LIT(KPrivateSubDir, "c:\\private\\10281e17\\cfg-TestDir.db\\"); sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: //Test macros and functions sl@0: static void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: RDebug::Print(_L("*** Line %d\r\n"), aLine); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: static void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: void DoRun() sl@0: { sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-LEGACY-T_SQLENVCREATE-0001 Copy secure databases from Z: to C: ")); sl@0: sl@0: //Create a subdir in the private datacage. The SQL production code should properly detects sl@0: //KPrivateSubDir is a directory not a database file sl@0: err = fs.MkDir(KPrivateSubDir); sl@0: TEST(err == KErrNone || err == KErrAlreadyExists); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDbZFileName1, KDbCFileName1); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDbCFileName1, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDbZFileName2, KDbCFileName2); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDbCFileName2, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDbZFileName3, KDbCFileName3); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDbCFileName3, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDbZFileName4, KDbCFileName4); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDbCFileName4, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDbZFileName5, KDbCFileName5); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDbCFileName5, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb1org, KDb1); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb1, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb2org, KDb2); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb2, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb3org, KDb3); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb3, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb4org, KDb4); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb4, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb5org, KDb5); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb5, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb6org, KDb6); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb6, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb7org, KDb7); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb7, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: err = BaflUtils::CopyFile(fs, KDb8org, KDb8); sl@0: TEST2(err, KErrNone); sl@0: err = fs.SetAtt(KDb8, 0, KEntryAttReadOnly); sl@0: TEST2(err, KErrNone); sl@0: sl@0: fs.Close(); sl@0: } sl@0: sl@0: void CreateSqlServerPrivateDir() sl@0: { sl@0: RFs fs; sl@0: TInt err = fs.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TRAP(err, BaflUtils::EnsurePathExistsL(fs, KSqlServerPrivateDirC)); sl@0: TEST2(err, KErrNone); sl@0: sl@0: fs.Close(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: TheTest.Title(); sl@0: sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: CreateSqlServerPrivateDir(); sl@0: sl@0: DoRun(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: delete tc; sl@0: sl@0: User::Heap().Check(); sl@0: return KErrNone; sl@0: }