os/persistentdata/persistentstorage/centralrepository/pccenrep/test/t_cenreppc.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/centralrepository/pccenrep/test/t_cenreppc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,413 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <x86tool/centralrepository.h>
1.20 +#include <e32test.h>
1.21 +#include <f32file.h>
1.22 +
1.23 +#ifdef __TOOLS2__
1.24 +#define CENREP_PC_TEST
1.25 +#endif
1.26 +
1.27 +enum TestMode{
1.28 + ETxt,
1.29 + ECre,
1.30 + EAutoCre,
1.31 + EAutoTxt
1.32 +};
1.33 +
1.34 +RTest TheTest(_L("Central Repository Tests"));
1.35 +RFs TheFs;
1.36 +
1.37 +//uid for txt testing purpose
1.38 +const TUid uid={0x000001FF};
1.39 +//uid for cre testing purpose
1.40 +const TUid uidcre={0x00001FFF};
1.41 +const TUid uidcretest = {0x000002FF};
1.42 +#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
1.43 +const TUid uidcrev1= {0x00004FFF};
1.44 +#endif
1.45 +
1.46 +const TUid uidmetatest = {0x00022222};
1.47 +
1.48 +#ifndef __TOOLS2__
1.49 +/** FILES FOR MAN NEWL TESTING */
1.50 + _LIT(KTemplateTxtFile,"c:\\000001ff.txt");
1.51 + _LIT(KTemplateTxtOutFile,"c:\\000001ff.cre");
1.52 + //cre equivalent is generated through centrepconv of the txt version
1.53 + _LIT(KTemplateCreFile,"c:\\00001fff.cre");
1.54 + _LIT(KCopyTemplateCreFile,"c:\\copy00001fff.cre");
1.55 + //the target output is set to a different name
1.56 + _LIT(KTemplateCreOutFile,"c:\\00001eee.cre");
1.57 +
1.58 + _LIT(KMetaTxtTestInFile,"c:\\00022222.txt"); // Txt test input
1.59 + _LIT(KMetaTestCreFile,"c:\\00022222.cre"); // Txt test output, Cre test in/output
1.60 + _LIT(KMetaTestCreCopy,"c:\\copy00022222.cre");
1.61 + _LIT(KMetaTxtTestOgnFile, "c:\\00022222.ogn");
1.62 +
1.63 +/** FILES FOR AUTO NEWL TESTING */
1.64 + _LIT(KPrivateTemplateCreFile,"c:\\private\\00000000\\00001fff.cre");
1.65 +#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
1.66 + _LIT(KPrivateTemplateCreV1File,"c:\\private\\00000000\\00004fff.cre");
1.67 + _LIT(KCopyPrivateTemplateCreV1File,"c:\\private\\00000000\\copy00004fff.cre");
1.68 +#endif
1.69 + _LIT(KCopyPrivateTemplateCreFile,"c:\\private\\00000000\\copy00001fff.cre");
1.70 + _LIT(KPrivateTemplateTxtFile,"c:\\private\\0000000\\000001ff.txt");
1.71 + _LIT(KPrivateTemplateTxtOutFile,"c:\\private\\00000000\\000001ff.cre");
1.72 +
1.73 + //for comparison test
1.74 + _LIT(KPrivateCreFileForCreTest,"c:\\private\\00000000\\000002ff.cre");
1.75 + _LIT(KCopyCreFileForCreTest,"c:\\private\\00000000\\copy000002ff.cre");
1.76 + _LIT(KTxtTestRefFile,"c:\\private\\00000000\\ref_winscwtxt.cre");
1.77 + _LIT(KCreTestRefFile,"c:\\private\\00000000\\ref_winscwcre.cre");
1.78 + _LIT(KTxtTestGenFile,"c:\\private\\00000000\\winscwtxt.cre");
1.79 + _LIT(KCreTestGenFile,"c:\\private\\00000000\\winscwcre.cre");
1.80 +
1.81 + // Make sure the contents of the following 2 files is the same as crc.txt and
1.82 + // ref_00022222.cre, which are generated by the WINSCW t_cenrepcs.exe test.
1.83 + _LIT(KCrcRecordFile,"c:\\common_crc.txt");
1.84 + _LIT(KMetaTestRefFile,"c:\\private\\00000000\\common_ref_00022222.cre");
1.85 +
1.86 + _LIT(KOgnFile1FF, "c:\\private\\00000000\\000001ff.ogn");
1.87 + _LIT(KOgnFile1FFF, "c:\\private\\00000000\\00001fff.ogn");
1.88 + _LIT(KOgnFile2FF, "c:\\private\\00000000\\000002ff.ogn");
1.89 + _LIT(KOgnFile22222, "c:\\private\\00000000\\00022222.ogn");
1.90 +
1.91 + _LIT(KMetaTestFile,"c:\\private\\00000000\\00022222.cre");
1.92 + _LIT(KMetaTestCopy,"c:\\private\\00000000\\copy00022222.cre");
1.93 +
1.94 +// __TOOLS2__
1.95 +#else
1.96 +/** FILES FOR MAN NEWL TESTING */
1.97 + //in TOOLS2 this is relative
1.98 + _LIT(KTemplateTxtFile,"000001ff.txt");
1.99 + _LIT(KTemplateTxtOutFile,"000001ff.cre");
1.100 + //cre equivalent is generated through centrepconv of the txt version
1.101 + _LIT(KTemplateCreFile,"00001fff.cre");
1.102 + _LIT(KCopyTemplateCreFile,"copy00001fff.cre");
1.103 + _LIT(KTemplateCreOutFile,"00001eee.cre");
1.104 +
1.105 + _LIT(KMetaTxtTestInFile,"00022222.txt"); // Txt test input
1.106 + _LIT(KMetaTestCreFile,"00022222.cre"); // Txt test output, Cre test in/output
1.107 + _LIT(KMetaTestCreCopy,"copy00022222.cre");
1.108 + _LIT(KMetaTxtTestOgnFile, "00022222.ogn");
1.109 +
1.110 +/** FILES FOR AUTO NEWL TESTING */
1.111 + _LIT(KPrivateTemplateCreFile,"00001fff.cre");
1.112 +#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
1.113 + _LIT(KPrivateTemplateCreV1File,"00004fff.cre");
1.114 + _LIT(KCopyPrivateTemplateCreV1File,"copy00004fff.cre");
1.115 +#endif
1.116 + _LIT(KCopyPrivateTemplateCreFile,"copy00001fff.cre");
1.117 + _LIT(KPrivateTemplateTxtFile,"000001ff.txt");
1.118 + _LIT(KPrivateTemplateTxtOutFile,"000001ff.cre");
1.119 +
1.120 + //for comparison test
1.121 + _LIT(KPrivateCreFileForCreTest,"000002ff.cre");
1.122 + _LIT(KCopyCreFileForCreTest,"copy000002ff.cre");
1.123 + _LIT(KTxtTestRefFile,"ref_winscwtxt.cre");
1.124 + _LIT(KCreTestRefFile,"ref_winscwcre.cre");
1.125 + _LIT(KTxtTestGenFile,"winscwtxt.cre");
1.126 + _LIT(KCreTestGenFile,"winscwcre.cre");
1.127 + // if start with \epoc32, symfile resolves the address related to EPOCROOT
1.128 +
1.129 + // Make sure the contents of the following 2 files is the same as crc.txt and
1.130 + // ref_00022222.cre, which are generated by the WINSCW t_cenrepcs.exe test.
1.131 + _LIT(KCrcRecordFile,"\\epoc32\\winscw\\c\\common_crc.txt");
1.132 + _LIT(KMetaTestRefFile,"\\epoc32\\winscw\\c\\private\\00000000\\common_ref_00022222.cre");
1.133 +
1.134 + _LIT(KOgnFile1FF, "000001ff.ogn");
1.135 + _LIT(KOgnFile1FFF, "00001fff.ogn");
1.136 + _LIT(KOgnFile2FF, "000002ff.ogn");
1.137 + _LIT(KOgnFile22222, "00022222.ogn");
1.138 +
1.139 +
1.140 + _LIT(KMetaTestFile,"00022222.cre");
1.141 + _LIT(KMetaTestCopy,"copy00022222.cre");
1.142 +#endif
1.143 +
1.144 +///////////////////////////////////////////////////////////////////////////////////////
1.145 +
1.146 +LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
1.147 + {
1.148 + if(aValue != aExpected)
1.149 + {
1.150 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.151 + TheTest(EFalse, aLine);
1.152 + }
1.153 + }
1.154 +
1.155 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.156 +
1.157 +///////////////////////////////////////////////////////////////////////////////////////
1.158 +
1.159 +//DEFINED IN THE COMMON CPP FILE
1.160 +extern TInt CopyFile(const TDesC& aSource, const TDesC& aTarget);
1.161 +extern void ObjectCreateDeleteOOM(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.162 +extern void OomTest(void (*testFuncL)(CRepository* aRepository),TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.163 +extern void BasicFunctionL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.164 +extern void OomBasicFunction(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.165 +extern void DoFileCompL(const TDesC& aGenerated, const TDesC& aReference, TUint32& aCrcValue);
1.166 +extern void DoCrcCompL(const TUint32& aCrcValue, const TDesC& aCrcRecord, TBool aCrcOfTxt);
1.167 +extern void DEF130394L(TUid aUid);
1.168 +
1.169 +void InitialiseLC(CRepository*& aRepository,TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
1.170 + {
1.171 +#ifdef CENREP_PC_TEST
1.172 + if (aTestMode==ETxt || aTestMode==ECre)
1.173 + aRepository=CRepository::NewLC(aInFilePath,aOutFilePath);
1.174 + else
1.175 +#endif
1.176 + aRepository=CRepository::NewLC(aUid);
1.177 + }
1.178 +
1.179 +void ClearOgns()
1.180 + {
1.181 + TheFs.Delete(KMetaTxtTestOgnFile);
1.182 + TheFs.Delete(KOgnFile1FF);
1.183 + TheFs.Delete(KOgnFile1FFF);
1.184 + TheFs.Delete(KOgnFile2FF);
1.185 + TheFs.Delete(KOgnFile22222);
1.186 + }
1.187 +
1.188 +void SetupEnv(const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
1.189 + {
1.190 + ClearOgns();
1.191 + if (aTestMode==ETxt || aTestMode==EAutoTxt)
1.192 + TheFs.Delete(aOutFilePath);
1.193 + if (aTestMode==ECre)
1.194 + {
1.195 + //always copy so we always start the OOM with fresh original cre file
1.196 + CopyFile(KCopyTemplateCreFile,aInFilePath);
1.197 + TheFs.Delete(aOutFilePath);
1.198 + }
1.199 + if (aTestMode==EAutoCre)
1.200 + {
1.201 + TheFs.Delete(aOutFilePath);
1.202 +#ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
1.203 + CopyFile(KCopyPrivateTemplateCreFile,aInFilePath);
1.204 +#else
1.205 + if (aInFilePath.Compare(KPrivateTemplateCreFile)==0)
1.206 + CopyFile(KCopyPrivateTemplateCreFile,aInFilePath);
1.207 + else
1.208 + CopyFile(KCopyPrivateTemplateCreV1File,aInFilePath);
1.209 +#endif
1.210 + }
1.211 + }
1.212 +
1.213 +// If testsymcenrep or t_cenreppc fails, common_crc.txt and common_ref_00022222.cre might need
1.214 +// to be updated (with the versions generated by the WINSCW t_cenrepcs.exe test,
1.215 +// crc.txt and ref_00022222.cre), if the format of the repository files has changed.
1.216 +void CrcComparisonTestL()
1.217 + {
1.218 + // Auto Txt Test
1.219 + TUint32 txtTestCrcVal;
1.220 + BasicFunctionL(uid,KPrivateTemplateTxtFile,KPrivateTemplateTxtOutFile,EAutoTxt);
1.221 + CopyFile(KPrivateTemplateTxtOutFile, KTxtTestGenFile);
1.222 + DoFileCompL(KTxtTestGenFile, KTxtTestRefFile, txtTestCrcVal);
1.223 + DoCrcCompL(txtTestCrcVal, KCrcRecordFile, EFalse);
1.224 +
1.225 + // Auto Cre Test
1.226 + TUint32 creTestCrcVal;
1.227 + TheFs.Delete(KPrivateCreFileForCreTest);
1.228 + CopyFile(KCopyCreFileForCreTest, KPrivateCreFileForCreTest);
1.229 + BasicFunctionL(uidcretest,KNullDesC,KNullDesC,EAutoTxt);
1.230 + CopyFile(KPrivateCreFileForCreTest, KCreTestGenFile);
1.231 + DoFileCompL(KCreTestGenFile, KCreTestRefFile, creTestCrcVal);
1.232 + DoCrcCompL(creTestCrcVal, KCrcRecordFile, ETrue);
1.233 + }
1.234 +
1.235 +void FlushFunctionalityTestingL(CRepository* aRepository)
1.236 + {
1.237 + TInt r= aRepository->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
1.238 + TheTest(r==KErrNone);
1.239 + aRepository->CleanupFailTransactionPushL();
1.240 +
1.241 + User::LeaveIfError(aRepository->Set(1,9));
1.242 +
1.243 + CleanupStack::Pop();
1.244 + aRepository->FailTransaction();
1.245 +
1.246 + User::LeaveIfError(aRepository->Flush());
1.247 + TInt value=0;
1.248 + User::LeaveIfError(aRepository->Get(1,value));
1.249 + TheTest(value==9);
1.250 + }
1.251 +
1.252 +void FlushTestingL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
1.253 + {
1.254 + __UHEAP_MARK;
1.255 + SetupEnv(aInFilePath,aOutFilePath,aTestMode);
1.256 +
1.257 + //basic functionality test
1.258 + CRepository* repository=NULL;
1.259 + InitialiseLC(repository,aUid,aInFilePath,aOutFilePath,aTestMode);
1.260 +
1.261 + //made some modification
1.262 + FlushFunctionalityTestingL(repository);
1.263 + CleanupStack::PopAndDestroy();
1.264 +
1.265 + //oom functionality test
1.266 + OomTest(FlushFunctionalityTestingL,aUid,aInFilePath,aOutFilePath,aTestMode);
1.267 +
1.268 + __UHEAP_MARKEND;
1.269 + }
1.270 +
1.271 +/**
1.272 +@SYMTestCaseID PDS-CENTRALREPOSITORY-CT-4080
1.273 +@SYMTestCaseDesc Test for DEF130394
1.274 +@SYMTestPriority Medium
1.275 +@SYMTestActions This is Part 2 of the test - Part 1 is in t_cenrrepcs.cpp
1.276 + Loading a repository multiple times and then compare
1.277 + (using CRC compare) the created cre file with the reference
1.278 + cre from CS test.
1.279 +@SYMTestExpectedResults Cre file is identical as the reference cre.
1.280 +@SYMDEF DEF130394
1.281 +*/
1.282 +void TestLoadingDEF130394L(const TDesC& aInFilePath, const TDesC& aOutFilePath)
1.283 + {
1.284 + CRepository* repos = NULL;
1.285 +
1.286 + repos = CRepository::NewLC(aInFilePath, aOutFilePath);
1.287 + TInt err = repos->Create(1,1);
1.288 + TEST2(err, KErrNone);
1.289 +
1.290 + CleanupStack::PopAndDestroy();
1.291 +
1.292 + // Second time we need to load from output file it self, otherwise it is not loading
1.293 + // a repository multiple times because changes of the first time loading is not
1.294 + // flushed into input file.
1.295 + repos = CRepository::NewLC(aOutFilePath, aOutFilePath);
1.296 + err = repos->Create(1,1);
1.297 + TEST2(err, KErrAlreadyExists);
1.298 +
1.299 + CleanupStack::PopAndDestroy();
1.300 + }
1.301 +
1.302 +void TestForDEF130394L()
1.303 + {
1.304 + TUint32 dummy;
1.305 +
1.306 + // NewLC Txt=>Cre Loading test
1.307 + ClearOgns();
1.308 + TheFs.Delete(KMetaTestCreFile);
1.309 + TestLoadingDEF130394L(KMetaTxtTestInFile, KMetaTestCreFile);
1.310 + DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy);
1.311 +
1.312 + // NewLC Cre=>Cre Loading test
1.313 + ClearOgns();
1.314 + TheFs.Delete(KMetaTestCreFile);
1.315 + CopyFile(KMetaTestCreCopy, KMetaTestCreFile);
1.316 + TestLoadingDEF130394L(KMetaTestCreFile, KMetaTestCreFile);
1.317 + DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy);
1.318 +
1.319 + // Auto Loading Cre test
1.320 + ClearOgns();
1.321 + TheFs.Delete(KMetaTestFile);
1.322 + CopyFile(KMetaTestCopy, KMetaTestFile);
1.323 + DEF130394L(uidmetatest);
1.324 + DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy);
1.325 +
1.326 + //Auto Loading Txt test
1.327 + ClearOgns();
1.328 + TheFs.Delete(KMetaTestFile);
1.329 + DEF130394L(uidmetatest);
1.330 + DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy);
1.331 + }
1.332 +
1.333 +/**
1.334 +@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4041
1.335 +@SYMTestCaseDesc PC-side CentralRepository functionality test
1.336 +@SYMTestPriority High
1.337 +@SYMTestActions Wrapper function calling up test functions. Test functions include test for basic
1.338 + functions of the component, OOm test and CRC comparison test.
1.339 +@SYMTestExpectedResults Test must not fail
1.340 +@SYMPREQ PREQ2111
1.341 +*/
1.342 +LOCAL_C void MainL()
1.343 + {
1.344 + //Note these files are equivalent, the cre being generated from txt
1.345 + User::LeaveIfError(TheFs.Connect());
1.346 +
1.347 + //TXT => CRE
1.348 + TheTest.Start(_L("Functional NewLC TXT tests"));
1.349 + BasicFunctionL(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt);
1.350 + TheTest.Next(_L("OOM NewLC TXT tests"));
1.351 + ObjectCreateDeleteOOM(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt);
1.352 + OomBasicFunction(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt);
1.353 +
1.354 + //CRE => CRE
1.355 + TheTest.Next(_L("Functional NewLC CRE tests"));
1.356 + BasicFunctionL(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre);
1.357 + TheTest.Next(_L("OOM NewL CRE tests"));
1.358 + ObjectCreateDeleteOOM(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre);
1.359 + OomBasicFunction(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre);
1.360 +
1.361 + //CRE exists only
1.362 + TheTest.Next(_L("Functional NewLC Auto CRE tests"));
1.363 + BasicFunctionL(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
1.364 + TheTest.Next(_L("OOM NewLC Auto CRE tests"));
1.365 + ObjectCreateDeleteOOM(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
1.366 + OomBasicFunction(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
1.367 +
1.368 + //TXT exists only
1.369 + TheTest.Next(_L("Functional NewLC Auto TXT tests"));
1.370 + BasicFunctionL(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
1.371 + TheTest.Next(_L("OOM NewLC Auto TXT tests"));
1.372 + ObjectCreateDeleteOOM(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
1.373 + OomBasicFunction(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
1.374 +
1.375 + //PC side only testing
1.376 + TheTest.Next(_L("Flush Functionality test"));
1.377 + FlushTestingL(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
1.378 + FlushTestingL(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);
1.379 +
1.380 + TheTest.Next(_L("CRC comparison test"));
1.381 + CrcComparisonTestL();
1.382 +
1.383 +#ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
1.384 + //perform testing on CREV1 , only CRE exists only
1.385 + TheTest.Next(_L("Functional NewLC Auto CREV1 tests"));
1.386 + BasicFunctionL(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre);
1.387 + TheTest.Next(_L("OOM NewLC Auto CREV1 tests"));
1.388 + ObjectCreateDeleteOOM(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre);
1.389 + OomBasicFunction(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre);
1.390 +
1.391 +#endif
1.392 +
1.393 + TheTest.Next(_L("Test for DEF130394L"));
1.394 + TestForDEF130394L();
1.395 +
1.396 + TheFs.Close();
1.397 + TheTest.End();
1.398 + TheTest.Close();
1.399 + }
1.400 +
1.401 +TInt E32Main()
1.402 + {
1.403 + __UHEAP_MARK;
1.404 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.405 + if(!cleanup)
1.406 + return KErrNoMemory;
1.407 +
1.408 + TRAPD(err, MainL());
1.409 + if (err != KErrNone)
1.410 + User::Panic(_L("Testing failed: "), err);
1.411 +
1.412 + delete cleanup;
1.413 + __UHEAP_MARKEND;
1.414 +
1.415 + return 0;
1.416 + }