os/persistentdata/persistentstorage/centralrepository/pccenrep/test/t_cenreppc.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <x86tool/centralrepository.h>
    17 #include <e32test.h>
    18 #include <f32file.h>
    19 
    20 #ifdef __TOOLS2__
    21 #define CENREP_PC_TEST
    22 #endif
    23 
    24 enum TestMode{
    25 	ETxt,
    26 	ECre,
    27 	EAutoCre,
    28 	EAutoTxt
    29 };
    30 
    31 RTest TheTest(_L("Central Repository Tests"));
    32 RFs TheFs;
    33 
    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};
    41 #endif
    42 
    43 const TUid uidmetatest = {0x00022222};
    44 
    45 #ifndef __TOOLS2__
    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");
    54 	
    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");
    59 
    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");	
    65 #endif	
    66 	_LIT(KCopyPrivateTemplateCreFile,"c:\\private\\00000000\\copy00001fff.cre");
    67 	_LIT(KPrivateTemplateTxtFile,"c:\\private\\0000000\\000001ff.txt");
    68 	_LIT(KPrivateTemplateTxtOutFile,"c:\\private\\00000000\\000001ff.cre");
    69 
    70 	//for comparison test
    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");
    77 
    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");
    82 
    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");
    87 	
    88 	_LIT(KMetaTestFile,"c:\\private\\00000000\\00022222.cre");
    89 	_LIT(KMetaTestCopy,"c:\\private\\00000000\\copy00022222.cre");
    90 
    91 // __TOOLS2__	
    92 #else
    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");
   101 	
   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");
   106 	
   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");	
   112 #endif	
   113 	_LIT(KCopyPrivateTemplateCreFile,"copy00001fff.cre");	
   114 	_LIT(KPrivateTemplateTxtFile,"000001ff.txt");
   115 	_LIT(KPrivateTemplateTxtOutFile,"000001ff.cre");	
   116 		
   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
   125 
   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");
   130 
   131 	_LIT(KOgnFile1FF, "000001ff.ogn");
   132 	_LIT(KOgnFile1FFF, "00001fff.ogn");
   133 	_LIT(KOgnFile2FF, "000002ff.ogn");
   134 	_LIT(KOgnFile22222, "00022222.ogn");
   135 	
   136 
   137 	_LIT(KMetaTestFile,"00022222.cre");
   138 	_LIT(KMetaTestCopy,"copy00022222.cre");
   139 #endif	
   140 
   141 ///////////////////////////////////////////////////////////////////////////////////////
   142 
   143 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
   144     {
   145     if(aValue != aExpected)
   146         {
   147         RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
   148         TheTest(EFalse, aLine);
   149         }
   150     }
   151 	
   152 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
   153 
   154 ///////////////////////////////////////////////////////////////////////////////////////
   155 
   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);
   165 
   166 void InitialiseLC(CRepository*& aRepository,TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
   167 	{
   168 #ifdef CENREP_PC_TEST	
   169 	if (aTestMode==ETxt || aTestMode==ECre)
   170 		aRepository=CRepository::NewLC(aInFilePath,aOutFilePath);
   171 	else
   172 #endif	
   173 		aRepository=CRepository::NewLC(aUid);
   174 	}
   175 
   176 void ClearOgns()
   177 	{
   178 	TheFs.Delete(KMetaTxtTestOgnFile);
   179 	TheFs.Delete(KOgnFile1FF);
   180 	TheFs.Delete(KOgnFile1FFF);
   181 	TheFs.Delete(KOgnFile2FF);
   182 	TheFs.Delete(KOgnFile22222);
   183 	}
   184 
   185 void SetupEnv(const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
   186 	{
   187 	ClearOgns();
   188 	if (aTestMode==ETxt || aTestMode==EAutoTxt)
   189 		TheFs.Delete(aOutFilePath);
   190 	if (aTestMode==ECre)
   191 		{
   192 		//always copy so we always start the OOM with fresh original cre file
   193 		CopyFile(KCopyTemplateCreFile,aInFilePath);
   194 		TheFs.Delete(aOutFilePath);
   195 		}
   196 	if (aTestMode==EAutoCre)
   197 		{
   198 		TheFs.Delete(aOutFilePath);
   199 #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
   200 		CopyFile(KCopyPrivateTemplateCreFile,aInFilePath);
   201 #else
   202 		if (aInFilePath.Compare(KPrivateTemplateCreFile)==0)
   203 			CopyFile(KCopyPrivateTemplateCreFile,aInFilePath);
   204 		else
   205 			CopyFile(KCopyPrivateTemplateCreV1File,aInFilePath);
   206 #endif		
   207 		}
   208 	}
   209 
   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()
   214 	{
   215 	// Auto Txt Test
   216 	TUint32 txtTestCrcVal;
   217 	BasicFunctionL(uid,KPrivateTemplateTxtFile,KPrivateTemplateTxtOutFile,EAutoTxt);
   218 	CopyFile(KPrivateTemplateTxtOutFile, KTxtTestGenFile);
   219 	DoFileCompL(KTxtTestGenFile, KTxtTestRefFile, txtTestCrcVal);
   220 	DoCrcCompL(txtTestCrcVal, KCrcRecordFile, EFalse);
   221 
   222 	// Auto Cre Test
   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);
   230 	}
   231 
   232 void FlushFunctionalityTestingL(CRepository* aRepository)
   233 	{
   234 	TInt r= aRepository->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
   235 	TheTest(r==KErrNone);
   236 	aRepository->CleanupFailTransactionPushL();	
   237 	
   238 	User::LeaveIfError(aRepository->Set(1,9));
   239 	
   240 	CleanupStack::Pop();
   241 	aRepository->FailTransaction();
   242 	
   243 	User::LeaveIfError(aRepository->Flush());
   244 	TInt value=0;
   245 	User::LeaveIfError(aRepository->Get(1,value));
   246 	TheTest(value==9);
   247 	}
   248 
   249 void FlushTestingL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode)
   250 	{
   251 	__UHEAP_MARK;
   252 	SetupEnv(aInFilePath,aOutFilePath,aTestMode);
   253 	
   254 	//basic functionality test
   255 	CRepository* repository=NULL;
   256 	InitialiseLC(repository,aUid,aInFilePath,aOutFilePath,aTestMode);	
   257 	
   258 	//made some modification
   259 	FlushFunctionalityTestingL(repository);
   260 	CleanupStack::PopAndDestroy();
   261 
   262 	//oom functionality test
   263 	OomTest(FlushFunctionalityTestingL,aUid,aInFilePath,aOutFilePath,aTestMode);
   264 
   265 	__UHEAP_MARKEND;
   266 	}
   267 
   268 /**
   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 
   275 						cre from CS test.
   276 @SYMTestExpectedResults Cre file is identical as the reference cre.
   277 @SYMDEF					DEF130394
   278 */	
   279 void TestLoadingDEF130394L(const TDesC& aInFilePath, const TDesC& aOutFilePath)
   280 	{
   281 	CRepository* repos = NULL;
   282 	
   283 	repos = CRepository::NewLC(aInFilePath, aOutFilePath);
   284 	TInt err = repos->Create(1,1);
   285 	TEST2(err, KErrNone);
   286 	
   287 	CleanupStack::PopAndDestroy();
   288 	
   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);
   295 	
   296 	CleanupStack::PopAndDestroy();
   297 	}
   298 
   299 void TestForDEF130394L()
   300 	{
   301 	TUint32 dummy;
   302 	
   303 	// NewLC Txt=>Cre Loading test
   304 	ClearOgns();
   305 	TheFs.Delete(KMetaTestCreFile);
   306 	TestLoadingDEF130394L(KMetaTxtTestInFile, KMetaTestCreFile);
   307 	DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy);
   308 
   309 	// NewLC Cre=>Cre Loading test
   310 	ClearOgns();
   311 	TheFs.Delete(KMetaTestCreFile);
   312 	CopyFile(KMetaTestCreCopy, KMetaTestCreFile);
   313 	TestLoadingDEF130394L(KMetaTestCreFile, KMetaTestCreFile);
   314 	DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy);
   315 
   316 	// Auto Loading Cre test
   317 	ClearOgns();
   318 	TheFs.Delete(KMetaTestFile);
   319 	CopyFile(KMetaTestCopy, KMetaTestFile);
   320 	DEF130394L(uidmetatest);
   321 	DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy);
   322 	
   323 	//Auto Loading Txt test
   324 	ClearOgns();
   325 	TheFs.Delete(KMetaTestFile);
   326 	DEF130394L(uidmetatest);
   327 	DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy);
   328 	}
   329 
   330 /**
   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
   337 @SYMPREQ				PREQ2111
   338 */						   
   339 LOCAL_C void MainL()
   340 	{
   341 	//Note these files are equivalent, the cre being generated from txt
   342 	User::LeaveIfError(TheFs.Connect());
   343 
   344 	//TXT => CRE
   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);
   350 
   351 	//CRE => CRE 
   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);
   357 
   358 	//CRE exists only
   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);		
   364 
   365 	//TXT exists only
   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);	
   371 
   372 	//PC side only testing
   373 	TheTest.Next(_L("Flush Functionality test"));
   374 	FlushTestingL(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre);
   375 	FlushTestingL(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt);	
   376 
   377 	TheTest.Next(_L("CRC comparison test"));
   378 	CrcComparisonTestL();
   379 	
   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);
   387 
   388 #endif	
   389 	
   390 	TheTest.Next(_L("Test for DEF130394L"));
   391 	TestForDEF130394L();
   392 	
   393 	TheFs.Close();
   394 	TheTest.End();
   395 	TheTest.Close();
   396 	}
   397 
   398 TInt E32Main()
   399 	{	
   400 	__UHEAP_MARK;
   401 	CTrapCleanup* cleanup = CTrapCleanup::New();
   402 	if(!cleanup)
   403 		return KErrNoMemory;
   404 
   405 	TRAPD(err, MainL());
   406 	if (err != KErrNone)
   407 		User::Panic(_L("Testing failed: "), err);
   408 	
   409 	delete cleanup;
   410 	__UHEAP_MARKEND;
   411 
   412 	return 0;
   413 	}