|
1 // Copyright (c) 2003-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 // |
|
15 |
|
16 #include <e32std.h> |
|
17 #include <e32test.h> |
|
18 #include <cntdb.h> |
|
19 #include <f32file.h> |
|
20 #include <coreappstest/testserver.h> |
|
21 |
|
22 _LIT(KTestName, "T_DataCompatibility"); |
|
23 |
|
24 //That file is a contact model database from a Calypso device |
|
25 _LIT(KDatabaseV4, "Z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\FormatV4.cdb"); |
|
26 _LIT(KDatabaseV5, "Z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\FormatV5.cdb"); |
|
27 |
|
28 _LIT(KDatabaseV6With10Entries, "Z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\FormatV6-10.cdb"); |
|
29 _LIT(KDatabaseV7With25Entries, "Z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\FormatV7-25.cdb"); |
|
30 _LIT(KDatabaseV4With4Entries, "Z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\FormatV4-4.cdb"); |
|
31 _LIT(KDatabaseV8, "Z:\\Core-Apps\\App-Engines\\CntModel\\Databases\\DBS_100065FF_performance_100_4.cdb"); |
|
32 |
|
33 _LIT(KDatabaseCDriveFullPath,"C:\\private\\10003A73\\contacts.cdb"); |
|
34 _LIT(KOldDatabaseCDriveFullPath,"C:\\private\\10003A73\\DBS_100065FF_performance_100_4.cdb"); |
|
35 |
|
36 _LIT(KDatabaseCDrive,"C:contacts.cdb"); |
|
37 _LIT(KOldDatabaseCDrive,"C:DBS_100065FF_performance_100_4.cdb"); |
|
38 |
|
39 _LIT(KOldFileFormatPrefix,"DBS_100065FF"); |
|
40 |
|
41 RFs fs; |
|
42 |
|
43 // Logging macros & utilities // |
|
44 GLDEF_C RTest test(KTestName); |
|
45 |
|
46 |
|
47 LOCAL_C void CleanupFilesL() |
|
48 { |
|
49 // delete the database files |
|
50 if (CContactDatabase::ContactDatabaseExistsL(KDatabaseCDrive) ) |
|
51 { |
|
52 CContactDatabase::DeleteDatabaseL(KDatabaseCDrive); |
|
53 } |
|
54 if (CContactDatabase::ContactDatabaseExistsL(KOldDatabaseCDrive) ) |
|
55 { |
|
56 CContactDatabase::DeleteDatabaseL(KOldDatabaseCDrive); |
|
57 } |
|
58 } |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 void CopyCdbFileToCDriveL(const TDesC& aFileName) |
|
65 { |
|
66 //Will probably need more additions to sos to do this |
|
67 RPIMTestServer serv; |
|
68 User::LeaveIfError(serv.Connect()); |
|
69 serv.CopyFileL(aFileName, KDatabaseCDriveFullPath); |
|
70 serv.Close(); |
|
71 } |
|
72 |
|
73 void CopyOldCdbFileToCDriveL(const TDesC& aFileName) |
|
74 { |
|
75 //Will probably need more additions to sos to do this |
|
76 RPIMTestServer serv; |
|
77 User::LeaveIfError(serv.Connect()); |
|
78 serv.CopyFileL(aFileName, KOldDatabaseCDriveFullPath); |
|
79 serv.Close(); |
|
80 } |
|
81 |
|
82 typedef void (*TTestFunction)(TBool); |
|
83 |
|
84 void DoTestV8DatabaseL() |
|
85 { |
|
86 CopyOldCdbFileToCDriveL(KDatabaseV8); |
|
87 CContactDatabase* db=CContactDatabase::OpenL(KDatabaseCDrive); |
|
88 TDriveUnit driveUnit = _L("c:"); |
|
89 TBuf<190> driveName; |
|
90 CDesCArray* dataBaseList = db->ListDatabasesL(driveUnit); |
|
91 CleanupStack::PushL(dataBaseList); |
|
92 TInt theCount = dataBaseList->Count(); |
|
93 TBool oldFileFormat = EFalse; |
|
94 for(TInt i = 0; i< theCount; i++) |
|
95 { |
|
96 driveName = (*dataBaseList)[i]; |
|
97 test.Printf(_L("ListDatabaseTestL, ListDatabasesL: %s \n"),driveName.PtrZ()); |
|
98 TPtrC filenamePtr(driveName); |
|
99 TInt found = filenamePtr.FindF(KOldFileFormatPrefix); |
|
100 if (found != 0 && found != KErrNotFound) |
|
101 { |
|
102 oldFileFormat = ETrue; |
|
103 } |
|
104 } |
|
105 test(oldFileFormat); |
|
106 |
|
107 CleanupStack::PopAndDestroy(dataBaseList); |
|
108 delete db; |
|
109 } |
|
110 |
|
111 void DoTestV7DatabaseL() |
|
112 { |
|
113 CopyCdbFileToCDriveL(KDatabaseV7With25Entries); |
|
114 CContactDatabase* db=CContactDatabase::OpenL(KDatabaseCDrive); |
|
115 delete db; |
|
116 } |
|
117 |
|
118 void DoTestV6DatabaseL() |
|
119 { |
|
120 CopyCdbFileToCDriveL(KDatabaseV6With10Entries); |
|
121 CContactDatabase* db=CContactDatabase::OpenL(KDatabaseCDrive); |
|
122 delete db; |
|
123 } |
|
124 |
|
125 void DoTestV5DatabaseL() |
|
126 { |
|
127 CopyCdbFileToCDriveL(KDatabaseV5); |
|
128 CContactDatabase* db=CContactDatabase::OpenL(KDatabaseCDrive); |
|
129 delete db; |
|
130 } |
|
131 |
|
132 void DoTestV4DatabaseL(TBool aOOMTest = ETrue) |
|
133 { |
|
134 if (aOOMTest) |
|
135 { |
|
136 CopyCdbFileToCDriveL(KDatabaseV4With4Entries); |
|
137 } |
|
138 else |
|
139 { |
|
140 CopyCdbFileToCDriveL(KDatabaseV4); |
|
141 } |
|
142 |
|
143 TTime startTime; |
|
144 TTime endTime; |
|
145 |
|
146 |
|
147 //Test end profiling |
|
148 startTime.UniversalTime(); //start profiling |
|
149 CContactDatabase* db=CContactDatabase::OpenL(KDatabaseCDrive); |
|
150 endTime.UniversalTime(); //end profiling |
|
151 CleanupStack::PushL(db); |
|
152 |
|
153 //need to sort item otherwise CountL return 0 - only in old model |
|
154 /* CContactDatabase::TSortPref sortPref(KUidContactFieldGivenName); |
|
155 CArrayFix<CContactDatabase::TSortPref>* sortOrder=new(ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(1); |
|
156 CleanupStack::PushL(sortOrder); |
|
157 sortOrder->AppendL(sortPref); |
|
158 db->SortL(sortOrder); //Takes ownership |
|
159 CleanupStack::Pop(sortOrder);*/ |
|
160 |
|
161 TInt count=db->CountL(); |
|
162 |
|
163 //Now compute delay and print on the screen |
|
164 TTimeIntervalMicroSeconds delay=endTime.MicroSecondsFrom(startTime); |
|
165 test.Printf(_L("A v4 database containing %d contacts was converted in %d µs\n"),count,delay.Int64()); |
|
166 |
|
167 CleanupStack::PopAndDestroy(db); //db |
|
168 } |
|
169 |
|
170 void DoOOMTestL(TTestFunction aTestFunction) |
|
171 { |
|
172 TInt ret = KErrNoMemory; |
|
173 TInt failAt = 0; |
|
174 while(ret != KErrNone) |
|
175 { |
|
176 failAt += 1 + failAt/30; |
|
177 test.Printf(_L("OOM step: %d\n"), failAt); |
|
178 __UHEAP_SETFAIL(RHeap::EDeterministic, failAt); |
|
179 __UHEAP_MARK; |
|
180 TRAP(ret, aTestFunction(ETrue)); |
|
181 __UHEAP_MARKEND; |
|
182 __UHEAP_RESET; |
|
183 |
|
184 if (ret != KErrNoMemory && ret != KErrNone) |
|
185 { |
|
186 test.Printf(_L("OOM test failed: %d\n"),ret); |
|
187 } |
|
188 |
|
189 if (!(ret == KErrNoMemory || ret == KErrNone) ) |
|
190 { |
|
191 TRAP_IGNORE(CleanupFilesL() ); |
|
192 } |
|
193 test(ret == KErrNoMemory || ret == KErrNone); |
|
194 } |
|
195 } |
|
196 |
|
197 |
|
198 void DoTestL() |
|
199 { |
|
200 User::LeaveIfError(fs.Connect()); |
|
201 CleanupClosePushL(fs); |
|
202 CTestRegister* TempFiles = CTestRegister::NewLC(); |
|
203 TempFiles->RegisterL(KDatabaseCDrive, EFileTypeCnt); |
|
204 |
|
205 _LIT(KTestV8Database,"Opening DBMS secured (old) database..."); |
|
206 _LIT(KTestV7Database,"Opening v7 format database..."); |
|
207 _LIT(KTestV6Database,"Opening v6 format database..."); |
|
208 _LIT(KTestV5Database,"Opening v5 format database..."); |
|
209 _LIT(KTestV4Database,"Opening v4 format database..."); |
|
210 |
|
211 |
|
212 test.Next(_L("Opening v7 format database...")); |
|
213 |
|
214 DoTestV7DatabaseL(); |
|
215 |
|
216 test.Next(_L("Opening DBMS secured (old) database...")); |
|
217 |
|
218 DoTestV8DatabaseL(); |
|
219 |
|
220 |
|
221 test.Next(_L("Opening v6 format database...")); |
|
222 |
|
223 DoTestV6DatabaseL(); |
|
224 |
|
225 test.Next(_L("Opening v5 format database...")); |
|
226 |
|
227 DoTestV5DatabaseL(); |
|
228 |
|
229 test.Next(_L("Opening v4 format database...")); |
|
230 |
|
231 DoTestV4DatabaseL(EFalse); |
|
232 |
|
233 //v4 conversion to v7 executes code involved in any other conversion. |
|
234 DoOOMTestL(DoTestV4DatabaseL); |
|
235 //DoOOMTestL(DoTestV5DatabaseL); |
|
236 //DoOOMTestL(DoTestV6DatabaseL); |
|
237 //DoOOMTestL(DoTestV7DatabaseL); |
|
238 |
|
239 CleanupStack::PopAndDestroy(2); // TempFiles, fs |
|
240 } |
|
241 |
|
242 /** |
|
243 |
|
244 @SYMTestCaseID PIM-T-DATACOMPATIBILITY-0001 |
|
245 |
|
246 */ |
|
247 |
|
248 GLDEF_C TInt E32Main() |
|
249 { |
|
250 __UHEAP_MARK; |
|
251 CActiveScheduler* scheduler=new CActiveScheduler; |
|
252 if (scheduler) |
|
253 { |
|
254 CActiveScheduler::Install(scheduler); |
|
255 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
256 if (cleanup) |
|
257 { |
|
258 test.Title(); |
|
259 test.Start(_L("@SYMTESTCaseID:PIM-T-DATACOMPATIBILITY-0001 T_DataCompatibility")); |
|
260 |
|
261 TRAPD(err, DoTestL()); |
|
262 // delete database files if they are not cleaned up elsewhere |
|
263 TRAP_IGNORE(CleanupFilesL() ); |
|
264 test(err == KErrNone); |
|
265 test.End(); |
|
266 User::After(1000000); // wait 1 second and exit |
|
267 test.Close(); |
|
268 delete cleanup; |
|
269 } |
|
270 delete scheduler; |
|
271 } |
|
272 __UHEAP_MARKEND; |
|
273 return KErrNone; |
|
274 } |
|
275 |
|
276 |