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 - deleting secure test databases from C:
|
sl@0
|
15 |
// Please, ensure that t_sqlenvdestroy test is executed after the other sql security 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_sqlenvdestroy - deleting secure test databases from C:"));
|
sl@0
|
23 |
|
sl@0
|
24 |
_LIT(KDbCFileName1, "c:\\private\\10281e17\\[21212122]AADb2.db");
|
sl@0
|
25 |
_LIT(KDbCFileName2, "c:\\private\\10281e17\\[21212122]BBDb2.db");
|
sl@0
|
26 |
_LIT(KDbCFileName3, "c:\\private\\10281e17\\[21212125]T_AB.db");
|
sl@0
|
27 |
_LIT(KDbCFileName4, "c:\\private\\10281e17\\[1111CCCC]T_AB.db");
|
sl@0
|
28 |
_LIT(KDbCFileName5, "c:\\private\\10281e17\\[21212125]T_OneDefPolicy.db");
|
sl@0
|
29 |
|
sl@0
|
30 |
_LIT(KDb1, "c:\\private\\10281e17\\[98765432]t_nosettings.db");
|
sl@0
|
31 |
_LIT(KDb2, "c:\\private\\10281e17\\[98765432]t_emptysettings.db");
|
sl@0
|
32 |
_LIT(KDb3, "c:\\private\\10281e17\\[98765432]t_invversion.db");
|
sl@0
|
33 |
_LIT(KDb4, "c:\\private\\10281e17\\[98765432]t_nocollation.db");
|
sl@0
|
34 |
_LIT(KDb5, "c:\\private\\10281e17\\[98765432]t_longcollation.db");
|
sl@0
|
35 |
_LIT(KDb6, "c:\\private\\10281e17\\[98765432]t_nodefaultpolicy.db");
|
sl@0
|
36 |
_LIT(KDb7, "c:\\private\\10281e17\\[98765432]t_invobject.db");
|
sl@0
|
37 |
_LIT(KDb8, "c:\\private\\10281e17\\[98765432]t_2defaultpolicies.db");
|
sl@0
|
38 |
|
sl@0
|
39 |
_LIT(KPrivateSubDir, "c:\\private\\10281e17\\cfg-TestDir.db\\");
|
sl@0
|
40 |
|
sl@0
|
41 |
TParse TheParse;
|
sl@0
|
42 |
|
sl@0
|
43 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
44 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
45 |
//Test macros and functions
|
sl@0
|
46 |
static void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
if(aValue != aExpected)
|
sl@0
|
49 |
{
|
sl@0
|
50 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
51 |
TheTest(EFalse, aLine);
|
sl@0
|
52 |
}
|
sl@0
|
53 |
}
|
sl@0
|
54 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
55 |
|
sl@0
|
56 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
57 |
|
sl@0
|
58 |
void DoDeleteFile(RFs& aFs, const TDesC& aFilePath)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
TInt err = BaflUtils::DeleteFile(aFs, aFilePath);
|
sl@0
|
61 |
if(err != KErrNone && err != KErrNotFound)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
TheTest.Printf(_L("Error %d deleting \"%S\" file.\n"), err, &aFilePath);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
void PrintDiskUsage(RFs& aFs, const TDesC& aPath, TInt aOffset = 0)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
_LIT(KSpace, " ");
|
sl@0
|
70 |
TheTest.Printf(_L("%*.*S%S\r\n"), aOffset, aOffset, &KSpace, &aPath);
|
sl@0
|
71 |
TFindFile findFile(aFs);
|
sl@0
|
72 |
CDir* fileNameCol = NULL;
|
sl@0
|
73 |
TBuf<8> fileNameMask;
|
sl@0
|
74 |
fileNameMask.Copy(_L("*.*"));
|
sl@0
|
75 |
TInt err = findFile.FindWildByDir(fileNameMask, aPath, fileNameCol);
|
sl@0
|
76 |
if(err == KErrNone)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
do
|
sl@0
|
79 |
{
|
sl@0
|
80 |
const TDesC& file = findFile.File();//"file" variable contains the drive and the path. the file name in "file" is invalid in this case.
|
sl@0
|
81 |
(void)TheParse.Set(file, NULL, NULL);
|
sl@0
|
82 |
TPtrC driveName = TheParse.Drive();
|
sl@0
|
83 |
if(aPath.FindF(driveName) >= 0)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
TInt cnt = fileNameCol->Count();
|
sl@0
|
86 |
for(TInt i=0;i<cnt;++i)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
const ::TEntry& entry = (*fileNameCol)[i];
|
sl@0
|
89 |
if(!entry.IsDir())
|
sl@0
|
90 |
{
|
sl@0
|
91 |
TheTest.Printf(_L("%*.*S %S, size=%d\r\n"), aOffset, aOffset, &KSpace, &entry.iName, entry.iSize);
|
sl@0
|
92 |
}
|
sl@0
|
93 |
else
|
sl@0
|
94 |
{
|
sl@0
|
95 |
TBuf<100> path;
|
sl@0
|
96 |
path.Copy(aPath);
|
sl@0
|
97 |
path.Append(entry.iName);
|
sl@0
|
98 |
path.Append(_L("\\"));
|
sl@0
|
99 |
PrintDiskUsage(aFs, path, aOffset + 4);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
}
|
sl@0
|
102 |
} // if(aPath.FindF(driveName) >= 0)
|
sl@0
|
103 |
|
sl@0
|
104 |
delete fileNameCol;
|
sl@0
|
105 |
fileNameCol = NULL;
|
sl@0
|
106 |
} while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files
|
sl@0
|
107 |
}
|
sl@0
|
108 |
else
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TheTest.Printf(_L(" FindWildByDir() failed with err=%d\r\n"), err);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
void DoRun()
|
sl@0
|
115 |
{
|
sl@0
|
116 |
RFs fs;
|
sl@0
|
117 |
TInt err = fs.Connect();
|
sl@0
|
118 |
TEST2(err, KErrNone);
|
sl@0
|
119 |
|
sl@0
|
120 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-SQL-LEGACY-T_SQLENVDESTROY-0001 Delete secure databases from C: "));
|
sl@0
|
121 |
|
sl@0
|
122 |
DoDeleteFile(fs, KDbCFileName1);
|
sl@0
|
123 |
DoDeleteFile(fs, KDbCFileName2);
|
sl@0
|
124 |
DoDeleteFile(fs, KDbCFileName3);
|
sl@0
|
125 |
DoDeleteFile(fs, KDbCFileName4);
|
sl@0
|
126 |
DoDeleteFile(fs, KDbCFileName5);
|
sl@0
|
127 |
|
sl@0
|
128 |
DoDeleteFile(fs, KDb1);
|
sl@0
|
129 |
DoDeleteFile(fs, KDb2);
|
sl@0
|
130 |
DoDeleteFile(fs, KDb3);
|
sl@0
|
131 |
DoDeleteFile(fs, KDb4);
|
sl@0
|
132 |
DoDeleteFile(fs, KDb5);
|
sl@0
|
133 |
DoDeleteFile(fs, KDb6);
|
sl@0
|
134 |
DoDeleteFile(fs, KDb7);
|
sl@0
|
135 |
DoDeleteFile(fs, KDb8);
|
sl@0
|
136 |
|
sl@0
|
137 |
TheTest.Printf(_L("====================================================\r\n"));
|
sl@0
|
138 |
PrintDiskUsage(fs, _L("c:\\"));
|
sl@0
|
139 |
TheTest.Printf(_L("====================================================\r\n"));
|
sl@0
|
140 |
|
sl@0
|
141 |
//Remove the created subdir in the private datacage.
|
sl@0
|
142 |
err = fs.RmDir(KPrivateSubDir);
|
sl@0
|
143 |
if(err != KErrNone && err != KErrNotFound)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
TheTest.Printf(_L("Error %d deleting \"%S\" directory.\n"), err, &KPrivateSubDir);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
fs.Close();
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
TInt E32Main()
|
sl@0
|
152 |
{
|
sl@0
|
153 |
TheTest.Title();
|
sl@0
|
154 |
|
sl@0
|
155 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
156 |
|
sl@0
|
157 |
__UHEAP_MARK;
|
sl@0
|
158 |
|
sl@0
|
159 |
DoRun();
|
sl@0
|
160 |
|
sl@0
|
161 |
__UHEAP_MARKEND;
|
sl@0
|
162 |
|
sl@0
|
163 |
TheTest.End();
|
sl@0
|
164 |
TheTest.Close();
|
sl@0
|
165 |
|
sl@0
|
166 |
delete tc;
|
sl@0
|
167 |
|
sl@0
|
168 |
User::Heap().Check();
|
sl@0
|
169 |
return KErrNone;
|
sl@0
|
170 |
}
|