os/persistentdata/persistentstorage/sql/TEST/t_sqlenvcreate.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // SQL security - copying secure test databases to C:
    15 // Please, ensure that t_sqlenvcreate test is executed before the other sql tests
    16 // 
    17 //
    18 
    19 #include <e32test.h>
    20 #include <bautils.h>
    21 
    22 RTest TheTest(_L("t_sqlenvcreate - copying secure test databases to C:"));
    23 
    24 _LIT(KSqlServerPrivateDirC, "c:\\private\\10281e17\\");
    25 
    26 _LIT(KDbZFileName1, "z:\\private\\10281e17\\[21212122]AADb2.db");
    27 _LIT(KDbZFileName2, "z:\\private\\10281e17\\[21212122]BBDb2.db");
    28 _LIT(KDbZFileName3, "z:\\private\\10281e17\\[21212125]T_AB.db");
    29 _LIT(KDbZFileName4, "z:\\private\\10281e17\\[1111CCCC]T_AB.db");
    30 _LIT(KDbZFileName5, "z:\\private\\10281e17\\[21212125]T_OneDefPolicy.db");
    31 
    32 _LIT(KDbCFileName1, "c:\\private\\10281e17\\[21212122]AADb2.db");
    33 _LIT(KDbCFileName2, "c:\\private\\10281e17\\[21212122]BBDb2.db");
    34 _LIT(KDbCFileName3, "c:\\private\\10281e17\\[21212125]T_AB.db");
    35 _LIT(KDbCFileName4, "c:\\private\\10281e17\\[1111CCCC]T_AB.db");
    36 _LIT(KDbCFileName5, "c:\\private\\10281e17\\[21212125]T_OneDefPolicy.db");
    37 
    38 _LIT(KDb1org, "z:\\private\\10281e17\\[98765432]t_nosettings.db");
    39 _LIT(KDb1, "c:\\private\\10281e17\\[98765432]t_nosettings.db");
    40 
    41 _LIT(KDb2org, "z:\\private\\10281e17\\[98765432]t_emptysettings.db");
    42 _LIT(KDb2, "c:\\private\\10281e17\\[98765432]t_emptysettings.db");
    43 
    44 _LIT(KDb3org, "z:\\private\\10281e17\\[98765432]t_invversion.db");
    45 _LIT(KDb3, "c:\\private\\10281e17\\[98765432]t_invversion.db");
    46 
    47 _LIT(KDb4org, "z:\\private\\10281e17\\[98765432]t_nocollation.db");
    48 _LIT(KDb4, "c:\\private\\10281e17\\[98765432]t_nocollation.db");
    49 
    50 _LIT(KDb5org, "z:\\private\\10281e17\\[98765432]t_longcollation.db");
    51 _LIT(KDb5, "c:\\private\\10281e17\\[98765432]t_longcollation.db");
    52 
    53 _LIT(KDb6org, "z:\\private\\10281e17\\[98765432]t_nodefaultpolicy.db");
    54 _LIT(KDb6, "c:\\private\\10281e17\\[98765432]t_nodefaultpolicy.db");
    55 
    56 _LIT(KDb7org, "z:\\private\\10281e17\\[98765432]t_invobject.db");
    57 _LIT(KDb7, "c:\\private\\10281e17\\[98765432]t_invobject.db");
    58 
    59 _LIT(KDb8org, "z:\\private\\10281e17\\[98765432]t_2defaultpolicies.db");
    60 _LIT(KDb8, "c:\\private\\10281e17\\[98765432]t_2defaultpolicies.db");
    61 
    62 _LIT(KPrivateSubDir, "c:\\private\\10281e17\\cfg-TestDir.db\\");
    63 
    64 ///////////////////////////////////////////////////////////////////////////////////////
    65 ///////////////////////////////////////////////////////////////////////////////////////
    66 //Test macros and functions
    67 static void Check(TInt aValue, TInt aLine)
    68 	{
    69 	if(!aValue)
    70 		{
    71 		RDebug::Print(_L("*** Line %d\r\n"), aLine);
    72 		TheTest(EFalse, aLine);
    73 		}
    74 	}
    75 static void Check(TInt aValue, TInt aExpected, TInt aLine)
    76 	{
    77 	if(aValue != aExpected)
    78 		{
    79 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    80 		TheTest(EFalse, aLine);
    81 		}
    82 	}
    83 #define TEST(arg) ::Check((arg), __LINE__)
    84 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    85 
    86 ///////////////////////////////////////////////////////////////////////////////////////
    87 
    88 void DoRun()
    89 	{
    90     RFs fs;
    91 	TInt err = fs.Connect();
    92 	TEST2(err, KErrNone);
    93 
    94 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-LEGACY-T_SQLENVCREATE-0001 Copy secure databases from Z: to C: "));
    95 
    96 	//Create a subdir in the private datacage. The SQL production code should properly detects
    97 	//KPrivateSubDir is a directory not a database file
    98 	err = fs.MkDir(KPrivateSubDir);
    99 	TEST(err == KErrNone || err == KErrAlreadyExists);
   100 	
   101 	err = BaflUtils::CopyFile(fs, KDbZFileName1, KDbCFileName1);
   102 	TEST2(err, KErrNone);
   103 	err = fs.SetAtt(KDbCFileName1, 0, KEntryAttReadOnly);
   104 	TEST2(err, KErrNone);
   105 
   106 	err = BaflUtils::CopyFile(fs, KDbZFileName2, KDbCFileName2);
   107 	TEST2(err, KErrNone);
   108 	err = fs.SetAtt(KDbCFileName2, 0, KEntryAttReadOnly);
   109 	TEST2(err, KErrNone);
   110 
   111 	err = BaflUtils::CopyFile(fs, KDbZFileName3, KDbCFileName3);
   112 	TEST2(err, KErrNone);
   113 	err = fs.SetAtt(KDbCFileName3, 0, KEntryAttReadOnly);
   114 	TEST2(err, KErrNone);
   115 
   116 	err = BaflUtils::CopyFile(fs, KDbZFileName4, KDbCFileName4);
   117 	TEST2(err, KErrNone);
   118 	err = fs.SetAtt(KDbCFileName4, 0, KEntryAttReadOnly);
   119 	TEST2(err, KErrNone);
   120 
   121 	err = BaflUtils::CopyFile(fs, KDbZFileName5, KDbCFileName5);
   122 	TEST2(err, KErrNone);
   123 	err = fs.SetAtt(KDbCFileName5, 0, KEntryAttReadOnly);
   124 	TEST2(err, KErrNone);
   125 
   126 	err = BaflUtils::CopyFile(fs, KDb1org, KDb1);
   127 	TEST2(err, KErrNone);
   128 	err = fs.SetAtt(KDb1, 0, KEntryAttReadOnly);
   129 	TEST2(err, KErrNone);
   130 
   131 	err = BaflUtils::CopyFile(fs, KDb2org, KDb2);
   132 	TEST2(err, KErrNone);
   133 	err = fs.SetAtt(KDb2, 0, KEntryAttReadOnly);
   134 	TEST2(err, KErrNone);
   135 
   136 	err = BaflUtils::CopyFile(fs, KDb3org, KDb3);
   137 	TEST2(err, KErrNone);
   138 	err = fs.SetAtt(KDb3, 0, KEntryAttReadOnly);
   139 	TEST2(err, KErrNone);
   140 
   141 	err = BaflUtils::CopyFile(fs, KDb4org, KDb4);
   142 	TEST2(err, KErrNone);
   143 	err = fs.SetAtt(KDb4, 0, KEntryAttReadOnly);
   144 	TEST2(err, KErrNone);
   145 
   146 	err = BaflUtils::CopyFile(fs, KDb5org, KDb5);
   147 	TEST2(err, KErrNone);
   148 	err = fs.SetAtt(KDb5, 0, KEntryAttReadOnly);
   149 	TEST2(err, KErrNone);
   150 
   151 	err = BaflUtils::CopyFile(fs, KDb6org, KDb6);
   152 	TEST2(err, KErrNone);
   153 	err = fs.SetAtt(KDb6, 0, KEntryAttReadOnly);
   154 	TEST2(err, KErrNone);
   155 
   156 	err = BaflUtils::CopyFile(fs, KDb7org, KDb7);
   157 	TEST2(err, KErrNone);
   158 	err = fs.SetAtt(KDb7, 0, KEntryAttReadOnly);
   159 	TEST2(err, KErrNone);
   160 
   161 	err = BaflUtils::CopyFile(fs, KDb8org, KDb8);
   162 	TEST2(err, KErrNone);
   163 	err = fs.SetAtt(KDb8, 0, KEntryAttReadOnly);
   164 	TEST2(err, KErrNone);
   165 
   166 	fs.Close();
   167 	}
   168 
   169 void CreateSqlServerPrivateDir()
   170     {
   171     RFs fs;
   172 	TInt err = fs.Connect();
   173 	TEST2(err, KErrNone);
   174 
   175 	TRAP(err, BaflUtils::EnsurePathExistsL(fs, KSqlServerPrivateDirC));
   176 	TEST2(err, KErrNone);
   177 
   178 	fs.Close();
   179 	}
   180 
   181 TInt E32Main()
   182     {
   183 	TheTest.Title();
   184 
   185 	CTrapCleanup* tc = CTrapCleanup::New();
   186 
   187 	__UHEAP_MARK;
   188 
   189 	CreateSqlServerPrivateDir();
   190 
   191 	DoRun();
   192 
   193 	__UHEAP_MARKEND;
   194 
   195 	TheTest.End();
   196 	TheTest.Close();
   197 
   198 	delete tc;
   199 
   200 	User::Heap().Check();
   201 	return KErrNone;
   202     }