Пример #1
0
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);
	}
Пример #2
0
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);
	}