os/persistentdata/persistentstorage/centralrepository/pccenrep/test/t_cenreppc.cpp
Update contrib.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <x86tool/centralrepository.h>
21 #define CENREP_PC_TEST
31 RTest TheTest(_L("Central Repository Tests"));
34 //uid for txt testing purpose
35 const TUid uid={0x000001FF};
36 //uid for cre testing purpose
37 const TUid uidcre={0x00001FFF};
38 const TUid uidcretest = {0x000002FF};
39 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
40 const TUid uidcrev1= {0x00004FFF};
43 const TUid uidmetatest = {0x00022222};
46 /** FILES FOR MAN NEWL TESTING */
47 _LIT(KTemplateTxtFile,"c:\\000001ff.txt");
48 _LIT(KTemplateTxtOutFile,"c:\\000001ff.cre");
49 //cre equivalent is generated through centrepconv of the txt version
50 _LIT(KTemplateCreFile,"c:\\00001fff.cre");
51 _LIT(KCopyTemplateCreFile,"c:\\copy00001fff.cre");
52 //the target output is set to a different name
53 _LIT(KTemplateCreOutFile,"c:\\00001eee.cre");
55 _LIT(KMetaTxtTestInFile,"c:\\00022222.txt"); // Txt test input
56 _LIT(KMetaTestCreFile,"c:\\00022222.cre"); // Txt test output, Cre test in/output
57 _LIT(KMetaTestCreCopy,"c:\\copy00022222.cre");
58 _LIT(KMetaTxtTestOgnFile, "c:\\00022222.ogn");
60 /** FILES FOR AUTO NEWL TESTING */
61 _LIT(KPrivateTemplateCreFile,"c:\\private\\00000000\\00001fff.cre");
62 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
63 _LIT(KPrivateTemplateCreV1File,"c:\\private\\00000000\\00004fff.cre");
64 _LIT(KCopyPrivateTemplateCreV1File,"c:\\private\\00000000\\copy00004fff.cre");
66 _LIT(KCopyPrivateTemplateCreFile,"c:\\private\\00000000\\copy00001fff.cre");
67 _LIT(KPrivateTemplateTxtFile,"c:\\private\\0000000\\000001ff.txt");
68 _LIT(KPrivateTemplateTxtOutFile,"c:\\private\\00000000\\000001ff.cre");
71 _LIT(KPrivateCreFileForCreTest,"c:\\private\\00000000\\000002ff.cre");
72 _LIT(KCopyCreFileForCreTest,"c:\\private\\00000000\\copy000002ff.cre");
73 _LIT(KTxtTestRefFile,"c:\\private\\00000000\\ref_winscwtxt.cre");
74 _LIT(KCreTestRefFile,"c:\\private\\00000000\\ref_winscwcre.cre");
75 _LIT(KTxtTestGenFile,"c:\\private\\00000000\\winscwtxt.cre");
76 _LIT(KCreTestGenFile,"c:\\private\\00000000\\winscwcre.cre");
78 // Make sure the contents of the following 2 files is the same as crc.txt and
79 // ref_00022222.cre, which are generated by the WINSCW t_cenrepcs.exe test.
80 _LIT(KCrcRecordFile,"c:\\common_crc.txt");
81 _LIT(KMetaTestRefFile,"c:\\private\\00000000\\common_ref_00022222.cre");
83 _LIT(KOgnFile1FF, "c:\\private\\00000000\\000001ff.ogn");
84 _LIT(KOgnFile1FFF, "c:\\private\\00000000\\00001fff.ogn");
85 _LIT(KOgnFile2FF, "c:\\private\\00000000\\000002ff.ogn");
86 _LIT(KOgnFile22222, "c:\\private\\00000000\\00022222.ogn");
88 _LIT(KMetaTestFile,"c:\\private\\00000000\\00022222.cre");
89 _LIT(KMetaTestCopy,"c:\\private\\00000000\\copy00022222.cre");
93 /** FILES FOR MAN NEWL TESTING */
94 //in TOOLS2 this is relative
95 _LIT(KTemplateTxtFile,"000001ff.txt");
96 _LIT(KTemplateTxtOutFile,"000001ff.cre");
97 //cre equivalent is generated through centrepconv of the txt version
98 _LIT(KTemplateCreFile,"00001fff.cre");
99 _LIT(KCopyTemplateCreFile,"copy00001fff.cre");
100 _LIT(KTemplateCreOutFile,"00001eee.cre");
102 _LIT(KMetaTxtTestInFile,"00022222.txt"); // Txt test input
103 _LIT(KMetaTestCreFile,"00022222.cre"); // Txt test output, Cre test in/output
104 _LIT(KMetaTestCreCopy,"copy00022222.cre");
105 _LIT(KMetaTxtTestOgnFile, "00022222.ogn");
107 /** FILES FOR AUTO NEWL TESTING */
108 _LIT(KPrivateTemplateCreFile,"00001fff.cre");
109 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
110 _LIT(KPrivateTemplateCreV1File,"00004fff.cre");
111 _LIT(KCopyPrivateTemplateCreV1File,"copy00004fff.cre");
113 _LIT(KCopyPrivateTemplateCreFile,"copy00001fff.cre");
114 _LIT(KPrivateTemplateTxtFile,"000001ff.txt");
115 _LIT(KPrivateTemplateTxtOutFile,"000001ff.cre");
117 //for comparison test
118 _LIT(KPrivateCreFileForCreTest,"000002ff.cre");
119 _LIT(KCopyCreFileForCreTest,"copy000002ff.cre");
120 _LIT(KTxtTestRefFile,"ref_winscwtxt.cre");
121 _LIT(KCreTestRefFile,"ref_winscwcre.cre");
122 _LIT(KTxtTestGenFile,"winscwtxt.cre");
123 _LIT(KCreTestGenFile,"winscwcre.cre");
124 // if start with \epoc32, symfile resolves the address related to EPOCROOT
126 // Make sure the contents of the following 2 files is the same as crc.txt and
127 // ref_00022222.cre, which are generated by the WINSCW t_cenrepcs.exe test.
128 _LIT(KCrcRecordFile,"\\epoc32\\winscw\\c\\common_crc.txt");
129 _LIT(KMetaTestRefFile,"\\epoc32\\winscw\\c\\private\\00000000\\common_ref_00022222.cre");
131 _LIT(KOgnFile1FF, "000001ff.ogn");
132 _LIT(KOgnFile1FFF, "00001fff.ogn");
133 _LIT(KOgnFile2FF, "000002ff.ogn");
134 _LIT(KOgnFile22222, "00022222.ogn");
137 _LIT(KMetaTestFile,"00022222.cre");
138 _LIT(KMetaTestCopy,"copy00022222.cre");
141 ///////////////////////////////////////////////////////////////////////////////////////
143 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
145 if(aValue != aExpected)
147 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
148 TheTest(EFalse, aLine);
152 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
154 ///////////////////////////////////////////////////////////////////////////////////////
156 //DEFINED IN THE COMMON CPP FILE
157 extern TInt CopyFile(const TDesC& aSource, const TDesC& aTarget);
158 extern void ObjectCreateDeleteOOM(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
159 extern void OomTest(void (*testFuncL)(CRepository* aRepository),TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
160 extern void BasicFunctionL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
161 extern void OomBasicFunction(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
162 extern void DoFileCompL(const TDesC& aGenerated, const TDesC& aReference, TUint32& aCrcValue);
163 extern void DoCrcCompL(const TUint32& aCrcValue, const TDesC& aCrcRecord, TBool aCrcOfTxt);
164 extern void DEF130394L(TUid aUid);
166 void InitialiseLC(CRepository*& aRepository,TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
168 #ifdef CENREP_PC_TEST
169 if (aTestMode==ETxt || aTestMode==ECre)
170 aRepository=CRepository::NewLC(aInFilePath,aOutFilePath);
173 aRepository=CRepository::NewLC(aUid);
178 TheFs.Delete(KMetaTxtTestOgnFile);
179 TheFs.Delete(KOgnFile1FF);
180 TheFs.Delete(KOgnFile1FFF);
181 TheFs.Delete(KOgnFile2FF);
182 TheFs.Delete(KOgnFile22222);
185 void SetupEnv(const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
188 if (aTestMode==ETxt || aTestMode==EAutoTxt)
189 TheFs.Delete(aOutFilePath);
192 //always copy so we always start the OOM with fresh original cre file
193 CopyFile(KCopyTemplateCreFile,aInFilePath);
194 TheFs.Delete(aOutFilePath);
196 if (aTestMode==EAutoCre)
198 TheFs.Delete(aOutFilePath);
199 #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
200 CopyFile(KCopyPrivateTemplateCreFile,aInFilePath);
202 if (aInFilePath.Compare(KPrivateTemplateCreFile)==0)
203 CopyFile(KCopyPrivateTemplateCreFile,aInFilePath);
205 CopyFile(KCopyPrivateTemplateCreV1File,aInFilePath);
210 // If testsymcenrep or t_cenreppc fails, common_crc.txt and common_ref_00022222.cre might need
211 // to be updated (with the versions generated by the WINSCW t_cenrepcs.exe test,
212 // crc.txt and ref_00022222.cre), if the format of the repository files has changed.
213 void CrcComparisonTestL()
216 TUint32 txtTestCrcVal;
217 BasicFunctionL(uid,KPrivateTemplateTxtFile,KPrivateTemplateTxtOutFile,EAutoTxt);
218 CopyFile(KPrivateTemplateTxtOutFile, KTxtTestGenFile);
219 DoFileCompL(KTxtTestGenFile, KTxtTestRefFile, txtTestCrcVal);
220 DoCrcCompL(txtTestCrcVal, KCrcRecordFile, EFalse);
223 TUint32 creTestCrcVal;
224 TheFs.Delete(KPrivateCreFileForCreTest);
225 CopyFile(KCopyCreFileForCreTest, KPrivateCreFileForCreTest);
226 BasicFunctionL(uidcretest,KNullDesC,KNullDesC,EAutoTxt);
227 CopyFile(KPrivateCreFileForCreTest, KCreTestGenFile);
228 DoFileCompL(KCreTestGenFile, KCreTestRefFile, creTestCrcVal);
229 DoCrcCompL(creTestCrcVal, KCrcRecordFile, ETrue);
232 void FlushFunctionalityTestingL(CRepository* aRepository)
234 TInt r= aRepository->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
235 TheTest(r==KErrNone);
236 aRepository->CleanupFailTransactionPushL();
238 User::LeaveIfError(aRepository->Set(1,9));
241 aRepository->FailTransaction();
243 User::LeaveIfError(aRepository->Flush());
245 User::LeaveIfError(aRepository->Get(1,value));
249 void FlushTestingL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
252 SetupEnv(aInFilePath,aOutFilePath,aTestMode);
254 //basic functionality test
255 CRepository* repository=NULL;
256 InitialiseLC(repository,aUid,aInFilePath,aOutFilePath,aTestMode);
258 //made some modification
259 FlushFunctionalityTestingL(repository);
260 CleanupStack::PopAndDestroy();
262 //oom functionality test
263 OomTest(FlushFunctionalityTestingL,aUid,aInFilePath,aOutFilePath,aTestMode);
269 @SYMTestCaseID PDS-CENTRALREPOSITORY-CT-4080
270 @SYMTestCaseDesc Test for DEF130394
271 @SYMTestPriority Medium
272 @SYMTestActions This is Part 2 of the test - Part 1 is in t_cenrrepcs.cpp
273 Loading a repository multiple times and then compare
274 (using CRC compare) the created cre file with the reference
276 @SYMTestExpectedResults Cre file is identical as the reference cre.
279 void TestLoadingDEF130394L(const TDesC& aInFilePath, const TDesC& aOutFilePath)
281 CRepository* repos = NULL;
283 repos = CRepository::NewLC(aInFilePath, aOutFilePath);
284 TInt err = repos->Create(1,1);
285 TEST2(err, KErrNone);
287 CleanupStack::PopAndDestroy();
289 // Second time we need to load from output file it self, otherwise it is not loading
290 // a repository multiple times because changes of the first time loading is not
291 // flushed into input file.
292 repos = CRepository::NewLC(aOutFilePath, aOutFilePath);
293 err = repos->Create(1,1);
294 TEST2(err, KErrAlreadyExists);
296 CleanupStack::PopAndDestroy();
299 void TestForDEF130394L()
303 // NewLC Txt=>Cre Loading test
305 TheFs.Delete(KMetaTestCreFile);
306 TestLoadingDEF130394L(KMetaTxtTestInFile, KMetaTestCreFile);
307 DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy);
309 // NewLC Cre=>Cre Loading test
311 TheFs.Delete(KMetaTestCreFile);
312 CopyFile(KMetaTestCreCopy, KMetaTestCreFile);
313 TestLoadingDEF130394L(KMetaTestCreFile, KMetaTestCreFile);
314 DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy);
316 // Auto Loading Cre test
318 TheFs.Delete(KMetaTestFile);
319 CopyFile(KMetaTestCopy, KMetaTestFile);
320 DEF130394L(uidmetatest);
321 DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy);
323 //Auto Loading Txt test
325 TheFs.Delete(KMetaTestFile);
326 DEF130394L(uidmetatest);
327 DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy);
331 @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4041
332 @SYMTestCaseDesc PC-side CentralRepository functionality test
333 @SYMTestPriority High
334 @SYMTestActions Wrapper function calling up test functions. Test functions include test for basic
335 functions of the component, OOm test and CRC comparison test.
336 @SYMTestExpectedResults Test must not fail
341 //Note these files are equivalent, the cre being generated from txt
342 User::LeaveIfError(TheFs.Connect());
345 TheTest.Start(_L("Functional NewLC TXT tests"));
346 BasicFunctionL(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt);
347 TheTest.Next(_L("OOM NewLC TXT tests"));
348 ObjectCreateDeleteOOM(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt);
349 OomBasicFunction(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt);
352 TheTest.Next(_L("Functional NewLC CRE tests"));
353 BasicFunctionL(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre);
354 TheTest.Next(_L("OOM NewL CRE tests"));
355 ObjectCreateDeleteOOM(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre);
356 OomBasicFunction(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre);
359 TheTest.Next(_L("Functional NewLC Auto CRE tests"));
360 BasicFunctionL(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
361 TheTest.Next(_L("OOM NewLC Auto CRE tests"));
362 ObjectCreateDeleteOOM(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
363 OomBasicFunction(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
366 TheTest.Next(_L("Functional NewLC Auto TXT tests"));
367 BasicFunctionL(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
368 TheTest.Next(_L("OOM NewLC Auto TXT tests"));
369 ObjectCreateDeleteOOM(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
370 OomBasicFunction(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
372 //PC side only testing
373 TheTest.Next(_L("Flush Functionality test"));
374 FlushTestingL(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
375 FlushTestingL(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
377 TheTest.Next(_L("CRC comparison test"));
378 CrcComparisonTestL();
380 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
381 //perform testing on CREV1 , only CRE exists only
382 TheTest.Next(_L("Functional NewLC Auto CREV1 tests"));
383 BasicFunctionL(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre);
384 TheTest.Next(_L("OOM NewLC Auto CREV1 tests"));
385 ObjectCreateDeleteOOM(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre);
386 OomBasicFunction(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre);
390 TheTest.Next(_L("Test for DEF130394L"));
401 CTrapCleanup* cleanup = CTrapCleanup::New();
407 User::Panic(_L("Testing failed: "), err);