os/persistentdata/persistentstorage/sql/TEST/t_sqlenvcreate.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sql/TEST/t_sqlenvcreate.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,202 @@
     1.4 +// Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// SQL security - copying secure test databases to C:
    1.18 +// Please, ensure that t_sqlenvcreate test is executed before the other sql tests
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <e32test.h>
    1.23 +#include <bautils.h>
    1.24 +
    1.25 +RTest TheTest(_L("t_sqlenvcreate - copying secure test databases to C:"));
    1.26 +
    1.27 +_LIT(KSqlServerPrivateDirC, "c:\\private\\10281e17\\");
    1.28 +
    1.29 +_LIT(KDbZFileName1, "z:\\private\\10281e17\\[21212122]AADb2.db");
    1.30 +_LIT(KDbZFileName2, "z:\\private\\10281e17\\[21212122]BBDb2.db");
    1.31 +_LIT(KDbZFileName3, "z:\\private\\10281e17\\[21212125]T_AB.db");
    1.32 +_LIT(KDbZFileName4, "z:\\private\\10281e17\\[1111CCCC]T_AB.db");
    1.33 +_LIT(KDbZFileName5, "z:\\private\\10281e17\\[21212125]T_OneDefPolicy.db");
    1.34 +
    1.35 +_LIT(KDbCFileName1, "c:\\private\\10281e17\\[21212122]AADb2.db");
    1.36 +_LIT(KDbCFileName2, "c:\\private\\10281e17\\[21212122]BBDb2.db");
    1.37 +_LIT(KDbCFileName3, "c:\\private\\10281e17\\[21212125]T_AB.db");
    1.38 +_LIT(KDbCFileName4, "c:\\private\\10281e17\\[1111CCCC]T_AB.db");
    1.39 +_LIT(KDbCFileName5, "c:\\private\\10281e17\\[21212125]T_OneDefPolicy.db");
    1.40 +
    1.41 +_LIT(KDb1org, "z:\\private\\10281e17\\[98765432]t_nosettings.db");
    1.42 +_LIT(KDb1, "c:\\private\\10281e17\\[98765432]t_nosettings.db");
    1.43 +
    1.44 +_LIT(KDb2org, "z:\\private\\10281e17\\[98765432]t_emptysettings.db");
    1.45 +_LIT(KDb2, "c:\\private\\10281e17\\[98765432]t_emptysettings.db");
    1.46 +
    1.47 +_LIT(KDb3org, "z:\\private\\10281e17\\[98765432]t_invversion.db");
    1.48 +_LIT(KDb3, "c:\\private\\10281e17\\[98765432]t_invversion.db");
    1.49 +
    1.50 +_LIT(KDb4org, "z:\\private\\10281e17\\[98765432]t_nocollation.db");
    1.51 +_LIT(KDb4, "c:\\private\\10281e17\\[98765432]t_nocollation.db");
    1.52 +
    1.53 +_LIT(KDb5org, "z:\\private\\10281e17\\[98765432]t_longcollation.db");
    1.54 +_LIT(KDb5, "c:\\private\\10281e17\\[98765432]t_longcollation.db");
    1.55 +
    1.56 +_LIT(KDb6org, "z:\\private\\10281e17\\[98765432]t_nodefaultpolicy.db");
    1.57 +_LIT(KDb6, "c:\\private\\10281e17\\[98765432]t_nodefaultpolicy.db");
    1.58 +
    1.59 +_LIT(KDb7org, "z:\\private\\10281e17\\[98765432]t_invobject.db");
    1.60 +_LIT(KDb7, "c:\\private\\10281e17\\[98765432]t_invobject.db");
    1.61 +
    1.62 +_LIT(KDb8org, "z:\\private\\10281e17\\[98765432]t_2defaultpolicies.db");
    1.63 +_LIT(KDb8, "c:\\private\\10281e17\\[98765432]t_2defaultpolicies.db");
    1.64 +
    1.65 +_LIT(KPrivateSubDir, "c:\\private\\10281e17\\cfg-TestDir.db\\");
    1.66 +
    1.67 +///////////////////////////////////////////////////////////////////////////////////////
    1.68 +///////////////////////////////////////////////////////////////////////////////////////
    1.69 +//Test macros and functions
    1.70 +static void Check(TInt aValue, TInt aLine)
    1.71 +	{
    1.72 +	if(!aValue)
    1.73 +		{
    1.74 +		RDebug::Print(_L("*** Line %d\r\n"), aLine);
    1.75 +		TheTest(EFalse, aLine);
    1.76 +		}
    1.77 +	}
    1.78 +static void Check(TInt aValue, TInt aExpected, TInt aLine)
    1.79 +	{
    1.80 +	if(aValue != aExpected)
    1.81 +		{
    1.82 +		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    1.83 +		TheTest(EFalse, aLine);
    1.84 +		}
    1.85 +	}
    1.86 +#define TEST(arg) ::Check((arg), __LINE__)
    1.87 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    1.88 +
    1.89 +///////////////////////////////////////////////////////////////////////////////////////
    1.90 +
    1.91 +void DoRun()
    1.92 +	{
    1.93 +    RFs fs;
    1.94 +	TInt err = fs.Connect();
    1.95 +	TEST2(err, KErrNone);
    1.96 +
    1.97 +	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-LEGACY-T_SQLENVCREATE-0001 Copy secure databases from Z: to C: "));
    1.98 +
    1.99 +	//Create a subdir in the private datacage. The SQL production code should properly detects
   1.100 +	//KPrivateSubDir is a directory not a database file
   1.101 +	err = fs.MkDir(KPrivateSubDir);
   1.102 +	TEST(err == KErrNone || err == KErrAlreadyExists);
   1.103 +	
   1.104 +	err = BaflUtils::CopyFile(fs, KDbZFileName1, KDbCFileName1);
   1.105 +	TEST2(err, KErrNone);
   1.106 +	err = fs.SetAtt(KDbCFileName1, 0, KEntryAttReadOnly);
   1.107 +	TEST2(err, KErrNone);
   1.108 +
   1.109 +	err = BaflUtils::CopyFile(fs, KDbZFileName2, KDbCFileName2);
   1.110 +	TEST2(err, KErrNone);
   1.111 +	err = fs.SetAtt(KDbCFileName2, 0, KEntryAttReadOnly);
   1.112 +	TEST2(err, KErrNone);
   1.113 +
   1.114 +	err = BaflUtils::CopyFile(fs, KDbZFileName3, KDbCFileName3);
   1.115 +	TEST2(err, KErrNone);
   1.116 +	err = fs.SetAtt(KDbCFileName3, 0, KEntryAttReadOnly);
   1.117 +	TEST2(err, KErrNone);
   1.118 +
   1.119 +	err = BaflUtils::CopyFile(fs, KDbZFileName4, KDbCFileName4);
   1.120 +	TEST2(err, KErrNone);
   1.121 +	err = fs.SetAtt(KDbCFileName4, 0, KEntryAttReadOnly);
   1.122 +	TEST2(err, KErrNone);
   1.123 +
   1.124 +	err = BaflUtils::CopyFile(fs, KDbZFileName5, KDbCFileName5);
   1.125 +	TEST2(err, KErrNone);
   1.126 +	err = fs.SetAtt(KDbCFileName5, 0, KEntryAttReadOnly);
   1.127 +	TEST2(err, KErrNone);
   1.128 +
   1.129 +	err = BaflUtils::CopyFile(fs, KDb1org, KDb1);
   1.130 +	TEST2(err, KErrNone);
   1.131 +	err = fs.SetAtt(KDb1, 0, KEntryAttReadOnly);
   1.132 +	TEST2(err, KErrNone);
   1.133 +
   1.134 +	err = BaflUtils::CopyFile(fs, KDb2org, KDb2);
   1.135 +	TEST2(err, KErrNone);
   1.136 +	err = fs.SetAtt(KDb2, 0, KEntryAttReadOnly);
   1.137 +	TEST2(err, KErrNone);
   1.138 +
   1.139 +	err = BaflUtils::CopyFile(fs, KDb3org, KDb3);
   1.140 +	TEST2(err, KErrNone);
   1.141 +	err = fs.SetAtt(KDb3, 0, KEntryAttReadOnly);
   1.142 +	TEST2(err, KErrNone);
   1.143 +
   1.144 +	err = BaflUtils::CopyFile(fs, KDb4org, KDb4);
   1.145 +	TEST2(err, KErrNone);
   1.146 +	err = fs.SetAtt(KDb4, 0, KEntryAttReadOnly);
   1.147 +	TEST2(err, KErrNone);
   1.148 +
   1.149 +	err = BaflUtils::CopyFile(fs, KDb5org, KDb5);
   1.150 +	TEST2(err, KErrNone);
   1.151 +	err = fs.SetAtt(KDb5, 0, KEntryAttReadOnly);
   1.152 +	TEST2(err, KErrNone);
   1.153 +
   1.154 +	err = BaflUtils::CopyFile(fs, KDb6org, KDb6);
   1.155 +	TEST2(err, KErrNone);
   1.156 +	err = fs.SetAtt(KDb6, 0, KEntryAttReadOnly);
   1.157 +	TEST2(err, KErrNone);
   1.158 +
   1.159 +	err = BaflUtils::CopyFile(fs, KDb7org, KDb7);
   1.160 +	TEST2(err, KErrNone);
   1.161 +	err = fs.SetAtt(KDb7, 0, KEntryAttReadOnly);
   1.162 +	TEST2(err, KErrNone);
   1.163 +
   1.164 +	err = BaflUtils::CopyFile(fs, KDb8org, KDb8);
   1.165 +	TEST2(err, KErrNone);
   1.166 +	err = fs.SetAtt(KDb8, 0, KEntryAttReadOnly);
   1.167 +	TEST2(err, KErrNone);
   1.168 +
   1.169 +	fs.Close();
   1.170 +	}
   1.171 +
   1.172 +void CreateSqlServerPrivateDir()
   1.173 +    {
   1.174 +    RFs fs;
   1.175 +	TInt err = fs.Connect();
   1.176 +	TEST2(err, KErrNone);
   1.177 +
   1.178 +	TRAP(err, BaflUtils::EnsurePathExistsL(fs, KSqlServerPrivateDirC));
   1.179 +	TEST2(err, KErrNone);
   1.180 +
   1.181 +	fs.Close();
   1.182 +	}
   1.183 +
   1.184 +TInt E32Main()
   1.185 +    {
   1.186 +	TheTest.Title();
   1.187 +
   1.188 +	CTrapCleanup* tc = CTrapCleanup::New();
   1.189 +
   1.190 +	__UHEAP_MARK;
   1.191 +
   1.192 +	CreateSqlServerPrivateDir();
   1.193 +
   1.194 +	DoRun();
   1.195 +
   1.196 +	__UHEAP_MARKEND;
   1.197 +
   1.198 +	TheTest.End();
   1.199 +	TheTest.Close();
   1.200 +
   1.201 +	delete tc;
   1.202 +
   1.203 +	User::Heap().Check();
   1.204 +	return KErrNone;
   1.205 +    }