os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_window.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
//
sl@0
    15
sl@0
    16
#include <d32dbms.h>
sl@0
    17
#include <s32file.h>
sl@0
    18
#include <e32test.h>
sl@0
    19
sl@0
    20
#include "crccheck.h"
sl@0
    21
sl@0
    22
#undef __UHEAP_MARK
sl@0
    23
#define __UHEAP_MARK
sl@0
    24
#undef __UHEAP_MARKEND
sl@0
    25
#define __UHEAP_MARKEND
sl@0
    26
sl@0
    27
LOCAL_D TDBMS_CRCChecks TheCrcChecker;
sl@0
    28
sl@0
    29
#ifndef __linux__ //No CRC test on LINUX
sl@0
    30
#ifdef __TOOLS2__
sl@0
    31
const TPtrC	KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_WINDOW.CRC");
sl@0
    32
#else
sl@0
    33
const TPtrC	KCrcRecord=_L("C:\\dbms-tst\\T_WINDOW.CRC");
sl@0
    34
#endif
sl@0
    35
#endif
sl@0
    36
sl@0
    37
sl@0
    38
LOCAL_D RTest test(_L("T_WINDOW : Testing the 'window' stage"));
sl@0
    39
LOCAL_D CTrapCleanup* TheTrapCleanup;
sl@0
    40
LOCAL_D CFileStore* TheStore;
sl@0
    41
LOCAL_D RDbStoreDatabase TheDatabase;
sl@0
    42
LOCAL_D RDbView TheView;
sl@0
    43
LOCAL_D RFs TheFs;
sl@0
    44
sl@0
    45
const TInt KTestCleanupStack=0x20;
sl@0
    46
sl@0
    47
#ifdef __TOOLS2__
sl@0
    48
const TPtrC KTestDir=_L(".\\dbms-tst\\");
sl@0
    49
#else
sl@0
    50
const TPtrC KTestDir=_L("C:\\dbms-tst\\");
sl@0
    51
#endif
sl@0
    52
sl@0
    53
const TPtrC KTestFile=_S("T_WINDOW.DB");
sl@0
    54
const TPtrC KTableName=_S("TestTable");
sl@0
    55
const TPtrC KColumnID=_S("id");
sl@0
    56
const TPtrC KIndexName=_S("TestIndex");
sl@0
    57
const TInt KRecords=10;
sl@0
    58
const TPtrC KCreateTable=_L("CREATE TABLE TestTable (id INTEGER NOT NULL)");
sl@0
    59
const TPtrC KCreateIndex=_L("CREATE UNIQUE INDEX TestIndex ON TestTable (id)");
sl@0
    60
const TPtrC KEmptyQuery=_L("select * from TestTable where id is null");
sl@0
    61
const TPtrC KOrderQuery=_L("select * from TestTable order by id");
sl@0
    62
const TDbWindow KSingleSlotWindow(0,0);
sl@0
    63
const TDbWindow KSmallWindow(2,2);
sl@0
    64
const TDbWindow KLargeWindow(20,0);
sl@0
    65
sl@0
    66
//
sl@0
    67
// Create the database-in-a-store
sl@0
    68
//
sl@0
    69
LOCAL_C void CreateDatabaseL()
sl@0
    70
	{
sl@0
    71
	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,KTestFile,EFileRead|EFileWrite);
sl@0
    72
	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0
    73
	TStreamId id;
sl@0
    74
		id=TheDatabase.CreateL(store);
sl@0
    75
	store->SetRootL(id);
sl@0
    76
	store->CommitL();
sl@0
    77
	CleanupStack::Pop();
sl@0
    78
	TheStore=store;
sl@0
    79
	}
sl@0
    80
sl@0
    81
LOCAL_C void CloseDatabaseL()
sl@0
    82
	{
sl@0
    83
	// cannot evaluate size info for store database
sl@0
    84
	RDbDatabase::TSize size=TheDatabase.Size();
sl@0
    85
	test (size.iSize<0);
sl@0
    86
	test (size.iUsage<0);
sl@0
    87
	test (TheDatabase.UpdateStats()==KErrNone);
sl@0
    88
	size=TheDatabase.Size();
sl@0
    89
	test (size.iSize<0);
sl@0
    90
	test (size.iUsage<0);
sl@0
    91
	TheDatabase.Close();
sl@0
    92
	delete TheStore;
sl@0
    93
	
sl@0
    94
	TInt err = TheCrcChecker.GenerateCrcL(KTestFile);
sl@0
    95
	test(err == KErrNone);
sl@0
    96
	}
sl@0
    97
sl@0
    98
LOCAL_C void CreateTable()
sl@0
    99
	{
sl@0
   100
	TheDatabase.Begin();
sl@0
   101
	test(TheDatabase.Execute(KCreateTable)==KErrNone);
sl@0
   102
	RDbTable table;
sl@0
   103
	test(table.Open(TheDatabase,KTableName,table.EInsertOnly)==KErrNone);
sl@0
   104
	for (TInt ii=0;ii<KRecords;++ii)
sl@0
   105
		{
sl@0
   106
		table.InsertL();
sl@0
   107
		table.SetColL(1,ii);
sl@0
   108
		table.PutL();
sl@0
   109
		}
sl@0
   110
	table.Close();
sl@0
   111
	test(TheDatabase.Execute(KCreateIndex)==KErrNone);
sl@0
   112
	test (TheDatabase.Commit()==KErrNone);
sl@0
   113
	}
sl@0
   114
sl@0
   115
LOCAL_C void Init()
sl@0
   116
	{
sl@0
   117
	CreateDatabaseL();
sl@0
   118
	CreateTable();
sl@0
   119
	}
sl@0
   120
sl@0
   121
/**
sl@0
   122
@SYMTestCaseID          SYSLIB-DBMS-CT-0638
sl@0
   123
@SYMTestCaseDesc        Tests for navigation 
sl@0
   124
@SYMTestPriority        Medium
sl@0
   125
@SYMTestActions         Tests for navigation in an empty window
sl@0
   126
@SYMTestExpectedResults Test must not fail
sl@0
   127
@SYMREQ                 REQ0000
sl@0
   128
*/
sl@0
   129
LOCAL_C void TestEmpty()
sl@0
   130
	{
sl@0
   131
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0638 Unevaluated "));
sl@0
   132
	test(TheView.Prepare(TheDatabase,KEmptyQuery,TDbWindow::EUnlimited)==KErrNone);
sl@0
   133
	test(TheView.CountL(TheView.EQuick)==0);
sl@0
   134
	test(!TheView.FirstL());
sl@0
   135
	test(TheView.AtEnd());
sl@0
   136
	test(!TheView.PreviousL());
sl@0
   137
	test(TheView.AtBeginning());
sl@0
   138
	test(!TheView.LastL());
sl@0
   139
	test(TheView.AtBeginning());
sl@0
   140
	test(!TheView.NextL());
sl@0
   141
	test(TheView.AtEnd());
sl@0
   142
	test.Next(_L("Evaluated"));
sl@0
   143
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   144
	test(TheView.CountL()==0);
sl@0
   145
	test(!TheView.FirstL());
sl@0
   146
	test(TheView.AtEnd());
sl@0
   147
	test(!TheView.PreviousL());
sl@0
   148
	test(TheView.AtBeginning());
sl@0
   149
	test(!TheView.LastL());
sl@0
   150
	test(TheView.AtBeginning());
sl@0
   151
	test(!TheView.NextL());
sl@0
   152
	test(TheView.AtEnd());
sl@0
   153
	test.End();
sl@0
   154
	TheView.Close();
sl@0
   155
	}
sl@0
   156
sl@0
   157
/**
sl@0
   158
@SYMTestCaseID          SYSLIB-DBMS-CT-0639
sl@0
   159
@SYMTestCaseDesc        Tests for navigation 
sl@0
   160
@SYMTestPriority        Medium
sl@0
   161
@SYMTestActions         Tests for the unlimited (dynaset) window
sl@0
   162
@SYMTestExpectedResults Test must not fail
sl@0
   163
@SYMREQ                 REQ0000
sl@0
   164
*/
sl@0
   165
LOCAL_C void TestUnlimited()
sl@0
   166
	{
sl@0
   167
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0639 EvaluateAll "));
sl@0
   168
	test(TheView.Prepare(TheDatabase,KOrderQuery,TDbWindow::EUnlimited)==KErrNone);
sl@0
   169
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   170
	test(!TheView.Unevaluated());
sl@0
   171
	test(TheView.CountL()==KRecords);
sl@0
   172
	TInt cc=0;
sl@0
   173
	for (TheView.BeginningL();TheView.NextL();)
sl@0
   174
		++cc;
sl@0
   175
	test(cc==KRecords);
sl@0
   176
	for (TheView.EndL();TheView.PreviousL();)
sl@0
   177
		--cc;
sl@0
   178
	test(cc==0);
sl@0
   179
	test(!TheView.Unevaluated());
sl@0
   180
	test.Next(_L("Incremental evaluate"));
sl@0
   181
	TheView.Reset();
sl@0
   182
	cc=TheView.CountL(TheView.EQuick);
sl@0
   183
	test(cc==0);
sl@0
   184
	test(!TheView.FirstL());
sl@0
   185
	while (TheView.Unevaluated())
sl@0
   186
		{
sl@0
   187
		test(TheView.Evaluate()>=KErrNone);
sl@0
   188
		TInt ii=TheView.CountL()-cc;
sl@0
   189
		test(ii>=0);
sl@0
   190
		cc+=ii;
sl@0
   191
		while (--ii>=0)
sl@0
   192
			{
sl@0
   193
			test(TheView.AtRow());
sl@0
   194
			TheView.NextL();
sl@0
   195
			}
sl@0
   196
		test(!TheView.AtRow());
sl@0
   197
		}
sl@0
   198
	test(cc==KRecords);
sl@0
   199
	test.Next(_L("Insert"));
sl@0
   200
// The new records should go on the end of the set
sl@0
   201
	TheView.InsertL();
sl@0
   202
	TheView.SetColL(1,TInt(-1));
sl@0
   203
	TheView.PutL();
sl@0
   204
	test(TheView.CountL()==KRecords+1);
sl@0
   205
	test(TheView.LastL());
sl@0
   206
	TheView.GetL();
sl@0
   207
	test(TheView.ColInt(1)==-1);
sl@0
   208
// because of order, it should appear at beginning on re-evaluation
sl@0
   209
	TheView.Reset();
sl@0
   210
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   211
	test(TheView.CountL()==KRecords+1);
sl@0
   212
	test(TheView.FirstL());
sl@0
   213
	TheView.GetL();
sl@0
   214
	test(TheView.ColInt(1)==-1);
sl@0
   215
	test.Next(_L("Update"));
sl@0
   216
// updated records should not move (or disappear) in the set
sl@0
   217
	TheView.UpdateL();
sl@0
   218
	TheView.SetColL(1,KRecords);
sl@0
   219
	TheView.PutL();
sl@0
   220
	test(TheView.CountL()==KRecords+1);
sl@0
   221
	test(TheView.FirstL());
sl@0
   222
	TheView.GetL();
sl@0
   223
	test(TheView.ColInt(1)==KRecords);
sl@0
   224
// because of order, it should appear at end on re-evaluation
sl@0
   225
	TheView.Reset();
sl@0
   226
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   227
	test(TheView.CountL()==KRecords+1);
sl@0
   228
	test(TheView.LastL());
sl@0
   229
	TheView.GetL();
sl@0
   230
	test(TheView.ColInt(1)==KRecords);
sl@0
   231
	test.Next(_L("Bookmarks"));
sl@0
   232
	TDbBookmark mark=TheView.Bookmark();
sl@0
   233
	TheView.BeginningL();
sl@0
   234
	TRAPD(r,TheView.GotoL(mark));
sl@0
   235
	test(r==KErrNone);
sl@0
   236
	TheView.GetL();
sl@0
   237
	test(TheView.ColInt(1)==KRecords);
sl@0
   238
	test(!TheView.NextL());
sl@0
   239
	test(TheView.PreviousL());
sl@0
   240
	test.Next(_L("Delete"));
sl@0
   241
// should disappear from the set
sl@0
   242
	TheView.DeleteL();
sl@0
   243
	test(TheView.CountL()==KRecords);
sl@0
   244
	for (TheView.BeginningL();TheView.NextL();)
sl@0
   245
		{
sl@0
   246
		TheView.GetL();
sl@0
   247
		test(TheView.ColInt(1)!=KRecords);
sl@0
   248
		}
sl@0
   249
	TRAP(r,TheView.GotoL(mark));
sl@0
   250
	test(r!=KErrNone);
sl@0
   251
	TheView.Reset();
sl@0
   252
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   253
	test(TheView.CountL()==KRecords);
sl@0
   254
	for (TheView.BeginningL();TheView.NextL();)
sl@0
   255
		{
sl@0
   256
		TheView.GetL();
sl@0
   257
		test(TheView.ColInt(1)!=KRecords);
sl@0
   258
		}
sl@0
   259
	TRAP(r,TheView.GotoL(mark));
sl@0
   260
	test(r!=KErrNone);
sl@0
   261
	test.End();
sl@0
   262
	TheView.Close();
sl@0
   263
	}
sl@0
   264
sl@0
   265
//
sl@0
   266
// do as much incremental evaluation as possible
sl@0
   267
//
sl@0
   268
LOCAL_C void Evaluate()
sl@0
   269
	{
sl@0
   270
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   271
	}
sl@0
   272
sl@0
   273
//
sl@0
   274
// get to the true end of set
sl@0
   275
//
sl@0
   276
LOCAL_C void GotoEnd()
sl@0
   277
	{
sl@0
   278
	for (;;)
sl@0
   279
		{
sl@0
   280
		while (TheView.AtRow())
sl@0
   281
			TheView.NextL();
sl@0
   282
		if (!TheView.Unevaluated())
sl@0
   283
			break;
sl@0
   284
		Evaluate();
sl@0
   285
		}
sl@0
   286
	}
sl@0
   287
sl@0
   288
LOCAL_C void CheckWindow(TInt forward,TInt back)
sl@0
   289
	{
sl@0
   290
	TInt ii;
sl@0
   291
	for (ii=0;ii<forward;++ii)
sl@0
   292
		test(TheView.NextL());
sl@0
   293
	test(!TheView.NextL());
sl@0
   294
	for (ii=0;ii<forward+back+1;++ii)
sl@0
   295
		test(TheView.PreviousL());
sl@0
   296
	test(!TheView.PreviousL());
sl@0
   297
	for (ii=0;ii<back+1;++ii)
sl@0
   298
		test(TheView.NextL());
sl@0
   299
	}
sl@0
   300
sl@0
   301
/**
sl@0
   302
@SYMTestCaseID          SYSLIB-DBMS-CT-0640
sl@0
   303
@SYMTestCaseDesc        Tests for RDbView 
sl@0
   304
@SYMTestPriority        Medium
sl@0
   305
@SYMTestActions         Tests for a restricted sized window
sl@0
   306
@SYMTestExpectedResults Test must not fail
sl@0
   307
@SYMREQ                 REQ0000
sl@0
   308
*/
sl@0
   309
LOCAL_C void TestRestricted()
sl@0
   310
	{
sl@0
   311
	test.Start(_L("	@SYMTestCaseID:SYSLIB-DBMS-CT-0640 Behaviour at start of set "));
sl@0
   312
	test(TheView.Prepare(TheDatabase,KOrderQuery,KSingleSlotWindow)==KErrNone);
sl@0
   313
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   314
	test(TheView.CountL()==1);
sl@0
   315
	test(!TheView.Unevaluated());
sl@0
   316
	test(TheView.NextL());
sl@0
   317
	test(!TheView.Unevaluated());
sl@0
   318
	TheView.GetL();
sl@0
   319
	TInt id=TheView.ColInt(1);
sl@0
   320
	test(!TheView.NextL());
sl@0
   321
	test(TheView.Unevaluated());
sl@0
   322
	Evaluate();
sl@0
   323
	test(TheView.CountL()==1);
sl@0
   324
	test(TheView.AtRow());
sl@0
   325
	test(!TheView.PreviousL());
sl@0
   326
	test(TheView.Unevaluated());
sl@0
   327
	Evaluate();
sl@0
   328
	test(TheView.CountL()==1);
sl@0
   329
	test(TheView.AtRow());
sl@0
   330
	TheView.GetL();
sl@0
   331
	test(TheView.ColInt(1)==id);
sl@0
   332
	test(!TheView.PreviousL());
sl@0
   333
	test(TheView.Unevaluated());
sl@0
   334
	Evaluate();
sl@0
   335
	test(TheView.CountL()==1);
sl@0
   336
	test(TheView.AtBeginning());
sl@0
   337
	test(TheView.NextL());
sl@0
   338
	TheView.GetL();
sl@0
   339
	test(TheView.ColInt(1)==id);
sl@0
   340
	test(!TheView.Unevaluated());
sl@0
   341
	test.Next(_L("Behaviour at end of set"));
sl@0
   342
	GotoEnd();
sl@0
   343
	test(TheView.LastL());
sl@0
   344
	test(!TheView.Unevaluated());
sl@0
   345
	TheView.GetL();
sl@0
   346
	id=TheView.ColInt(1);
sl@0
   347
	test(!TheView.PreviousL());
sl@0
   348
	test(TheView.Unevaluated());
sl@0
   349
	Evaluate();
sl@0
   350
	test(TheView.CountL()==1);
sl@0
   351
	test(TheView.AtRow());
sl@0
   352
	test(!TheView.NextL());
sl@0
   353
	test(TheView.Unevaluated());
sl@0
   354
	Evaluate();
sl@0
   355
	test(TheView.CountL()==1);
sl@0
   356
	test(TheView.AtRow());
sl@0
   357
	TheView.GetL();
sl@0
   358
	test(TheView.ColInt(1)==id);
sl@0
   359
	test(!TheView.NextL());
sl@0
   360
	test(TheView.Unevaluated());
sl@0
   361
	Evaluate();
sl@0
   362
	test(TheView.CountL()==1);
sl@0
   363
	test(TheView.AtEnd());
sl@0
   364
	test(TheView.PreviousL());
sl@0
   365
	TheView.GetL();
sl@0
   366
	test(TheView.ColInt(1)==id);
sl@0
   367
	test(!TheView.Unevaluated());
sl@0
   368
	TheView.Close();
sl@0
   369
//
sl@0
   370
	test.Next(_L("Forward and backwards slots"));
sl@0
   371
	test(TheView.Prepare(TheDatabase,KOrderQuery,KSmallWindow)==KErrNone);
sl@0
   372
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   373
	test(TheView.CountL()==5);
sl@0
   374
	test(TheView.FirstL());
sl@0
   375
	CheckWindow(4,0);
sl@0
   376
	test(TheView.NextL());
sl@0
   377
	test(TheView.NextL());		// now on preferred slot (id=2)
sl@0
   378
	test(!TheView.Unevaluated());
sl@0
   379
	test(TheView.NextL());
sl@0
   380
	test(TheView.Unevaluated());
sl@0
   381
	Evaluate();
sl@0
   382
	CheckWindow(2,2);
sl@0
   383
	test(TheView.LastL());		// id=5
sl@0
   384
	Evaluate();
sl@0
   385
	test(TheView.LastL());		// id=7
sl@0
   386
	Evaluate();					// should now have last five rows
sl@0
   387
	CheckWindow(2,2);
sl@0
   388
	test(TheView.LastL());		// id=9
sl@0
   389
	Evaluate();					// no more rows
sl@0
   390
	CheckWindow(0,4);			// all behind us now
sl@0
   391
	TheView.GetL();
sl@0
   392
	test(TheView.ColInt(1)==9);
sl@0
   393
	TheView.FirstL();			// id=5
sl@0
   394
	Evaluate();
sl@0
   395
	TheView.FirstL();			// id=3
sl@0
   396
	Evaluate();
sl@0
   397
	TheView.FirstL();			// id=1
sl@0
   398
	Evaluate();
sl@0
   399
	CheckWindow(3,1);
sl@0
   400
//
sl@0
   401
	test.Next(_L("Bookmarks"));
sl@0
   402
	TDbBookmark mark=TheView.Bookmark();
sl@0
   403
	test(TheView.NextL());
sl@0
   404
	test(TheView.NextL());
sl@0
   405
	test(TheView.NextL());
sl@0
   406
	Evaluate();
sl@0
   407
	TRAPD(r,TheView.GotoL(mark));
sl@0
   408
	test(r!=KErrNone);
sl@0
   409
	TheView.FirstL();
sl@0
   410
	Evaluate();
sl@0
   411
	TRAP(r,TheView.GotoL(mark));
sl@0
   412
	test(r==KErrNone);
sl@0
   413
	test.Next(_L("Delete"));
sl@0
   414
	test(TheView.FirstL());
sl@0
   415
	TheView.GetL();
sl@0
   416
	test(TheView.ColInt(1)==0);
sl@0
   417
	TheView.DeleteL();
sl@0
   418
	test(TheView.CountL()==4);
sl@0
   419
	TheView.FirstL();
sl@0
   420
	CheckWindow(3,0);
sl@0
   421
	test.Next(_L("Insert"));
sl@0
   422
	TheView.InsertL();
sl@0
   423
	TheView.SetColL(1,TInt(0));
sl@0
   424
	TheView.PutL();
sl@0
   425
	test(TheView.CountL()==4);
sl@0
   426
	TheView.FirstL();
sl@0
   427
	TheView.GetL();
sl@0
   428
	test(TheView.ColInt(1)==1);
sl@0
   429
	TheView.Reset();
sl@0
   430
	test(TheView.EvaluateAll()==KErrNone);
sl@0
   431
	test(TheView.FirstL());
sl@0
   432
	TheView.GetL();
sl@0
   433
	test(TheView.ColInt(1)==0);
sl@0
   434
//
sl@0
   435
	test.End();
sl@0
   436
	TheView.Close();
sl@0
   437
	}
sl@0
   438
sl@0
   439
LOCAL_C void Test()
sl@0
   440
	{
sl@0
   441
	__UHEAP_MARK;
sl@0
   442
	test.Start(_L("Setting up test table"));
sl@0
   443
	TRAPD(r,Init();)
sl@0
   444
	test(r==KErrNone);
sl@0
   445
	test.Next(_L("Empty Window"));
sl@0
   446
	TRAP(r,TestEmpty();)
sl@0
   447
	test(r==KErrNone);
sl@0
   448
	test.Next(_L("Unlimited Window"));
sl@0
   449
	TRAP(r,TestUnlimited();)
sl@0
   450
	test(r==KErrNone);
sl@0
   451
	test.Next(_L("Sized window"));
sl@0
   452
	TRAP(r,TestRestricted();)
sl@0
   453
	test(r==KErrNone);
sl@0
   454
	test.Next(_L("Cleanup"));
sl@0
   455
	TRAP(r,CloseDatabaseL();)
sl@0
   456
	test(r==KErrNone);
sl@0
   457
	test.End();
sl@0
   458
	__UHEAP_MARKEND;
sl@0
   459
	}
sl@0
   460
sl@0
   461
//
sl@0
   462
// Prepare the test directory.
sl@0
   463
//
sl@0
   464
LOCAL_C void setupTestDirectory()
sl@0
   465
    {
sl@0
   466
	TInt r=TheFs.Connect();
sl@0
   467
	test(r==KErrNone);
sl@0
   468
//
sl@0
   469
	r=TheFs.MkDir(KTestDir);
sl@0
   470
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   471
	r=TheFs.SetSessionPath(KTestDir);
sl@0
   472
	test(r==KErrNone);
sl@0
   473
// On TOOLS2 - RFs::SetSessionPath() will affect all RFs Sessions, 
sl@0
   474
// the two RFs need same session path anyway
sl@0
   475
#ifdef __WINSCW__ 
sl@0
   476
	r=TheCrcChecker.SetSessionPath(KTestDir);
sl@0
   477
	test(r==KErrNone);
sl@0
   478
#endif
sl@0
   479
	}
sl@0
   480
sl@0
   481
//
sl@0
   482
// Initialise the cleanup stack.
sl@0
   483
//
sl@0
   484
LOCAL_C void setupCleanup()
sl@0
   485
    {
sl@0
   486
	TheTrapCleanup=CTrapCleanup::New();
sl@0
   487
	test(TheTrapCleanup!=NULL);
sl@0
   488
	TRAPD(r,\
sl@0
   489
		{\
sl@0
   490
		for (TInt i=KTestCleanupStack;i>0;i--)\
sl@0
   491
			CleanupStack::PushL((TAny*)0);\
sl@0
   492
		CleanupStack::Pop(KTestCleanupStack);\
sl@0
   493
		});
sl@0
   494
	test(r==KErrNone);
sl@0
   495
	}
sl@0
   496
sl@0
   497
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
   498
	{
sl@0
   499
	RFs fsSession;
sl@0
   500
	TInt err = fsSession.Connect();
sl@0
   501
	if(err == KErrNone)
sl@0
   502
		{
sl@0
   503
		TEntry entry;
sl@0
   504
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   505
			{
sl@0
   506
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0
   507
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   508
			if(err != KErrNone) 
sl@0
   509
				{
sl@0
   510
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   511
				}
sl@0
   512
			err = fsSession.Delete(aFullName);
sl@0
   513
			if(err != KErrNone) 
sl@0
   514
				{
sl@0
   515
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   516
				}
sl@0
   517
			}
sl@0
   518
		fsSession.Close();
sl@0
   519
		}
sl@0
   520
	else
sl@0
   521
		{
sl@0
   522
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   523
		}
sl@0
   524
	}
sl@0
   525
sl@0
   526
//
sl@0
   527
// Test streaming conversions.
sl@0
   528
//
sl@0
   529
GLDEF_C TInt E32Main()
sl@0
   530
    {
sl@0
   531
	test.Title();
sl@0
   532
	setupTestDirectory();
sl@0
   533
	setupCleanup();
sl@0
   534
//
sl@0
   535
	test.Start(_L("Standard database"));
sl@0
   536
	Test();
sl@0
   537
	test.Next(_L("Secure database"));
sl@0
   538
	Test();
sl@0
   539
sl@0
   540
	//deletion of data files must be done before call to end - DEF047652
sl@0
   541
#ifndef __TOOLS2__
sl@0
   542
	_LIT(KTestDbName, "C:\\dbms-tst\\T_WINDOW.DB");
sl@0
   543
	::DeleteDataFile(KTestDbName);
sl@0
   544
#else
sl@0
   545
	::DeleteDataFile(KTestFile);
sl@0
   546
#endif
sl@0
   547
sl@0
   548
#ifndef __linux__
sl@0
   549
	TInt err;
sl@0
   550
#ifndef __TOOLS2__
sl@0
   551
	TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
sl@0
   552
	test(err==KErrNone);
sl@0
   553
	test(lc==KErrNone);
sl@0
   554
#else
sl@0
   555
	TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
sl@0
   556
	TPtrC errmsg;
sl@0
   557
	TheCrcChecker.ErrorReportL(err, errmsg);
sl@0
   558
	RDebug::Print(errmsg);
sl@0
   559
	test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
sl@0
   560
#endif
sl@0
   561
#endif
sl@0
   562
sl@0
   563
	test.End();
sl@0
   564
//
sl@0
   565
sl@0
   566
	delete TheTrapCleanup;
sl@0
   567
	TheFs.Close();
sl@0
   568
	test.Close();
sl@0
   569
	return 0;
sl@0
   570
    }