os/persistentdata/persistentstorage/centralrepository/pccenrep/test/t_cenrepcs.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 <centralrepository.h>
    17 #include <e32test.h>
    18 #include <f32file.h>
    19 #include "../../test/t_cenrep_helper.h"
    20 
    21 _LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
    22 
    23 enum TestMode{
    24 	ETxt,
    25 	ECre,
    26 	EAutoCre,
    27 	EAutoTxt
    28 };
    29 
    30 RTest TheTest(_L("Central Repository Tests"));
    31 RFs TheFs;
    32 
    33 //uid for txt testing purpose
    34 const TUid uid={0x000001FF};
    35 //uid for cre testing purpose
    36 const TUid uidcre={0x00001FFF};
    37 const TUid uidcretest = {0x000002FF};
    38 const TUid uidmetatest = {0x00022222};
    39 
    40 /** FILES FOR AUTO NEWL TESTING */
    41 _LIT(KPrivateTemplateCreOutFile,"c:\\private\\10202be9\\persists\\00001fff.cre");
    42 _LIT(KPrivateTemplateTxtOutFile,"c:\\private\\10202be9\\persists\\000001ff.cre");
    43 
    44 _LIT(KPersistCreFileTxt,"c:\\private\\10202be9\\persists\\000001ff.cre");
    45 _LIT(KPersistCreFileCre,"c:\\private\\10202be9\\persists\\000002ff.cre");
    46 _LIT(KPersistMetaTestFile,"c:\\private\\10202be9\\persists\\00022222.cre");
    47 
    48 _LIT(KTxtTestRefFile,"c:\\private\\00000000\\ref_winscwtxt.cre");
    49 _LIT(KCreTestRefFile,"c:\\private\\00000000\\ref_winscwcre.cre");
    50 
    51 _LIT(KMetaTestRefFile,"c:\\private\\00000000\\ref_00022222.cre");
    52 
    53 _LIT(KCrcRecordFile,"c:\\crc.txt");
    54 
    55 ///////////////////////////////////////////////////////////////////////////////////////
    56 
    57 
    58 //DEFINED IN THE COMMON CPP FILE
    59 extern TInt CopyFile(const TDesC& aSource, const TDesC& aTarget);
    60 extern void ObjectCreateDeleteOOM(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
    61 extern void OomTest(void (*testFuncL)(CRepository* aRepository),TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
    62 extern void BasicFunctionL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
    63 extern void OomBasicFunction(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
    64 extern void DoFileCompL(const TDesC& aGenerated, const TDesC& aReference, TUint32& aCrcValue);
    65 extern void DEF130394L(TUid aUid);
    66 
    67 void InitialiseLC(CRepository*& aRepository,TUid aUid,const TDesC& /**aInFilePath */,const TDesC& /**aOutFilePath*/,TUint /**aTestMode*/)
    68 	{
    69 	aRepository=CRepository::NewLC(aUid);
    70 	}
    71 
    72 void SetupEnv(const TDesC& /**aInFilePath*/,const TDesC& aOutFilePath,TUint aTestMode)
    73 	{
    74 	if (aTestMode==EAutoCre || aTestMode==EAutoTxt)
    75 		TheFs.Delete(aOutFilePath);
    76 	}
    77 
    78 void CrcReferenceGenL()
    79 	{
    80 	KillProcess(KCentralRepositoryServerName);
    81 	
    82 	TheFs.Delete(KCrcRecordFile);
    83 	
    84 	// Auto Cre Test
    85 	TUint32 crcCre;
    86 	BasicFunctionL(uidcretest, KNullDesC, KPersistCreFileCre, EAutoCre);
    87 	DoFileCompL(KPersistCreFileCre, KCreTestRefFile, crcCre);
    88 	
    89 	// Auto Txt Test
    90 	TUint32 crcTxt = 0;
    91 	BasicFunctionL(uid, KNullDesC(), KPersistCreFileTxt, EAutoTxt);
    92 	DoFileCompL(KPersistCreFileTxt, KTxtTestRefFile, crcTxt);
    93 	
    94 	TBuf8<100> buf;
    95 	buf.Format(_L8("%u-%u"), crcTxt, crcCre);
    96 	
    97 	RFile file;
    98 	file.Create(TheFs, KCrcRecordFile, EFileWrite);
    99 	file.Write(buf);
   100 	}
   101 
   102 /**
   103 @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4080
   104 @SYMTestCaseDesc		Test for DEF130394
   105 @SYMTestPriority		Normal
   106 @SYMTestActions			This is Part 1 of the test - Part 2 is in t_cenrreppc.cpp
   107 						Loading a repository multiple times and copy the created cre file
   108 						to the test location of PC test.
   109 @SYMTestExpectedResults A reference cre file in PC test test location
   110 @SYMDEF					DEF130394
   111 */	
   112 void TestForDEF130394L()
   113 	{
   114 	TheFs.Delete(KPersistMetaTestFile);
   115 	DEF130394L(uidmetatest);
   116 	CopyFile(KPersistMetaTestFile, KMetaTestRefFile);
   117 	}
   118 
   119 /**
   120 @SYMTestCaseID			SYSLIB-CENTRALREPOSITORY-CT-4043
   121 @SYMTestCaseDesc		Client-Server-side CentralRepository functionality test
   122 @SYMTestPriority		High
   123 @SYMTestActions			Wrapper function calling up test functions. Test functions include test for basic
   124 						functions of the component, OOm test and CRC comparison test.
   125 @SYMTestExpectedResults Test must not fail
   126 @SYMPREQ				PREQ2111
   127 */						   
   128 LOCAL_C void MainL()
   129 	{
   130 	//Note these files are equivalent, the cre being generated from txt
   131 	TheTest.Start(_L("Functional TXT tests"));		
   132 
   133 	User::LeaveIfError(TheFs.Connect());
   134 
   135 	//CRE exists only
   136 	TheTest.Next(_L("Functional NewLC Auto CRE tests"));	
   137 	BasicFunctionL(uidcre,KNullDesC(),KPrivateTemplateCreOutFile(),EAutoCre);
   138 	TheTest.Next(_L("OOM NewLC Auto CRE tests"));
   139 	ObjectCreateDeleteOOM(uidcre,KNullDesC(),KPrivateTemplateCreOutFile(),EAutoCre);
   140 	OomBasicFunction(uidcre,KNullDesC(),KPrivateTemplateCreOutFile(),EAutoCre);		
   141 
   142 	//TXT exists only
   143 	TheTest.Next(_L("Functional NewLC Auto TXT tests"));	
   144 	BasicFunctionL(uid,KNullDesC(),KPrivateTemplateTxtOutFile(),EAutoTxt);
   145 	TheTest.Next(_L("OOM NewLC Auto TXT tests"));					
   146 	ObjectCreateDeleteOOM(uid,KNullDesC(),KPrivateTemplateTxtOutFile(),EAutoTxt);
   147 	OomBasicFunction(uid,KNullDesC(),KPrivateTemplateTxtOutFile(),EAutoTxt);
   148 
   149 #ifdef __WINSCW__ // no need to run on ARM
   150 	TheTest.Next(_L("CRC comparison preparation for PC side test"));
   151 	CrcReferenceGenL();
   152 	
   153 	TheTest.Next(_L("Test for DEF130394L"));
   154 	TestForDEF130394L();
   155 #endif
   156 	
   157 	TheFs.Close();
   158 	TheTest.End();
   159 	TheTest.Close();
   160 	}
   161 
   162 TInt E32Main()
   163 	{	
   164 	__UHEAP_MARK;
   165 	CTrapCleanup* cleanup = CTrapCleanup::New();
   166 	if(!cleanup)
   167 		return KErrNoMemory;
   168 
   169 	TRAPD(err, MainL());
   170 	if (err != KErrNone)
   171 		User::Panic(_L("Testing failed: "), err);
   172 	
   173 	delete cleanup;
   174 	__UHEAP_MARKEND;
   175 
   176 	return 0;
   177 	}