os/persistentdata/persistentstorage/centralrepository/test/t_cenrep_transactions.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "t_cenrep_helper.h"
sl@0
    17
#include <centralrepository.h>
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <f32file.h>
sl@0
    20
#include <bautils.h>
sl@0
    21
#include "e32math.h"
sl@0
    22
#include "srvparams.h"
sl@0
    23
#include "transstate.h"
sl@0
    24
#include "clientrequest.h"
sl@0
    25
#include "panic.h"
sl@0
    26
sl@0
    27
//#define Additional_Test
sl@0
    28
sl@0
    29
using namespace NCentralRepositoryConstants;
sl@0
    30
sl@0
    31
RTest TheTest(_L("Central Repository Transaction Tests"));
sl@0
    32
sl@0
    33
const TUid KUidTestRepository 	= { 0x0000101 };
sl@0
    34
sl@0
    35
//
sl@0
    36
// Repository A
sl@0
    37
//
sl@0
    38
sl@0
    39
const TUint32 KUnprotectedSettingsMask = 0xFF000000 ;
sl@0
    40
sl@0
    41
const TInt KThreadStackSize	=0x2000; // 8k
sl@0
    42
const TInt KThreadMinHeapSize	=0x4000; // 16k
sl@0
    43
const TInt KThreadMaxHeapSize	=0xa000; // 60k
sl@0
    44
sl@0
    45
const TUint32 KInt1 = 1;
sl@0
    46
const TInt KInt1_InitialValue = 1;
sl@0
    47
sl@0
    48
const TUint32 KReal1 = 2;
sl@0
    49
const TReal KReal1_InitialValue = 2.732;
sl@0
    50
const TUint32 KString8 = 5;
sl@0
    51
const TUint32 KString16 = 6;
sl@0
    52
_LIT(KString16_InitialValue, "test\\\"string\"");
sl@0
    53
_LIT8(KString8_InitialValue, "test\\\"string\"");
sl@0
    54
sl@0
    55
const TInt KInt2 = 3;
sl@0
    56
const TInt KInt2_InitialValue = 20;
sl@0
    57
const TUint32 KReal2 = 28;
sl@0
    58
const TReal KReal2_InitialValue = 2.5;
sl@0
    59
const TReal KReal2_SecondValue = 3.5;
sl@0
    60
const TUint32 KNewString8 = 21;
sl@0
    61
const TUint32 KNewString16 = 22;
sl@0
    62
_LIT(KString16_InitialValue2, "another\\\"string\"");
sl@0
    63
_LIT8(KString8_InitialValue2, "another\\\"string\"");
sl@0
    64
sl@0
    65
_LIT(KString16_Small_Value, "te");
sl@0
    66
_LIT8(KString8_Small_Value, "te");
sl@0
    67
sl@0
    68
const TUint32 KMoveTarget            = 0x02000001  ;
sl@0
    69
const TUint32 KMoveSourceDoesntExist = 0x01000000 ;
sl@0
    70
const TUint32 KMoveMask              = 0xFF0000FF ;
sl@0
    71
sl@0
    72
const TUint32 KInt3 = 10; //Ranged Policy Key
sl@0
    73
const TInt KInt3_InitialValue = 34;
sl@0
    74
const TUint32 KInt4 = 0x201; //Default Policy Key
sl@0
    75
const TInt KInt4_InitialValue = 10;
sl@0
    76
const TUint32 KInt5 = 0x1000001; //Single Policy Key
sl@0
    77
const TInt KInt5_SecondValue = 123;
sl@0
    78
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    79
///////////////////////////////////////////////////////////////////////////////////////
sl@0
    80
//Test macroses and functions
sl@0
    81
LOCAL_C void CheckL(TInt aValue, TInt aLine)
sl@0
    82
	{
sl@0
    83
	if(!aValue)
sl@0
    84
		{
sl@0
    85
		CleanupCDriveL();
sl@0
    86
		TheTest(EFalse, aLine);
sl@0
    87
		}
sl@0
    88
	}
sl@0
    89
LOCAL_C void CheckL(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    90
	{
sl@0
    91
	if(aValue != aExpected)
sl@0
    92
		{
sl@0
    93
		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
    94
		CleanupCDriveL();
sl@0
    95
		TheTest(EFalse, aLine);
sl@0
    96
		}
sl@0
    97
	}
sl@0
    98
#define TEST(arg) ::CheckL((arg), __LINE__)
sl@0
    99
#define TEST2(aValue, aExpected) ::CheckL(aValue, aExpected, __LINE__)
sl@0
   100
sl@0
   101
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   102
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   103
sl@0
   104
typedef void (*TRepositoryFunc)(CRepository&);
sl@0
   105
sl@0
   106
void ChangeByCreate(CRepository& aRep)
sl@0
   107
	{
sl@0
   108
	TInt r;
sl@0
   109
	// Create a setting outside of a transaction
sl@0
   110
	r = aRep.Create(KReal2, KReal2_InitialValue);
sl@0
   111
	TEST2(r, KErrNone);
sl@0
   112
	// confirm setting created
sl@0
   113
	TReal value;
sl@0
   114
	r = aRep.Get(KReal2, value);
sl@0
   115
	TEST2(r, KErrNone);
sl@0
   116
	TEST(value == KReal2_InitialValue);
sl@0
   117
	}
sl@0
   118
sl@0
   119
void ChangeBySet(CRepository& aRep)
sl@0
   120
	{
sl@0
   121
	TInt r;
sl@0
   122
	// Set a value outside of a transaction
sl@0
   123
	r = aRep.Set(KReal2, KReal2_SecondValue);
sl@0
   124
	TEST2(r, KErrNone);
sl@0
   125
	// confirm value changed
sl@0
   126
	TReal value;
sl@0
   127
	r = aRep.Get(KReal2, value);
sl@0
   128
	TEST2(r, KErrNone);
sl@0
   129
	TEST(value == KReal2_SecondValue);
sl@0
   130
	}
sl@0
   131
sl@0
   132
void ChangeByDelete(CRepository& aRep)
sl@0
   133
	{
sl@0
   134
	TInt r;
sl@0
   135
	// Delete a setting outside of a transaction
sl@0
   136
	r = aRep.Delete(KReal2);
sl@0
   137
	TEST2(r, KErrNone);
sl@0
   138
	// confirm it's deleted
sl@0
   139
	TReal value;
sl@0
   140
	r = aRep.Get(KReal2, value);
sl@0
   141
	TEST2(r, KErrNotFound);
sl@0
   142
	}
sl@0
   143
sl@0
   144
void ChangeByTransaction(CRepository& aRep)
sl@0
   145
	{
sl@0
   146
	TInt r;
sl@0
   147
	TUint32 keyInfo;
sl@0
   148
sl@0
   149
	// Lock should prevent ERead/WriteTransactions from being able to start from
sl@0
   150
	// within function CommittingChangesFailsOtherTransactions.
sl@0
   151
	r = aRep.StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   152
	TEST2(r, KErrLocked);
sl@0
   153
	r = aRep.StartTransaction(CRepository::EReadTransaction);
sl@0
   154
	TEST2(r, KErrLocked);
sl@0
   155
sl@0
   156
	// Concurrent Read/Write transactions can be opened at any time
sl@0
   157
	r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
   158
	TEST2(r, KErrNone);
sl@0
   159
	r = TransactionState(&aRep);
sl@0
   160
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   161
sl@0
   162
	// Create a setting within transaction
sl@0
   163
	r = aRep.Create(KReal2, KReal2_InitialValue);
sl@0
   164
	TEST2(r, KErrNone);
sl@0
   165
	// confirm setting created
sl@0
   166
	TReal value;
sl@0
   167
	r = aRep.Get(KReal2, value);
sl@0
   168
	TEST2(r, KErrNone);
sl@0
   169
	TEST(value == KReal2_InitialValue);
sl@0
   170
sl@0
   171
	r = aRep.CommitTransaction(keyInfo);
sl@0
   172
	TEST2(r, KErrNone);
sl@0
   173
	TEST2(keyInfo, 1); // 1 successful change
sl@0
   174
sl@0
   175
	// re-confirm setting is still there
sl@0
   176
	r = aRep.Get(KReal2, value);
sl@0
   177
	TEST2(r, KErrNone);
sl@0
   178
	TEST(value == KReal2_InitialValue);
sl@0
   179
	}
sl@0
   180
sl@0
   181
// checking that async start and commit, with WaitForRequest do same as ChangeByTransaction
sl@0
   182
void ChangeByAsyncTransaction(CRepository& aRep)
sl@0
   183
	{
sl@0
   184
	TInt r;
sl@0
   185
	CRepository::TTransactionKeyInfoBuf keyInfoBuf;
sl@0
   186
	TRequestStatus status;
sl@0
   187
sl@0
   188
	// Lock should prevent ERead/WriteTransactions from being able to start from
sl@0
   189
	// within function CommittingChangesFailsOtherTransactions.
sl@0
   190
	aRep.StartTransaction(CRepository::EReadWriteTransaction, status);
sl@0
   191
	User::WaitForRequest(status);
sl@0
   192
	TEST2(status.Int(), KErrLocked);
sl@0
   193
	aRep.StartTransaction(CRepository::EReadTransaction, status);
sl@0
   194
	User::WaitForRequest(status);
sl@0
   195
	TEST2(status.Int(), KErrLocked);
sl@0
   196
sl@0
   197
	// Concurrent Read/Write transactions can be opened at any time
sl@0
   198
	aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction, status);
sl@0
   199
	// can't predict whether status will be KRequestPending at this time, so don't check
sl@0
   200
	User::WaitForRequest(status);
sl@0
   201
	TEST2(status.Int(), KErrNone);
sl@0
   202
	r = TransactionState(&aRep);
sl@0
   203
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   204
sl@0
   205
	// Create a setting within transaction
sl@0
   206
	r = aRep.Create(KReal2, KReal2_InitialValue);
sl@0
   207
	TEST2(r, KErrNone);
sl@0
   208
	// confirm setting created
sl@0
   209
	TReal value;
sl@0
   210
	r = aRep.Get(KReal2, value);
sl@0
   211
	TEST2(r, KErrNone);
sl@0
   212
	TEST(value == KReal2_InitialValue);
sl@0
   213
sl@0
   214
	aRep.CommitTransaction(keyInfoBuf, status);
sl@0
   215
	User::WaitForRequest(status);
sl@0
   216
	TEST2(status.Int(), KErrNone);
sl@0
   217
	TEST2(keyInfoBuf(), 1); // 1 successful change
sl@0
   218
sl@0
   219
	// re-confirm setting is still there
sl@0
   220
	r = aRep.Get(KReal2, value);
sl@0
   221
	TEST2(r, KErrNone);
sl@0
   222
	TEST(value == KReal2_InitialValue);
sl@0
   223
	}
sl@0
   224
sl@0
   225
void ChangeByReset(CRepository& aRep)
sl@0
   226
	{
sl@0
   227
	TInt r;
sl@0
   228
	// Delete a setting outside of a transaction
sl@0
   229
	r = aRep.Reset(KReal2);
sl@0
   230
	TEST2(r, KErrNone);
sl@0
   231
	// confirm it's reset (should be deleted)
sl@0
   232
	TReal value;
sl@0
   233
	r = aRep.Get(KReal2, value);
sl@0
   234
	TEST2(r, KErrNotFound);
sl@0
   235
	}
sl@0
   236
sl@0
   237
void ChangeByResetAll(CRepository& aRep)
sl@0
   238
	{
sl@0
   239
	TInt r;
sl@0
   240
	// Delete a setting outside of a transaction
sl@0
   241
	r = aRep.Reset();
sl@0
   242
	TEST2(r, KErrNone);
sl@0
   243
	// confirm it's reset (should be deleted)
sl@0
   244
	TReal value;
sl@0
   245
	r = aRep.Get(KReal2, value);
sl@0
   246
	TEST2(r, KErrNotFound);
sl@0
   247
	}
sl@0
   248
sl@0
   249
// tests that changes made by calling ChangeFunc with aCommittingRepository fail active
sl@0
   250
// transactions with reason KErrLocked, and correctly discard changes
sl@0
   251
LOCAL_C void CallFuncCheckOtherTransactionsFail(TRepositoryFunc ChangeFunc, CRepository& aCommittingRepository)
sl@0
   252
	{
sl@0
   253
	TInt r;
sl@0
   254
	TUint32 keyInfo;
sl@0
   255
	CRepository* repository1;
sl@0
   256
	CRepository* repository2;
sl@0
   257
sl@0
   258
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
   259
	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository));
sl@0
   260
sl@0
   261
	// Start two types of transaction
sl@0
   262
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   263
	TEST2(r, KErrNone);
sl@0
   264
	r = repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
   265
	TEST2(r, KErrNone);
sl@0
   266
sl@0
   267
	// check transactions haven't failed yet.
sl@0
   268
	r = TransactionState(repository1);
sl@0
   269
	TEST2(r, EReadWriteTransaction);
sl@0
   270
	r = TransactionState(repository2);
sl@0
   271
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   272
sl@0
   273
	// create a value in repository2's transaction and check it is there
sl@0
   274
	r = repository2->Create(KInt1, KInt1_InitialValue);
sl@0
   275
	TEST2(r, KErrNone);
sl@0
   276
	TInt value;
sl@0
   277
	r = repository2->Get(KInt1, value);
sl@0
   278
	TEST2(r, KErrNone);
sl@0
   279
	TEST(value == KInt1_InitialValue);
sl@0
   280
sl@0
   281
	(*ChangeFunc)(aCommittingRepository);
sl@0
   282
sl@0
   283
	// check transactions have now failed
sl@0
   284
	r = TransactionState(repository1);
sl@0
   285
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
   286
	r = TransactionState(repository2);
sl@0
   287
	TEST2(r, EConcurrentReadWriteTransaction | EFailedBit);
sl@0
   288
sl@0
   289
	// operations should abort after failing
sl@0
   290
	r = repository2->Get(KInt1, value);
sl@0
   291
	TEST2(r, KErrAbort);
sl@0
   292
	r = repository1->Set(KInt1, value);
sl@0
   293
	TEST2(r, KErrAbort);
sl@0
   294
sl@0
   295
	// commits should fail with KErrLocked
sl@0
   296
	r = repository2->CommitTransaction(keyInfo);
sl@0
   297
	TEST2(r, KErrLocked);
sl@0
   298
	TEST2(keyInfo, KUnspecifiedKey);
sl@0
   299
	r = repository1->CommitTransaction(keyInfo);
sl@0
   300
	TEST2(r, KErrLocked);
sl@0
   301
	TEST2(keyInfo, KUnspecifiedKey);
sl@0
   302
sl@0
   303
	// integer should not be persistent
sl@0
   304
	r = repository2->Get(KInt1, value);
sl@0
   305
	TEST2(r, KErrNotFound);
sl@0
   306
sl@0
   307
	CleanupStack::PopAndDestroy(repository2);
sl@0
   308
	CleanupStack::PopAndDestroy(repository1);
sl@0
   309
	}
sl@0
   310
sl@0
   311
/**
sl@0
   312
@SYMTestCaseID SYSLIB-CENREP-CT-0150
sl@0
   313
@SYMTestCaseDesc Check committing changes causes other transactions to fail.
sl@0
   314
@SYMTestPriority High
sl@0
   315
@SYMTestActions Run a series of commands that modify repository, check they fail active transactions.
sl@0
   316
 Start concurrent read write transaction and try to create and get values using other repository.
sl@0
   317
@SYMTestExpectedResults The test should not fail with any panics
sl@0
   318
@SYMPREQ PREQ752
sl@0
   319
*/
sl@0
   320
LOCAL_C void CommittingChangesFailsOtherTransactionsL()
sl@0
   321
	{
sl@0
   322
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0150 "));
sl@0
   323
	CRepository* repository;
sl@0
   324
sl@0
   325
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository));
sl@0
   326
sl@0
   327
	repository->Reset();
sl@0
   328
sl@0
   329
	// non-transaction create should fail active transactions
sl@0
   330
	CallFuncCheckOtherTransactionsFail(ChangeByCreate, *repository);
sl@0
   331
sl@0
   332
	// non-transaction set should fail active transactions
sl@0
   333
	CallFuncCheckOtherTransactionsFail(ChangeBySet, *repository);
sl@0
   334
sl@0
   335
	// non-transaction delete should fail active transactions
sl@0
   336
	CallFuncCheckOtherTransactionsFail(ChangeByDelete, *repository);
sl@0
   337
sl@0
   338
	// transaction commit with changes should fail active transactions
sl@0
   339
	CallFuncCheckOtherTransactionsFail(ChangeByTransaction, *repository);
sl@0
   340
sl@0
   341
	ChangeByDelete(*repository); // just to ready for next test
sl@0
   342
sl@0
   343
	// async started and committed transaction with changes should fail active transactions
sl@0
   344
	CallFuncCheckOtherTransactionsFail(ChangeByAsyncTransaction, *repository);
sl@0
   345
sl@0
   346
	// individual reset that has an effect should fail active transactions
sl@0
   347
	CallFuncCheckOtherTransactionsFail(ChangeByReset, *repository);
sl@0
   348
sl@0
   349
	ChangeByCreate(*repository); // just to ready for next test
sl@0
   350
sl@0
   351
	// reset all should fail active transactions
sl@0
   352
	CallFuncCheckOtherTransactionsFail(ChangeByResetAll, *repository);
sl@0
   353
sl@0
   354
	CleanupStack::PopAndDestroy(repository);
sl@0
   355
	}
sl@0
   356
sl@0
   357
void NoChangeByTransactionCreateDelete(CRepository& aRep)
sl@0
   358
	{
sl@0
   359
	TInt r;
sl@0
   360
	TUint32 keyInfo;
sl@0
   361
	// Concurrent Read/Write transactions can be opened at any time
sl@0
   362
	r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
   363
	TEST2(r, KErrNone);
sl@0
   364
	r = TransactionState(&aRep);
sl@0
   365
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   366
	// deleting the setting that was just added should result in no change when committing:
sl@0
   367
	ChangeByCreate(aRep);
sl@0
   368
	ChangeByDelete(aRep);
sl@0
   369
	r = aRep.CommitTransaction(keyInfo);
sl@0
   370
	TEST2(r, KErrNone);
sl@0
   371
	TEST2(keyInfo, 0); // no changes
sl@0
   372
	}
sl@0
   373
sl@0
   374
void NoChangeByTransactionSetSameValue(CRepository& aRep)
sl@0
   375
	{
sl@0
   376
	TInt r;
sl@0
   377
	TUint32 keyInfo;
sl@0
   378
	// Concurrent Read/Write transactions can be opened at any time
sl@0
   379
	r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
   380
	TEST2(r, KErrNone);
sl@0
   381
	r = TransactionState(&aRep);
sl@0
   382
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   383
	// changing setting to the value it already has should result in no change when committing:
sl@0
   384
	ChangeBySet(aRep);
sl@0
   385
	r = aRep.CommitTransaction(keyInfo);
sl@0
   386
	TEST2(r, KErrNone);
sl@0
   387
	TEST2(keyInfo, 0); // no changes
sl@0
   388
	}
sl@0
   389
sl@0
   390
void NoChangeByReadTransaction(CRepository& aRep)
sl@0
   391
	{
sl@0
   392
	TInt r;
sl@0
   393
	TUint32 keyInfo;
sl@0
   394
	// Read transactions can be opened now because there is no EReadWriteTransaction open
sl@0
   395
	r = aRep.StartTransaction(CRepository::EReadTransaction);
sl@0
   396
	TEST2(r, KErrNone);
sl@0
   397
	r = TransactionState(&aRep);
sl@0
   398
	TEST2(r, EReadTransaction);
sl@0
   399
	// Getting a value should result in no change when committing:
sl@0
   400
	TReal value;
sl@0
   401
	r = aRep.Get(KReal2, value);
sl@0
   402
	TEST2(r, KErrNone);
sl@0
   403
	TEST(value == KReal2_InitialValue);
sl@0
   404
	r = aRep.CommitTransaction(keyInfo);
sl@0
   405
	TEST2(r, KErrNone);
sl@0
   406
	TEST2(keyInfo, 0); // no changes
sl@0
   407
	}
sl@0
   408
sl@0
   409
void NoChangeByEmptyWriteTransaction(CRepository& aRep)
sl@0
   410
	{
sl@0
   411
	TInt r;
sl@0
   412
	TUint32 keyInfo;
sl@0
   413
	// can't start an EReadWriteTransaction because a ReadTransaction is active
sl@0
   414
	r = aRep.StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   415
	TEST2(r, KErrLocked);
sl@0
   416
	// Concurrent Read/Write transactions can be opened at any time
sl@0
   417
	r = aRep.StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
   418
	TEST2(r, KErrNone);
sl@0
   419
	r = TransactionState(&aRep);
sl@0
   420
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   421
	// make no changes before committing
sl@0
   422
	r = aRep.CommitTransaction(keyInfo);
sl@0
   423
	TEST2(r, KErrNone);
sl@0
   424
	TEST2(keyInfo, 0); // no changes
sl@0
   425
	}
sl@0
   426
sl@0
   427
// tests that changes made by calling ChangeFunc with aCommittingRepository
sl@0
   428
// do not fail active transactions. Must Reset before calling this.
sl@0
   429
LOCAL_C void CallFuncCheckOtherTransactionsDoNotFail(TRepositoryFunc ChangeFunc, CRepository& aCommittingRepository)
sl@0
   430
	{
sl@0
   431
	TInt r;
sl@0
   432
	CRepository::TTransactionKeyInfoBuf keyInfoBuf;
sl@0
   433
	TUint32 keyInfo;
sl@0
   434
	TRequestStatus status;
sl@0
   435
	CRepository* repository1;
sl@0
   436
	CRepository* repository2;
sl@0
   437
sl@0
   438
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
   439
	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository));
sl@0
   440
sl@0
   441
	// Start two types of transaction and wait for completion
sl@0
   442
	r = repository1->StartTransaction(CRepository::EReadTransaction);
sl@0
   443
	TEST2(r, KErrNone);
sl@0
   444
	repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction, status);
sl@0
   445
	User::WaitForRequest(status);
sl@0
   446
	TEST2(status.Int(), KErrNone);
sl@0
   447
sl@0
   448
	// create values in repository2's transaction cache
sl@0
   449
	r = repository2->Create(KNewString8, KString8_InitialValue);
sl@0
   450
	TEST2(r, KErrNone);
sl@0
   451
	r = repository2->Create(KNewString16, KString16_InitialValue);
sl@0
   452
	TEST2(r, KErrNone);
sl@0
   453
sl@0
   454
	// check transactions not failed
sl@0
   455
	r = TransactionState(repository1);
sl@0
   456
	TEST2(r, EReadTransaction);
sl@0
   457
	r = TransactionState(repository2);
sl@0
   458
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   459
sl@0
   460
	(*ChangeFunc)(aCommittingRepository);
sl@0
   461
sl@0
   462
	// create setting in repository 1's cache
sl@0
   463
	r = repository1->Create(KInt2, KInt2_InitialValue);
sl@0
   464
	TEST2(r, KErrNone);
sl@0
   465
sl@0
   466
	// check transactions not failed & Read upgraded to ReadWrite
sl@0
   467
	r = TransactionState(repository1);
sl@0
   468
	TEST2(r, EReadWriteTransaction);
sl@0
   469
	r = TransactionState(repository2);
sl@0
   470
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
   471
sl@0
   472
	// commit repository2 asynchronously
sl@0
   473
	repository2->CommitTransaction(keyInfoBuf, status);
sl@0
   474
	User::WaitForRequest(status);
sl@0
   475
	TEST2(status.Int(), KErrNone);
sl@0
   476
	TEST2(keyInfoBuf(), 2); // 2 successful changes
sl@0
   477
sl@0
   478
	// check transaction2 finished, transaction 1 failed
sl@0
   479
	r = TransactionState(repository1);
sl@0
   480
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
   481
	r = TransactionState(repository2);
sl@0
   482
	TEST2(r, ENoTransaction);
sl@0
   483
sl@0
   484
	// operations on repository 1 should abort after failing
sl@0
   485
	TInt intValue;
sl@0
   486
	r = repository1->Get(KInt1, intValue);
sl@0
   487
	TEST2(r, KErrAbort);
sl@0
   488
	r = repository1->Set(KInt1, intValue);
sl@0
   489
	TEST2(r, KErrAbort);
sl@0
   490
sl@0
   491
	// commit of repository 1 should fail with KErrLocked
sl@0
   492
	r = repository1->CommitTransaction(keyInfo);
sl@0
   493
	TEST2(r, KErrLocked);
sl@0
   494
	TEST2(keyInfo, KUnspecifiedKey);
sl@0
   495
sl@0
   496
	// check changes by repository 2 are still present
sl@0
   497
	TBuf8<40> buf8Value;
sl@0
   498
	TBuf16<40> buf16Value;
sl@0
   499
sl@0
   500
	r = repository2->Get(KNewString8, buf8Value);
sl@0
   501
	TEST2(r, KErrNone);
sl@0
   502
	TEST(buf8Value == KString8_InitialValue);
sl@0
   503
	r = repository2->Get(KNewString16, buf16Value);
sl@0
   504
	TEST2(r, KErrNone);
sl@0
   505
	TEST(buf16Value == KString16_InitialValue);
sl@0
   506
sl@0
   507
	CleanupStack::PopAndDestroy(repository2);
sl@0
   508
	CleanupStack::PopAndDestroy(repository1);
sl@0
   509
	}
sl@0
   510
sl@0
   511
/**
sl@0
   512
@SYMTestCaseID SYSLIB-CENREP-CT-0151
sl@0
   513
@SYMTestCaseDesc Check committing no changes (incl. setting same value) does not cause other transactions to fail.
sl@0
   514
@SYMTestPriority High
sl@0
   515
@SYMTestActions Run a series of commands that modify repository, check they fail active transactions.
sl@0
   516
 Start concurrent read write transaction and try to create and get values using other repository.
sl@0
   517
@SYMTestExpectedResults The test should not fail with any panics
sl@0
   518
@SYMPREQ PREQ752
sl@0
   519
*/
sl@0
   520
LOCAL_C void CommittingNoChangesDoesNotFailOtherTransactionsL()
sl@0
   521
	{
sl@0
   522
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0151 "));
sl@0
   523
	CRepository* repository;
sl@0
   524
sl@0
   525
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository));
sl@0
   526
sl@0
   527
	// creating and deleting the same setting in the same transaction should have no effect
sl@0
   528
	repository->Reset();
sl@0
   529
	CallFuncCheckOtherTransactionsDoNotFail(NoChangeByTransactionCreateDelete, *repository);
sl@0
   530
sl@0
   531
	// changing a setting to the same value in a transaction should have no effect
sl@0
   532
	repository->Reset();
sl@0
   533
	ChangeByCreate(*repository);
sl@0
   534
	ChangeBySet(*repository);
sl@0
   535
	CallFuncCheckOtherTransactionsDoNotFail(NoChangeByTransactionSetSameValue, *repository);
sl@0
   536
sl@0
   537
	// committing a Read transaction should have no effect
sl@0
   538
	repository->Reset();
sl@0
   539
	ChangeByCreate(*repository);
sl@0
   540
	CallFuncCheckOtherTransactionsDoNotFail(NoChangeByReadTransaction, *repository);
sl@0
   541
sl@0
   542
	// committing an empty transaction should have no effect
sl@0
   543
	repository->Reset();
sl@0
   544
	CallFuncCheckOtherTransactionsDoNotFail(NoChangeByEmptyWriteTransaction, *repository);
sl@0
   545
sl@0
   546
	CleanupStack::PopAndDestroy(repository);
sl@0
   547
sl@0
   548
	// restart session and check values are indeed saved
sl@0
   549
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository));
sl@0
   550
sl@0
   551
	TInt r;
sl@0
   552
	TBuf8<40> buf8Value;
sl@0
   553
	TBuf16<40> buf16Value;
sl@0
   554
	r = repository->Get(KNewString8, buf8Value);
sl@0
   555
	TEST2(r, KErrNone);
sl@0
   556
	TEST(buf8Value == KString8_InitialValue);
sl@0
   557
	r = repository->Get(KNewString16, buf16Value);
sl@0
   558
	TEST2(r, KErrNone);
sl@0
   559
	TEST(buf16Value == KString16_InitialValue);
sl@0
   560
	// final cleanup
sl@0
   561
	repository->Reset();
sl@0
   562
sl@0
   563
	CleanupStack::PopAndDestroy(repository);
sl@0
   564
	}
sl@0
   565
sl@0
   566
/**
sl@0
   567
@SYMTestCaseID SYSLIB-CENREP-CT-0152
sl@0
   568
@SYMTestCaseDesc Testing creates in a read write transaction
sl@0
   569
@SYMTestPriority High
sl@0
   570
@SYMTestActions  Starts a read write transaction which creates values for KInt1, KReal1, KString8 and KString16
sl@0
   571
@SYMTestExpectedResults The test should not fail with any panics
sl@0
   572
@SYMPREQ PREQ752
sl@0
   573
*/
sl@0
   574
LOCAL_C void CreateValueUsingTransactionL()
sl@0
   575
	{
sl@0
   576
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0152 "));
sl@0
   577
	TInt r;
sl@0
   578
	TUint32 errorId;
sl@0
   579
sl@0
   580
	CRepository* repository;
sl@0
   581
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository));
sl@0
   582
sl@0
   583
	// Begin read write transaction
sl@0
   584
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   585
	TEST2(r, KErrNone);
sl@0
   586
sl@0
   587
	r = repository->Create(KInt1, KInt1_InitialValue);
sl@0
   588
	TEST2(r, KErrNone);
sl@0
   589
sl@0
   590
	r = repository->Create(KReal1, KReal1_InitialValue);
sl@0
   591
	TEST2(r, KErrNone);
sl@0
   592
sl@0
   593
	r = repository->Create(KString8, KString8_InitialValue);
sl@0
   594
	TEST2(r, KErrNone);
sl@0
   595
sl@0
   596
	r = repository->Create(KString16, KString16_InitialValue);
sl@0
   597
	TEST2(r, KErrNone);
sl@0
   598
sl@0
   599
	// Commit transaction
sl@0
   600
	r = repository->CommitTransaction(errorId);
sl@0
   601
	TEST2(r, KErrNone);
sl@0
   602
	// Test for the value of errorId for a successful read write transaction = 4 changes
sl@0
   603
	TEST2(errorId, 4);
sl@0
   604
sl@0
   605
	CleanupStack::PopAndDestroy(repository);
sl@0
   606
sl@0
   607
	}
sl@0
   608
sl@0
   609
/**
sl@0
   610
@SYMTestCaseID SYSLIB-CENREP-CT-0153
sl@0
   611
@SYMTestCaseDesc Testing state and rollback in a transaction
sl@0
   612
@SYMTestPriority High
sl@0
   613
@SYMTestActions  Use both transactionstate and failtransaction while being in a transaction and not in a transaction.
sl@0
   614
	Check on the state and test to see if rollback occurs when required.
sl@0
   615
@SYMTestExpectedResults The test should not fail with any panics
sl@0
   616
@SYMPREQ PREQ752
sl@0
   617
*/
sl@0
   618
LOCAL_C void TransactionStateAndRollBackL()
sl@0
   619
	{
sl@0
   620
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0153 "));
sl@0
   621
	TInt r;
sl@0
   622
	TUint32 errorId;
sl@0
   623
	TReal getValue;
sl@0
   624
sl@0
   625
	CRepository* repository;
sl@0
   626
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository));
sl@0
   627
sl@0
   628
	r = TransactionState(repository);
sl@0
   629
	TEST2(r, ENoTransaction);
sl@0
   630
sl@0
   631
	// Try to fail transaction without being in a transaction
sl@0
   632
	repository->FailTransaction();
sl@0
   633
sl@0
   634
	r = TransactionState(repository);
sl@0
   635
	TEST2(r, ENoTransaction);
sl@0
   636
sl@0
   637
	// Begin concurrent read write transaction
sl@0
   638
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   639
	TEST2(r, KErrNone);
sl@0
   640
sl@0
   641
	r = TransactionState(repository);
sl@0
   642
	TEST2(r, EReadWriteTransaction);
sl@0
   643
sl@0
   644
	r = repository->Create(KReal2, KReal2_InitialValue);
sl@0
   645
	TEST2(r, KErrNone);
sl@0
   646
sl@0
   647
	r = repository->Get(KReal2, getValue);
sl@0
   648
	TEST(getValue == KReal2_InitialValue);
sl@0
   649
	TEST2(r, KErrNone);
sl@0
   650
sl@0
   651
	// Fail transaction should roll back transaction i.e. Create KReal2 should not work.
sl@0
   652
	repository->FailTransaction();
sl@0
   653
sl@0
   654
	r = TransactionState(repository);
sl@0
   655
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
   656
sl@0
   657
	// Commit transaction
sl@0
   658
	r = repository->CommitTransaction(errorId);
sl@0
   659
	TEST2(r, KErrAbort);
sl@0
   660
	// Test the value of errorId for a failed read write transaction
sl@0
   661
	TEST2(errorId, KUnspecifiedKey);
sl@0
   662
sl@0
   663
	// Try to get a value which should not exist as transaction failed
sl@0
   664
	r = repository->Get(KReal2, getValue);
sl@0
   665
	TEST2(r, KErrNotFound);
sl@0
   666
sl@0
   667
	r = TransactionState(repository);
sl@0
   668
	TEST2(r, ENoTransaction);
sl@0
   669
sl@0
   670
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   671
	TEST2(r, KErrNone);
sl@0
   672
sl@0
   673
	r = repository->Create(KReal2, KReal2_InitialValue);
sl@0
   674
	TEST2(r, KErrNone);
sl@0
   675
sl@0
   676
	repository->RollbackTransaction();
sl@0
   677
sl@0
   678
	// Try to get a value which should not exist as transaction rolled back
sl@0
   679
	r = repository->Get(KReal2, getValue);
sl@0
   680
	TEST2(r, KErrNotFound);
sl@0
   681
sl@0
   682
	// Transaction state should be ENoTransaction due to call to RollbackTransaction()
sl@0
   683
	r = TransactionState(repository);
sl@0
   684
	TEST2(r, ENoTransaction);
sl@0
   685
sl@0
   686
	// Begin read transaction
sl@0
   687
	r = repository->StartTransaction(CRepository::EReadTransaction);
sl@0
   688
	TEST2(r, KErrNone);
sl@0
   689
sl@0
   690
	r = TransactionState(repository);
sl@0
   691
	TEST2(r, EReadTransaction);
sl@0
   692
sl@0
   693
	r = repository->Get(KReal1, getValue);
sl@0
   694
	TEST2(r, KErrNone);
sl@0
   695
	TEST(getValue == KReal1_InitialValue);
sl@0
   696
sl@0
   697
	// Fail transaction
sl@0
   698
	repository->FailTransaction();
sl@0
   699
sl@0
   700
	r = TransactionState(repository);
sl@0
   701
	TEST2(r, EReadTransaction | EFailedBit);
sl@0
   702
sl@0
   703
	// Commit transaction
sl@0
   704
	r = repository->CommitTransaction(errorId);
sl@0
   705
	TEST2(r, KErrAbort);
sl@0
   706
sl@0
   707
	r = TransactionState(repository);
sl@0
   708
	TEST2(r, ENoTransaction);
sl@0
   709
sl@0
   710
	// Begin another read transaction
sl@0
   711
	r = repository->StartTransaction(CRepository::EReadTransaction);
sl@0
   712
	TEST2(r, KErrNone);
sl@0
   713
sl@0
   714
	r = repository->Get(KReal1, getValue);
sl@0
   715
	TEST2(r, KErrNone);
sl@0
   716
	TEST(getValue == KReal1_InitialValue);
sl@0
   717
sl@0
   718
	r = TransactionState(repository);
sl@0
   719
	TEST2(r, EReadTransaction);
sl@0
   720
sl@0
   721
	// Perform Create in a ReadTransaction as upgrade has occured
sl@0
   722
	r = repository->Create(KReal2, KReal2_InitialValue);
sl@0
   723
	TEST2(r, KErrNone);
sl@0
   724
sl@0
   725
	// The state should be updated to be EInReadWriteTransaction
sl@0
   726
	r = TransactionState(repository);
sl@0
   727
	TEST2(r, EReadWriteTransaction);
sl@0
   728
sl@0
   729
	r = repository->Get(KReal2, getValue);
sl@0
   730
	TEST2(r, KErrNone);
sl@0
   731
sl@0
   732
	// Commit transaction
sl@0
   733
	r = repository->CommitTransaction(errorId);
sl@0
   734
	TEST2(r, KErrNone);
sl@0
   735
sl@0
   736
	// Delete KReal2 to reset available test case variables
sl@0
   737
	r = repository->Delete(KReal2);
sl@0
   738
	TEST2(r, KErrNone);
sl@0
   739
sl@0
   740
	r = TransactionState(repository);
sl@0
   741
	TEST2(r, ENoTransaction);
sl@0
   742
sl@0
   743
	CleanupStack::PopAndDestroy(repository);
sl@0
   744
	}
sl@0
   745
sl@0
   746
LOCAL_C void StartTransactionPanicConditionsL()
sl@0
   747
	{
sl@0
   748
	TInt r;
sl@0
   749
	TUint32 errorId;
sl@0
   750
sl@0
   751
	CRepository* repository1;
sl@0
   752
sl@0
   753
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
   754
sl@0
   755
	// Begin read write transaction
sl@0
   756
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   757
	TEST2(r, KErrNone);
sl@0
   758
sl@0
   759
	// This should panic can't start second transaction in one session
sl@0
   760
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   761
	TEST2(r, KErrNone);
sl@0
   762
sl@0
   763
	// Commit transaction
sl@0
   764
	r = repository1->CommitTransaction(errorId);
sl@0
   765
	TEST2(r, KErrNone);
sl@0
   766
sl@0
   767
	CleanupStack::PopAndDestroy(repository1);
sl@0
   768
	}
sl@0
   769
sl@0
   770
LOCAL_C TInt TestStartTransactionPanics(TAny* /*aData*/)
sl@0
   771
	{
sl@0
   772
	__UHEAP_MARK;
sl@0
   773
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   774
	if(!cleanup)
sl@0
   775
		return KErrNoMemory;
sl@0
   776
sl@0
   777
	TRAPD(err, StartTransactionPanicConditionsL());
sl@0
   778
sl@0
   779
	// Won't get here but add this line to get rid of ARMV5 warning
sl@0
   780
	TEST2(err, KErrNone);
sl@0
   781
sl@0
   782
	delete cleanup;
sl@0
   783
	__UHEAP_MARKEND;
sl@0
   784
sl@0
   785
	return (KErrNone);
sl@0
   786
	}
sl@0
   787
sl@0
   788
/**
sl@0
   789
@SYMTestCaseID SYSLIB-CENREP-CT-0154
sl@0
   790
@SYMTestCaseDesc Testing valid panics while using StartTransaction
sl@0
   791
@SYMTestPriority High
sl@0
   792
@SYMTestActions  Start a separate thread and within that thread try to start transaction twice
sl@0
   793
@SYMTestExpectedResults The thread should exit with the exit type EExitPanic and exit reason EStartAlreadyInTransaction
sl@0
   794
@SYMPREQ PREQ752
sl@0
   795
*/
sl@0
   796
LOCAL_C void TransactionPanicConditionsThread()
sl@0
   797
	{
sl@0
   798
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0154 "));
sl@0
   799
	TBool jitEnabled = User::JustInTime();
sl@0
   800
	User::SetJustInTime(EFalse);
sl@0
   801
sl@0
   802
	TRequestStatus status;
sl@0
   803
sl@0
   804
	_LIT(KName, "Transaction_Panic_Thread");
sl@0
   805
sl@0
   806
	RThread thread;
sl@0
   807
	TInt rc = thread.Create(KName,TestStartTransactionPanics,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL);
sl@0
   808
sl@0
   809
	TEST2(rc,KErrNone);
sl@0
   810
sl@0
   811
	thread.Logon(status);
sl@0
   812
	thread.Resume();
sl@0
   813
sl@0
   814
	User::WaitForRequest(status);
sl@0
   815
sl@0
   816
	// Should result in a EExitPanic exit type and an EStartAlreadyInTransaction exit reason
sl@0
   817
	TEST2(thread.ExitType(), EExitPanic);
sl@0
   818
	TEST2(thread.ExitReason(), EStartAlreadyInTransaction);
sl@0
   819
sl@0
   820
	thread.Close();
sl@0
   821
sl@0
   822
	User::SetJustInTime(jitEnabled);
sl@0
   823
	}
sl@0
   824
sl@0
   825
LOCAL_C void CommitTransactionPanicConditionL()
sl@0
   826
	{
sl@0
   827
	TInt r;
sl@0
   828
	TUint32 errorId;
sl@0
   829
sl@0
   830
	CRepository* repository1;
sl@0
   831
sl@0
   832
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
   833
sl@0
   834
	// Commit transaction when there is not transaction should cause a panic
sl@0
   835
	r = repository1->CommitTransaction(errorId);
sl@0
   836
	TEST2(r, KErrNone);
sl@0
   837
sl@0
   838
	CleanupStack::PopAndDestroy(repository1);
sl@0
   839
	}
sl@0
   840
sl@0
   841
sl@0
   842
LOCAL_C TInt TestCommitTransactionPanics(TAny* /*aData*/)
sl@0
   843
	{
sl@0
   844
	__UHEAP_MARK;
sl@0
   845
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   846
	if(!cleanup)
sl@0
   847
		return KErrNoMemory;
sl@0
   848
sl@0
   849
	TRAPD(err,CommitTransactionPanicConditionL());
sl@0
   850
sl@0
   851
	// Won't get here but add this line to get rid of ARMV5 warning
sl@0
   852
	TEST2(err, KErrNone);
sl@0
   853
sl@0
   854
	delete cleanup;
sl@0
   855
	__UHEAP_MARKEND;
sl@0
   856
	return (KErrNone);
sl@0
   857
	}
sl@0
   858
sl@0
   859
/**
sl@0
   860
@SYMTestCaseID SYSLIB-CENREP-CT-0155
sl@0
   861
@SYMTestCaseDesc Testing valid panics while using CommitTransaction
sl@0
   862
@SYMTestPriority High
sl@0
   863
@SYMTestActions  Start a separate thread and within that thread try to commit a transaction without being in one
sl@0
   864
@SYMTestExpectedResults The thread should exit with the exit type EExitPanic and the exit reason ECommitNotInTransaction
sl@0
   865
@SYMPREQ PREQ752
sl@0
   866
*/
sl@0
   867
LOCAL_C void CommitTransactionPanicConditionsThread()
sl@0
   868
	{
sl@0
   869
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0155 "));
sl@0
   870
	TBool jitEnabled = User::JustInTime();
sl@0
   871
	User::SetJustInTime(EFalse);
sl@0
   872
sl@0
   873
	TRequestStatus status;
sl@0
   874
sl@0
   875
	_LIT(KName, "Commit_Transaction_Panic_Thread");
sl@0
   876
sl@0
   877
	RThread thread;
sl@0
   878
	TInt rc = thread.Create(KName,TestCommitTransactionPanics,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL);
sl@0
   879
sl@0
   880
	TEST2(rc,KErrNone);
sl@0
   881
sl@0
   882
	thread.Logon(status);
sl@0
   883
	thread.Resume();
sl@0
   884
sl@0
   885
	User::WaitForRequest(status);
sl@0
   886
sl@0
   887
	// Should result in a EExitPanic exit type and an ECommitNotInTransaction exit reason
sl@0
   888
	TEST2(thread.ExitType(), EExitPanic);
sl@0
   889
	TEST2(thread.ExitReason(), ECommitNotInTransaction);
sl@0
   890
sl@0
   891
	thread.Close();
sl@0
   892
sl@0
   893
	User::SetJustInTime(jitEnabled);
sl@0
   894
	}
sl@0
   895
sl@0
   896
LOCAL_C void LeaveWithCleanupRollbackTransactionPushL(CRepository& aRepository)
sl@0
   897
	{
sl@0
   898
	TInt r = TransactionState(&aRepository);
sl@0
   899
	TEST2(r, CRepository::EReadWriteTransaction);
sl@0
   900
sl@0
   901
	aRepository.CleanupRollbackTransactionPushL();
sl@0
   902
sl@0
   903
	// Purposely leave in a transaction...
sl@0
   904
	User::LeaveNoMemory();
sl@0
   905
sl@0
   906
	// this code should never be reached...
sl@0
   907
	TEST(EFalse);
sl@0
   908
	// ...but if it did we'd have to cleanup the PushL
sl@0
   909
	CleanupStack::Pop();
sl@0
   910
	}
sl@0
   911
sl@0
   912
LOCAL_C void LeaveWithCleanupFailTransactionPushL(CRepository& aRepository)
sl@0
   913
	{
sl@0
   914
	TInt r = TransactionState(&aRepository);
sl@0
   915
	TEST2(r, CRepository::EReadWriteTransaction);
sl@0
   916
sl@0
   917
	aRepository.CleanupFailTransactionPushL();
sl@0
   918
sl@0
   919
	// Purposely leave in a transaction...
sl@0
   920
	User::LeaveNoMemory();
sl@0
   921
sl@0
   922
	// this code should never be reached...
sl@0
   923
	TEST(EFalse);
sl@0
   924
	// ...but if it did we'd have to cleanup the PushL
sl@0
   925
	CleanupStack::Pop();
sl@0
   926
	}
sl@0
   927
sl@0
   928
/**
sl@0
   929
@SYMTestCaseID SYSLIB-CENREP-CT-0156
sl@0
   930
@SYMTestCaseDesc Testing CleanupRollbackTransactionPushL and CleanupFailTransactionPushL
sl@0
   931
@SYMTestPriority High
sl@0
   932
@SYMTestActions Start a transaction and use CleanupRollbackTransactionPushL. Within the transaction purposely leave, as this will
sl@0
   933
	result in CleanupRollbackTransactionPushL being used. Similar operation required for CleanupFailTransactionPushL
sl@0
   934
@SYMTestExpectedResults The test should not fail with any panics
sl@0
   935
@SYMPREQ PREQ752
sl@0
   936
*/
sl@0
   937
LOCAL_C void CleanupRollBackAndFailTransactionL()
sl@0
   938
	{
sl@0
   939
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0156 "));
sl@0
   940
	TInt r;
sl@0
   941
	TUint32 errorId;
sl@0
   942
	TReal getValue;
sl@0
   943
sl@0
   944
	CRepository* repository;
sl@0
   945
sl@0
   946
	User::LeaveIfNull(repository = CRepository::NewLC(KUidTestRepository));
sl@0
   947
sl@0
   948
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   949
	TEST2(r, KErrNone);
sl@0
   950
sl@0
   951
	repository->CleanupRollbackTransactionPushL();
sl@0
   952
sl@0
   953
	r = repository->Create(KReal2, KReal2_InitialValue);
sl@0
   954
	TEST2(r, KErrNone);
sl@0
   955
sl@0
   956
	// Purposely leave in a transaction...
sl@0
   957
	TRAP(r, LeaveWithCleanupRollbackTransactionPushL(*repository));
sl@0
   958
	TEST2(r, KErrNoMemory);
sl@0
   959
sl@0
   960
	// should cause RollbackTransaction, therefore transaction state should be ENoTransaction...
sl@0
   961
sl@0
   962
	r = TransactionState(repository);
sl@0
   963
	TEST2(r, ENoTransaction);
sl@0
   964
sl@0
   965
	// and getting the value KReal2 should result in KErrNotFound
sl@0
   966
	r = repository->Get(KReal2, getValue);
sl@0
   967
	TEST2(r, KErrNotFound);
sl@0
   968
sl@0
   969
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
   970
sl@0
   971
	r = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
   972
	TEST2(r, KErrNone);
sl@0
   973
sl@0
   974
	repository->CleanupFailTransactionPushL();
sl@0
   975
sl@0
   976
	r = repository->Create(KReal2, KReal2_InitialValue);
sl@0
   977
	TEST2(r, KErrNone);
sl@0
   978
sl@0
   979
	// Purposely leave in a transaction...
sl@0
   980
	TRAP(r, LeaveWithCleanupFailTransactionPushL(*repository));
sl@0
   981
	TEST2(r, KErrNoMemory);
sl@0
   982
sl@0
   983
	// should cause FailTransaction, therefore transaction state should be EInFailedReadWriteTransaction...
sl@0
   984
	r = TransactionState(repository);
sl@0
   985
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
   986
sl@0
   987
	// only after commit will Fail Transaction call roll back...
sl@0
   988
	r = repository->CommitTransaction(errorId);
sl@0
   989
	TEST2(r, KErrAbort);
sl@0
   990
sl@0
   991
	// so getting the value KReal2 should result in KErrNotFound
sl@0
   992
	r = repository->Get(KReal2, getValue);
sl@0
   993
	TEST2(r, KErrNotFound);
sl@0
   994
sl@0
   995
	r = TransactionState(repository);
sl@0
   996
	TEST2(r, ENoTransaction);
sl@0
   997
sl@0
   998
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
   999
sl@0
  1000
	CleanupStack::PopAndDestroy(repository);
sl@0
  1001
	}
sl@0
  1002
sl@0
  1003
/**
sl@0
  1004
@SYMTestCaseID SYSLIB-CENREP-CT-0157
sl@0
  1005
@SYMTestCaseDesc Test Read Transaction Conditions
sl@0
  1006
@SYMTestPriority High
sl@0
  1007
@SYMTestActions Start read transactions and perform read operations
sl@0
  1008
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1009
@SYMPREQ PREQ752
sl@0
  1010
*/
sl@0
  1011
LOCAL_C void ReadTransactionConditionsL()
sl@0
  1012
	{
sl@0
  1013
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0157 "));
sl@0
  1014
	TInt r;
sl@0
  1015
	TUint32 errorId;
sl@0
  1016
	TInt intVal;
sl@0
  1017
sl@0
  1018
	CRepository* repository1;
sl@0
  1019
	CRepository* repository2;
sl@0
  1020
	CRepository* repository3;
sl@0
  1021
sl@0
  1022
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1023
	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository));
sl@0
  1024
	User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository));
sl@0
  1025
sl@0
  1026
	// Begin transaction for repository1
sl@0
  1027
	r = repository1->StartTransaction(CRepository::EReadTransaction);
sl@0
  1028
	TEST2(r, KErrNone);
sl@0
  1029
sl@0
  1030
	// Should be able to start another read transaction
sl@0
  1031
	r = repository2->StartTransaction(CRepository::EReadTransaction);
sl@0
  1032
	TEST2(r, KErrNone);
sl@0
  1033
sl@0
  1034
	// Perform some gets using the open transactions and repository
sl@0
  1035
	r = repository1->Get(KInt1, intVal);
sl@0
  1036
	TEST2(r, KErrNone);
sl@0
  1037
	TEST2(intVal, KInt1_InitialValue);
sl@0
  1038
sl@0
  1039
	r = repository2->Get(KInt1, intVal);
sl@0
  1040
	TEST2(r, KErrNone);
sl@0
  1041
	TEST2(intVal, KInt1_InitialValue);
sl@0
  1042
sl@0
  1043
	r = repository3->Get(KInt1, intVal);
sl@0
  1044
	TEST2(r, KErrNone);
sl@0
  1045
	TEST2(intVal, KInt1_InitialValue);
sl@0
  1046
sl@0
  1047
	// Get the state of Transactions
sl@0
  1048
	r = TransactionState(repository1);
sl@0
  1049
	TEST2(r, EReadTransaction);
sl@0
  1050
sl@0
  1051
	r = TransactionState(repository1);
sl@0
  1052
	TEST2(r, EReadTransaction);
sl@0
  1053
sl@0
  1054
	r = repository1->CommitTransaction(errorId);
sl@0
  1055
	TEST2(r, KErrNone);
sl@0
  1056
	// Test for the value of errorId for a successful read transaction: no changes
sl@0
  1057
	TEST2(errorId, 0);
sl@0
  1058
sl@0
  1059
	r = repository2->CommitTransaction(errorId);
sl@0
  1060
	TEST2(r, KErrNone);
sl@0
  1061
	// Test for the value of errorId for a successful read transaction: no changes
sl@0
  1062
	TEST2(errorId, 0);
sl@0
  1063
sl@0
  1064
	CleanupStack::PopAndDestroy(repository3);
sl@0
  1065
	CleanupStack::PopAndDestroy(repository2);
sl@0
  1066
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1067
	}
sl@0
  1068
sl@0
  1069
/**
sl@0
  1070
@SYMTestCaseID SYSLIB-CENREP-CT-0158
sl@0
  1071
@SYMTestCaseDesc Test upgrade read transaction with error conditions
sl@0
  1072
@SYMTestPriority High
sl@0
  1073
@SYMTestActions Start read transactions and try to upgrade one of the read transactions
sl@0
  1074
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1075
@SYMPREQ PREQ752
sl@0
  1076
*/
sl@0
  1077
LOCAL_C void UpgradeReadTransactionErrorConditionsL()
sl@0
  1078
	{
sl@0
  1079
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0158 "));
sl@0
  1080
	TInt r;
sl@0
  1081
	TUint32 errorId;
sl@0
  1082
	TInt intVal;
sl@0
  1083
sl@0
  1084
	CRepository* repository1;
sl@0
  1085
	CRepository* repository2;
sl@0
  1086
	CRepository* repository3;
sl@0
  1087
sl@0
  1088
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1089
	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository));
sl@0
  1090
	User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository));
sl@0
  1091
sl@0
  1092
	// Begin transaction for repository1
sl@0
  1093
	r = repository1->StartTransaction(CRepository::EReadTransaction);
sl@0
  1094
	TEST2(r, KErrNone);
sl@0
  1095
sl@0
  1096
	// Should be able to start another read transaction
sl@0
  1097
	r = repository2->StartTransaction(CRepository::EReadTransaction);
sl@0
  1098
	TEST2(r, KErrNone);
sl@0
  1099
sl@0
  1100
	// Perform get using open transaction
sl@0
  1101
	r = repository2->Get(KInt1, intVal);
sl@0
  1102
	TEST2(r, KErrNone);
sl@0
  1103
	TEST2(intVal, KInt1_InitialValue);
sl@0
  1104
sl@0
  1105
	// Perform create which should fail transaction with KErrLocked
sl@0
  1106
	r = repository1->Create(KInt2, KInt2_InitialValue);
sl@0
  1107
	TEST2(r, KErrLocked);
sl@0
  1108
sl@0
  1109
	// check the value is not there as far as repository 3 is concerned
sl@0
  1110
	r = repository3->Get(KInt2, intVal);
sl@0
  1111
	TEST2(r, KErrNotFound);
sl@0
  1112
sl@0
  1113
	// Get the state of Transactions
sl@0
  1114
	r = TransactionState(repository1);
sl@0
  1115
	TEST2(r, EReadTransaction | EFailedBit);
sl@0
  1116
sl@0
  1117
	r = TransactionState(repository2);
sl@0
  1118
	TEST2(r, EReadTransaction);
sl@0
  1119
sl@0
  1120
	r = repository2->CommitTransaction(errorId);
sl@0
  1121
	TEST2(r, KErrNone);
sl@0
  1122
sl@0
  1123
	r = repository1->CommitTransaction(errorId);
sl@0
  1124
	TEST2(r, KErrLocked);
sl@0
  1125
	// Check the key responsible for the failed read transaction promote
sl@0
  1126
	TEST2(errorId, KInt2);
sl@0
  1127
sl@0
  1128
	CleanupStack::PopAndDestroy(repository3);
sl@0
  1129
	CleanupStack::PopAndDestroy(repository2);
sl@0
  1130
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1131
	}
sl@0
  1132
sl@0
  1133
/**
sl@0
  1134
@SYMTestCaseID SYSLIB-CENREP-CT-0159
sl@0
  1135
@SYMTestCaseDesc Test read operations with a read write transaction open
sl@0
  1136
@SYMTestPriority High
sl@0
  1137
@SYMTestActions Start a transaction and try to perform some read operations outside of the open transaction
sl@0
  1138
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1139
@SYMPREQ PREQ752
sl@0
  1140
*/
sl@0
  1141
LOCAL_C void TransactionConditionsForReadL()
sl@0
  1142
	{
sl@0
  1143
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0159 "));
sl@0
  1144
	TInt r;
sl@0
  1145
	TUint32 errorId;
sl@0
  1146
	RArray<TUint32> foundIds;
sl@0
  1147
sl@0
  1148
	CRepository* repository1;
sl@0
  1149
	CRepository* repository2;
sl@0
  1150
sl@0
  1151
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1152
	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository));
sl@0
  1153
sl@0
  1154
	// Begin transaction for repository1
sl@0
  1155
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1156
	TEST2(r, KErrNone);
sl@0
  1157
sl@0
  1158
	r = TransactionState(repository1);
sl@0
  1159
	TEST2(r, EReadWriteTransaction);
sl@0
  1160
sl@0
  1161
	// Should be able to get values regardless of transaction1 being open
sl@0
  1162
	TInt intVal;
sl@0
  1163
	r = repository2->Get(KInt1, intVal);
sl@0
  1164
	TEST2(r, KErrNone);
sl@0
  1165
	TEST2(intVal, KInt1_InitialValue);
sl@0
  1166
sl@0
  1167
	TReal realVal;
sl@0
  1168
	r = repository2->Get(KReal1, realVal);
sl@0
  1169
	TEST2(r, KErrNone);
sl@0
  1170
	TEST(realVal==KReal1_InitialValue);
sl@0
  1171
sl@0
  1172
	TBuf8<14> buf8Val;
sl@0
  1173
	r = repository2->Get(KString8, buf8Val);
sl@0
  1174
	TEST2(r, KErrNone);
sl@0
  1175
	TEST(buf8Val==KString8_InitialValue);
sl@0
  1176
sl@0
  1177
	TBuf16<14> buf16Val;
sl@0
  1178
	r = repository2->Get(KString16, buf16Val);
sl@0
  1179
	TEST2(r, KErrNone);
sl@0
  1180
	TEST(buf16Val==KString16_InitialValue);
sl@0
  1181
sl@0
  1182
	r = repository2->FindL(0, KUnprotectedSettingsMask, foundIds);
sl@0
  1183
	TEST2(r, KErrNone);
sl@0
  1184
	TEST(foundIds.Count()==4);
sl@0
  1185
sl@0
  1186
	foundIds.Reset();
sl@0
  1187
sl@0
  1188
	// Find in range for values equal to KInt1_InitialValue
sl@0
  1189
	r = repository2->FindEqL(0, KUnprotectedSettingsMask, KInt1_InitialValue, foundIds);
sl@0
  1190
	TEST2(r, KErrNone);
sl@0
  1191
	TEST(foundIds.Count()==1);
sl@0
  1192
sl@0
  1193
	foundIds.Reset();
sl@0
  1194
sl@0
  1195
	// Find in range for values NOT equal to KInt1_InitialValue
sl@0
  1196
	r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KInt1_InitialValue, foundIds);
sl@0
  1197
	TEST2(r, KErrNone);
sl@0
  1198
	TEST(foundIds.Count()==3);
sl@0
  1199
sl@0
  1200
	foundIds.Reset();
sl@0
  1201
sl@0
  1202
	// Find in range for values equal to KReal1_InitialValue
sl@0
  1203
	r = repository2->FindEqL(0, KUnprotectedSettingsMask, KReal1_InitialValue, foundIds);
sl@0
  1204
	TEST2(r, KErrNone);
sl@0
  1205
	TEST2(foundIds.Count(),1);
sl@0
  1206
sl@0
  1207
	foundIds.Reset();
sl@0
  1208
sl@0
  1209
	// Find in range for values NOT equal to KReal1_InitialValue
sl@0
  1210
	r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KReal1_InitialValue, foundIds);
sl@0
  1211
	TEST2(r, KErrNone);
sl@0
  1212
	TEST2(foundIds.Count(),3);
sl@0
  1213
sl@0
  1214
	// Find in range for values equal to KString8_InitialValue
sl@0
  1215
	r = repository2->FindEqL(0, KUnprotectedSettingsMask, KString8_InitialValue, foundIds);
sl@0
  1216
	TEST2(r, KErrNone);
sl@0
  1217
	TEST(foundIds.Count()==1);
sl@0
  1218
sl@0
  1219
	foundIds.Reset();
sl@0
  1220
sl@0
  1221
	// Find in range for values NOT equal to KString8_InitialValue
sl@0
  1222
	r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KString8_InitialValue, foundIds);
sl@0
  1223
	TEST2(r, KErrNone);
sl@0
  1224
	TEST2(foundIds.Count(),3);
sl@0
  1225
sl@0
  1226
sl@0
  1227
	// Find in range for values equal to KString16_InitialValue
sl@0
  1228
	r = repository2->FindEqL(0, KUnprotectedSettingsMask, KString16_InitialValue, foundIds);
sl@0
  1229
	TEST2(r, KErrNone);
sl@0
  1230
	TEST2(foundIds.Count(),1);
sl@0
  1231
sl@0
  1232
	foundIds.Reset();
sl@0
  1233
sl@0
  1234
	// Find in range for values NOT equal to KString16_InitialValue
sl@0
  1235
	r = repository2->FindNeqL(0, KUnprotectedSettingsMask, KString16_InitialValue, foundIds);
sl@0
  1236
	TEST2(r, KErrNone);
sl@0
  1237
	TEST2(foundIds.Count(),3);
sl@0
  1238
sl@0
  1239
	foundIds.Reset();
sl@0
  1240
sl@0
  1241
	r = repository1->CommitTransaction(errorId);
sl@0
  1242
	TEST2(r, KErrNone);
sl@0
  1243
sl@0
  1244
	CleanupStack::PopAndDestroy(repository2);
sl@0
  1245
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1246
	}
sl@0
  1247
sl@0
  1248
/**
sl@0
  1249
@SYMTestCaseID SYSLIB-CENREP-CT-0160
sl@0
  1250
@SYMTestCaseDesc Test Transaction error conditions with get
sl@0
  1251
@SYMTestPriority High
sl@0
  1252
@SYMTestActions Start a transaction and perform some problematic gets. Test to see if it fails transactions or not.
sl@0
  1253
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1254
@SYMPREQ PREQ752
sl@0
  1255
*/
sl@0
  1256
LOCAL_C void TransactionErrorConditionsForGetL()
sl@0
  1257
	{
sl@0
  1258
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0160 "));
sl@0
  1259
	TInt r;
sl@0
  1260
	TUint32 errorId;
sl@0
  1261
sl@0
  1262
	CRepository* repository1;
sl@0
  1263
sl@0
  1264
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1265
sl@0
  1266
	// Begin transaction for repository1
sl@0
  1267
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1268
	TEST2(r, KErrNone);
sl@0
  1269
sl@0
  1270
	// Should NOT fail transaction
sl@0
  1271
	TInt intVal;
sl@0
  1272
	r = repository1->Get(KInt2, intVal);
sl@0
  1273
	TEST2(r, KErrNotFound);
sl@0
  1274
sl@0
  1275
	r = TransactionState(repository1);
sl@0
  1276
	TEST2(r, EReadWriteTransaction);
sl@0
  1277
sl@0
  1278
	// Should NOT fail transaction
sl@0
  1279
	TReal realVal;
sl@0
  1280
	r = repository1->Get(KInt1, realVal);
sl@0
  1281
	TEST2(r, KErrArgument);
sl@0
  1282
sl@0
  1283
	r = TransactionState(repository1);
sl@0
  1284
	TEST2(r, EReadWriteTransaction);
sl@0
  1285
sl@0
  1286
	// Should NOT fail transaction
sl@0
  1287
	r = repository1->Get(KReal2, realVal);
sl@0
  1288
	TEST2(r, KErrNotFound);
sl@0
  1289
sl@0
  1290
	r = TransactionState(repository1);
sl@0
  1291
	TEST2(r, EReadWriteTransaction);
sl@0
  1292
sl@0
  1293
	// Should NOT fail transaction
sl@0
  1294
	r = repository1->Get(KReal1, intVal);
sl@0
  1295
	TEST2(r, KErrArgument);
sl@0
  1296
sl@0
  1297
	r = TransactionState(repository1);
sl@0
  1298
	TEST2(r, EReadWriteTransaction);
sl@0
  1299
sl@0
  1300
	// Should NOT fail transaction
sl@0
  1301
	TBuf8<14> buf8Val;
sl@0
  1302
	r = repository1->Get(KNewString8, buf8Val);
sl@0
  1303
	TEST2(r, KErrNotFound);
sl@0
  1304
sl@0
  1305
	r = TransactionState(repository1);
sl@0
  1306
	TEST2(r, EReadWriteTransaction);
sl@0
  1307
sl@0
  1308
	// Should NOT fail transaction
sl@0
  1309
	r = repository1->Get(KString8, intVal);
sl@0
  1310
	TEST2(r, KErrArgument);
sl@0
  1311
sl@0
  1312
	r = TransactionState(repository1);
sl@0
  1313
	TEST2(r, EReadWriteTransaction);
sl@0
  1314
sl@0
  1315
	// Should NOT fail transaction
sl@0
  1316
	TBuf8<2> smallBuf8Val;
sl@0
  1317
	r = repository1->Get(KString8, smallBuf8Val);
sl@0
  1318
	TEST2(r, KErrOverflow);
sl@0
  1319
	TEST(smallBuf8Val==KString8_Small_Value);
sl@0
  1320
sl@0
  1321
	r = TransactionState(repository1);
sl@0
  1322
	TEST2(r, EReadWriteTransaction);
sl@0
  1323
sl@0
  1324
	// Should NOT fail transaction
sl@0
  1325
	TBuf16<14> buf16Val;
sl@0
  1326
	r = repository1->Get(KNewString16, buf16Val);
sl@0
  1327
	TEST2(r, KErrNotFound);
sl@0
  1328
sl@0
  1329
	r = TransactionState(repository1);
sl@0
  1330
	TEST2(r, EReadWriteTransaction);
sl@0
  1331
sl@0
  1332
	// Should NOT fail transaction
sl@0
  1333
	r = repository1->Get(KString16, intVal);
sl@0
  1334
	TEST2(r, KErrArgument);
sl@0
  1335
sl@0
  1336
	r = TransactionState(repository1);
sl@0
  1337
	TEST2(r, EReadWriteTransaction);
sl@0
  1338
sl@0
  1339
	// Should NOT fail transaction
sl@0
  1340
	TBuf16<2> smallBuf16Val;
sl@0
  1341
	r = repository1->Get(KString16, smallBuf16Val);
sl@0
  1342
	TEST2(r, KErrOverflow);
sl@0
  1343
	TEST(smallBuf16Val==KString16_Small_Value);
sl@0
  1344
sl@0
  1345
	r = TransactionState(repository1);
sl@0
  1346
	TEST2(r, EReadWriteTransaction);
sl@0
  1347
sl@0
  1348
	r = repository1->CommitTransaction(errorId);
sl@0
  1349
	TEST2(r, KErrNone);
sl@0
  1350
sl@0
  1351
	r = TransactionState(repository1);
sl@0
  1352
	TEST2(r, ENoTransaction);
sl@0
  1353
sl@0
  1354
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1355
	}
sl@0
  1356
sl@0
  1357
/**
sl@0
  1358
@SYMTestCaseID SYSLIB-CENREP-CT-0161
sl@0
  1359
@SYMTestCaseDesc Test Transaction error conditions with find
sl@0
  1360
@SYMTestPriority High
sl@0
  1361
@SYMTestActions Start a transaction and perform some problematic find operations. Test to see if it fails transactions or not.
sl@0
  1362
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1363
@SYMPREQ PREQ752
sl@0
  1364
*/
sl@0
  1365
LOCAL_C void TransactionErrorConditionsForFindL()
sl@0
  1366
	{
sl@0
  1367
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0161 "));
sl@0
  1368
	TInt r;
sl@0
  1369
	TUint32 errorId;
sl@0
  1370
	RArray<TUint32> foundIds;
sl@0
  1371
sl@0
  1372
	CRepository* repository1;
sl@0
  1373
sl@0
  1374
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1375
sl@0
  1376
	// Begin transaction for repository1
sl@0
  1377
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1378
	TEST2(r, KErrNone);
sl@0
  1379
sl@0
  1380
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1381
sl@0
  1382
	// Should NOT fail transaction
sl@0
  1383
	r = repository1->FindL(100, 110, foundIds);
sl@0
  1384
	TEST2(r, KErrNotFound);
sl@0
  1385
sl@0
  1386
	foundIds.Reset();
sl@0
  1387
sl@0
  1388
	r = TransactionState(repository1);
sl@0
  1389
	TEST2(r, EReadWriteTransaction);
sl@0
  1390
sl@0
  1391
	r = repository1->CommitTransaction(errorId);
sl@0
  1392
	TEST2(r, KErrNone);
sl@0
  1393
sl@0
  1394
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1395
sl@0
  1396
	r = TransactionState(repository1);
sl@0
  1397
	TEST2(r, ENoTransaction);
sl@0
  1398
sl@0
  1399
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1400
	}
sl@0
  1401
sl@0
  1402
/**
sl@0
  1403
@SYMTestCaseID SYSLIB-CENREP-CT-0162
sl@0
  1404
@SYMTestCaseDesc Test Transaction error conditions with findeq
sl@0
  1405
@SYMTestPriority High
sl@0
  1406
@SYMTestActions Start a transaction and perform some problematic findeq operations. Test to see if it fails transactions or not.
sl@0
  1407
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1408
@SYMPREQ PREQ752
sl@0
  1409
*/
sl@0
  1410
LOCAL_C void TransactionErrorConditionsForFindEqL()
sl@0
  1411
	{
sl@0
  1412
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0162 "));
sl@0
  1413
	TInt r;
sl@0
  1414
	TUint32 errorId;
sl@0
  1415
	RArray<TUint32> foundIds;
sl@0
  1416
sl@0
  1417
	CRepository* repository1;
sl@0
  1418
sl@0
  1419
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1420
sl@0
  1421
	// Begin transaction for repository1
sl@0
  1422
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1423
	TEST2(r, KErrNone);
sl@0
  1424
sl@0
  1425
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1426
sl@0
  1427
	// Should NOT fail transaction
sl@0
  1428
	r = repository1->FindEqL(0, KUnprotectedSettingsMask, KInt2_InitialValue, foundIds);
sl@0
  1429
	TEST2(r, KErrNotFound);
sl@0
  1430
sl@0
  1431
	foundIds.Reset();
sl@0
  1432
sl@0
  1433
	r = TransactionState(repository1);
sl@0
  1434
	TEST2(r, EReadWriteTransaction);
sl@0
  1435
sl@0
  1436
	r = repository1->CommitTransaction(errorId);
sl@0
  1437
	TEST2(r, KErrNone);
sl@0
  1438
sl@0
  1439
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1440
sl@0
  1441
	r = TransactionState(repository1);
sl@0
  1442
	TEST2(r, ENoTransaction);
sl@0
  1443
sl@0
  1444
	// Begin transaction for repository1
sl@0
  1445
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1446
	TEST2(r, KErrNone);
sl@0
  1447
sl@0
  1448
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1449
sl@0
  1450
	// Should NOT fail transaction
sl@0
  1451
	r = repository1->FindEqL(0, KUnprotectedSettingsMask, KReal2_InitialValue, foundIds);
sl@0
  1452
	TEST2(r, KErrNotFound);
sl@0
  1453
sl@0
  1454
	foundIds.Reset();
sl@0
  1455
sl@0
  1456
	r = TransactionState(repository1);
sl@0
  1457
	TEST2(r, EReadWriteTransaction);
sl@0
  1458
sl@0
  1459
	r = repository1->CommitTransaction(errorId);
sl@0
  1460
	TEST2(r, KErrNone);
sl@0
  1461
sl@0
  1462
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1463
sl@0
  1464
	r = TransactionState(repository1);
sl@0
  1465
	TEST2(r, ENoTransaction);
sl@0
  1466
sl@0
  1467
	// Begin transaction for repository1
sl@0
  1468
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1469
	TEST2(r, KErrNone);
sl@0
  1470
sl@0
  1471
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1472
sl@0
  1473
	// Should NOT fail transaction
sl@0
  1474
	r = repository1->FindEqL(0, KUnprotectedSettingsMask, KString8_InitialValue2, foundIds);
sl@0
  1475
	TEST2(r, KErrNotFound);
sl@0
  1476
sl@0
  1477
	foundIds.Reset();
sl@0
  1478
sl@0
  1479
	r = TransactionState(repository1);
sl@0
  1480
	TEST2(r, EReadWriteTransaction);
sl@0
  1481
sl@0
  1482
	r = repository1->CommitTransaction(errorId);
sl@0
  1483
	TEST2(r, KErrNone);
sl@0
  1484
sl@0
  1485
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1486
sl@0
  1487
	r = TransactionState(repository1);
sl@0
  1488
	TEST2(r, ENoTransaction);
sl@0
  1489
sl@0
  1490
	// Begin transaction for repository1
sl@0
  1491
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1492
	TEST2(r, KErrNone);
sl@0
  1493
sl@0
  1494
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1495
sl@0
  1496
	// Should NOT fail transaction
sl@0
  1497
	r = repository1->FindEqL(0, KUnprotectedSettingsMask, KString16_InitialValue2, foundIds);
sl@0
  1498
	TEST2(r, KErrNotFound);
sl@0
  1499
sl@0
  1500
	foundIds.Reset();
sl@0
  1501
sl@0
  1502
	r = TransactionState(repository1);
sl@0
  1503
	TEST2(r, EReadWriteTransaction);
sl@0
  1504
sl@0
  1505
	r = repository1->CommitTransaction(errorId);
sl@0
  1506
	TEST2(r, KErrNone);
sl@0
  1507
sl@0
  1508
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1509
sl@0
  1510
	r = TransactionState(repository1);
sl@0
  1511
	TEST2(r, ENoTransaction);
sl@0
  1512
sl@0
  1513
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1514
	}
sl@0
  1515
sl@0
  1516
/**
sl@0
  1517
@SYMTestCaseID SYSLIB-CENREP-CT-0163
sl@0
  1518
@SYMTestCaseDesc Test Transaction error conditions with findneq
sl@0
  1519
@SYMTestPriority High
sl@0
  1520
@SYMTestActions Start a transaction and perform some problematic findneq operations. Test to see if it fails transactions or not.
sl@0
  1521
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1522
@SYMPREQ PREQ752
sl@0
  1523
*/
sl@0
  1524
LOCAL_C void TransactionErrorConditionsForFindNeqL()
sl@0
  1525
	{
sl@0
  1526
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0163 "));
sl@0
  1527
	TInt r;
sl@0
  1528
	TUint32 errorId;
sl@0
  1529
	RArray<TUint32> foundIds;
sl@0
  1530
sl@0
  1531
	CRepository* repository1;
sl@0
  1532
sl@0
  1533
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1534
sl@0
  1535
	// Begin transaction for repository1
sl@0
  1536
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1537
	TEST2(r, KErrNone);
sl@0
  1538
sl@0
  1539
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1540
sl@0
  1541
	// Should NOT fail transaction
sl@0
  1542
	r = repository1->FindNeqL(100, 110, KInt1_InitialValue, foundIds);
sl@0
  1543
	TEST2(r, KErrNotFound);
sl@0
  1544
sl@0
  1545
	foundIds.Reset();
sl@0
  1546
sl@0
  1547
	r = TransactionState(repository1);
sl@0
  1548
	TEST2(r, EReadWriteTransaction);
sl@0
  1549
sl@0
  1550
	r = repository1->CommitTransaction(errorId);
sl@0
  1551
	TEST2(r, KErrNone);
sl@0
  1552
sl@0
  1553
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1554
sl@0
  1555
	r = TransactionState(repository1);
sl@0
  1556
	TEST2(r, ENoTransaction);
sl@0
  1557
sl@0
  1558
	// Begin transaction for repository1
sl@0
  1559
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1560
	TEST2(r, KErrNone);
sl@0
  1561
sl@0
  1562
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1563
sl@0
  1564
	// Should NOT fail transaction
sl@0
  1565
	r = repository1->FindNeqL(100, 110, KReal1_InitialValue, foundIds);
sl@0
  1566
	TEST2(r, KErrNotFound);
sl@0
  1567
sl@0
  1568
	foundIds.Reset();
sl@0
  1569
sl@0
  1570
	r = TransactionState(repository1);
sl@0
  1571
	TEST2(r, EReadWriteTransaction);
sl@0
  1572
sl@0
  1573
	r = repository1->CommitTransaction(errorId);
sl@0
  1574
	TEST2(r, KErrNone);
sl@0
  1575
sl@0
  1576
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1577
sl@0
  1578
	r = TransactionState(repository1);
sl@0
  1579
	TEST2(r, ENoTransaction);
sl@0
  1580
sl@0
  1581
	// Begin transaction for repository1
sl@0
  1582
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1583
	TEST2(r, KErrNone);
sl@0
  1584
sl@0
  1585
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1586
sl@0
  1587
	// Should NOT fail transaction
sl@0
  1588
	r = repository1->FindNeqL(100, 110, KString8_InitialValue, foundIds);
sl@0
  1589
	TEST2(r, KErrNotFound);
sl@0
  1590
sl@0
  1591
	foundIds.Reset();
sl@0
  1592
sl@0
  1593
	r = TransactionState(repository1);
sl@0
  1594
	TEST2(r, EReadWriteTransaction);
sl@0
  1595
sl@0
  1596
	r = repository1->CommitTransaction(errorId);
sl@0
  1597
	TEST2(r, KErrNone);
sl@0
  1598
sl@0
  1599
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1600
sl@0
  1601
	r = TransactionState(repository1);
sl@0
  1602
	TEST2(r, ENoTransaction);
sl@0
  1603
sl@0
  1604
	// Begin transaction for repository1
sl@0
  1605
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1606
	TEST2(r, KErrNone);
sl@0
  1607
sl@0
  1608
	repository1->CleanupRollbackTransactionPushL();
sl@0
  1609
sl@0
  1610
	// Should NOT fail transaction
sl@0
  1611
	r = repository1->FindNeqL(100, 110, KString16_InitialValue, foundIds);
sl@0
  1612
	TEST2(r, KErrNotFound);
sl@0
  1613
sl@0
  1614
	foundIds.Reset();
sl@0
  1615
sl@0
  1616
	r = TransactionState(repository1);
sl@0
  1617
	TEST2(r, EReadWriteTransaction);
sl@0
  1618
sl@0
  1619
	r = repository1->CommitTransaction(errorId);
sl@0
  1620
	TEST2(r, KErrNone);
sl@0
  1621
sl@0
  1622
	CleanupStack::Pop();				// CleanupRollbackTransaction
sl@0
  1623
sl@0
  1624
	r = TransactionState(repository1);
sl@0
  1625
	TEST2(r, ENoTransaction);
sl@0
  1626
sl@0
  1627
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1628
	}
sl@0
  1629
sl@0
  1630
/**
sl@0
  1631
@SYMTestCaseID SYSLIB-CENREP-CT-0164
sl@0
  1632
@SYMTestCaseDesc Test Transaction error conditions with create
sl@0
  1633
@SYMTestPriority High
sl@0
  1634
@SYMTestActions Start a transaction and perform some problematic create operations. Test to see if it fails transactions or not.
sl@0
  1635
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1636
@SYMPREQ PREQ752
sl@0
  1637
*/
sl@0
  1638
LOCAL_C void TransactionErrorConditionsForCreateL()
sl@0
  1639
	{
sl@0
  1640
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0164 "));
sl@0
  1641
	TInt r;
sl@0
  1642
	TUint32 errorId;
sl@0
  1643
sl@0
  1644
	CRepository* repository1;
sl@0
  1645
sl@0
  1646
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1647
sl@0
  1648
	// Begin transaction for repository1
sl@0
  1649
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1650
	TEST2(r, KErrNone);
sl@0
  1651
sl@0
  1652
	// Should fail the transaction
sl@0
  1653
	r = repository1->Create(KInt1, KInt1_InitialValue);
sl@0
  1654
	TEST2(r, KErrAlreadyExists);
sl@0
  1655
sl@0
  1656
	r = TransactionState(repository1);
sl@0
  1657
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
  1658
sl@0
  1659
	r = repository1->CommitTransaction(errorId);
sl@0
  1660
	TEST2(r, KErrAlreadyExists);
sl@0
  1661
	TEST2(errorId, KInt1);
sl@0
  1662
sl@0
  1663
	r = TransactionState(repository1);
sl@0
  1664
	TEST2(r, ENoTransaction);
sl@0
  1665
sl@0
  1666
	// Begin transaction for repository1
sl@0
  1667
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1668
	TEST2(r, KErrNone);
sl@0
  1669
sl@0
  1670
	// Should fail the transaction
sl@0
  1671
	r = repository1->Create(KReal1, KReal1_InitialValue);
sl@0
  1672
	TEST2(r, KErrAlreadyExists);
sl@0
  1673
sl@0
  1674
	r = TransactionState(repository1);
sl@0
  1675
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
  1676
sl@0
  1677
	r = repository1->CommitTransaction(errorId);
sl@0
  1678
	TEST2(r, KErrAlreadyExists);
sl@0
  1679
	TEST2(errorId, KReal1);
sl@0
  1680
sl@0
  1681
	r = TransactionState(repository1);
sl@0
  1682
	TEST2(r, ENoTransaction);
sl@0
  1683
sl@0
  1684
	// Begin transaction for repository1
sl@0
  1685
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1686
	TEST2(r, KErrNone);
sl@0
  1687
sl@0
  1688
	// Should fail the transaction
sl@0
  1689
	r = repository1->Create(KString8, KString8_InitialValue);
sl@0
  1690
	TEST2(r, KErrAlreadyExists);
sl@0
  1691
sl@0
  1692
	r = TransactionState(repository1);
sl@0
  1693
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
  1694
sl@0
  1695
	r = repository1->CommitTransaction(errorId);
sl@0
  1696
	TEST2(r, KErrAlreadyExists);
sl@0
  1697
	TEST2(errorId, KString8);
sl@0
  1698
sl@0
  1699
	r = TransactionState(repository1);
sl@0
  1700
	TEST2(r, ENoTransaction);
sl@0
  1701
sl@0
  1702
	// Begin transaction for repository1
sl@0
  1703
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1704
	TEST2(r, KErrNone);
sl@0
  1705
sl@0
  1706
	// Should fail the transaction
sl@0
  1707
	r = repository1->Create(KString16, KString16_InitialValue);
sl@0
  1708
	TEST2(r, KErrAlreadyExists);
sl@0
  1709
sl@0
  1710
	r = TransactionState(repository1);
sl@0
  1711
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
  1712
sl@0
  1713
	r = repository1->CommitTransaction(errorId);
sl@0
  1714
	TEST2(r, KErrAlreadyExists);
sl@0
  1715
	TEST2(errorId, KString16);
sl@0
  1716
sl@0
  1717
	r = TransactionState(repository1);
sl@0
  1718
	TEST2(r, ENoTransaction);
sl@0
  1719
sl@0
  1720
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1721
	}
sl@0
  1722
sl@0
  1723
/**
sl@0
  1724
@SYMTestCaseID SYSLIB-CENREP-CT-0165
sl@0
  1725
@SYMTestCaseDesc Test Transaction error conditions with delete
sl@0
  1726
@SYMTestPriority High
sl@0
  1727
@SYMTestActions Start a transaction and perform some problematic delete operations. Test to see if it fails transactions or not.
sl@0
  1728
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1729
@SYMPREQ PREQ752
sl@0
  1730
*/
sl@0
  1731
LOCAL_C void TransactionErrorConditionsForDeleteL()
sl@0
  1732
	{
sl@0
  1733
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0165 "));
sl@0
  1734
	TInt r;
sl@0
  1735
	TUint32 errorId;
sl@0
  1736
sl@0
  1737
	CRepository* repository1;
sl@0
  1738
sl@0
  1739
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1740
sl@0
  1741
	// Begin transaction for repository1
sl@0
  1742
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1743
	TEST2(r, KErrNone);
sl@0
  1744
sl@0
  1745
	// Delete KInt2 which does not exist
sl@0
  1746
	r = repository1->Delete(KInt2);
sl@0
  1747
	TEST2(r, KErrNotFound);
sl@0
  1748
sl@0
  1749
	r = TransactionState(repository1);
sl@0
  1750
	TEST2(r, EReadWriteTransaction);
sl@0
  1751
sl@0
  1752
	r = repository1->CommitTransaction(errorId);
sl@0
  1753
	TEST2(r, KErrNone);
sl@0
  1754
sl@0
  1755
	r = TransactionState(repository1);
sl@0
  1756
	TEST2(r, ENoTransaction);
sl@0
  1757
sl@0
  1758
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1759
	}
sl@0
  1760
sl@0
  1761
/**
sl@0
  1762
@SYMTestCaseID SYSLIB-CENREP-CT-0166
sl@0
  1763
@SYMTestCaseDesc Test Transaction error conditions with set
sl@0
  1764
@SYMTestPriority High
sl@0
  1765
@SYMTestActions Start a transaction and perform some problematic set operations. Test to see if it fails transactions or not.
sl@0
  1766
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1767
@SYMPREQ PREQ752
sl@0
  1768
*/
sl@0
  1769
LOCAL_C void TransactionErrorConditionsForSetL()
sl@0
  1770
	{
sl@0
  1771
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0166 "));
sl@0
  1772
	TInt r;
sl@0
  1773
	TUint32 errorId;
sl@0
  1774
    TInt i;
sl@0
  1775
sl@0
  1776
	CRepository* repository1;
sl@0
  1777
sl@0
  1778
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1779
sl@0
  1780
	// Begin transaction for repository1
sl@0
  1781
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1782
	TEST2(r, KErrNone);
sl@0
  1783
sl@0
  1784
	r = repository1->Get(KInt2, i);
sl@0
  1785
	TEST2(r, KErrNotFound);
sl@0
  1786
sl@0
  1787
	// Set KInt2 which does not exist
sl@0
  1788
	r = repository1->Set(KInt2, KInt2_InitialValue);
sl@0
  1789
	TEST2(r, KErrNone);
sl@0
  1790
sl@0
  1791
	r = repository1->Get(KInt2, i);
sl@0
  1792
	TEST2(r, KErrNone);
sl@0
  1793
    TEST2(i, KInt2_InitialValue);
sl@0
  1794
sl@0
  1795
    // Set KInt2 to a value of real type
sl@0
  1796
    r = repository1->Set(KInt2, KReal2_InitialValue);
sl@0
  1797
    TEST2(r, KErrArgument);
sl@0
  1798
sl@0
  1799
	r = TransactionState(repository1);
sl@0
  1800
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
  1801
sl@0
  1802
	r = repository1->CommitTransaction(errorId);
sl@0
  1803
	TEST2(r, KErrArgument);
sl@0
  1804
	TEST2(errorId, KInt2);
sl@0
  1805
sl@0
  1806
	r = TransactionState(repository1);
sl@0
  1807
	TEST2(r, ENoTransaction);
sl@0
  1808
sl@0
  1809
	// Begin transaction for repository1
sl@0
  1810
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1811
	TEST2(r, KErrNone);
sl@0
  1812
sl@0
  1813
	r = repository1->Set(KInt2, KInt2_InitialValue + 1);
sl@0
  1814
	TEST2(r, KErrNone);
sl@0
  1815
sl@0
  1816
	// Set KInt2 to a value of string8 type
sl@0
  1817
	r = repository1->Set(KInt2, KString8_InitialValue);
sl@0
  1818
	TEST2(r, KErrArgument);
sl@0
  1819
sl@0
  1820
	r = TransactionState(repository1);
sl@0
  1821
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
  1822
sl@0
  1823
	r = repository1->CommitTransaction(errorId);
sl@0
  1824
	TEST2(r, KErrArgument);
sl@0
  1825
	TEST2(errorId, KInt2);
sl@0
  1826
sl@0
  1827
	r = TransactionState(repository1);
sl@0
  1828
	TEST2(r, ENoTransaction);
sl@0
  1829
sl@0
  1830
	// Begin transaction for repository1
sl@0
  1831
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1832
	TEST2(r, KErrNone);
sl@0
  1833
sl@0
  1834
	r = repository1->Set(KInt2, KInt2_InitialValue + 1);
sl@0
  1835
	TEST2(r, KErrNone);
sl@0
  1836
sl@0
  1837
	// Set KInt2 to a value of string16 type
sl@0
  1838
	r = repository1->Set(KInt2, KString16_InitialValue);
sl@0
  1839
	TEST2(r, KErrArgument);
sl@0
  1840
sl@0
  1841
	r = TransactionState(repository1);
sl@0
  1842
	TEST2(r, EReadWriteTransaction | EFailedBit);
sl@0
  1843
sl@0
  1844
	r = repository1->CommitTransaction(errorId);
sl@0
  1845
	TEST2(r, KErrArgument);
sl@0
  1846
	TEST2(errorId, KInt2);
sl@0
  1847
sl@0
  1848
	r = TransactionState(repository1);
sl@0
  1849
	TEST2(r, ENoTransaction);
sl@0
  1850
sl@0
  1851
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1852
	}
sl@0
  1853
sl@0
  1854
/**
sl@0
  1855
@SYMTestCaseID SYSLIB-CENREP-CT-0167
sl@0
  1856
@SYMTestCaseDesc Test Transaction error conditions with move
sl@0
  1857
@SYMTestPriority High
sl@0
  1858
@SYMTestActions Start a transaction and perform some problematic move operations. Test to see if it fails transactions or not.
sl@0
  1859
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1860
@SYMPREQ PREQ752
sl@0
  1861
*/
sl@0
  1862
LOCAL_C void TransactionErrorConditionsForMoveL()
sl@0
  1863
	{
sl@0
  1864
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0167 "));
sl@0
  1865
	TInt r;
sl@0
  1866
	TUint32 errorId;
sl@0
  1867
sl@0
  1868
	CRepository* repository1;
sl@0
  1869
sl@0
  1870
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1871
sl@0
  1872
	// Begin transaction for repository1
sl@0
  1873
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1874
	TEST2(r, KErrNone);
sl@0
  1875
sl@0
  1876
	// Move a set of keys which does not exist
sl@0
  1877
	r = repository1->Move(KMoveSourceDoesntExist, KMoveTarget, KMoveMask, errorId) ;
sl@0
  1878
	TEST2(r, KErrNotFound);
sl@0
  1879
sl@0
  1880
	r = TransactionState(repository1);
sl@0
  1881
	TEST2(r, EReadWriteTransaction);
sl@0
  1882
sl@0
  1883
	r = repository1->Move(KInt1, KInt1, KMoveMask, errorId) ;
sl@0
  1884
	TEST2(r, KErrNone);
sl@0
  1885
sl@0
  1886
	r = TransactionState(repository1);
sl@0
  1887
	TEST2(r, EReadWriteTransaction);
sl@0
  1888
sl@0
  1889
	r = repository1->CommitTransaction(errorId);
sl@0
  1890
	TEST2(r, KErrNone);
sl@0
  1891
sl@0
  1892
	r = TransactionState(repository1);
sl@0
  1893
	TEST2(r, ENoTransaction);
sl@0
  1894
sl@0
  1895
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1896
	}
sl@0
  1897
sl@0
  1898
/**
sl@0
  1899
@SYMTestCaseID SYSLIB-CENREP-CT-0168
sl@0
  1900
@SYMTestCaseDesc Test move operation with more comprehensive test cases
sl@0
  1901
@SYMTestPriority High
sl@0
  1902
@SYMTestActions Start a transaction and try to perform some problematic move operations. Check result of operation.
sl@0
  1903
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1904
@SYMPREQ PREQ752
sl@0
  1905
*/
sl@0
  1906
LOCAL_C void TransactionConditionsForMoveL()
sl@0
  1907
	{
sl@0
  1908
	// More comprehensive test cases for MOVE
sl@0
  1909
sl@0
  1910
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0168 "));
sl@0
  1911
	TInt r;
sl@0
  1912
	TUint32 errorId;
sl@0
  1913
	TBuf8<16> buf8Val;
sl@0
  1914
sl@0
  1915
	CRepository* repository1;
sl@0
  1916
sl@0
  1917
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1918
sl@0
  1919
	// Begin transaction for repository1
sl@0
  1920
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  1921
	TEST2(r, KErrNone);
sl@0
  1922
sl@0
  1923
	// Move a set of keys which does not exist
sl@0
  1924
	r = repository1->Move(KNewString8, KMoveTarget, KMoveMask, errorId);
sl@0
  1925
	TEST2(r, KErrNotFound);
sl@0
  1926
sl@0
  1927
	r = TransactionState(repository1);
sl@0
  1928
	TEST2(r, EReadWriteTransaction);
sl@0
  1929
sl@0
  1930
	r = repository1->Create(KNewString8, KString8_InitialValue2);
sl@0
  1931
	TEST2(r, KErrNone);
sl@0
  1932
sl@0
  1933
	//Move KNewString8 to KMoveTarget
sl@0
  1934
	r = repository1->Move(KNewString8, KMoveTarget, KMoveMask, errorId);
sl@0
  1935
	TEST2(r, KErrNone);
sl@0
  1936
sl@0
  1937
	r = repository1->Get(KNewString8, buf8Val);
sl@0
  1938
	TEST2(r, KErrNotFound);
sl@0
  1939
sl@0
  1940
	r = TransactionState(repository1);
sl@0
  1941
	TEST2(r, EReadWriteTransaction);
sl@0
  1942
sl@0
  1943
	// Move keys back again
sl@0
  1944
	r = repository1->Move(KMoveTarget, KNewString8, KMoveMask, errorId);
sl@0
  1945
	TEST2(r, KErrNone);
sl@0
  1946
sl@0
  1947
	r = repository1->Get(KNewString8, buf8Val);
sl@0
  1948
	TEST2(r, KErrNone);
sl@0
  1949
	TEST(buf8Val==KString8_InitialValue2);
sl@0
  1950
sl@0
  1951
	r = repository1->CommitTransaction(errorId);
sl@0
  1952
	TEST2(r, KErrNone);
sl@0
  1953
sl@0
  1954
	// Reset the test by deleting KNewString8...
sl@0
  1955
	r = repository1->Delete(KNewString8);
sl@0
  1956
	TEST2(r, KErrNone);
sl@0
  1957
sl@0
  1958
	CleanupStack::PopAndDestroy(repository1);
sl@0
  1959
	}
sl@0
  1960
sl@0
  1961
/**
sl@0
  1962
@SYMTestCaseID SYSLIB-CENREP-CT-0169
sl@0
  1963
@SYMTestCaseDesc Test concurrent read and write transactions
sl@0
  1964
@SYMTestPriority High
sl@0
  1965
@SYMTestActions Start a concurrent read write transaction and perform some operations. Check the state of transaction
sl@0
  1966
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  1967
@SYMPREQ PREQ752
sl@0
  1968
*/
sl@0
  1969
LOCAL_C void ConcurrentReadWriteTransactionStatesL()
sl@0
  1970
	{
sl@0
  1971
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0169 "));
sl@0
  1972
	TInt r;
sl@0
  1973
	TUint32 errorId;
sl@0
  1974
	TReal getValue;
sl@0
  1975
sl@0
  1976
	CRepository* repository1;
sl@0
  1977
sl@0
  1978
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  1979
sl@0
  1980
	// Begin transaction for repository1
sl@0
  1981
	r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
  1982
	TEST2(r, KErrNone);
sl@0
  1983
sl@0
  1984
	r = TransactionState(repository1);
sl@0
  1985
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
  1986
sl@0
  1987
	r = repository1->Create(KReal2, KReal2_InitialValue);
sl@0
  1988
	TEST2(r, KErrNone);
sl@0
  1989
sl@0
  1990
	r = repository1->Get(KReal2, getValue);
sl@0
  1991
	TEST2(r, KErrNone);
sl@0
  1992
sl@0
  1993
	// Fail transaction should roll back transaction i.e. Create KReal2 should not work.
sl@0
  1994
	repository1->FailTransaction();
sl@0
  1995
sl@0
  1996
	r = TransactionState(repository1);
sl@0
  1997
	TEST2(r, EConcurrentReadWriteTransaction | EFailedBit);
sl@0
  1998
sl@0
  1999
	// Commit transaction
sl@0
  2000
	r = repository1->CommitTransaction(errorId);
sl@0
  2001
	TEST2(r, KErrAbort);
sl@0
  2002
sl@0
  2003
	// Try to get a value which should not exist as transaction failed
sl@0
  2004
	r = repository1->Get(KReal2, getValue);
sl@0
  2005
	TEST2(r, KErrNotFound);
sl@0
  2006
sl@0
  2007
	r = TransactionState(repository1);
sl@0
  2008
	TEST2(r, ENoTransaction);
sl@0
  2009
sl@0
  2010
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2011
	}
sl@0
  2012
sl@0
  2013
/**
sl@0
  2014
@SYMTestCaseID SYSLIB-CENREP-CT-0170
sl@0
  2015
@SYMTestCaseDesc Test concurrent read and write transaction with read operations
sl@0
  2016
@SYMTestPriority High
sl@0
  2017
@SYMTestActions Start a concurrent read write and a read transaction and perform some read operations. Check the state of transaction
sl@0
  2018
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  2019
@SYMPREQ PREQ752
sl@0
  2020
*/
sl@0
  2021
LOCAL_C void ConcurrentReadWriteTransactionWithReadOperationsL()
sl@0
  2022
	{
sl@0
  2023
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENREP-CT-0170 "));
sl@0
  2024
	TInt r;
sl@0
  2025
	TUint32 errorId;
sl@0
  2026
	TReal getValue;
sl@0
  2027
sl@0
  2028
	CRepository* repository1;
sl@0
  2029
	CRepository* repository2;
sl@0
  2030
	CRepository* repository3;
sl@0
  2031
sl@0
  2032
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  2033
	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository));
sl@0
  2034
	User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository));
sl@0
  2035
sl@0
  2036
	// Begin concurrent read write transaction for repository1
sl@0
  2037
	r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
  2038
	TEST2(r, KErrNone);
sl@0
  2039
sl@0
  2040
	// Begin read transaction for repository2
sl@0
  2041
	r = repository2->StartTransaction(CRepository::EReadTransaction);
sl@0
  2042
sl@0
  2043
	r = TransactionState(repository1);
sl@0
  2044
	TEST2(r, EConcurrentReadWriteTransaction);
sl@0
  2045
sl@0
  2046
	r = TransactionState(repository2);
sl@0
  2047
	TEST2(r, EReadTransaction);
sl@0
  2048
sl@0
  2049
	// Create value in with a concurrent read write transaction
sl@0
  2050
	r = repository1->Create(KReal2, KReal2_InitialValue);
sl@0
  2051
	TEST2(r, KErrNone);
sl@0
  2052
sl@0
  2053
	// Get value set using another transaction
sl@0
  2054
	r = repository2->Get(KReal1, getValue);
sl@0
  2055
	TEST2(r, KErrNone);
sl@0
  2056
	TEST(getValue == KReal1_InitialValue);
sl@0
  2057
sl@0
  2058
	// Get value set outside of a transaction using repository3
sl@0
  2059
	r = repository3->Get(KReal1, getValue);
sl@0
  2060
	TEST2(r, KErrNone);
sl@0
  2061
	TEST(getValue == KReal1_InitialValue);
sl@0
  2062
sl@0
  2063
	// Get value set within another transaction but not commited, within a transaction
sl@0
  2064
	r = repository2->Get(KReal2, getValue);
sl@0
  2065
	TEST2(r, KErrNotFound);
sl@0
  2066
sl@0
  2067
	// Get value set within another transaction but not commited, outside of a transaction
sl@0
  2068
	r = repository3->Get(KReal2, getValue);
sl@0
  2069
	TEST2(r, KErrNotFound);
sl@0
  2070
sl@0
  2071
	// Commit repository2
sl@0
  2072
	r = repository2->CommitTransaction(errorId);
sl@0
  2073
	TEST2(r, KErrNone);
sl@0
  2074
sl@0
  2075
	// Commit repository1
sl@0
  2076
	r = repository1->CommitTransaction(errorId);
sl@0
  2077
	TEST2(r, KErrNone);
sl@0
  2078
sl@0
  2079
	CleanupStack::PopAndDestroy(repository3);
sl@0
  2080
	CleanupStack::PopAndDestroy(repository2);
sl@0
  2081
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2082
sl@0
  2083
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  2084
sl@0
  2085
	// Check that value was persisted
sl@0
  2086
	r = repository1->Get(KReal2, getValue);
sl@0
  2087
	TEST2(r, KErrNone);
sl@0
  2088
	TEST(getValue == KReal2_InitialValue);
sl@0
  2089
sl@0
  2090
	// Delete KReal2 to reset available test case variables
sl@0
  2091
	r = repository1->Delete(KReal2);
sl@0
  2092
	TEST2(r, KErrNone);
sl@0
  2093
sl@0
  2094
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2095
	}
sl@0
  2096
sl@0
  2097
LOCAL_C void Defect058796()
sl@0
  2098
	{
sl@0
  2099
	TInt r;
sl@0
  2100
	TUint32 errorId;
sl@0
  2101
sl@0
  2102
	TBuf8<2> buf8ValSmall;
sl@0
  2103
	TBuf16<2> buf16ValSmall;
sl@0
  2104
sl@0
  2105
	TBuf8<16> buf8Val;
sl@0
  2106
	TBuf16<16> buf16Val;
sl@0
  2107
sl@0
  2108
	TInt length;
sl@0
  2109
sl@0
  2110
	CRepository* repository1;
sl@0
  2111
sl@0
  2112
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  2113
sl@0
  2114
	// Start a read write transaction
sl@0
  2115
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  2116
	TEST2(r, KErrNone);
sl@0
  2117
sl@0
  2118
	// Try to get a string value using a TBuf8 with length which is too small
sl@0
  2119
	r = repository1->Get(KString8, buf8ValSmall, length);
sl@0
  2120
	TEST2(r, KErrOverflow);
sl@0
  2121
	TEST(buf8ValSmall == KString8_Small_Value);
sl@0
  2122
	TEST2(length, 13);
sl@0
  2123
sl@0
  2124
	// Try to get a string value using a TBuf16 with length which is too small
sl@0
  2125
	r = repository1->Get(KString16, buf16ValSmall, length);
sl@0
  2126
	TEST2(r, KErrOverflow);
sl@0
  2127
	TEST(buf16ValSmall == KString16_Small_Value);
sl@0
  2128
	TEST2(length, 13);
sl@0
  2129
sl@0
  2130
	// Set KNewString16 and KNewString8
sl@0
  2131
	r = repository1->Create(KNewString16, KString16_InitialValue2);
sl@0
  2132
	TEST2(r, KErrNone);
sl@0
  2133
	r = repository1->Create(KNewString8, KString8_InitialValue2);
sl@0
  2134
	TEST2(r, KErrNone);
sl@0
  2135
sl@0
  2136
	// Try to get KNewString16 with a TBuf16 which is a suitable size
sl@0
  2137
	r = repository1->Get(KNewString16, buf16Val, length);
sl@0
  2138
	TEST2(r, KErrNone);
sl@0
  2139
	TEST(buf16Val == KString16_InitialValue2);
sl@0
  2140
	TEST2(length, 16);
sl@0
  2141
sl@0
  2142
	// Try to get KNewString8 with a TBuf8 which is a suitable size
sl@0
  2143
	r = repository1->Get(KNewString8, buf8Val, length);
sl@0
  2144
	TEST2(r, KErrNone);
sl@0
  2145
	TEST(buf8Val == KString8_InitialValue2);
sl@0
  2146
	TEST2(length, 16);
sl@0
  2147
sl@0
  2148
	// Commit the transaction
sl@0
  2149
	r = repository1->CommitTransaction(errorId);
sl@0
  2150
	TEST2(r, KErrNone);
sl@0
  2151
sl@0
  2152
	// Delete KNewString8 to reset available test case variables
sl@0
  2153
	r = repository1->Delete(KNewString8);
sl@0
  2154
	TEST2(r, KErrNone);
sl@0
  2155
sl@0
  2156
	// Delete KNewString16 to reset available test case variables
sl@0
  2157
	r = repository1->Delete(KNewString16);
sl@0
  2158
	TEST2(r, KErrNone);
sl@0
  2159
sl@0
  2160
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2161
	}
sl@0
  2162
sl@0
  2163
sl@0
  2164
LOCAL_C void UnloadedPolicyKeyTest()
sl@0
  2165
	{
sl@0
  2166
	TInt r;
sl@0
  2167
	TUint32 KeyId;
sl@0
  2168
	CRepository* repository1;
sl@0
  2169
sl@0
  2170
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  2171
sl@0
  2172
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  2173
	TEST2(r, KErrNone);
sl@0
  2174
sl@0
  2175
	//Creating Single Policy Key
sl@0
  2176
	r = repository1->Create(KInt5, KInt5_SecondValue );
sl@0
  2177
	TEST2(r,KErrNone);
sl@0
  2178
sl@0
  2179
	//Creating Ranged Policy Key
sl@0
  2180
	r = repository1->Create(KInt3, KInt3_InitialValue);
sl@0
  2181
	TEST2(r, KErrNone);
sl@0
  2182
sl@0
  2183
	//Creating Default Policy Key
sl@0
  2184
	r = repository1->Create(KInt4, KInt4_InitialValue);
sl@0
  2185
	TEST2(r,KErrNone);
sl@0
  2186
sl@0
  2187
	//Waiting for enough time for the repository to be evicted
sl@0
  2188
	User::After(1000000);
sl@0
  2189
sl@0
  2190
	r = repository1->CommitTransaction(KeyId);
sl@0
  2191
	TEST2(r, KErrNone);
sl@0
  2192
	TEST2(KeyId, 3);
sl@0
  2193
sl@0
  2194
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  2195
	TEST2(r, KErrNone);
sl@0
  2196
sl@0
  2197
	//Deleting Default Policy Key
sl@0
  2198
	r = repository1->Delete(KInt5);
sl@0
  2199
	TEST2(r, KErrNone);
sl@0
  2200
sl@0
  2201
	//Deleting Ranged Policy Key
sl@0
  2202
	r = repository1->Delete(KInt3);
sl@0
  2203
	TEST2(r, KErrNone);
sl@0
  2204
sl@0
  2205
	//Deleting Single Policy Key
sl@0
  2206
	r = repository1->Delete(KInt4);
sl@0
  2207
	TEST2(r, KErrNone);
sl@0
  2208
sl@0
  2209
	r = repository1->CommitTransaction(KeyId);
sl@0
  2210
	TEST2(r, KErrNone);
sl@0
  2211
	TEST2(KeyId, 3);
sl@0
  2212
sl@0
  2213
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2214
	}
sl@0
  2215
sl@0
  2216
/**
sl@0
  2217
@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-3239
sl@0
  2218
@SYMTestCaseDesc Test for corrupt access policy when a repository is evicted and reloaded during a transaction
sl@0
  2219
@SYMTestPriority High
sl@0
  2220
@SYMTestActions Start a transaction and create keys with different access policies but evicts the repository prior to commiting it
sl@0
  2221
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  2222
@SYMDEF DEF095718
sl@0
  2223
*/
sl@0
  2224
LOCAL_C void Defect095718()
sl@0
  2225
	{
sl@0
  2226
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3239 "));
sl@0
  2227
	CRepository* repository1;
sl@0
  2228
	TInt r;
sl@0
  2229
	TUint32 KeyId;
sl@0
  2230
	TBuf<KMaxFileName> src1;
sl@0
  2231
	TBuf<KMaxFileName> dest1;
sl@0
  2232
	_LIT(KDest, "c:\\private\\10202BE9\\centrep.ini");
sl@0
  2233
	_LIT(KSrc, "z:\\private\\10202BE9\\centrepcache.ini10");
sl@0
  2234
	_LIT( KCentralRepositoryServerName, "Centralrepositorysrv");
sl@0
  2235
	const TInt test_total = 3; //The test runs 3 times
sl@0
  2236
sl@0
  2237
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  2238
sl@0
  2239
	r = repository1->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  2240
	TEST2(r, KErrNone);
sl@0
  2241
sl@0
  2242
	//Deleting the existing key so that we can re-create it later
sl@0
  2243
	r = repository1->Delete(KInt5);
sl@0
  2244
	TEST2(r, KErrNone);
sl@0
  2245
sl@0
  2246
	r = repository1->CommitTransaction(KeyId);
sl@0
  2247
	TEST2(r, KErrNone);
sl@0
  2248
	TEST2(KeyId, 1);
sl@0
  2249
sl@0
  2250
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2251
sl@0
  2252
	//Kill the server so that a new .ini file can be loaded when the server restarts
sl@0
  2253
	KillProcess(KCentralRepositoryServerName);
sl@0
  2254
	//Copy the .ini file from z: to c: so the server will load it
sl@0
  2255
	RFs FileServer;
sl@0
  2256
	FileServer.Connect();
sl@0
  2257
	CleanupClosePushL(FileServer);
sl@0
  2258
	CFileMan* fm = CFileMan::NewL(FileServer);
sl@0
  2259
	CleanupStack::PushL(fm);
sl@0
  2260
	dest1.Copy(KDest);
sl@0
  2261
	src1.Copy(KSrc);
sl@0
  2262
	r = fm->Delete(dest1);
sl@0
  2263
	User::LeaveIfError(fm->Copy(src1,dest1));
sl@0
  2264
	r = fm->Attribs(dest1, KEntryAttArchive, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse);
sl@0
  2265
	TEST2(r, KErrNone);
sl@0
  2266
sl@0
  2267
	//Test for unloaded policy key a set amount of times
sl@0
  2268
	for(TInt i=0; i<test_total; i++)
sl@0
  2269
		{
sl@0
  2270
		//Check that the policy key used isn't from the unloaded/evicted repository
sl@0
  2271
		UnloadedPolicyKeyTest();
sl@0
  2272
		}
sl@0
  2273
sl@0
  2274
	//Deleting the ini file so that default values will be used again
sl@0
  2275
	r = fm->Delete(dest1);
sl@0
  2276
	TEST2(r, KErrNone);
sl@0
  2277
sl@0
  2278
	//Killing the server and restarting it so that default values are loaded
sl@0
  2279
	KillProcess(KCentralRepositoryServerName);
sl@0
  2280
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  2281
sl@0
  2282
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2283
	CleanupStack::PopAndDestroy(fm);
sl@0
  2284
	CleanupStack::PopAndDestroy();
sl@0
  2285
	}
sl@0
  2286
sl@0
  2287
/**
sl@0
  2288
@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-CT-3243
sl@0
  2289
@SYMTestCaseDesc Test that a repository client can be reused after a CommitTransaction and CancelTransaction Operation involving mulitple concurrent transactions
sl@0
  2290
@SYMTestPriority High
sl@0
  2291
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  2292
@SYMTestActions Start concurrent transactions and create keys in each one. Cancel one transaction and commit the others. Then restart the transactions to test for panics
sl@0
  2293
@SYMDEF DEF098242
sl@0
  2294
*/
sl@0
  2295
LOCAL_C void Defect098242()
sl@0
  2296
	{
sl@0
  2297
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-CT-3243 "));
sl@0
  2298
	TInt r;
sl@0
  2299
	TUint32 KeyId;
sl@0
  2300
	CRepository* repository1;
sl@0
  2301
	CRepository* repository2;
sl@0
  2302
	CRepository* repository3;
sl@0
  2303
	User::LeaveIfNull(repository1 = CRepository::NewLC(KUidTestRepository));
sl@0
  2304
	User::LeaveIfNull(repository2 = CRepository::NewLC(KUidTestRepository));
sl@0
  2305
	User::LeaveIfNull(repository3 = CRepository::NewLC(KUidTestRepository));
sl@0
  2306
sl@0
  2307
	//Starting 3 transactions
sl@0
  2308
	r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
  2309
	TEST2(r, KErrNone);
sl@0
  2310
sl@0
  2311
	r = repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
  2312
	TEST2(r, KErrNone);
sl@0
  2313
sl@0
  2314
	r = repository3->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
  2315
	TEST2(r, KErrNone);
sl@0
  2316
sl@0
  2317
	//Adding values in each
sl@0
  2318
	r = repository1->Create(KInt2, KInt2_InitialValue);
sl@0
  2319
	TEST2(r, KErrNone);
sl@0
  2320
sl@0
  2321
	r = repository2->Create(KInt3, KInt3_InitialValue);
sl@0
  2322
	TEST2(r, KErrNone);
sl@0
  2323
sl@0
  2324
	r = repository3->Create(KInt4, KInt4_InitialValue);
sl@0
  2325
	TEST2(r, KErrNone);
sl@0
  2326
sl@0
  2327
	//Cancel the transaction of the first client
sl@0
  2328
	repository1->CancelTransaction();
sl@0
  2329
sl@0
  2330
	//Committing the other 2 transactions
sl@0
  2331
	r = repository2->CommitTransaction(KeyId);
sl@0
  2332
	TEST2(r, KErrNone);
sl@0
  2333
	TEST2(KeyId,1);
sl@0
  2334
sl@0
  2335
	r = repository3->CommitTransaction(KeyId);
sl@0
  2336
	TEST2(r, KErrLocked);
sl@0
  2337
	TEST2(KeyId,KUnspecifiedKey);
sl@0
  2338
sl@0
  2339
	//Try Re-starting a transaction with the clients
sl@0
  2340
	r = repository1->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
  2341
	TEST2(r, KErrNone);
sl@0
  2342
	r = repository1->CommitTransaction(KeyId);
sl@0
  2343
	TEST2(r, KErrNone);
sl@0
  2344
	TEST2(KeyId,0);
sl@0
  2345
sl@0
  2346
	r = repository2->StartTransaction(CRepository::EConcurrentReadWriteTransaction);
sl@0
  2347
	TEST2(r, KErrNone);
sl@0
  2348
sl@0
  2349
	//Deleting the key so the repository is in the same state as prior to the function call
sl@0
  2350
	r = repository2->Delete(KInt3);
sl@0
  2351
	TEST2(r, KErrNone);
sl@0
  2352
sl@0
  2353
	//Checking that these values were not made persistent
sl@0
  2354
	r = repository2->Delete(KInt2);
sl@0
  2355
	TEST2(r, KErrNotFound);
sl@0
  2356
sl@0
  2357
	r = repository2->Delete(KInt4);
sl@0
  2358
	TEST2(r, KErrNotFound);
sl@0
  2359
sl@0
  2360
	r = repository2->CommitTransaction(KeyId);
sl@0
  2361
	TEST2(r, KErrNone);
sl@0
  2362
	TEST2(KeyId,1);
sl@0
  2363
sl@0
  2364
	r = repository1->Reset();
sl@0
  2365
	TEST2(r, KErrNone);
sl@0
  2366
sl@0
  2367
	CleanupStack::PopAndDestroy(repository3);
sl@0
  2368
	CleanupStack::PopAndDestroy(repository2);
sl@0
  2369
	CleanupStack::PopAndDestroy(repository1);
sl@0
  2370
	}
sl@0
  2371
sl@0
  2372
/**
sl@0
  2373
@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4011
sl@0
  2374
@SYMTestCaseDesc  Test for PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly
sl@0
  2375
@SYMTestPriority High
sl@0
  2376
@SYMTestActions The test uses the 00112273.TXT ini file, where the default meta data value is set to be 0x00100000.
sl@0
  2377
				The test creates a CRepository object with UID=0x00112273 and creates a single integer setting with
sl@0
  2378
				value 1 and no meta data. In this case the setting meta data should be the default one - 0x00100000.
sl@0
  2379
				Then the test begins a transaction and within the transaction: the setting gets deleted and then - recreated
sl@0
  2380
				again but with a different value and no meta data. The transaction is commited.
sl@0
  2381
				The setting meta data value should be 0x00100000 within the transaction and outisde the transaction.
sl@0
  2382
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  2383
@SYMDEF PDEF112273
sl@0
  2384
*/
sl@0
  2385
void DoPDEF112273Test1L()
sl@0
  2386
	{
sl@0
  2387
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4011 "));
sl@0
  2388
	const TUid KTestCenRepUid = {0x00112273};
sl@0
  2389
	CRepository* repository = CRepository::NewLC(KTestCenRepUid);
sl@0
  2390
	//Create a setting
sl@0
  2391
	const TInt KTestSettingId = 123;
sl@0
  2392
	TInt err = repository->Create(KTestSettingId, 1);
sl@0
  2393
	TEST2(err, KErrNone);
sl@0
  2394
sl@0
  2395
	const TUint32 KDefaultMeta = 0x00100000;
sl@0
  2396
	//Check setting meta. The meta value should be KDefaultMeta.
sl@0
  2397
	TUint32 meta = 0;
sl@0
  2398
	err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2399
	TEST2(err, KErrNone);
sl@0
  2400
	TEST2(meta, KDefaultMeta);
sl@0
  2401
sl@0
  2402
	err = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  2403
	TEST2(err, KErrNone);
sl@0
  2404
	//In a transaction. Delete the created setting.
sl@0
  2405
	err = repository->Delete(KTestSettingId);
sl@0
  2406
	TEST2(err, KErrNone);
sl@0
  2407
	//In a transaction. Re-create the deleted setting but with a different value.
sl@0
  2408
	err = repository->Create(KTestSettingId, 2);
sl@0
  2409
	TEST2(err, KErrNone);
sl@0
  2410
	//In a transaction. Get the setting meta. The meta value should be KDefaultMeta.
sl@0
  2411
	err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2412
	TEST2(err, KErrNone);
sl@0
  2413
	TEST2(meta, KDefaultMeta);
sl@0
  2414
sl@0
  2415
	TUint32 keyInfo = 0;
sl@0
  2416
	err = repository->CommitTransaction(keyInfo);
sl@0
  2417
	TEST2(err, KErrNone);
sl@0
  2418
sl@0
  2419
	//Not in transaction. Get the setting meta. The meta value should be KDefaultMeta.
sl@0
  2420
	err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2421
	TEST2(err, KErrNone);
sl@0
  2422
	TEST2(meta, KDefaultMeta);
sl@0
  2423
sl@0
  2424
	CleanupStack::PopAndDestroy(repository);
sl@0
  2425
	}
sl@0
  2426
sl@0
  2427
/**
sl@0
  2428
@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4012
sl@0
  2429
@SYMTestCaseDesc  Test for PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly
sl@0
  2430
@SYMTestPriority High
sl@0
  2431
@SYMTestActions The test uses the 00112273.TXT ini file, where the default meta data value is set to be 0x00100000.
sl@0
  2432
				The test creates a CRepository object with UID=0x00112273.
sl@0
  2433
				Then the test begins a transaction and within the transaction: setting with id=0x0000001 (from the ini file)
sl@0
  2434
				and setting meta=0x00200000 will be deleted and then recreated again with a different value and no meta.
sl@0
  2435
				The transaction is commited.
sl@0
  2436
				The setting meta data value should be 0x00200000 within the transaction and outisde the transaction.
sl@0
  2437
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  2438
@SYMDEF PDEF112273
sl@0
  2439
*/
sl@0
  2440
void DoPDEF112273Test2L()
sl@0
  2441
	{
sl@0
  2442
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4012 "));
sl@0
  2443
	const TUid KTestCenRepUid = {0x00112273};
sl@0
  2444
	CRepository* repository = CRepository::NewLC(KTestCenRepUid);
sl@0
  2445
	//Ini file - KTestSettingId setting properties:
sl@0
  2446
	const TInt KTestSettingId = 0x0000001;
sl@0
  2447
	const TInt KTestSettingVal = 1;
sl@0
  2448
	const TUint32 KSettingMeta = 0x00200000;
sl@0
  2449
	//Check setting meta. The meta value should be KDefaultMeta.
sl@0
  2450
	TUint32 meta = 0;
sl@0
  2451
	TInt err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2452
	TEST2(err, KErrNone);
sl@0
  2453
	TEST2(meta, KSettingMeta);
sl@0
  2454
sl@0
  2455
	err = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  2456
	TEST2(err, KErrNone);
sl@0
  2457
	//In a transaction. Delete the created setting.
sl@0
  2458
	err = repository->Delete(KTestSettingId);
sl@0
  2459
	TEST2(err, KErrNone);
sl@0
  2460
	//In a transaction. Re-create the deleted setting with different value.
sl@0
  2461
	err = repository->Create(KTestSettingId, KTestSettingVal + 1);
sl@0
  2462
	TEST2(err, KErrNone);
sl@0
  2463
	//In a transaction. Get the setting meta. The meta value should be KSettingMeta.
sl@0
  2464
	err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2465
	TEST2(err, KErrNone);
sl@0
  2466
	TEST2(meta, KSettingMeta);
sl@0
  2467
sl@0
  2468
	TUint32 keyInfo = 0;
sl@0
  2469
	err = repository->CommitTransaction(keyInfo);
sl@0
  2470
	TEST2(err, KErrNone);
sl@0
  2471
sl@0
  2472
	//Not in transaction. Get the setting meta. The meta value should be KSettingMeta.
sl@0
  2473
	err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2474
	TEST2(err, KErrNone);
sl@0
  2475
	TEST2(meta, KSettingMeta);
sl@0
  2476
sl@0
  2477
	CleanupStack::PopAndDestroy(repository);
sl@0
  2478
	}
sl@0
  2479
sl@0
  2480
/**
sl@0
  2481
@SYMTestCaseID SYSLIB-CENTRALREPOSITORY-UT-4013
sl@0
  2482
@SYMTestCaseDesc  Test for PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly
sl@0
  2483
@SYMTestPriority High
sl@0
  2484
@SYMTestActions The test uses the 00112273.TXT ini file, where the default meta data value is set to be 0x00100000.
sl@0
  2485
				The test creates a CRepository object with UID=0x00112273.
sl@0
  2486
				Then the test begins a transaction and within the transaction: a new setting with no meta is created.
sl@0
  2487
				The transaction is commited.
sl@0
  2488
				The setting meta data value should be 0x00100000 within the transaction and outisde the transaction.
sl@0
  2489
@SYMTestExpectedResults The test should not fail with any panics
sl@0
  2490
@SYMDEF PDEF112273
sl@0
  2491
*/
sl@0
  2492
void DoPDEF112273Test3L()
sl@0
  2493
	{
sl@0
  2494
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-UT-4013 "));
sl@0
  2495
	const TUid KTestCenRepUid = {0x00112273};
sl@0
  2496
	CRepository* repository = CRepository::NewLC(KTestCenRepUid);
sl@0
  2497
sl@0
  2498
	TInt err = repository->StartTransaction(CRepository::EReadWriteTransaction);
sl@0
  2499
	TEST2(err, KErrNone);
sl@0
  2500
	//In a transaction. Create a setting
sl@0
  2501
	const TInt KTestSettingId = 1234;
sl@0
  2502
	err = repository->Create(KTestSettingId, 1);
sl@0
  2503
	TEST2(err, KErrNone);
sl@0
  2504
sl@0
  2505
	const TUint32 KDefaultMeta = 0x00100000;
sl@0
  2506
	TUint32 meta = 0;
sl@0
  2507
	//In a transaction. Get the setting meta. The meta value should be KDefaultMeta.
sl@0
  2508
	err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2509
	TEST2(err, KErrNone);
sl@0
  2510
	TEST2(meta, KDefaultMeta);
sl@0
  2511
sl@0
  2512
	TUint32 keyInfo = 0;
sl@0
  2513
	err = repository->CommitTransaction(keyInfo);
sl@0
  2514
	TEST2(err, KErrNone);
sl@0
  2515
sl@0
  2516
	//Not in transaction. Get the setting meta. The meta value should be KDefaultMeta.
sl@0
  2517
	err = repository->GetMeta(KTestSettingId, meta);
sl@0
  2518
	TEST2(err, KErrNone);
sl@0
  2519
	TEST2(meta, KDefaultMeta);
sl@0
  2520
sl@0
  2521
	CleanupStack::PopAndDestroy(repository);
sl@0
  2522
	}
sl@0
  2523
sl@0
  2524
void PDEF112273L()
sl@0
  2525
	{
sl@0
  2526
	DoPDEF112273Test1L();
sl@0
  2527
	DoPDEF112273Test2L();
sl@0
  2528
	DoPDEF112273Test3L();
sl@0
  2529
	}
sl@0
  2530
sl@0
  2531
LOCAL_C void TransactionsFuncTestsL()
sl@0
  2532
	{
sl@0
  2533
	TheTest.Next(_L("Committing changes causes other sessions' active transactions to fail with KErrLocked"));
sl@0
  2534
	CommittingChangesFailsOtherTransactionsL();
sl@0
  2535
sl@0
  2536
	TheTest.Next(_L("Committing no changes does not fail other sessions' active transactions"));
sl@0
  2537
	CommittingNoChangesDoesNotFailOtherTransactionsL();
sl@0
  2538
sl@0
  2539
	TheTest.Start(_L("Create values using transaction"));
sl@0
  2540
	CreateValueUsingTransactionL();
sl@0
  2541
sl@0
  2542
	TheTest.Next(_L("Get transaction state in transactions and test for rollback in failed transactions"));
sl@0
  2543
	TransactionStateAndRollBackL();
sl@0
  2544
sl@0
  2545
	TheTest.Next(_L("Multiple Read-Write Transaction error and panic conditions"));
sl@0
  2546
	TransactionPanicConditionsThread();
sl@0
  2547
sl@0
  2548
	TheTest.Next(_L("Commit Transaction error and panic condition"));
sl@0
  2549
	CommitTransactionPanicConditionsThread();
sl@0
  2550
sl@0
  2551
	TheTest.Next(_L("Clean up using rollback and failed transactions"));
sl@0
  2552
	CleanupRollBackAndFailTransactionL();
sl@0
  2553
sl@0
  2554
	TheTest.Next(_L("Multiple Read Transaction conditions"));
sl@0
  2555
	ReadTransactionConditionsL();
sl@0
  2556
sl@0
  2557
	TheTest.Next(_L("Multiple Read Transaction with upgrade error conditions"));
sl@0
  2558
	UpgradeReadTransactionErrorConditionsL();
sl@0
  2559
sl@0
  2560
	TheTest.Next(_L("Transaction conditions with read operations"));
sl@0
  2561
	TransactionConditionsForReadL();
sl@0
  2562
sl@0
  2563
	TheTest.Next(_L("Transaction error conditions with get operations"));
sl@0
  2564
	TransactionErrorConditionsForGetL();
sl@0
  2565
sl@0
  2566
	TheTest.Next(_L("Transaction error conditions with find operations"));
sl@0
  2567
	TransactionErrorConditionsForFindL();
sl@0
  2568
sl@0
  2569
	TheTest.Next(_L("Transaction error conditions with findeq operations"));
sl@0
  2570
	TransactionErrorConditionsForFindEqL();
sl@0
  2571
sl@0
  2572
	TheTest.Next(_L("Transaction error conditions with findneq operations"));
sl@0
  2573
	TransactionErrorConditionsForFindNeqL();
sl@0
  2574
sl@0
  2575
	TheTest.Next(_L("Transaction error conditions with create operations"));
sl@0
  2576
	TransactionErrorConditionsForCreateL();
sl@0
  2577
sl@0
  2578
	TheTest.Next(_L("Transaction error conditions with delete operations"));
sl@0
  2579
	TransactionErrorConditionsForDeleteL();
sl@0
  2580
sl@0
  2581
	TheTest.Next(_L("Transaction error conditions with set operations"));
sl@0
  2582
	TransactionErrorConditionsForSetL();
sl@0
  2583
sl@0
  2584
	TheTest.Next(_L("Transaction error conditions with move operations"));
sl@0
  2585
	TransactionErrorConditionsForMoveL();
sl@0
  2586
sl@0
  2587
	TheTest.Next(_L("Transaction conditions with move operations"));
sl@0
  2588
	TransactionConditionsForMoveL();
sl@0
  2589
sl@0
  2590
	// Concurrent read/write transactions...
sl@0
  2591
sl@0
  2592
	TheTest.Next(_L("Concurrent read/write transaction"));
sl@0
  2593
	ConcurrentReadWriteTransactionStatesL();
sl@0
  2594
sl@0
  2595
	TheTest.Next(_L("Concurrent read/write transaction with other reads operations"));
sl@0
  2596
	ConcurrentReadWriteTransactionWithReadOperationsL();
sl@0
  2597
sl@0
  2598
	// Test cases for defects ...
sl@0
  2599
sl@0
  2600
	TheTest.Next(_L("Tests for get functions, as required in DEF058796"));
sl@0
  2601
	Defect058796();
sl@0
  2602
sl@0
  2603
	TheTest.Next(_L("Checks for corrupt policy keys, as required in DEF095718"));
sl@0
  2604
	Defect095718();
sl@0
  2605
sl@0
  2606
	TheTest.Next(_L("Test for restarting a transaction from the same client, as required in DEF098242"));
sl@0
  2607
	Defect098242();
sl@0
  2608
sl@0
  2609
	TheTest.Next(_L("PDEF112273 - When creating commsdat Backup & restore metadata is not set correctly"));
sl@0
  2610
	PDEF112273L();
sl@0
  2611
sl@0
  2612
	TheTest.End();
sl@0
  2613
	}
sl@0
  2614
sl@0
  2615
LOCAL_C void MainL()
sl@0
  2616
	{
sl@0
  2617
	TheTest.Start(_L("Central Repository transactions functional tests"));
sl@0
  2618
	CleanupCDriveL();
sl@0
  2619
	TransactionsFuncTestsL();
sl@0
  2620
sl@0
  2621
	TheTest.Next(_L("Clean out C: files"));
sl@0
  2622
	CleanupCDriveL();
sl@0
  2623
sl@0
  2624
	TheTest.End();
sl@0
  2625
	TheTest.Close();
sl@0
  2626
	}
sl@0
  2627
sl@0
  2628
TInt E32Main()
sl@0
  2629
	{
sl@0
  2630
	__UHEAP_MARK;
sl@0
  2631
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
  2632
	if(!cleanup)
sl@0
  2633
		return KErrNoMemory;
sl@0
  2634
sl@0
  2635
	TRAPD(err, MainL());
sl@0
  2636
	if (err != KErrNone)
sl@0
  2637
		User::Panic(_L("Testing failed: "), err);
sl@0
  2638
sl@0
  2639
	delete cleanup;
sl@0
  2640
	__UHEAP_MARKEND;
sl@0
  2641
sl@0
  2642
	return 0;
sl@0
  2643
	}
sl@0
  2644