sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __TOOLS2__ sl@0: #define CENREP_PC_TEST sl@0: #endif sl@0: sl@0: enum TestMode{ sl@0: ETxt, sl@0: ECre, sl@0: EAutoCre, sl@0: EAutoTxt sl@0: }; sl@0: sl@0: RTest TheTest(_L("Central Repository Tests")); sl@0: RFs TheFs; sl@0: sl@0: //uid for txt testing purpose sl@0: const TUid uid={0x000001FF}; sl@0: //uid for cre testing purpose sl@0: const TUid uidcre={0x00001FFF}; sl@0: const TUid uidcretest = {0x000002FF}; sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: const TUid uidcrev1= {0x00004FFF}; sl@0: #endif sl@0: sl@0: const TUid uidmetatest = {0x00022222}; sl@0: sl@0: #ifndef __TOOLS2__ sl@0: /** FILES FOR MAN NEWL TESTING */ sl@0: _LIT(KTemplateTxtFile,"c:\\000001ff.txt"); sl@0: _LIT(KTemplateTxtOutFile,"c:\\000001ff.cre"); sl@0: //cre equivalent is generated through centrepconv of the txt version sl@0: _LIT(KTemplateCreFile,"c:\\00001fff.cre"); sl@0: _LIT(KCopyTemplateCreFile,"c:\\copy00001fff.cre"); sl@0: //the target output is set to a different name sl@0: _LIT(KTemplateCreOutFile,"c:\\00001eee.cre"); sl@0: sl@0: _LIT(KMetaTxtTestInFile,"c:\\00022222.txt"); // Txt test input sl@0: _LIT(KMetaTestCreFile,"c:\\00022222.cre"); // Txt test output, Cre test in/output sl@0: _LIT(KMetaTestCreCopy,"c:\\copy00022222.cre"); sl@0: _LIT(KMetaTxtTestOgnFile, "c:\\00022222.ogn"); sl@0: sl@0: /** FILES FOR AUTO NEWL TESTING */ sl@0: _LIT(KPrivateTemplateCreFile,"c:\\private\\00000000\\00001fff.cre"); sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: _LIT(KPrivateTemplateCreV1File,"c:\\private\\00000000\\00004fff.cre"); sl@0: _LIT(KCopyPrivateTemplateCreV1File,"c:\\private\\00000000\\copy00004fff.cre"); sl@0: #endif sl@0: _LIT(KCopyPrivateTemplateCreFile,"c:\\private\\00000000\\copy00001fff.cre"); sl@0: _LIT(KPrivateTemplateTxtFile,"c:\\private\\0000000\\000001ff.txt"); sl@0: _LIT(KPrivateTemplateTxtOutFile,"c:\\private\\00000000\\000001ff.cre"); sl@0: sl@0: //for comparison test sl@0: _LIT(KPrivateCreFileForCreTest,"c:\\private\\00000000\\000002ff.cre"); sl@0: _LIT(KCopyCreFileForCreTest,"c:\\private\\00000000\\copy000002ff.cre"); sl@0: _LIT(KTxtTestRefFile,"c:\\private\\00000000\\ref_winscwtxt.cre"); sl@0: _LIT(KCreTestRefFile,"c:\\private\\00000000\\ref_winscwcre.cre"); sl@0: _LIT(KTxtTestGenFile,"c:\\private\\00000000\\winscwtxt.cre"); sl@0: _LIT(KCreTestGenFile,"c:\\private\\00000000\\winscwcre.cre"); sl@0: sl@0: // Make sure the contents of the following 2 files is the same as crc.txt and sl@0: // ref_00022222.cre, which are generated by the WINSCW t_cenrepcs.exe test. sl@0: _LIT(KCrcRecordFile,"c:\\common_crc.txt"); sl@0: _LIT(KMetaTestRefFile,"c:\\private\\00000000\\common_ref_00022222.cre"); sl@0: sl@0: _LIT(KOgnFile1FF, "c:\\private\\00000000\\000001ff.ogn"); sl@0: _LIT(KOgnFile1FFF, "c:\\private\\00000000\\00001fff.ogn"); sl@0: _LIT(KOgnFile2FF, "c:\\private\\00000000\\000002ff.ogn"); sl@0: _LIT(KOgnFile22222, "c:\\private\\00000000\\00022222.ogn"); sl@0: sl@0: _LIT(KMetaTestFile,"c:\\private\\00000000\\00022222.cre"); sl@0: _LIT(KMetaTestCopy,"c:\\private\\00000000\\copy00022222.cre"); sl@0: sl@0: // __TOOLS2__ sl@0: #else sl@0: /** FILES FOR MAN NEWL TESTING */ sl@0: //in TOOLS2 this is relative sl@0: _LIT(KTemplateTxtFile,"000001ff.txt"); sl@0: _LIT(KTemplateTxtOutFile,"000001ff.cre"); sl@0: //cre equivalent is generated through centrepconv of the txt version sl@0: _LIT(KTemplateCreFile,"00001fff.cre"); sl@0: _LIT(KCopyTemplateCreFile,"copy00001fff.cre"); sl@0: _LIT(KTemplateCreOutFile,"00001eee.cre"); sl@0: sl@0: _LIT(KMetaTxtTestInFile,"00022222.txt"); // Txt test input sl@0: _LIT(KMetaTestCreFile,"00022222.cre"); // Txt test output, Cre test in/output sl@0: _LIT(KMetaTestCreCopy,"copy00022222.cre"); sl@0: _LIT(KMetaTxtTestOgnFile, "00022222.ogn"); sl@0: sl@0: /** FILES FOR AUTO NEWL TESTING */ sl@0: _LIT(KPrivateTemplateCreFile,"00001fff.cre"); sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: _LIT(KPrivateTemplateCreV1File,"00004fff.cre"); sl@0: _LIT(KCopyPrivateTemplateCreV1File,"copy00004fff.cre"); sl@0: #endif sl@0: _LIT(KCopyPrivateTemplateCreFile,"copy00001fff.cre"); sl@0: _LIT(KPrivateTemplateTxtFile,"000001ff.txt"); sl@0: _LIT(KPrivateTemplateTxtOutFile,"000001ff.cre"); sl@0: sl@0: //for comparison test sl@0: _LIT(KPrivateCreFileForCreTest,"000002ff.cre"); sl@0: _LIT(KCopyCreFileForCreTest,"copy000002ff.cre"); sl@0: _LIT(KTxtTestRefFile,"ref_winscwtxt.cre"); sl@0: _LIT(KCreTestRefFile,"ref_winscwcre.cre"); sl@0: _LIT(KTxtTestGenFile,"winscwtxt.cre"); sl@0: _LIT(KCreTestGenFile,"winscwcre.cre"); sl@0: // if start with \epoc32, symfile resolves the address related to EPOCROOT sl@0: sl@0: // Make sure the contents of the following 2 files is the same as crc.txt and sl@0: // ref_00022222.cre, which are generated by the WINSCW t_cenrepcs.exe test. sl@0: _LIT(KCrcRecordFile,"\\epoc32\\winscw\\c\\common_crc.txt"); sl@0: _LIT(KMetaTestRefFile,"\\epoc32\\winscw\\c\\private\\00000000\\common_ref_00022222.cre"); sl@0: sl@0: _LIT(KOgnFile1FF, "000001ff.ogn"); sl@0: _LIT(KOgnFile1FFF, "00001fff.ogn"); sl@0: _LIT(KOgnFile2FF, "000002ff.ogn"); sl@0: _LIT(KOgnFile22222, "00022222.ogn"); sl@0: sl@0: sl@0: _LIT(KMetaTestFile,"00022222.cre"); sl@0: _LIT(KMetaTestCopy,"copy00022222.cre"); sl@0: #endif sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: /////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: //DEFINED IN THE COMMON CPP FILE sl@0: extern TInt CopyFile(const TDesC& aSource, const TDesC& aTarget); sl@0: extern void ObjectCreateDeleteOOM(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode); sl@0: extern void OomTest(void (*testFuncL)(CRepository* aRepository),TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode); sl@0: extern void BasicFunctionL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode); sl@0: extern void OomBasicFunction(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode); sl@0: extern void DoFileCompL(const TDesC& aGenerated, const TDesC& aReference, TUint32& aCrcValue); sl@0: extern void DoCrcCompL(const TUint32& aCrcValue, const TDesC& aCrcRecord, TBool aCrcOfTxt); sl@0: extern void DEF130394L(TUid aUid); sl@0: sl@0: void InitialiseLC(CRepository*& aRepository,TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode) sl@0: { sl@0: #ifdef CENREP_PC_TEST sl@0: if (aTestMode==ETxt || aTestMode==ECre) sl@0: aRepository=CRepository::NewLC(aInFilePath,aOutFilePath); sl@0: else sl@0: #endif sl@0: aRepository=CRepository::NewLC(aUid); sl@0: } sl@0: sl@0: void ClearOgns() sl@0: { sl@0: TheFs.Delete(KMetaTxtTestOgnFile); sl@0: TheFs.Delete(KOgnFile1FF); sl@0: TheFs.Delete(KOgnFile1FFF); sl@0: TheFs.Delete(KOgnFile2FF); sl@0: TheFs.Delete(KOgnFile22222); sl@0: } sl@0: sl@0: void SetupEnv(const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode) sl@0: { sl@0: ClearOgns(); sl@0: if (aTestMode==ETxt || aTestMode==EAutoTxt) sl@0: TheFs.Delete(aOutFilePath); sl@0: if (aTestMode==ECre) sl@0: { sl@0: //always copy so we always start the OOM with fresh original cre file sl@0: CopyFile(KCopyTemplateCreFile,aInFilePath); sl@0: TheFs.Delete(aOutFilePath); sl@0: } sl@0: if (aTestMode==EAutoCre) sl@0: { sl@0: TheFs.Delete(aOutFilePath); sl@0: #ifndef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: CopyFile(KCopyPrivateTemplateCreFile,aInFilePath); sl@0: #else sl@0: if (aInFilePath.Compare(KPrivateTemplateCreFile)==0) sl@0: CopyFile(KCopyPrivateTemplateCreFile,aInFilePath); sl@0: else sl@0: CopyFile(KCopyPrivateTemplateCreV1File,aInFilePath); sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: // If testsymcenrep or t_cenreppc fails, common_crc.txt and common_ref_00022222.cre might need sl@0: // to be updated (with the versions generated by the WINSCW t_cenrepcs.exe test, sl@0: // crc.txt and ref_00022222.cre), if the format of the repository files has changed. sl@0: void CrcComparisonTestL() sl@0: { sl@0: // Auto Txt Test sl@0: TUint32 txtTestCrcVal; sl@0: BasicFunctionL(uid,KPrivateTemplateTxtFile,KPrivateTemplateTxtOutFile,EAutoTxt); sl@0: CopyFile(KPrivateTemplateTxtOutFile, KTxtTestGenFile); sl@0: DoFileCompL(KTxtTestGenFile, KTxtTestRefFile, txtTestCrcVal); sl@0: DoCrcCompL(txtTestCrcVal, KCrcRecordFile, EFalse); sl@0: sl@0: // Auto Cre Test sl@0: TUint32 creTestCrcVal; sl@0: TheFs.Delete(KPrivateCreFileForCreTest); sl@0: CopyFile(KCopyCreFileForCreTest, KPrivateCreFileForCreTest); sl@0: BasicFunctionL(uidcretest,KNullDesC,KNullDesC,EAutoTxt); sl@0: CopyFile(KPrivateCreFileForCreTest, KCreTestGenFile); sl@0: DoFileCompL(KCreTestGenFile, KCreTestRefFile, creTestCrcVal); sl@0: DoCrcCompL(creTestCrcVal, KCrcRecordFile, ETrue); sl@0: } sl@0: sl@0: void FlushFunctionalityTestingL(CRepository* aRepository) sl@0: { sl@0: TInt r= aRepository->StartTransaction(CRepository::EConcurrentReadWriteTransaction); sl@0: TheTest(r==KErrNone); sl@0: aRepository->CleanupFailTransactionPushL(); sl@0: sl@0: User::LeaveIfError(aRepository->Set(1,9)); sl@0: sl@0: CleanupStack::Pop(); sl@0: aRepository->FailTransaction(); sl@0: sl@0: User::LeaveIfError(aRepository->Flush()); sl@0: TInt value=0; sl@0: User::LeaveIfError(aRepository->Get(1,value)); sl@0: TheTest(value==9); sl@0: } sl@0: sl@0: void FlushTestingL(TUid aUid,const TDesC& aInFilePath,const TDesC& aOutFilePath,TUint aTestMode) sl@0: { sl@0: __UHEAP_MARK; sl@0: SetupEnv(aInFilePath,aOutFilePath,aTestMode); sl@0: sl@0: //basic functionality test sl@0: CRepository* repository=NULL; sl@0: InitialiseLC(repository,aUid,aInFilePath,aOutFilePath,aTestMode); sl@0: sl@0: //made some modification sl@0: FlushFunctionalityTestingL(repository); sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: //oom functionality test sl@0: OomTest(FlushFunctionalityTestingL,aUid,aInFilePath,aOutFilePath,aTestMode); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID PDS-CENTRALREPOSITORY-CT-4080 sl@0: @SYMTestCaseDesc Test for DEF130394 sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions This is Part 2 of the test - Part 1 is in t_cenrrepcs.cpp sl@0: Loading a repository multiple times and then compare sl@0: (using CRC compare) the created cre file with the reference sl@0: cre from CS test. sl@0: @SYMTestExpectedResults Cre file is identical as the reference cre. sl@0: @SYMDEF DEF130394 sl@0: */ sl@0: void TestLoadingDEF130394L(const TDesC& aInFilePath, const TDesC& aOutFilePath) sl@0: { sl@0: CRepository* repos = NULL; sl@0: sl@0: repos = CRepository::NewLC(aInFilePath, aOutFilePath); sl@0: TInt err = repos->Create(1,1); sl@0: TEST2(err, KErrNone); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: // Second time we need to load from output file it self, otherwise it is not loading sl@0: // a repository multiple times because changes of the first time loading is not sl@0: // flushed into input file. sl@0: repos = CRepository::NewLC(aOutFilePath, aOutFilePath); sl@0: err = repos->Create(1,1); sl@0: TEST2(err, KErrAlreadyExists); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: void TestForDEF130394L() sl@0: { sl@0: TUint32 dummy; sl@0: sl@0: // NewLC Txt=>Cre Loading test sl@0: ClearOgns(); sl@0: TheFs.Delete(KMetaTestCreFile); sl@0: TestLoadingDEF130394L(KMetaTxtTestInFile, KMetaTestCreFile); sl@0: DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy); sl@0: sl@0: // NewLC Cre=>Cre Loading test sl@0: ClearOgns(); sl@0: TheFs.Delete(KMetaTestCreFile); sl@0: CopyFile(KMetaTestCreCopy, KMetaTestCreFile); sl@0: TestLoadingDEF130394L(KMetaTestCreFile, KMetaTestCreFile); sl@0: DoFileCompL(KMetaTestCreFile, KMetaTestRefFile, dummy); sl@0: sl@0: // Auto Loading Cre test sl@0: ClearOgns(); sl@0: TheFs.Delete(KMetaTestFile); sl@0: CopyFile(KMetaTestCopy, KMetaTestFile); sl@0: DEF130394L(uidmetatest); sl@0: DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy); sl@0: sl@0: //Auto Loading Txt test sl@0: ClearOgns(); sl@0: TheFs.Delete(KMetaTestFile); sl@0: DEF130394L(uidmetatest); sl@0: DoFileCompL(KMetaTestRefFile, KMetaTestFile, dummy); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-4041 sl@0: @SYMTestCaseDesc PC-side CentralRepository functionality test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Wrapper function calling up test functions. Test functions include test for basic sl@0: functions of the component, OOm test and CRC comparison test. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMPREQ PREQ2111 sl@0: */ sl@0: LOCAL_C void MainL() sl@0: { sl@0: //Note these files are equivalent, the cre being generated from txt sl@0: User::LeaveIfError(TheFs.Connect()); sl@0: sl@0: //TXT => CRE sl@0: TheTest.Start(_L("Functional NewLC TXT tests")); sl@0: BasicFunctionL(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt); sl@0: TheTest.Next(_L("OOM NewLC TXT tests")); sl@0: ObjectCreateDeleteOOM(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt); sl@0: OomBasicFunction(uid,KTemplateTxtFile(),KTemplateTxtOutFile(),ETxt); sl@0: sl@0: //CRE => CRE sl@0: TheTest.Next(_L("Functional NewLC CRE tests")); sl@0: BasicFunctionL(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre); sl@0: TheTest.Next(_L("OOM NewL CRE tests")); sl@0: ObjectCreateDeleteOOM(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre); sl@0: OomBasicFunction(uidcre,KTemplateCreFile(),KTemplateCreOutFile,ECre); sl@0: sl@0: //CRE exists only sl@0: TheTest.Next(_L("Functional NewLC Auto CRE tests")); sl@0: BasicFunctionL(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre); sl@0: TheTest.Next(_L("OOM NewLC Auto CRE tests")); sl@0: ObjectCreateDeleteOOM(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre); sl@0: OomBasicFunction(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre); sl@0: sl@0: //TXT exists only sl@0: TheTest.Next(_L("Functional NewLC Auto TXT tests")); sl@0: BasicFunctionL(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt); sl@0: TheTest.Next(_L("OOM NewLC Auto TXT tests")); sl@0: ObjectCreateDeleteOOM(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt); sl@0: OomBasicFunction(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt); sl@0: sl@0: //PC side only testing sl@0: TheTest.Next(_L("Flush Functionality test")); sl@0: FlushTestingL(uidcre,KPrivateTemplateCreFile(),KPrivateTemplateCreFile(),EAutoCre); sl@0: FlushTestingL(uid,KPrivateTemplateTxtFile(),KPrivateTemplateTxtOutFile(),EAutoTxt); sl@0: sl@0: TheTest.Next(_L("CRC comparison test")); sl@0: CrcComparisonTestL(); sl@0: sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: //perform testing on CREV1 , only CRE exists only sl@0: TheTest.Next(_L("Functional NewLC Auto CREV1 tests")); sl@0: BasicFunctionL(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre); sl@0: TheTest.Next(_L("OOM NewLC Auto CREV1 tests")); sl@0: ObjectCreateDeleteOOM(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre); sl@0: OomBasicFunction(uidcrev1,KPrivateTemplateCreV1File(),KPrivateTemplateCreV1File(),EAutoCre); sl@0: sl@0: #endif sl@0: sl@0: TheTest.Next(_L("Test for DEF130394L")); sl@0: TestForDEF130394L(); sl@0: sl@0: TheFs.Close(); sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if(!cleanup) sl@0: return KErrNoMemory; sl@0: sl@0: TRAPD(err, MainL()); sl@0: if (err != KErrNone) sl@0: User::Panic(_L("Testing failed: "), err); sl@0: sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: sl@0: return 0; sl@0: }