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