os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_bug.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) 1998-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
// Test code for bugs that have been fixed, to help prevent regression
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <d32dbms.h>
sl@0
    19
#include <f32file.h>
sl@0
    20
#include <e32test.h>
sl@0
    21
#include <s32mem.h>
sl@0
    22
#include "crccheck.h"
sl@0
    23
sl@0
    24
#undef __UHEAP_MARK
sl@0
    25
#undef __UHEAP_MARKEND
sl@0
    26
#define __UHEAP_MARK
sl@0
    27
#define __UHEAP_MARKEND
sl@0
    28
sl@0
    29
LOCAL_D TDBMS_CRCChecks TheCrcChecker;
sl@0
    30
sl@0
    31
#ifndef __linux__ //No CRC test on LINUX
sl@0
    32
#ifdef __TOOLS2__
sl@0
    33
const TPtrC	KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_BUG.CRC");
sl@0
    34
#else
sl@0
    35
const TPtrC	KCrcRecord=_L("C:\\dbms-tst\\T_BUG.CRC");
sl@0
    36
#endif
sl@0
    37
#endif
sl@0
    38
sl@0
    39
LOCAL_D RTest test(_L("T_BUG"));
sl@0
    40
LOCAL_D CTrapCleanup* TheTrapCleanup;
sl@0
    41
LOCAL_D RFs TheFs;
sl@0
    42
LOCAL_D RDbNamedDatabase TheDatabase;
sl@0
    43
sl@0
    44
const TInt KTestCleanupStack=0x40;
sl@0
    45
sl@0
    46
void Check(TInt aValue,TInt aExpected,TInt aLine)
sl@0
    47
	{
sl@0
    48
	if (aValue!=aExpected)
sl@0
    49
		{
sl@0
    50
		test.Printf(_L("*** Expected %d: got %d\r\n"),aExpected,aValue);
sl@0
    51
		test.operator()(EFalse,aLine);
sl@0
    52
		}
sl@0
    53
	}
sl@0
    54
#define test2(a,b) Check(a,b,__LINE__)
sl@0
    55
sl@0
    56
static void Print(const TText* aString)
sl@0
    57
	{
sl@0
    58
	test.Printf(_L("%s\n"),aString);
sl@0
    59
	}
sl@0
    60
sl@0
    61
////////////////////////////////////////////
sl@0
    62
sl@0
    63
sl@0
    64
#ifdef __TOOLS2__
sl@0
    65
const TPtrC KTestDatabase=_L(".\\dbms-tst\\t_bug.db");
sl@0
    66
#else
sl@0
    67
const TPtrC KTestDatabase=_L("C:\\dbms-tst\\t_bug.db");
sl@0
    68
#endif
sl@0
    69
sl@0
    70
_LIT(KTableA,"A");
sl@0
    71
_LIT(KTableB,"B");
sl@0
    72
_LIT(KTableC,"C");
sl@0
    73
sl@0
    74
class Defect_590829
sl@0
    75
	{
sl@0
    76
public:
sl@0
    77
	static void TestL();
sl@0
    78
	static const TDesC& Name();
sl@0
    79
	};
sl@0
    80
sl@0
    81
sl@0
    82
const TDesC& Defect_590829::Name()
sl@0
    83
	{
sl@0
    84
	_LIT(KName,"590829");
sl@0
    85
	return KName;
sl@0
    86
	}
sl@0
    87
sl@0
    88
/////////////////////////////////////////////////
sl@0
    89
sl@0
    90
// Length of text data used for each entry. This will be
sl@0
    91
// equivalent to 400 bytes for ansi characters. The number of
sl@0
    92
// bytes must not be less than 256 (or 128 for this const).
sl@0
    93
// If it is a stream will not be used for transfer of data.
sl@0
    94
const TInt KTextDataLength = 200;
sl@0
    95
sl@0
    96
// max column size
sl@0
    97
const TInt KMaxColLength = 1000;
sl@0
    98
sl@0
    99
// Buffer size to cause HDbsBuf::DoReadL() ipc check to be executed
sl@0
   100
const TInt KBufSizeDoReadL = 1000;
sl@0
   101
sl@0
   102
// Buffer size to cause HDbsBuf::UnderflowL() ipc check to be executed
sl@0
   103
const TInt KBufSizeUnderflowL = 500;
sl@0
   104
sl@0
   105
class Defect_071149
sl@0
   106
	{
sl@0
   107
public:
sl@0
   108
	static void TestL();
sl@0
   109
	static const TDesC& Name();
sl@0
   110
	};
sl@0
   111
sl@0
   112
sl@0
   113
const TDesC& Defect_071149::Name()
sl@0
   114
	{
sl@0
   115
	_LIT(KName,"071149");
sl@0
   116
	return KName;
sl@0
   117
	}
sl@0
   118
sl@0
   119
/**
sl@0
   120
HDbsBuf did not handle case when iIpc.iHandle is 0 causing IPC calls to panic.
sl@0
   121
The handle is 0 when opening a stream and all data is retrieved in this request.
sl@0
   122
sl@0
   123
@SYMTestCaseID			SYSLIB-DBMS-CT-1491
sl@0
   124
@SYMTestCaseDesc		Tests for defect number 590829
sl@0
   125
@SYMTestPriority			High
sl@0
   126
@SYMTestActions			Tests by setting up failure conditions.
sl@0
   127
@SYMTestExpectedResults	Test must not fail
sl@0
   128
@SYMDEF				INC071149
sl@0
   129
*/
sl@0
   130
void Defect_071149::TestL()
sl@0
   131
	{
sl@0
   132
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1491 "));
sl@0
   133
	Print(_S("Creating test database"));
sl@0
   134
sl@0
   135
	// Connect to dbms and open db
sl@0
   136
	RDbs dbs;
sl@0
   137
	RDbNamedDatabase db;
sl@0
   138
	test2 (db.Replace(TheFs,KTestDatabase),KErrNone);
sl@0
   139
	db.Close();
sl@0
   140
	TheCrcChecker.GenerateCrcL(KTestDatabase);
sl@0
   141
sl@0
   142
#ifndef __TOOLS2__
sl@0
   143
	test2(dbs.Connect(), KErrNone);
sl@0
   144
#endif
sl@0
   145
	test2(db.Open(dbs,KTestDatabase), KErrNone);
sl@0
   146
sl@0
   147
	// creating column to hold LongText
sl@0
   148
	CDbColSet *colSet = CDbColSet::NewL();
sl@0
   149
	CleanupStack::PushL(colSet);
sl@0
   150
	colSet->AddL(TDbCol(_L("Id"), EDbColLongText, KMaxColLength));
sl@0
   151
	
sl@0
   152
	// create table
sl@0
   153
	test2(db.CreateTable(KTableA, *colSet), KErrNone);
sl@0
   154
	CleanupStack::PopAndDestroy(colSet);
sl@0
   155
	
sl@0
   156
	// create text data to add to table	
sl@0
   157
	HBufC* testText = HBufC::New(KTextDataLength);
sl@0
   158
	test(testText !=NULL );
sl@0
   159
	TPtr ptr = testText->Des();
sl@0
   160
	for(TInt y=0;y<KTextDataLength;++y)
sl@0
   161
		{
sl@0
   162
		ptr.Append(TChar('A'));
sl@0
   163
		}
sl@0
   164
sl@0
   165
	// add data to table
sl@0
   166
	RDbTable newTable;
sl@0
   167
	test2 (newTable.Open(db,KTableA),KErrNone);
sl@0
   168
	db.Begin();
sl@0
   169
	newTable.InsertL();
sl@0
   170
	newTable.SetColL(1, ptr);
sl@0
   171
	newTable.PutL();
sl@0
   172
sl@0
   173
	test2 (db.Commit(),KErrNone);
sl@0
   174
	test2 (newTable.CountL(), 1);
sl@0
   175
	newTable.Close();
sl@0
   176
	
sl@0
   177
	// cleanup
sl@0
   178
	delete testText;
sl@0
   179
sl@0
   180
	// disconnect from db and dbms
sl@0
   181
	db.Close();
sl@0
   182
	TheCrcChecker.GenerateCrcL(KTestDatabase);
sl@0
   183
#ifndef __TOOLS2__
sl@0
   184
	dbs.Close();
sl@0
   185
#endif
sl@0
   186
sl@0
   187
//
sl@0
   188
	// Connect to dbms and open db
sl@0
   189
#ifndef __TOOLS2__
sl@0
   190
	test2(dbs.Connect(), KErrNone);
sl@0
   191
#endif
sl@0
   192
	test2(db.Open(dbs,KTestDatabase), KErrNone);
sl@0
   193
sl@0
   194
	// Test handle check in HDbsBuf::DoReadL() - See defect
sl@0
   195
	// If the handle check did not exist in the production code then
sl@0
   196
	// it would panic.
sl@0
   197
sl@0
   198
	// create test table
sl@0
   199
	RDbTable testTable;
sl@0
   200
	test2 (testTable.Open(db,KTableA),KErrNone);
sl@0
   201
	db.Begin();
sl@0
   202
	testTable.FirstL();
sl@0
   203
	testTable.GetL();
sl@0
   204
	
sl@0
   205
	// Open stream
sl@0
   206
	RDbColReadStream rs;
sl@0
   207
    	rs.OpenLC( testTable, 1);
sl@0
   208
	
sl@0
   209
	// Read data
sl@0
   210
	TBuf<KBufSizeDoReadL> buf;
sl@0
   211
	TRAPD(err, rs.ReadL( buf, buf.MaxLength()));
sl@0
   212
	if(err != KErrNone)
sl@0
   213
		{
sl@0
   214
		test2(err, KErrEof);
sl@0
   215
		}
sl@0
   216
	CleanupStack::PopAndDestroy();  // Close rs
sl@0
   217
	testTable.Close();
sl@0
   218
sl@0
   219
//
sl@0
   220
	// Test handle check in HDbsBuf::UnderflowL() - additional error not in defect
sl@0
   221
	// If the handle check did not exist in the production code then
sl@0
   222
	// it would panic.
sl@0
   223
sl@0
   224
	// create test table
sl@0
   225
	test2 (testTable.Open(db,KTableA),KErrNone);
sl@0
   226
	testTable.NextL();
sl@0
   227
	testTable.GetL();
sl@0
   228
sl@0
   229
	// Open stream
sl@0
   230
	RDbColReadStream rs2;
sl@0
   231
    	rs2.OpenLC( testTable, 1);
sl@0
   232
sl@0
   233
	// Read data
sl@0
   234
	TBuf<KBufSizeUnderflowL> buf2;
sl@0
   235
	TRAP(err, rs2.ReadL( buf2, buf2.MaxLength()));
sl@0
   236
	if(err != KErrNone)
sl@0
   237
		{
sl@0
   238
		test2(err, KErrEof);
sl@0
   239
		}
sl@0
   240
	CleanupStack::PopAndDestroy();  // Close rs
sl@0
   241
sl@0
   242
	// tidy up
sl@0
   243
	testTable.Close();
sl@0
   244
	db.Close();
sl@0
   245
#ifndef __TOOLS2__
sl@0
   246
	dbs.Close();
sl@0
   247
#endif
sl@0
   248
	}
sl@0
   249
sl@0
   250
/////////////////////////////////////////////////
sl@0
   251
sl@0
   252
/**
sl@0
   253
Cached, unused tables were breaking the iterator in CDbTableDatabase::CheckIdle
sl@0
   254
The latter function has been re-written to restart the iteration when tables are Idle()'d
sl@0
   255
sl@0
   256
@SYMTestCaseID          SYSLIB-DBMS-CT-0582
sl@0
   257
@SYMTestCaseDesc        Tests for defect number 590829
sl@0
   258
@SYMTestPriority        Medium
sl@0
   259
@SYMTestActions        	Tests by setting up failure conditions.
sl@0
   260
@SYMTestExpectedResults Test must not fail
sl@0
   261
@SYMREQ                 REQ0000
sl@0
   262
*/
sl@0
   263
void Defect_590829::TestL()
sl@0
   264
	{
sl@0
   265
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0582 "));
sl@0
   266
	Print(_S("Creating test database"));
sl@0
   267
	test2 (TheDatabase.Replace(TheFs,KTestDatabase),KErrNone);
sl@0
   268
	TheDatabase.Begin();
sl@0
   269
	test2 (TheDatabase.Execute(_L("create table A (id counter)")),KErrNone);
sl@0
   270
	test2 (TheDatabase.Execute(_L("create table B (id counter)")),KErrNone);
sl@0
   271
	test2 (TheDatabase.Execute(_L("create table C (id counter)")),KErrNone);
sl@0
   272
	test2 (TheDatabase.Commit(),KErrNone);
sl@0
   273
//
sl@0
   274
	Print(_S("Setting up failure"));
sl@0
   275
	RDbTable tA,tB,tC;
sl@0
   276
	test2 (tA.Open(TheDatabase,KTableA),KErrNone);
sl@0
   277
	test2 (tB.Open(TheDatabase,KTableB),KErrNone);
sl@0
   278
	tB.Close();
sl@0
   279
	test2 (tC.Open(TheDatabase,KTableC),KErrNone);
sl@0
   280
	tC.Close();
sl@0
   281
	TheDatabase.Begin();
sl@0
   282
	tA.Close();
sl@0
   283
//
sl@0
   284
	Print(_S("Testing fix"));
sl@0
   285
	test2 (TheDatabase.Commit(),KErrNone);
sl@0
   286
	TheDatabase.Destroy();
sl@0
   287
	}
sl@0
   288
sl@0
   289
/////////////////////////////////////////////////
sl@0
   290
sl@0
   291
#ifndef TOOLS2_VARIANT
sl@0
   292
class Defect_394751
sl@0
   293
	{
sl@0
   294
public:
sl@0
   295
	static void TestL();
sl@0
   296
	static const TDesC& Name();
sl@0
   297
private:
sl@0
   298
	static TInt Thread(TAny*);
sl@0
   299
	static void ThreadL();
sl@0
   300
	};
sl@0
   301
sl@0
   302
sl@0
   303
const TDesC& Defect_394751::Name()
sl@0
   304
	{
sl@0
   305
	_LIT(KName,"394751");
sl@0
   306
	return KName;
sl@0
   307
	}
sl@0
   308
sl@0
   309
void Defect_394751::ThreadL()
sl@0
   310
	{
sl@0
   311
	RDbs dbs;
sl@0
   312
	RDbNamedDatabase db;
sl@0
   313
	User::LeaveIfError(dbs.Connect());
sl@0
   314
	User::LeaveIfError(db.Open(dbs,KTestDatabase));
sl@0
   315
	db.Begin();
sl@0
   316
	db.Begin();	/// panic now
sl@0
   317
	User::Panic(_L("T_BUG failure"),0);
sl@0
   318
	}
sl@0
   319
sl@0
   320
TInt Defect_394751::Thread(TAny*)
sl@0
   321
	{
sl@0
   322
	User::SetJustInTime(EFalse);	// disable debugger panic handling
sl@0
   323
	CTrapCleanup* cleanup=CTrapCleanup::New();
sl@0
   324
	if (!cleanup)
sl@0
   325
		return KErrNoMemory;
sl@0
   326
	TRAPD(r,ThreadL());
sl@0
   327
	delete cleanup;
sl@0
   328
	return r;
sl@0
   329
	}
sl@0
   330
sl@0
   331
/**
sl@0
   332
@SYMTestCaseID          SYSLIB-DBMS-CT-0583
sl@0
   333
@SYMTestCaseDesc        Tests for defect number 394751 
sl@0
   334
@SYMTestPriority        Medium
sl@0
   335
@SYMTestActions        	Tests for thread exit status.
sl@0
   336
@SYMTestExpectedResults Test must not fail
sl@0
   337
@SYMREQ                 REQ0000
sl@0
   338
*/
sl@0
   339
void Defect_394751::TestL()
sl@0
   340
//
sl@0
   341
//
sl@0
   342
	{
sl@0
   343
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0583 "));
sl@0
   344
	Print(_S("Creating test database"));
sl@0
   345
	test2 (TheDatabase.Replace(TheFs,KTestDatabase),KErrNone);
sl@0
   346
	TheDatabase.Close();
sl@0
   347
	TheCrcChecker.GenerateCrcL(KTestDatabase);
sl@0
   348
//
sl@0
   349
	RDbs dbs;
sl@0
   350
	test2 (dbs.Connect(),KErrNone);
sl@0
   351
//
sl@0
   352
	Print(_S("Running test thread"));
sl@0
   353
	RThread t;
sl@0
   354
	_LIT(KTestThread,"Defect Fix 394751");
sl@0
   355
	test2 (t.Create(KTestThread,&Thread,0x2000,0x1000,0x10000,0,EOwnerThread),KErrNone);
sl@0
   356
	TRequestStatus s;
sl@0
   357
	t.Logon(s);
sl@0
   358
	test2 (s.Int(),KRequestPending);
sl@0
   359
	t.Resume();
sl@0
   360
	Print(_S("Awaiting completion"));
sl@0
   361
	User::WaitForRequest(s);
sl@0
   362
	_LIT(KCategory,"DBMS-Table");
sl@0
   363
	test2 (t.ExitType(),EExitPanic);
sl@0
   364
	test (t.ExitCategory()==KCategory);
sl@0
   365
	test2 (t.ExitReason(),11);		// begin nested transaction
sl@0
   366
	User::SetJustInTime(ETrue);	// enable debugger panic handling
sl@0
   367
	t.Close();
sl@0
   368
//
sl@0
   369
	test2 (dbs.ResourceCount(),0);
sl@0
   370
	dbs.Close();
sl@0
   371
	}
sl@0
   372
#endif
sl@0
   373
sl@0
   374
///////////////////////////////////////////////////////////
sl@0
   375
sl@0
   376
#ifndef TOOLS2_VARIANT
sl@0
   377
class Defect_COMBBAR_463J5D
sl@0
   378
	{
sl@0
   379
public:
sl@0
   380
	static void TestL();
sl@0
   381
	static const TDesC& Name();
sl@0
   382
private:
sl@0
   383
	static void WaitForServerExit();
sl@0
   384
	static TInt Thread(TAny*);
sl@0
   385
	};
sl@0
   386
sl@0
   387
const TDesC& Defect_COMBBAR_463J5D::Name()
sl@0
   388
	{
sl@0
   389
	_LIT(KName,"COMBBAR_463J5D");
sl@0
   390
	return KName;
sl@0
   391
	}
sl@0
   392
sl@0
   393
void Defect_COMBBAR_463J5D::WaitForServerExit()
sl@0
   394
	{
sl@0
   395
	_LIT(KDbmsServer,"*!DBMS server");
sl@0
   396
	TFullName n;
sl@0
   397
	TFindThread ft(KDbmsServer);
sl@0
   398
	if (ft.Next(n)==KErrNone)
sl@0
   399
		{
sl@0
   400
		RThread t;
sl@0
   401
		if (t.Open(ft)==KErrNone)
sl@0
   402
			{
sl@0
   403
			TRequestStatus s;
sl@0
   404
			t.Logon(s);
sl@0
   405
			User::WaitForRequest(s);
sl@0
   406
			t.Close();
sl@0
   407
			}
sl@0
   408
		}
sl@0
   409
	}
sl@0
   410
sl@0
   411
TInt Defect_COMBBAR_463J5D::Thread(TAny*)
sl@0
   412
//
sl@0
   413
// Just try to start the server
sl@0
   414
//
sl@0
   415
	{
sl@0
   416
	RDbs dbs;
sl@0
   417
	return dbs.Connect();
sl@0
   418
	}
sl@0
   419
sl@0
   420
/**
sl@0
   421
@SYMTestCaseID          SYSLIB-DBMS-CT-0584
sl@0
   422
@SYMTestCaseDesc        Tests for defect number COMBBAR_463J5D  
sl@0
   423
@SYMTestPriority        Medium
sl@0
   424
@SYMTestActions        	Testing that defect COMBBAR_463J5D in ER5 Defects database has been fixed
sl@0
   425
@SYMTestExpectedResults Test must not fail
sl@0
   426
@SYMREQ                 REQ0000
sl@0
   427
*/
sl@0
   428
void Defect_COMBBAR_463J5D::TestL()
sl@0
   429
	{
sl@0
   430
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0584 "));
sl@0
   431
	Print(_S("Wait for the server to exit"));
sl@0
   432
	WaitForServerExit();
sl@0
   433
//
sl@0
   434
	Print(_S("Create the launching threads"));
sl@0
   435
	RThread t1,t2;
sl@0
   436
	TRequestStatus s1,s2;
sl@0
   437
	_LIT(KThread1,"t1");
sl@0
   438
	test2 (t1.Create(KThread1,&Thread,0x2000,0,0,EOwnerThread),KErrNone);
sl@0
   439
	t1.SetPriority(EPriorityLess);
sl@0
   440
	t1.Logon(s1);
sl@0
   441
	_LIT(KThread2,"t2");
sl@0
   442
	test2 (t2.Create(KThread2,&Thread,0x2000,0,0,EOwnerThread),KErrNone);
sl@0
   443
	t2.SetPriority(EPriorityLess);
sl@0
   444
	t2.Logon(s2);
sl@0
   445
//
sl@0
   446
	Print(_S("Run the threads and wait"));
sl@0
   447
	t1.Resume();
sl@0
   448
	t2.Resume();
sl@0
   449
	User::WaitForRequest(s1,s2);
sl@0
   450
	if (s1==KRequestPending)
sl@0
   451
		User::WaitForRequest(s1);
sl@0
   452
	else
sl@0
   453
		User::WaitForRequest(s2);
sl@0
   454
//
sl@0
   455
	test2 (t1.ExitType(),EExitKill);
sl@0
   456
	if (s1.Int()!=KErrNotFound)
sl@0
   457
		test2 (s1.Int(),KErrNone);
sl@0
   458
	test2 (t2.ExitType(),EExitKill);
sl@0
   459
	if (s2.Int()!=KErrNotFound)
sl@0
   460
		test2 (s2.Int(),KErrNone);
sl@0
   461
	t1.Close();
sl@0
   462
	t2.Close();
sl@0
   463
	}
sl@0
   464
sl@0
   465
#endif
sl@0
   466
/////////////////////////////////////////////////////////
sl@0
   467
sl@0
   468
class Defect_EDNATHE_48AEZW
sl@0
   469
	{
sl@0
   470
public:
sl@0
   471
	static void TestL();
sl@0
   472
	static const TDesC& Name();
sl@0
   473
	};
sl@0
   474
sl@0
   475
const TDesC& Defect_EDNATHE_48AEZW::Name()
sl@0
   476
	{
sl@0
   477
	_LIT(KName,"EDNATHE_48AEZW");
sl@0
   478
	return KName;
sl@0
   479
	}
sl@0
   480
/**
sl@0
   481
@SYMTestCaseID          SYSLIB-DBMS-CT-0585
sl@0
   482
@SYMTestCaseDesc        Tests for defect number EDNATHE_48AEZW  
sl@0
   483
@SYMTestPriority        Medium
sl@0
   484
@SYMTestActions        	Tests for navigation and deletion 
sl@0
   485
@SYMTestExpectedResults Test must not fail
sl@0
   486
@SYMREQ                 REQ0000
sl@0
   487
*/
sl@0
   488
void Defect_EDNATHE_48AEZW::TestL()
sl@0
   489
	{
sl@0
   490
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0585 "));
sl@0
   491
	Print(_S("Set up database"));
sl@0
   492
	test2 (TheDatabase.Replace(TheFs,KTestDatabase),KErrNone);
sl@0
   493
	test2 (TheDatabase.Begin(),KErrNone);
sl@0
   494
	test2 (TheDatabase.Execute(_L("create table A (id counter)")),KErrNone);
sl@0
   495
	RDbView v1;
sl@0
   496
	test2 (v1.Prepare(TheDatabase,_L("select * from A"),v1.EInsertOnly),KErrNone);
sl@0
   497
	test2 (v1.EvaluateAll(),KErrNone);
sl@0
   498
	for (TInt ii=0;ii<4;++ii)
sl@0
   499
		{
sl@0
   500
		v1.InsertL();
sl@0
   501
		v1.PutL();
sl@0
   502
		}
sl@0
   503
	test2 (TheDatabase.Commit(),KErrNone);
sl@0
   504
	v1.Close();
sl@0
   505
//
sl@0
   506
	Print(_S("test navigation"));
sl@0
   507
	test2 (v1.Prepare(TheDatabase,_L("select * from A where id=0")),KErrNone);
sl@0
   508
	test2 (v1.EvaluateAll(),KErrNone);
sl@0
   509
	v1.FirstL();
sl@0
   510
	RDbView v2;
sl@0
   511
	test2 (v2.Prepare(TheDatabase,_L("select * from A where id=1")),KErrNone);
sl@0
   512
	test2 (v2.EvaluateAll(),KErrNone);
sl@0
   513
	v2.FirstL();
sl@0
   514
	v2.DeleteL();
sl@0
   515
	TRAPD(r, v1.NextL());
sl@0
   516
	test2 (r,KErrNone);
sl@0
   517
	test (v1.AtEnd());
sl@0
   518
	v2.Close();
sl@0
   519
//
sl@0
   520
	Print(_S("test deletion"));
sl@0
   521
	v1.FirstL();
sl@0
   522
	test2 (v2.Prepare(TheDatabase,_L("select * from A where id=2")),KErrNone);
sl@0
   523
	test2 (v2.EvaluateAll(),KErrNone);
sl@0
   524
	v2.FirstL();
sl@0
   525
	v2.DeleteL();
sl@0
   526
	TRAP(r,v1.DeleteL());
sl@0
   527
	test2 (r,KErrNone);
sl@0
   528
	TRAP(r, v1.NextL());
sl@0
   529
	test2 (r,KErrNone);
sl@0
   530
	test (v1.AtEnd());
sl@0
   531
//
sl@0
   532
	v1.Close();
sl@0
   533
	v2.Close();
sl@0
   534
	TheDatabase.Close();
sl@0
   535
	TheCrcChecker.GenerateCrcL(KTestDatabase);
sl@0
   536
	}
sl@0
   537
sl@0
   538
/////////////////////////////////////////////////////////
sl@0
   539
sl@0
   540
static void NextTest(const TDesC& aName)
sl@0
   541
	{
sl@0
   542
	TBuf<80> buf;
sl@0
   543
	buf=_S("Checking Defect ");
sl@0
   544
	buf+=aName;
sl@0
   545
	test.Next(buf);
sl@0
   546
	}
sl@0
   547
sl@0
   548
template <typename T>
sl@0
   549
struct RunTest
sl@0
   550
	{
sl@0
   551
	RunTest()
sl@0
   552
		{
sl@0
   553
		const TDesC& name = T::Name();
sl@0
   554
		NextTest(name);
sl@0
   555
		TRAPD(r,T::TestL());
sl@0
   556
		test2 (r,KErrNone);
sl@0
   557
		Print(_S("Defect fixed"));
sl@0
   558
		}
sl@0
   559
	};
sl@0
   560
sl@0
   561
LOCAL_C void setupTestDirectory()
sl@0
   562
//
sl@0
   563
// Prepare the test directory.
sl@0
   564
//
sl@0
   565
    {
sl@0
   566
	TInt r=TheFs.Connect();
sl@0
   567
	test(r==KErrNone);
sl@0
   568
//
sl@0
   569
	r=TheFs.MkDir(KTestDatabase);
sl@0
   570
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   571
	}
sl@0
   572
sl@0
   573
LOCAL_C void setupCleanup()
sl@0
   574
//
sl@0
   575
// Initialise the cleanup stack.
sl@0
   576
//
sl@0
   577
    {
sl@0
   578
	TheTrapCleanup=CTrapCleanup::New();
sl@0
   579
	test(TheTrapCleanup!=NULL);
sl@0
   580
	TRAPD(r,\
sl@0
   581
		{\
sl@0
   582
		for (TInt i=KTestCleanupStack;i>0;i--)\
sl@0
   583
			CleanupStack::PushL((TAny*)0);\
sl@0
   584
		CleanupStack::Pop(KTestCleanupStack);\
sl@0
   585
		});
sl@0
   586
	test(r==KErrNone);
sl@0
   587
	}
sl@0
   588
sl@0
   589
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
   590
	{
sl@0
   591
	RFs fsSession;
sl@0
   592
	TInt err = fsSession.Connect();
sl@0
   593
	if(err == KErrNone)
sl@0
   594
		{
sl@0
   595
		TEntry entry;
sl@0
   596
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   597
			{
sl@0
   598
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0
   599
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   600
			if(err != KErrNone) 
sl@0
   601
				{
sl@0
   602
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   603
				}
sl@0
   604
			err = fsSession.Delete(aFullName);
sl@0
   605
			if(err != KErrNone) 
sl@0
   606
				{
sl@0
   607
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   608
				}
sl@0
   609
			}
sl@0
   610
		fsSession.Close();
sl@0
   611
		}
sl@0
   612
	else
sl@0
   613
		{
sl@0
   614
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   615
		}
sl@0
   616
	}
sl@0
   617
sl@0
   618
sl@0
   619
GLDEF_C TInt E32Main()
sl@0
   620
    {
sl@0
   621
	__UHEAP_MARK;
sl@0
   622
	test.Title();
sl@0
   623
	setupTestDirectory();
sl@0
   624
	setupCleanup();
sl@0
   625
sl@0
   626
	test.Start(_L("Verifying defect fixes"));
sl@0
   627
#ifndef TOOLS2_VARIANT
sl@0
   628
	RunTest<Defect_COMBBAR_463J5D>();
sl@0
   629
#else
sl@0
   630
	test.Printf(_L("Skipping defect test Defect_COMBBAR_463J5D\n"));
sl@0
   631
#endif
sl@0
   632
// The following short delay is needed for ccover builds only.
sl@0
   633
// Without the pause, the kernel scheduler would intermittently 
sl@0
   634
// crash 0.3s after the last test ended.
sl@0
   635
	User::After(500000);
sl@0
   636
	test.Printf(_L("Resume test after delay.\n"));
sl@0
   637
sl@0
   638
#ifndef TOOLS2_VARIANT
sl@0
   639
	RunTest<Defect_394751>();
sl@0
   640
	User::After(500000);
sl@0
   641
	test.Printf(_L("Resume test after delay.\n"));
sl@0
   642
#else
sl@0
   643
	test.Printf(_L("Skipping defect test of Defect_394751\n"));
sl@0
   644
#endif
sl@0
   645
sl@0
   646
	RunTest<Defect_590829>();
sl@0
   647
	User::After(500000);
sl@0
   648
	test.Printf(_L("Resume test after delay.\n"));
sl@0
   649
sl@0
   650
	RunTest<Defect_071149>();
sl@0
   651
	User::After(500000);
sl@0
   652
	test.Printf(_L("Resume test after delay.\n"));
sl@0
   653
sl@0
   654
	RunTest<Defect_EDNATHE_48AEZW>();
sl@0
   655
	test.Next(_L("Waiting for server exit"));
sl@0
   656
	const TUint KExitDelay=6*0x100000;	// ~6 seconds
sl@0
   657
	User::After(KExitDelay);
sl@0
   658
sl@0
   659
	// clean up data files used by this test - must be done before call to End() - DEF047652
sl@0
   660
	::DeleteDataFile(KTestDatabase);
sl@0
   661
sl@0
   662
#ifndef __linux__
sl@0
   663
	TInt err;
sl@0
   664
#ifndef __TOOLS2__
sl@0
   665
	TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
sl@0
   666
	test(err==KErrNone);
sl@0
   667
	test(lc==KErrNone);
sl@0
   668
#else
sl@0
   669
	TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
sl@0
   670
	TPtrC errmsg;
sl@0
   671
	TheCrcChecker.ErrorReportL(err, errmsg);
sl@0
   672
	RDebug::Print(errmsg);
sl@0
   673
	test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
sl@0
   674
#endif // Tools2
sl@0
   675
#endif // Linux
sl@0
   676
sl@0
   677
	test.End();
sl@0
   678
//
sl@0
   679
	delete TheTrapCleanup;
sl@0
   680
sl@0
   681
	TheFs.Close();
sl@0
   682
	test.Close();
sl@0
   683
	__UHEAP_MARKEND;
sl@0
   684
	return 0;
sl@0
   685
    }