|
1 // Copyright (c) 2005-2009 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 // Tests Contacts Database can be opened and read with only ReadUserData capability |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32test.h> |
|
20 #include <cntdb.h> |
|
21 #include <cntitem.h> |
|
22 #include <cntfldst.h> |
|
23 #include "t_utils2.h" |
|
24 #include "T_UTILS.H" |
|
25 #include <coreappstest/testserver.h> |
|
26 #include "t_platsec.h" |
|
27 |
|
28 // |
|
29 // Configuration. |
|
30 // |
|
31 |
|
32 |
|
33 // |
|
34 // Constants. |
|
35 // |
|
36 |
|
37 _LIT(KTestName,"t_platsec"); |
|
38 |
|
39 #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
40 //_LIT(KDbFileName58920,"c:SQLite__Contacts58920.cdb"); |
|
41 _LIT(KDbFileName58920,"c:Contacts58920.cdb"); |
|
42 _LIT(KSourceDbFileName58920,"z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\SQLite__Contacts58920.cdb"); |
|
43 _LIT(KDestDbFileName58920,"SQLite__Contacts58920.cdb"); |
|
44 #else //__SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
45 _LIT(KDbFileName58920,"c:contacts58920.cdb"); |
|
46 _LIT(KSourceDbFileName58920,"z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\contacts58920.cdb"); |
|
47 _LIT(KDestDbFileName58920,"contacts58920.cdb"); |
|
48 #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
49 |
|
50 _LIT(KLogFileName,"t_platsec.log"); |
|
51 |
|
52 |
|
53 // |
|
54 // CPlatSecTest. |
|
55 // |
|
56 |
|
57 CPlatSecTest* CPlatSecTest::NewLC(RTest& aTest) |
|
58 { |
|
59 CPlatSecTest* self = new CPlatSecTest(aTest); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 CPlatSecTest::CPlatSecTest(RTest& aTest) : iTest(aTest) |
|
66 { |
|
67 } |
|
68 |
|
69 CPlatSecTest::~CPlatSecTest() |
|
70 { |
|
71 if (iTestServer.Handle() != 0) |
|
72 { // cleanup temp database |
|
73 HBufC* fullDbName = GetFullDbName(KDestDbFileName58920); |
|
74 if(fullDbName) |
|
75 { |
|
76 TRAP_IGNORE(iTestServer.DeleteFileL(*fullDbName)); |
|
77 delete fullDbName; |
|
78 } |
|
79 iTestServer.Close(); |
|
80 } |
|
81 delete iDb; |
|
82 delete iLog; |
|
83 iFs.Close(); |
|
84 iTest.Close(); |
|
85 } |
|
86 |
|
87 void CPlatSecTest::ConstructL() |
|
88 { |
|
89 User::LeaveIfError(iFs.Connect()); |
|
90 User::LeaveIfError(iTestServer.Connect()); |
|
91 |
|
92 // Copy test contacts database |
|
93 HBufC* fullDbName = GetFullDbName(KDestDbFileName58920); |
|
94 User::LeaveIfNull(fullDbName); |
|
95 |
|
96 CleanupStack::PushL(fullDbName); |
|
97 iTestServer.CopyFileL(KSourceDbFileName58920, *fullDbName); |
|
98 CleanupStack::PopAndDestroy(fullDbName); |
|
99 |
|
100 iLogFileName=KLogFileName; |
|
101 iDbFileName=KDbFileName58920; |
|
102 iLog=CLog::NewL(iTest,iLogFileName); |
|
103 } |
|
104 |
|
105 void CPlatSecTest::IdleFindCallback() |
|
106 { |
|
107 } |
|
108 |
|
109 void CPlatSecTest::DoTestL() |
|
110 { |
|
111 |
|
112 TPtrC match; |
|
113 |
|
114 // Test for DEF58920 (Contacts not usable if only ReadUserData capabilitiy) |
|
115 // Note absence of WriteUserData in .mmp file |
|
116 |
|
117 |
|
118 iLog->LogLine(_L("Open database with ReadUserData capability only")); |
|
119 // Prior to bug fix used to get the following when doing an open |
|
120 // *PlatSec* ERROR - Capability check failed |
|
121 // - A Message (function number=0x464000f1) from Thread |
|
122 // T_PLATSEC.EXE[00000000]0001::Main, sent to Server |
|
123 // !DBMS server, was checked by Thread EDBSRV.EXE[100012a5]0001::!DBMS |
|
124 // server and was found to be missing the capabilities: WriteUserData . |
|
125 // t_platsec finishes with -46 error |
|
126 iDb=CContactDatabase::OpenL(iDbFileName); |
|
127 |
|
128 |
|
129 iLog->LogLine(_L("DatabaseDrive()")); |
|
130 TDriveUnit driveUnit; |
|
131 TBool bHasBeenSet = iDb->DatabaseDrive(driveUnit); |
|
132 |
|
133 iLog->LogLine(_L("GetCurrentDatabase()")); |
|
134 TFileName currentDb; |
|
135 iDb->GetCurrentDatabase(currentDb); |
|
136 |
|
137 iLog->LogLine(_L("CountL()")); |
|
138 TInt numberContacts = iDb->CountL(); |
|
139 |
|
140 iLog->LogLine(_L("SortedItemsL()")); |
|
141 CContactIdArray* idList=CContactIdArray::NewLC(iDb->SortedItemsL()); |
|
142 const TInt index=(*idList)[0]; |
|
143 |
|
144 iLog->LogLine(_L("ReadContactLC()")); |
|
145 CContactItem* item= iDb->ReadContactLC(index); |
|
146 |
|
147 CContactItemFieldSet& fields=item->CardFields(); |
|
148 const TInt fieldCount=fields.Count(); |
|
149 |
|
150 CContactItemField &field1 = fields[1]; |
|
151 TPtrC fieldText1=field1.TextStorage()->Text(); |
|
152 |
|
153 // check that can read out of database |
|
154 iTest.Next(_L("Reading Contact field")); |
|
155 |
|
156 #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
157 iTest(fieldText1 == _L("Name1")); |
|
158 #else //__SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
159 iTest(fieldText1 == _L("9AB24C76BmQAte[POqjm_PoyFam\\\\cKq")); |
|
160 #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
161 |
|
162 CleanupStack::PopAndDestroy(item); |
|
163 CleanupStack::PopAndDestroy(idList); |
|
164 |
|
165 // |
|
166 } |
|
167 |
|
168 void RunTestsL(RTest& aTest) |
|
169 { |
|
170 CPlatSecTest* platSecTest=CPlatSecTest::NewLC(aTest); |
|
171 |
|
172 platSecTest->DoTestL(); |
|
173 |
|
174 CleanupStack::PopAndDestroy(platSecTest); |
|
175 } |
|
176 |
|
177 |
|
178 // |
|
179 // Main. |
|
180 // |
|
181 |
|
182 /** |
|
183 |
|
184 @SYMTestCaseID PIM-T-PLATSEC-0001 |
|
185 |
|
186 */ |
|
187 |
|
188 GLDEF_C TInt E32Main() |
|
189 { |
|
190 RDebug::Print(_L("t_platsec started")); |
|
191 __UHEAP_MARK; |
|
192 #ifndef __SECURE_API__ |
|
193 RProcess process; |
|
194 TBuf<256> commandLine; |
|
195 process.CommandLine(commandLine); |
|
196 #else |
|
197 TBuf<256> commandLine; |
|
198 User::CommandLine(commandLine); |
|
199 #endif |
|
200 TInt result(KErrNone); |
|
201 CActiveScheduler* scheduler=new CActiveScheduler; |
|
202 if (scheduler) |
|
203 { |
|
204 CActiveScheduler::Install(scheduler); |
|
205 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
206 if (cleanup) |
|
207 { |
|
208 RTest test(KTestName); |
|
209 |
|
210 test.Start(_L("@SYMTESTCaseID:PIM-T-PLATSEC-0001 Test for DEF58920")); |
|
211 |
|
212 |
|
213 TRAP(result,RunTestsL(test)); |
|
214 test(result == KErrNone); |
|
215 |
|
216 // test SUCCESS |
|
217 test.End(); |
|
218 test.Close(); |
|
219 delete cleanup; |
|
220 } |
|
221 |
|
222 delete scheduler; |
|
223 } |
|
224 __UHEAP_MARKEND; |
|
225 return result; |
|
226 } |