sl@0: // Copyright (c) 2004-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 "t_cenrep_helper.h"
sl@0: #include <centralrepository.h>
sl@0: #include <e32test.h>  // RTest
sl@0: #include <e32debug.h> // RDebug::Printf
sl@0: #include <f32file.h>  // RFs
sl@0: 
sl@0: #include "../cenrepsrv/srvparams.h" //KServerUid3
sl@0: 
sl@0: //using namespace NCentralRepositoryConstants;
sl@0: 
sl@0: _LIT(KSoftReset, "--SoftReset");
sl@0: 
sl@0: RTest TheTest(_L("Central Repository RFS Test"));
sl@0: 
sl@0: const TUid KUidRfsRepository = { 0xffffffff };
sl@0: const TUid KUidRfsRepositoryInstallOnlyDefaultFile = { 0xfffffffe };
sl@0: const TUid KUidRfsRepositoryDefaultRfsOn = { 0xfffffffa };
sl@0: 
sl@0: typedef enum
sl@0: 	{
sl@0: 	ERomOnly = 0x01,
sl@0: 	ERomAndInstall,
sl@0: 	EInstallOnly,
sl@0: 	ENoRomOrInstall
sl@0: 	} TRepositoryFileState;
sl@0: 
sl@0: const TUint32 KInt1 = 1;
sl@0: const TInt KInt1_UpdatedValue = 73;
sl@0: const TReal KReal1_InitialValue = 2.732;
sl@0: const TUint32 KNewInt = 1000;
sl@0: const TUint32 KNewInt2 = 0x0FFF; // outside range meta (in default meta)
sl@0: const TUint32 KNewInt3 = 0x1000; // inside range meta
sl@0: const TUint32 KReal1 = 2;
sl@0: const TReal KReal1_InstallValue = 4.53;
sl@0: const TReal KReal1_UpdatedValue = 7.32;
sl@0: const TUint32 KString1 = 5;
sl@0: _LIT(KString1_InitialValue, "test\\\"string\"");
sl@0: _LIT(KString1_UpdatedValue, "another one");
sl@0: 
sl@0: 
sl@0: LOCAL_C void CheckL(TInt aValue, TInt aLine)
sl@0: 	{
sl@0: 	if(!aValue)
sl@0: 		{
sl@0: 		CleanupCDriveL();
sl@0: 		TheTest(EFalse, aLine);
sl@0: 		}
sl@0: 	}
sl@0: LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
sl@0: 	{
sl@0: 	if(aValue != aExpected)
sl@0: 		{
sl@0: 		CleanupCDriveL();
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: #define TEST(arg) ::CheckL((arg), __LINE__)
sl@0: #define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
sl@0: 
sl@0: // This function kills the C32exe.exe process. This commsdat process will
sl@0: // interfere with the test if not killed. In a nutshell, some of the test cases 
sl@0: // will kill and then wait for 2 seconds and restart the centrep server 
sl@0: // with --SoftReset option. During that 2 seconds wait sometimes C32exe.exe 
sl@0: // will use centrep API, thus starting the server normally without --SoftReset.
sl@0: LOCAL_C void KillC32Exe()
sl@0:     {
sl@0:     _LIT( KC32ServerName, "c32exe");
sl@0:     KillProcess(KC32ServerName); // Don't need to check the return code, it always return KErrNone anyway.
sl@0:     User::After(KGeneralDelay);
sl@0:     }
sl@0: 
sl@0: //This function restores the state of the files required for this test
sl@0: //Existing files are deleted and then the required files are copied
sl@0: //back from the Z drive to the c drive
sl@0: LOCAL_C void RestoreRFSTestFilesL(TRepositoryFileState aState)
sl@0: 	{
sl@0: 	//Delete all files from C:\\private\\10202BE9\\persists\\ dir
sl@0: 	//and C:\\private\\10202BE9\\ dir
sl@0: 	CleanupCDriveL();
sl@0: 	RFs fs;
sl@0: 	User::LeaveIfError(fs.Connect());
sl@0: 	CleanupClosePushL(fs);
sl@0: 
sl@0: 	CFileMan* fm = CFileMan::NewL(fs);
sl@0: 	CleanupStack::PushL(fm);
sl@0: 
sl@0: 	_LIT(KPersistTargetPath, "C:\\private\\10202BE9\\persists\\ffffffff.txt");
sl@0: 	_LIT(KInstallTargetPath, "C:\\private\\10202BE9\\ffffffff.txt");
sl@0: 	_LIT(KPersistTargetPath1,"C:\\private\\10202BE9\\persists\\fffffffe.txt");
sl@0: 	_LIT(KPersistTargetPath2,"C:\\private\\10202BE9\\persists\\fffffffd.txt");
sl@0: 	_LIT(KInstallTargetPath1,"C:\\private\\10202BE9\\fffffffe.txt");
sl@0: 	_LIT(KRFSTestFileSourcePath, "Z:\\private\\10202BE9\\ffffffff.txc");
sl@0: 
sl@0: 	switch(aState)
sl@0: 	{
sl@0: 		case ERomOnly:
sl@0: 			CopyTestFilesL(*fm,KRFSTestFileSourcePath, KPersistTargetPath);
sl@0: 			break;
sl@0: 
sl@0: 		case ERomAndInstall:
sl@0: 			CopyTestFilesL(*fm,KRFSTestFileSourcePath, KPersistTargetPath);
sl@0: 			CopyTestFilesL(*fm,KRFSTestFileSourcePath, KInstallTargetPath);
sl@0: 			break;
sl@0: 
sl@0: 		case EInstallOnly:
sl@0: 			CopyTestFilesL(*fm,KRFSTestFileSourcePath, KPersistTargetPath1);
sl@0: 			CopyTestFilesL(*fm,KRFSTestFileSourcePath, KInstallTargetPath1);
sl@0: 			break;
sl@0: 
sl@0: 		case ENoRomOrInstall:
sl@0: 			CopyTestFilesL(*fm,KRFSTestFileSourcePath, KPersistTargetPath2);
sl@0: 			break;
sl@0: 
sl@0: 		default:
sl@0: 			break;
sl@0: 	}
sl@0: 
sl@0: 	CleanupStack::PopAndDestroy(2);
sl@0: 
sl@0: 	}
sl@0: 
sl@0: //
sl@0: // Start the server process or thread
sl@0: //
sl@0: LOCAL_C TInt ReStartServerInSoftResetMode()
sl@0: 	{
sl@0: 	const TUidType serverUid(KNullUid, KNullUid, KServerUid3);
sl@0: 
sl@0: 	//
sl@0: 	// EPOC and EKA2 is easy, we just create a new server process. Simultaneous
sl@0: 	// launching of two such processes should be detected when the second one
sl@0: 	// attempts to create the server object, failing with KErrAlreadyExists.
sl@0: 	//
sl@0: 	RProcess server;
sl@0: 	TInt r=server.Create(KServerImg,
sl@0: 						 KSoftReset,
sl@0: 						 serverUid);
sl@0: 
sl@0: 	if (r != KErrNone)
sl@0: 		{
sl@0: 		return r;
sl@0: 		}
sl@0: 
sl@0: 	TRequestStatus stat;
sl@0: 	server.Rendezvous(stat);
sl@0: 
sl@0: 	if (stat != KRequestPending)
sl@0: 		{
sl@0: 		server.Kill(0);		// abort startup
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		server.Resume();	// logon OK - start the server
sl@0: 		}
sl@0: 
sl@0: 	User::WaitForRequest(stat);		// wait for start or death
sl@0: 	// we can't use the 'exit reason' if the server panicked as this
sl@0: 	// is the panic 'reason' and may be '0' which cannot be distinguished
sl@0: 	// from KErrNone
sl@0: 	r = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
sl@0: 
sl@0: 	server.Close();
sl@0: 	return r;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: LOCAL_C void RestoreFactorySettingsTestL()
sl@0: 	{
sl@0: 	TheTest.Start(_L("ResetAllRepositoriesTestL"));
sl@0: 	TInt r;
sl@0: 	TInt i;
sl@0: 	TBuf<20> str;
sl@0: 
sl@0: 	TheTest.Next(_L("Open repository to ensure server is running"));
sl@0: 	CRepository* repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	TheTest.Next(_L("Add a Setting"));
sl@0: 	const TInt KIntValue = 1234;
sl@0: 	r = repository->Create(KNewInt, KIntValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	TheTest.Next(_L("Delete a Setting"));
sl@0: 	r = repository->Delete(KReal1);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	TheTest.Next(_L("Modify a Setting"));
sl@0: 	r = repository->Set(KInt1, KInt1_UpdatedValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	TheTest.Next(_L("Modify a String Setting"));
sl@0: 	r = repository->Set(KString1, KString1_UpdatedValue);
sl@0: 
sl@0: 	TEST2(r, KErrNone);
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.Next(_L("Kill the server process"));
sl@0: 	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
sl@0: 	r = KillProcess(KCentralRepositoryServerName);
sl@0: 	TEST2(r,KErrNone);
sl@0: 
sl@0: 	User::After(KGeneralDelay);
sl@0: 
sl@0: 	TheTest.Next(_L("Manually start central respository"));
sl@0: 	ReStartServerInSoftResetMode();
sl@0: 
sl@0: 	TheTest.Next(_L("Re-create the repository to ensure server is running"));
sl@0: 	repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	TheTest.Next(_L("Get 'Added' value"));
sl@0: 	r = repository->Get(KNewInt, i);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	TReal real;
sl@0: 	TheTest.Next(_L("Get 'Deleted' value"));
sl@0: 	r = repository->Get(KReal1, real);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(real == KReal1_InitialValue);
sl@0: 
sl@0: 	TheTest.Next(_L("Get 'Modified' value"));
sl@0: 	r = repository->Get(KInt1, i);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(i == KInt1_UpdatedValue);
sl@0: 
sl@0: 	r = repository->Get(KString1, str);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(str==KString1_InitialValue);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID 	 SYSLIB-CENTRALREPOSITORY-CT-3341
sl@0: @SYMTestCaseDesc Restore factory Settings from Rom file.
sl@0: @SYMTestPriority High
sl@0: @SYMTestActions  Ensure that the repository file only exists on the Rom.
sl@0: 				 Open the repository and modify a setting.  Force RFS
sl@0: 				 and check that the repository is restored against the ROM file
sl@0: @SYMTestExpectedResults The test repository should be reset against the ROM file
sl@0: @SYMDEF 		 PDEF099108
sl@0: */
sl@0: LOCAL_C void RFSRomOnlyL()
sl@0: 	{
sl@0: 
sl@0: 	//restore all test files - this ensures we have a repository file
sl@0: 	//only on the z:
sl@0: 	RestoreRFSTestFilesL(ERomOnly);
sl@0: 
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3341 ResetAllRepositoriesTestL "));
sl@0: 	TInt r, intVal;
sl@0: 	TReal realVal;
sl@0: 
sl@0: 	TheTest.Next(_L("Open repository to ensure server is running"));
sl@0: 	CRepository* repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	TheTest.Next(_L("Modify a Setting"));
sl@0: 	r = repository->Set(KInt1, KInt1_UpdatedValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	//verify the update
sl@0: 	r = repository->Get(KInt1, intVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(intVal == KInt1_UpdatedValue);
sl@0: 
sl@0: 	TheTest.Next(_L("Modify a Setting"));
sl@0: 	r = repository->Set(KReal1, KReal1_UpdatedValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	//verify the update
sl@0: 	r = repository->Get(KReal1, realVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(realVal == KReal1_UpdatedValue);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	//Kill the server
sl@0: 	TheTest.Next(_L("Kill the server process"));
sl@0: 	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
sl@0: 	r = KillProcess(KCentralRepositoryServerName);
sl@0: 	TEST2(r,KErrNone);
sl@0: 
sl@0: 	User::After(KGeneralDelay);
sl@0: 
sl@0: 	//Restart the server in soft reset mode to force a
sl@0: 	//repository reset
sl@0: 	TheTest.Next(_L("Manually start central respository"));
sl@0: 	ReStartServerInSoftResetMode();
sl@0: 
sl@0: 	//Open the repository
sl@0: 	repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	//Verify that the real value is reset against the value in the Rom version of
sl@0: 	//the repository file
sl@0: 	TheTest.Next(_L("Get 'Modified' value"));
sl@0: 	r = repository->Get(KReal1, realVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(realVal == KReal1_InitialValue);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID 	 SYSLIB-CENTRALREPOSITORY-CT-3342
sl@0: @SYMTestCaseDesc Restore factory Settings from merged repository.
sl@0: @SYMTestPriority High
sl@0: @SYMTestActions  Ensure that the repository file  exists in both the Rom and install
sl@0: 					directories.
sl@0: 				 Open the repository and modify a setting.  Force RFS
sl@0: 				 and check that the repository is restored against the merged repository
sl@0: @SYMTestExpectedResults The test repository should be reset against the merged repository
sl@0: @SYMDEF 		 PDEF099108
sl@0: */
sl@0: LOCAL_C void RFSRomAndInstallL()
sl@0: 	{
sl@0: 
sl@0: 	//restore all test files - this ensures we have a c: and z: file
sl@0: 	//for the test repository which causes a repository merge
sl@0: 	RestoreRFSTestFilesL(ERomAndInstall);
sl@0: 
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3342 ResetAllRepositoriesTestL "));
sl@0: 	TInt r;
sl@0: 	TReal realVal;
sl@0: 	TBuf<20> strVal;
sl@0: 
sl@0: 	TheTest.Next(_L("Open repository to ensure server is running"));
sl@0: 	CRepository* repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	TheTest.Next(_L("Modify a Setting"));
sl@0: 	r = repository->Set(KReal1, KReal1_UpdatedValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	//verify the update
sl@0: 	r = repository->Get(KReal1, realVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(realVal == KReal1_UpdatedValue);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	//Kill the server
sl@0: 	TheTest.Next(_L("Kill the server process"));
sl@0: 	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
sl@0: 	r = KillProcess(KCentralRepositoryServerName);
sl@0: 	TEST2(r,KErrNone);
sl@0: 
sl@0: 	User::After(KGeneralDelay);
sl@0: 
sl@0: 	//Restart the server in soft reset mode to force a
sl@0: 	//repository reset
sl@0: 	TheTest.Next(_L("Manually start central respository"));
sl@0: 	ReStartServerInSoftResetMode();
sl@0: 
sl@0: 	//Open the repository
sl@0: 	repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	//Verify that the string value, which is only found in the ROM file is
sl@0: 	//present in the merged repository
sl@0: 	r = repository->Get(KString1, strVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(strVal==KString1_InitialValue);
sl@0: 
sl@0: 	//verify that the Real value has been reset against the value in the install
sl@0: 	//repository file
sl@0: 	TheTest.Next(_L("Get 'Modified' value"));
sl@0: 	r = repository->Get(KReal1, realVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(realVal == KReal1_InstallValue);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID 	 SYSLIB-CENTRALREPOSITORY-CT-3343
sl@0: @SYMTestCaseDesc Restore factory Settings from Install file.
sl@0: @SYMTestPriority High
sl@0: @SYMTestActions  Ensure that the repository file only exists in the Install directory.
sl@0: 				 Open the repository and modify a setting.  Force RFS
sl@0: 				 and check that the repository is restored against the Install file
sl@0: @SYMTestExpectedResults The test repository should be reset against the Install file
sl@0: @SYMDEF 		 PDEF099108
sl@0: */
sl@0: LOCAL_C void RFSInstallOnlyL()
sl@0: 	{
sl@0: 
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3343 ResetAllRepositoriesTestL "));
sl@0: 	TInt r;
sl@0: 	TReal realVal;
sl@0: 	TBuf<20> strVal;
sl@0: 
sl@0: 	//restore all test files - this ensures we have a repository file
sl@0: 	//only on the c:
sl@0: 	RestoreRFSTestFilesL(EInstallOnly);
sl@0: 
sl@0: 	TheTest.Next(_L("Open repository to ensure server is running"));
sl@0: 	CRepository* repository = CRepository::NewLC(KUidRfsRepositoryInstallOnlyDefaultFile);
sl@0: 
sl@0: 	TheTest.Next(_L("Modify a Setting"));
sl@0: 	r = repository->Set(KReal1, KReal1_UpdatedValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	//verify the update
sl@0: 	r = repository->Get(KReal1, realVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(realVal == KReal1_UpdatedValue);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	//Kill the server
sl@0: 	TheTest.Next(_L("Kill the server process"));
sl@0: 	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
sl@0: 	r = KillProcess(KCentralRepositoryServerName);
sl@0: 	TEST2(r,KErrNone);
sl@0: 
sl@0: 	User::After(KGeneralDelay);
sl@0: 
sl@0: 	//Restart the server in soft reset mode to force a
sl@0: 	//repository reset
sl@0: 	TheTest.Next(_L("Manually start central respository"));
sl@0: 	ReStartServerInSoftResetMode();
sl@0: 
sl@0: 	//Open the repository
sl@0: 	repository = CRepository::NewLC(KUidRfsRepositoryInstallOnlyDefaultFile);
sl@0: 
sl@0: 	//verify that the Real value has been reset against the value in the install
sl@0: 	//repository file
sl@0: 	TheTest.Next(_L("Get 'Modified' value"));
sl@0: 	r = repository->Get(KReal1, realVal);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	TEST(realVal == KReal1_InstallValue);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID			SYSLIB-CENTRALREPOSITORY-CT-3435
sl@0: @SYMTestCaseDesc		PDEF105203: Start-up Settings: New access point remains after restoring factory setting
sl@0: @SYMTestPriority		High
sl@0: @SYMTestActions			Create a new setting inside a range with range meta RFS bit set, create another setting
sl@0: 						outside the range, restart server in RFS mode, check to see the setting created outside
sl@0: 						the range still exists, check to see the setting created inside the range has been deleted.
sl@0: 						Repeat same steps with another repository which has default meta having RFS on and range meta
sl@0: 						having RFS off, check to see the setting created outside the range has been deleted, check to
sl@0: 						see the setting created inside the range still exists.
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMDEF					PDEF105203
sl@0: */
sl@0: LOCAL_C void PDEF105203()
sl@0: 	{
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3435 PDEF105203: Start-up Settings: New access point remains after restoring factory setting "));
sl@0: 	TInt r;
sl@0: 	TInt i;
sl@0: 
sl@0: 	TheTest.Next(_L("Open repository to ensure server is running"));
sl@0: 	CRepository* repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	TheTest.Next(_L("Create a new setting outside RFSable range meta area"));
sl@0: 	const TInt KIntValue = 999;
sl@0: 	r = repository->Create(KNewInt2, KIntValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	TheTest.Next(_L("Create a new setting in RFSable range meta area"));
sl@0: 	r = repository->Create(KNewInt3, KIntValue);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.Next(_L("Kill the server process"));
sl@0: 	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
sl@0: 	r = KillProcess(KCentralRepositoryServerName);
sl@0: 	TEST2(r,KErrNone);
sl@0: 
sl@0: 	User::After(KGeneralDelay);
sl@0: 
sl@0: 	TheTest.Next(_L("Manually start central respository"));
sl@0: 	ReStartServerInSoftResetMode();
sl@0: 
sl@0: 	TheTest.Next(_L("Re-create the repository to ensure server is running"));
sl@0: 	repository = CRepository::NewLC(KUidRfsRepository);
sl@0: 
sl@0: 	TheTest.Next(_L("Get 'created' value outside range meta"));
sl@0: 	r = repository->Get(KNewInt2, i);
sl@0: 	TEST2(r, KErrNone); // should still exist
sl@0: 	TEST(i == KIntValue);
sl@0: 
sl@0: 	TheTest.Next(_L("Get 'created' value inside range meta"));
sl@0: 	r = repository->Get(KNewInt3, i);
sl@0: 	TEST2(r, KErrNotFound); // should have been deleted
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	repository = CRepository::NewLC(KUidRfsRepositoryDefaultRfsOn);
sl@0: 
sl@0: 	TheTest.Next(_L("Create a new setting in RFSable default meta area"));
sl@0: 	const TInt KIntValue2 = 990;
sl@0: 	r = repository->Create(KNewInt2, KIntValue2);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	TheTest.Next(_L("Create a new setting in non-RFSable range meta area"));
sl@0: 	r = repository->Create(KNewInt3, KIntValue2);
sl@0: 	TEST2(r, KErrNone);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.Next(_L("Kill the server process"));
sl@0: 	r = KillProcess(KCentralRepositoryServerName);
sl@0: 	TEST2(r,KErrNone);
sl@0: 
sl@0: 	User::After(KGeneralDelay);
sl@0: 
sl@0: 	TheTest.Next(_L("Manually start central respository"));
sl@0: 	ReStartServerInSoftResetMode();
sl@0: 
sl@0: 	TheTest.Next(_L("Re-create the repository to ensure server is running"));
sl@0: 	repository = CRepository::NewLC(KUidRfsRepositoryDefaultRfsOn);
sl@0: 
sl@0: 	TheTest.Next(_L("Get 'created' value outside range meta"));
sl@0: 	r = repository->Get(KNewInt2, i);
sl@0: 	TEST2(r, KErrNotFound); // should have been deleted
sl@0: 
sl@0: 	TheTest.Next(_L("Get 'created' value inside range meta"));
sl@0: 	r = repository->Get(KNewInt3, i);
sl@0: 	TEST2(r, KErrNone); // should still exist
sl@0: 	TEST(i == KIntValue2);
sl@0: 
sl@0: 	// Close repository
sl@0: 	CleanupStack::PopAndDestroy(repository);
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID			PDS-CENTRALREPOSITORY-CT-4082		
sl@0: @SYMTestCaseDesc		Test for PDEF133672: Cannot remove restored access points
sl@0: @SYMTestPriority		High
sl@0: @SYMTestActions			Create a repository, delete settings with RFS meta and reset repository, 
sl@0: 						then try to delete the settings again. 
sl@0: @SYMTestExpectedResults When deleting settings after reset, KErrAlreadyExists should not return.
sl@0: @SYMDEF					PDEF133672
sl@0: */	
sl@0: LOCAL_C void PDEF133672L()
sl@0: 	{
sl@0: 	TheTest.Start(_L("Test for PDEF133671"));
sl@0: 	
sl@0: 	const TUid KReposUid = {0xCCCCCC99};
sl@0: 
sl@0: 	const TInt KTestId1 = {0x00000001};
sl@0: 	const TInt KTestId2 = {0x0000000A};
sl@0: 	
sl@0: 	CRepository* repos=NULL;
sl@0: 		
sl@0: 	repos = CRepository::NewLC(KReposUid);
sl@0: 		
sl@0: 	User::LeaveIfNull(repos);
sl@0: 		
sl@0: 	TInt r;
sl@0: 	
sl@0: 	r = repos->Delete(KTestId1);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	r = repos->Delete(KTestId2);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	
sl@0: 	TheTest.Next(_L("try reset single settings"));
sl@0: 	r = repos->Reset(KTestId1);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	r = repos->Reset(KTestId2);
sl@0: 	TEST2(r, KErrNone);
sl@0: 		
sl@0: 	r = repos->Delete(KTestId1);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	r = repos->Delete(KTestId2);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	
sl@0: 	TheTest.Next(_L("try reset whole repository"));
sl@0: 	r = repos->Reset();
sl@0: 			
sl@0: 	r = repos->Delete(KTestId1);
sl@0: 	TEST2(r, KErrNone);
sl@0: 	r = repos->Delete(KTestId2);
sl@0: 	TEST2(r, KErrNone);
sl@0: 		
sl@0: 	CleanupStack::PopAndDestroy();
sl@0: 
sl@0: 	TheTest.End();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID			SYSLIB-CENTRALREPOSITORY-CT-0497-0001
sl@0: @SYMTestCaseDesc		CentralRepository functionality test
sl@0: @SYMTestPriority		High
sl@0: @SYMTestActions			Wrapper function calling up test functions
sl@0: @SYMTestExpectedResults Test must not fail
sl@0: @SYMREQ					REQ0000
sl@0: */
sl@0: LOCAL_C void MainL()
sl@0: 	{
sl@0: 	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-0497-0001 Restore Factory Settings tests "));
sl@0: 	CleanupCDriveL();
sl@0: 	KillC32Exe(); //Need to kill C32Exe as it is interfering with the test.
sl@0: 	RestoreFactorySettingsTestL();
sl@0: 	PDEF105203();
sl@0: 	RFSRomOnlyL();
sl@0: 	RFSRomAndInstallL();
sl@0: 	RFSInstallOnlyL();
sl@0: 	PDEF133672L();
sl@0: 	CleanupCDriveL();
sl@0: 
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: 	}