void TCmdSetUNSAFTimers::SetValuesToRepositoryL(
	CRepository& aRepository,
	TInt aStatus,
	TUint32 aKey,
	TInt aBindingRequestInterval,
	TInt aUdpKeepAliveInterval,
	TInt aTcpKeepAliveInterval )
	{
	User::LeaveIfError(
		aRepository.StartTransaction(
			CRepository::EConcurrentReadWriteTransaction ) );
    aRepository.CleanupCancelTransactionPushL();

	TPtrC8 iapName = ExtractTextL( KParamIAPName, EFalse );
	if( iapName != KNullDesC8 )
		{
		TInt iapId = iContext.IAPIdL( iapName );
		if ( aStatus == KErrNotFound )
			{
			aKey = CreateNewKeyL( aRepository,
                                  KUNSAFProtocolsIAPIdMask,
                                  KUNSAFProtocolsIAPTableMask );
			WriteL( aRepository, KUNSAFProtocolsIAPIdMask | aKey, iapId );
			}
		WriteIapParamsL( aRepository,
					 	 aKey,
					 	 aBindingRequestInterval,
					 	 aUdpKeepAliveInterval,
					 	 aTcpKeepAliveInterval );
		}
	else
		{
		// Since IAP was not given, domain is now mandatory
		TPtrC8 domainName = ExtractTextL( KParamDomainName, ETrue );
		if ( aStatus == KErrNotFound )
			{
		    aKey = CreateNewKeyL( aRepository,
                                  KUNSAFProtocolsDomainMask,
                                  KUNSAFProtocolsDomainTableMask );
		    WriteL( aRepository, KUNSAFProtocolsDomainMask | aKey, domainName );
			}
	    WriteDomainParamsL( aRepository, 
							aKey,
							aUdpKeepAliveInterval,
							aTcpKeepAliveInterval );
		}

	TUint32 dummy( 0 );
    User::LeaveIfError( aRepository.CommitTransaction( dummy ) );
    CleanupStack::Pop( 1 ); // transaction
	}
Esempio n. 2
0
void Util::SetAppropriateTimezoneL()
	{
	TUid repUid = {0x1020e4d3};
	CRepository* rep = CRepository::NewLC(repUid);
	
	// Set the date format to European
	User::LeaveIfError(rep->StartTransaction(CRepository::EConcurrentReadWriteTransaction));
	User::LeaveIfError(rep->Set(101, EDateEuropean)); // 101 is the date format reg entry
	TUint32 keys(0);
	User::LeaveIfError(rep->CommitTransaction(keys));
	
	CleanupStack::PopAndDestroy(rep);
	
	TExtendedLocale locale;
	locale.LoadSystemSettings();
	locale.GetLocale()->SetDateFormat(EDateEuropean);
	User::LeaveIfError(locale.SaveSystemSettings());
	}
LOCAL_C void CreateSetRealTransactionL()
	{
	CRepository* repository;
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository));

	// Remember that this repository need to be reset
	::AddRepositoryToReset(KUidTransactionTestRepository);

	//
	// Real transaction get/set
	//
	TInt r;
	TInt i = 0;
	const TInt imax = 0x0ff;

	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	TEST2(r, KErrNone);

	// create
	const TReal KRealStartValue = 100.05;
	const TUint32 KNewRealBase = 1;
	for(i=0;i<imax;i++)
		{
		r = repository->Create(KNewRealBase+i, KRealStartValue+i);
		TEST2(r, KErrNone);
		}

	TUint32 errorId;
	r = repository->CommitTransaction(errorId);
	TEST2(r, KErrNone);

	TReal real, real2;
	for(i=0; i<imax; i++)
		{
		r = repository->Get((KNewRealBase+i), real );
		real2 = KRealStartValue+i;
		TEST2(r, KErrNone);
		TEST( real2 == real );
		}

	CleanupStack::PopAndDestroy(repository);
	}
LOCAL_C void ResetTransactionL()
	{
#ifdef PENDING_REMOVAL
    // reset operations are not supported in transactions for now.
    // ResetAll will not ever be: still to decide on individual setting reset
    // Both are very slow.

	TUint32 errorId;
	CRepository* repository;
	User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository));

	// Remember that this repository need to be reset
	::AddRepositoryToReset(KUidPlatsecTestRepository);

	TInt r = repository->Set(KInt1, KInt1_UpdatedValue);
	TEST2(r, KErrNone);

	TInt x,y;
	r = repository->Get(KInt1, x);
	TEST2(r, KErrNone);

	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	TEST2(r, KErrNone);

	r = repository->Reset(KInt1);
	TEST2(r, KErrNone);

	r = repository->CommitTransaction(errorId);
	TEST2(r, KErrNone);

	r = repository->Get(KInt1, y);
	TEST2(r, KErrNone);

	// did we get what expected after commit?
	TEST(x!=KInt1_InitialValue);
	TEST(y==KInt1_InitialValue);

	CleanupStack::PopAndDestroy(repository);

	// Repository B
	// lets prepare for reset
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository));

	// Remember that this repository need to be reset
	::AddRepositoryToReset(KUidTransactionTestRepository);

	const TInt KNewSettingAlwaysPass = 0x101;

	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	TEST2(r, KErrNone);

	TInt i = 0;
	for(i=KNewSettingAlwaysPass;i<KNewSettingAlwaysPass+10;i++)
		{
		r = repository->Create(i, i);
		TEST2(r, KErrNone);
		}


	TRequestStatus status = -1;
	r = repository->NotifyRequest(0, 0, status);
	TEST2(r, KErrNone);

	r = repository->CommitTransaction(errorId);
	TEST2(r, KErrNone);

	TInt xArray[10];
	TInt xx=0;
	for(i=0;i<10;i++)
		{
		r = repository->Get(KNewSettingAlwaysPass+i, xArray[i]);
		TEST2(r, KErrNone);
		}

	//and do the reset business now
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	TEST2(r, KErrNone);

	r = repository->Reset();
	TEST2(r, KErrNone);

	r = repository->CommitTransaction(errorId);
	TEST2(r, KErrNone);

	// test reset after commit
	TEST(status==KNewSettingAlwaysPass);

	for(i=0;i<10;i++)
		{
		TEST(xArray[i]==(KNewSettingAlwaysPass+i));
		}

	for(i=KNewSettingAlwaysPass;i<KNewSettingAlwaysPass+10;i++)
		{
		r = repository->Get(i, xx);
		TEST2(r, KErrNotFound);
		}

	CleanupStack::PopAndDestroy(repository);
#endif // PENDING_REMOVAL
	}
LOCAL_C void CreateSetDesTransactionL()
	{
	TUint32 errorId;
	CRepository* repository;
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository));

	// Remember that this repository need to be reset
	::AddRepositoryToReset(KUidTransactionTestRepository);


	_LIT(KString1_TestValue, "test string 1");
	_LIT(KString2_TestValue, "test string 2");
	_LIT(KString3_TestValue, "test string 3");
	_LIT(KString4_TestValue, "test string 4");
	_LIT(KString5_TestValue, "test string 5");
	_LIT(KString1_UpdatedTestValue, "updated test string 1");
	_LIT(KString2_UpdatedTestValue, "updated test string 2");
	//
	// Descriptor get/set
	//
	TInt r;


	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	repository->CleanupRollbackTransactionPushL();
	TEST2(r, KErrNone);

	// create
	r = repository->Create(1, KString1_TestValue);
	if(OomTesting && (r==KErrNoMemory))
		User::Leave(KErrNoMemory);
	else
		TEST2(r, KErrNone);
	r = repository->Create(2, KString2_TestValue);
	if(OomTesting && (r==KErrNoMemory))
		User::Leave(KErrNoMemory);
	else
		TEST2(r, KErrNone);
	r = repository->Create(3, KString3_TestValue);
	if(OomTesting && (r==KErrNoMemory))
		User::Leave(KErrNoMemory);
	else
		TEST2(r, KErrNone);
	r = repository->Create(4, KString4_TestValue);
	if(OomTesting && (r==KErrNoMemory))
		User::Leave(KErrNoMemory);
	else
		TEST2(r, KErrNone);
	r = repository->Create(5, KString5_TestValue);
	if(OomTesting && (r==KErrNoMemory))
		User::Leave(KErrNoMemory);
	else
		TEST2(r, KErrNone);

	r = repository->CommitTransaction(errorId);
	CleanupStack::Pop();
	if(OomTesting && r!=KErrNone)
		{
		// in OOM test we may have alredy created settings
		TEST2(r, KErrAlreadyExists);
		}
	else
		TEST2(r, KErrNone);

	TBuf<50> buf;
	if(!OomTesting)
		{
		r = repository->Get(1,buf);
		TEST2(r, KErrNone);
		TEST(buf==KString1_TestValue);
		r = repository->Get(2,buf);
		TEST2(r, KErrNone);
		TEST(buf==KString2_TestValue);
		r = repository->Get(3,buf);
		TEST2(r, KErrNone);
		TEST(buf==KString3_TestValue);
		r = repository->Get(4,buf);
		TEST2(r, KErrNone);
		TEST(buf==KString4_TestValue);
		r = repository->Get(5,buf);
		TEST2(r, KErrNone);
		TEST(buf==KString5_TestValue);
		}

	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	repository->CleanupRollbackTransactionPushL();
	TEST2(r, KErrNone);

	// set
	r = repository->Set(1, KString1_UpdatedTestValue);
	if(OomTesting && (r==KErrNoMemory))
		User::Leave(KErrNoMemory);
	else
		TEST2(r, KErrNone);
	r = repository->Set(2, KString2_UpdatedTestValue);
	if(OomTesting && (r==KErrNoMemory))
		User::Leave(KErrNoMemory);
	else
		TEST2(r, KErrNone);

	r = repository->CommitTransaction(errorId);
	CleanupStack::Pop();
	TEST2(r, KErrNone);

	TBuf<50> buf1,buf2;
	r = repository->Get(1,buf1);
	TEST2(r, KErrNone);
	r = repository->Get(2,buf2);
	TEST2(r, KErrNone);

	TEST(buf1==KString1_UpdatedTestValue);
	TEST(buf2==KString2_UpdatedTestValue);

	CleanupStack::PopAndDestroy(repository);
	}
LOCAL_C void CreateSetIntTransactionL()
	{
	CRepository* repository;
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTransactionTestRepository));

	// Remember that this repository need to be reset
	::AddRepositoryToReset(KUidTransactionTestRepository);

	//
	// Integer get/set
	//
	TInt r;
	TInt i = 0;
	const TInt imax = 0x0ff;
	TUint32 errorId;

	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	repository->CleanupRollbackTransactionPushL();
	TEST2(r, KErrNone);

	// create
	TInt KIntStartValue = 100;
	const TUint32 KNewIntBase = 1;
	for(i=0;i<imax;i++)
		{
		r = repository->Create(KNewIntBase+i, KIntStartValue+i);
		if(OomTesting && (r==KErrNoMemory))
			User::Leave(KErrNoMemory);
		else
			TEST2(r, KErrNone);
		}

	r = repository->CommitTransaction(errorId);
	CleanupStack::Pop();
	if(OomTesting && r!=KErrNone)
		{
		// in OOM test we may have alredy created settings
		TEST2(r, KErrAlreadyExists);
		}
	else
		TEST2(r, KErrNone);

	TInt integer;
	if(!(OomTesting && r==KErrAlreadyExists))
	{
		// during OOM tests we have values from Sets rather then Create...
		for(i=0;i<imax;i++)
			{
			r = repository->Get(KNewIntBase+i,integer );
			TEST2(r, KErrNone);
			TEST(KIntStartValue+i==integer);
			}
	}
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	TEST2(r, KErrNone);

    repository->CleanupRollbackTransactionPushL();

	// set
	KIntStartValue = 200;
	for(i=0;i<imax;i++)
		{
		r = repository->Set(KNewIntBase+i, KIntStartValue+i);
		if(OomTesting && (r==KErrNoMemory))
			User::Leave(KErrNoMemory);
		else
			TEST2(r, KErrNone);
		}

	r = repository->CommitTransaction(errorId);
	CleanupStack::Pop();
	TEST2(r, KErrNone);
	for(i=0;i<imax;i++)
		{
		r = repository->Get(KNewIntBase+i,integer );
		TEST2(r, KErrNone);
		TEST(KIntStartValue+i==integer);
		}

	// lets check set where some are going to fail
	// set
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	repository->CleanupRollbackTransactionPushL();
	TEST2(r, KErrNone);
	KIntStartValue = 400;
	TInt base = KNewIntBase + 0x7f; // half the range ok other half should fail
	for(i=0;i<imax;i++)
		{
		r = repository->Set(base+i, KIntStartValue+i);
		if(OomTesting && (r==KErrNoMemory))
			User::Leave(KErrNoMemory);
		else
		    {
		    if (base + i < 0x100)
		        {
			    TEST2(r, KErrNone);
		        }
		    else if (base + i == 0x100)
		        {
			    TEST2(r, KErrNone);
		        // this causes transaction to fail
                const TReal KRealValue = 1.234;
		        r = repository->Set(base+i, KRealValue);
			    TEST2(r, KErrArgument);
		        }
		    else
		        {
		        // after transaction has failed, repository returns KErrAbort for every request
			    TEST2(r, KErrAbort);
		        }
		    }
		}

	r = repository->CommitTransaction(errorId);
	TEST2(r, KErrArgument);
	TEST2(errorId, 0x100);
	CleanupStack::Pop();
	// should be able to open again
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
	TEST2(r, KErrNone);
	repository->RollbackTransaction();

	// and after the failed transaction it should be in previous state!!
	KIntStartValue = 200;
	for(i=0;i<imax;i++)
		{
		r = repository->Get(KNewIntBase+i,integer );
		TEST2(r, KErrNone);
		TEST(KIntStartValue+i==integer);
		}

	// lets clear after ourselves
	for(i=0;i<imax;i++)
		{
		r = repository->Delete(KNewIntBase+i);
		TEST2(r, KErrNone);
		}

	CleanupStack::PopAndDestroy(repository);
	}