os/persistentdata/persistentstorage/centralrepository/pccenrep/test/t_cenrepcs.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/centralrepository/pccenrep/test/t_cenrepcs.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,177 @@
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 <centralrepository.h>
1.20 +#include <e32test.h>
1.21 +#include <f32file.h>
1.22 +#include "../../test/t_cenrep_helper.h"
1.23 +
1.24 +_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
1.25 +
1.26 +enum TestMode{
1.27 + ETxt,
1.28 + ECre,
1.29 + EAutoCre,
1.30 + EAutoTxt
1.31 +};
1.32 +
1.33 +RTest TheTest(_L("Central Repository Tests"));
1.34 +RFs TheFs;
1.35 +
1.36 +//uid for txt testing purpose
1.37 +const TUid uid={0x000001FF};
1.38 +//uid for cre testing purpose
1.39 +const TUid uidcre={0x00001FFF};
1.40 +const TUid uidcretest = {0x000002FF};
1.41 +const TUid uidmetatest = {0x00022222};
1.42 +
1.43 +/** FILES FOR AUTO NEWL TESTING */
1.44 +_LIT(KPrivateTemplateCreOutFile,"c:\\private\\10202be9\\persists\\00001fff.cre");
1.45 +_LIT(KPrivateTemplateTxtOutFile,"c:\\private\\10202be9\\persists\\000001ff.cre");
1.46 +
1.47 +_LIT(KPersistCreFileTxt,"c:\\private\\10202be9\\persists\\000001ff.cre");
1.48 +_LIT(KPersistCreFileCre,"c:\\private\\10202be9\\persists\\000002ff.cre");
1.49 +_LIT(KPersistMetaTestFile,"c:\\private\\10202be9\\persists\\00022222.cre");
1.50 +
1.51 +_LIT(KTxtTestRefFile,"c:\\private\\00000000\\ref_winscwtxt.cre");
1.52 +_LIT(KCreTestRefFile,"c:\\private\\00000000\\ref_winscwcre.cre");
1.53 +
1.54 +_LIT(KMetaTestRefFile,"c:\\private\\00000000\\ref_00022222.cre");
1.55 +
1.56 +_LIT(KCrcRecordFile,"c:\\crc.txt");
1.57 +
1.58 +///////////////////////////////////////////////////////////////////////////////////////
1.59 +
1.60 +
1.61 +//DEFINED IN THE COMMON CPP FILE
1.62 +extern TInt CopyFile(const TDesC& aSource, const TDesC& aTarget);
1.63 +extern void ObjectCreateDeleteOOM(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.64 +extern void OomTest(void (*testFuncL)(CRepository* aRepository),TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.65 +extern void BasicFunctionL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.66 +extern void OomBasicFunction(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode);
1.67 +extern void DoFileCompL(const TDesC& aGenerated, const TDesC& aReference, TUint32& aCrcValue);
1.68 +extern void DEF130394L(TUid aUid);
1.69 +
1.70 +void InitialiseLC(CRepository*& aRepository,TUid aUid,const TDesC& /**aInFilePath */,const TDesC& /**aOutFilePath*/,TUint /**aTestMode*/)
1.71 + {
1.72 + aRepository=CRepository::NewLC(aUid);
1.73 + }
1.74 +
1.75 +void SetupEnv(const TDesC& /**aInFilePath*/,const TDesC& aOutFilePath,TUint aTestMode)
1.76 + {
1.77 + if (aTestMode==EAutoCre || aTestMode==EAutoTxt)
1.78 + TheFs.Delete(aOutFilePath);
1.79 + }
1.80 +
1.81 +void CrcReferenceGenL()
1.82 + {
1.83 + KillProcess(KCentralRepositoryServerName);
1.84 +
1.85 + TheFs.Delete(KCrcRecordFile);
1.86 +
1.87 + // Auto Cre Test
1.88 + TUint32 crcCre;
1.89 + BasicFunctionL(uidcretest, KNullDesC, KPersistCreFileCre, EAutoCre);
1.90 + DoFileCompL(KPersistCreFileCre, KCreTestRefFile, crcCre);
1.91 +
1.92 + // Auto Txt Test
1.93 + TUint32 crcTxt = 0;
1.94 + BasicFunctionL(uid, KNullDesC(), KPersistCreFileTxt, EAutoTxt);
1.95 + DoFileCompL(KPersistCreFileTxt, KTxtTestRefFile, crcTxt);
1.96 +
1.97 + TBuf8<100> buf;
1.98 + buf.Format(_L8("%u-%u"), crcTxt, crcCre);
1.99 +
1.100 + RFile file;
1.101 + file.Create(TheFs, KCrcRecordFile, EFileWrite);
1.102 + file.Write(buf);
1.103 + }
1.104 +
1.105 +/**
1.106 +@SYMTestCaseID PDS-CENTRALREPOSITORY-CT-4080
1.107 +@SYMTestCaseDesc Test for DEF130394
1.108 +@SYMTestPriority Normal
1.109 +@SYMTestActions This is Part 1 of the test - Part 2 is in t_cenrreppc.cpp
1.110 + Loading a repository multiple times and copy the created cre file
1.111 + to the test location of PC test.
1.112 +@SYMTestExpectedResults A reference cre file in PC test test location
1.113 +@SYMDEF DEF130394
1.114 +*/
1.115 +void TestForDEF130394L()
1.116 + {
1.117 + TheFs.Delete(KPersistMetaTestFile);
1.118 + DEF130394L(uidmetatest);
1.119 + CopyFile(KPersistMetaTestFile, KMetaTestRefFile);
1.120 + }
1.121 +
1.122 +/**
1.123 +@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4043
1.124 +@SYMTestCaseDesc Client-Server-side CentralRepository functionality test
1.125 +@SYMTestPriority High
1.126 +@SYMTestActions Wrapper function calling up test functions. Test functions include test for basic
1.127 + functions of the component, OOm test and CRC comparison test.
1.128 +@SYMTestExpectedResults Test must not fail
1.129 +@SYMPREQ PREQ2111
1.130 +*/
1.131 +LOCAL_C void MainL()
1.132 + {
1.133 + //Note these files are equivalent, the cre being generated from txt
1.134 + TheTest.Start(_L("Functional TXT tests"));
1.135 +
1.136 + User::LeaveIfError(TheFs.Connect());
1.137 +
1.138 + //CRE exists only
1.139 + TheTest.Next(_L("Functional NewLC Auto CRE tests"));
1.140 + BasicFunctionL(uidcre,KNullDesC(),KPrivateTemplateCreOutFile(),EAutoCre);
1.141 + TheTest.Next(_L("OOM NewLC Auto CRE tests"));
1.142 + ObjectCreateDeleteOOM(uidcre,KNullDesC(),KPrivateTemplateCreOutFile(),EAutoCre);
1.143 + OomBasicFunction(uidcre,KNullDesC(),KPrivateTemplateCreOutFile(),EAutoCre);
1.144 +
1.145 + //TXT exists only
1.146 + TheTest.Next(_L("Functional NewLC Auto TXT tests"));
1.147 + BasicFunctionL(uid,KNullDesC(),KPrivateTemplateTxtOutFile(),EAutoTxt);
1.148 + TheTest.Next(_L("OOM NewLC Auto TXT tests"));
1.149 + ObjectCreateDeleteOOM(uid,KNullDesC(),KPrivateTemplateTxtOutFile(),EAutoTxt);
1.150 + OomBasicFunction(uid,KNullDesC(),KPrivateTemplateTxtOutFile(),EAutoTxt);
1.151 +
1.152 +#ifdef __WINSCW__ // no need to run on ARM
1.153 + TheTest.Next(_L("CRC comparison preparation for PC side test"));
1.154 + CrcReferenceGenL();
1.155 +
1.156 + TheTest.Next(_L("Test for DEF130394L"));
1.157 + TestForDEF130394L();
1.158 +#endif
1.159 +
1.160 + TheFs.Close();
1.161 + TheTest.End();
1.162 + TheTest.Close();
1.163 + }
1.164 +
1.165 +TInt E32Main()
1.166 + {
1.167 + __UHEAP_MARK;
1.168 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.169 + if(!cleanup)
1.170 + return KErrNoMemory;
1.171 +
1.172 + TRAPD(err, MainL());
1.173 + if (err != KErrNone)
1.174 + User::Panic(_L("Testing failed: "), err);
1.175 +
1.176 + delete cleanup;
1.177 + __UHEAP_MARKEND;
1.178 +
1.179 + return 0;
1.180 + }