os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_big.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 // MSVC++ up to 5.0 has problems with expanding inline functions
    17 // This disables the mad warnings for the whole project
    18 #if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
    19 #pragma warning(disable : 4710)			// function not expanded. MSVC 5.0 is stupid
    20 #endif
    21 
    22 #include <d32dbms.h>
    23 #include <s32file.h>
    24 #include <e32test.h>
    25 #include <e32math.h>
    26 #ifndef __TOOLS2__
    27 #include <hal.h>
    28 #endif
    29 
    30 #include "crccheck.h"
    31 
    32 #undef __UHEAP_MARK
    33 #define __UHEAP_MARK
    34 #undef __UHEAP_MARKEND
    35 #define __UHEAP_MARKEND
    36 #undef __UHEAP_CHECK
    37 #define __UHEAP_CHECK(a)
    38 #undef __UHEAP_FAILNEXT
    39 #define __UHEAP_FAILNEXT(a)
    40 
    41 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
    42 
    43 #ifndef __linux__ //No CRC test on LINUX
    44 #ifdef __TOOLS2__
    45 const TPtrC	KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_BIG.CRC");
    46 #else
    47 const TPtrC	KCrcRecord=_L("C:\\dbms-tst\\T_BIG.CRC");
    48 #endif
    49 #endif
    50 
    51 class TTimer
    52 	{
    53 public:
    54 	void Start(const TDesC& aDes);
    55 	void Stop();
    56 private:
    57 	TUint iTicks;
    58 	};
    59 	
    60 LOCAL_D RTest test(_L("T_BIG - Test Large DBMS objects"));
    61 LOCAL_D CTrapCleanup* TheTrapCleanup;
    62 LOCAL_D CFileStore* TheStore;
    63 LOCAL_D RDbStoreDatabase TheDatabase;
    64 LOCAL_D RDbTable TheTable;
    65 LOCAL_D RFs TheFs;
    66 
    67 const TInt KTestCleanupStack=0x20;
    68 
    69 #ifdef __TOOLS2__
    70 const TPtrC KTestDir=_L(".\\dbms-tst\\");
    71 #else
    72 const TPtrC KTestDir=_L("C:\\dbms-tst\\");
    73 #endif
    74 
    75 const TPtrC KTestFile=_L("T_BIG.DB");
    76 const TPtrC KTableName(_S("table"));
    77 const TPtrC KIndexText=_S("text");
    78 const TPtrC KIndexInt=_S("int");
    79 const TPtrC KColumnText=_S("text");
    80 const TPtrC KColumnInt=_S("int");
    81 const TPtrC KIncFormat=_S("%5d\r");
    82 const TInt KRecords=1000;
    83 const TPtrC KOtherTable=_S("extra");
    84 
    85 #ifndef __TOOLS2__
    86 static TTimer TheTimer;
    87 
    88 void TTimer::Start(const TDesC& aDes)
    89 	{
    90 	test.Printf(_L("  %S: "),&aDes);
    91 	iTicks=User::FastCounter();
    92 	}
    93 
    94 void TTimer::Stop()
    95 	{
    96 	TUint ticks = User::FastCounter() - iTicks;
    97 	TInt freq = 0;
    98 	test(HAL::Get(HAL::EFastCounterFrequency, freq) == KErrNone);
    99 	const TInt KMicroSecIn1Sec = 1000000;
   100 	const TInt KMsIn1Sec = 1000;
   101 	double v = ((double)ticks * KMicroSecIn1Sec) / (double)freq; TInt v2 = (TInt)v;
   102 	test.Printf(_L("%d ms\r\n"),v2/KMsIn1Sec);
   103 	}
   104 #endif
   105 
   106 /**
   107 @SYMTestCaseID          SYSLIB-DBMS-CT-1309
   108 @SYMTestCaseDesc        Create the database-in-a-store
   109 @SYMTestPriority        Medium
   110 @SYMTestActions        	Calls up RDbStoreDatabase::CreateL() function
   111 @SYMTestExpectedResults Test must not fail
   112 @SYMREQ                 REQ0000
   113 */
   114 LOCAL_C void CreateDatabaseL()
   115 	{
   116 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1309 "));
   117 	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,KTestFile,EFileRead|EFileWrite);
   118 	store->SetTypeL(KPermanentFileStoreLayoutUid);
   119 	TStreamId id;
   120 		id=TheDatabase.CreateL(store);
   121 	store->SetRootL(id);
   122 	store->CommitL();
   123 	CleanupStack::Pop();
   124 	TheStore=store;
   125 	}
   126 
   127 /**
   128 @SYMTestCaseID          SYSLIB-DBMS-CT-1310
   129 @SYMTestCaseDesc        Open the database-in-a-store
   130 @SYMTestPriority        Medium
   131 @SYMTestActions        	Call up RDbStoreDatabase::OpenL()
   132 @SYMTestExpectedResults Test must not fail
   133 @SYMREQ                 REQ0000
   134 */
   135 LOCAL_C void OpenDatabaseL()
   136 	{
   137 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1310 "));
   138 	CFileStore* store=CPermanentFileStore::OpenLC(TheFs,KTestFile,EFileRead|EFileWrite);
   139 		TheDatabase.OpenL(store,store->Root());
   140 	CleanupStack::Pop();
   141 	TheStore=store;
   142 	}
   143 
   144 /**
   145 @SYMTestCaseID          SYSLIB-DBMS-CT-1311
   146 @SYMTestCaseDesc        Close the database in store
   147 @SYMTestPriority        Medium
   148 @SYMTestActions        	Test for RDbStoreDatabase::Close() function
   149 @SYMTestExpectedResults Test must not fail
   150 @SYMREQ                 REQ0000
   151 */
   152 LOCAL_C void CloseDatabaseL()
   153 	{
   154 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1311 "));
   155 	TheDatabase.Close();
   156 	delete TheStore;
   157 	TInt err = TheCrcChecker.GenerateCrcL(KTestFile);
   158 	test(err == KErrNone);
   159 	}
   160 
   161 LOCAL_C void CreateTable()
   162 	{
   163 	CDbColSet *cs=CDbColSet::NewLC();
   164 	TDbCol col1(KColumnInt,EDbColInt32);
   165 	col1.iAttributes=TDbCol::ENotNull;
   166 	cs->AddL(col1);
   167 	TDbCol col2(KColumnText,EDbColText,200/sizeof(TText));
   168 	col2.iAttributes=TDbCol::ENotNull;
   169 	cs->AddL(col2);
   170 	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
   171 	CleanupStack::PopAndDestroy();
   172 	}
   173 
   174 LOCAL_C void WriteRecords(TInt aCount)
   175 	{
   176 	TBuf<10> text;
   177 	TInt jj=0;
   178 	for (TInt ii=0;ii<aCount;++ii)
   179 		{
   180 		TheTable.InsertL();
   181 		jj=(jj+23);
   182 		if (jj>=aCount)
   183 			jj-=aCount;
   184 		TheTable.SetColL(1,jj);
   185 		text.Num(jj);
   186 		TheTable.SetColL(2,text);
   187 		TheTable.PutL();
   188 		}
   189 	}
   190 
   191 /**
   192 @SYMTestCaseID          SYSLIB-DBMS-CT-1312
   193 @SYMTestCaseDesc        Create a table in database
   194 @SYMTestPriority        Medium
   195 @SYMTestActions        	Build a table and write records into the table.Test for commiting the transactions.
   196 @SYMTestExpectedResults Test must not fail
   197 @SYMREQ                 REQ0000
   198 */
   199 LOCAL_C void BuildTable(TInt aCount)
   200 	{
   201 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1312 "));
   202 #ifndef __TOOLS2__
   203 	TheTimer.Start(_L("build"));
   204 #endif
   205 	CreateTable();
   206 	TheDatabase.Begin();
   207 	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
   208 	WriteRecords(aCount);
   209 	test(TheDatabase.Commit()==KErrNone);
   210 	TheTable.Close();
   211 #ifndef __TOOLS2__
   212 	TheTimer.Stop();
   213 #endif
   214 	}
   215 
   216 /**
   217 @SYMTestCaseID          SYSLIB-DBMS-CT-1313
   218 @SYMTestCaseDesc        Tests for total rows in the rowset
   219 @SYMTestPriority        Medium
   220 @SYMTestActions        	Iterate through the table.Test for the total numbers of rows available 
   221 @SYMTestExpectedResults Test must not fail
   222 @SYMREQ                 REQ0000
   223 */
   224 LOCAL_C void IterateL(RDbTable::TPosition aDirection)
   225 	{
   226 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1313 "));
   227 #ifndef __TOOLS2__
   228 	TheTimer.Start(_L("iterate"));
   229 #endif
   230 	TInt cc=0;
   231 	while (TheTable.GotoL(aDirection))
   232 		{
   233 		++cc;
   234 		TheTable.GetL();
   235 		}
   236 #ifndef __TOOLS2__
   237 	TheTimer.Stop();
   238 #endif
   239 	test(cc=TheTable.CountL());
   240 	}
   241 
   242 /**
   243 @SYMTestCaseID          SYSLIB-DBMS-CT-0580
   244 @SYMTestCaseDesc        Tests the database definition and enquiry functions
   245 @SYMTestPriority        Medium
   246 @SYMTestActions        	Tests by setting an active index for the table.   
   247 @SYMTestExpectedResults Test must not fail
   248 @SYMREQ                 REQ0000
   249 */
   250 LOCAL_C void TestIndex(const TDesC& aName,const CDbKey& aKey)
   251 	{
   252 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0580 "));
   253 #ifndef __TOOLS2__
   254 	TheTimer.Start(_L("build"));
   255 #endif
   256 	test(TheDatabase.CreateIndex(aName,KTableName,aKey)==KErrNone);
   257 #ifndef __TOOLS2__
   258 	TheTimer.Stop();
   259 #endif
   260 	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
   261 	test(TheTable.SetIndex(aName)==KErrNone);
   262 	IterateL(TheTable.ENext);
   263 	TheTable.Close();
   264 	}
   265 
   266 /**
   267 @SYMTestCaseID          SYSLIB-DBMS-CT-0581
   268 @SYMTestCaseDesc        Tests the database definition and enquiry functions
   269 @SYMTestPriority        Medium
   270 @SYMTestActions        	Tests for bookmark which saves the current location of a rowset.
   271 @SYMTestExpectedResults Test must not fail
   272 @SYMREQ                 REQ0000
   273 */
   274 LOCAL_C void TestBookmark()
   275 	{
   276 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0581 creating alien bookmark "));
   277 	CDbColSet* cs=CDbColSet::NewLC();
   278 	TDbCol col(_L("column"),EDbColUint8);
   279 	col.iAttributes=TDbCol::ENotNull+TDbCol::EAutoIncrement;
   280 	cs->AddL(col);
   281 	test (TheDatabase.CreateTable(KOtherTable,*cs)==KErrNone);
   282 	CleanupStack::PopAndDestroy();
   283 	RDbTable extra;
   284 	test (extra.Open(TheDatabase,KOtherTable)==KErrNone);
   285 	extra.InsertL();
   286 	extra.PutL();
   287 	TDbBookmark alien=extra.Bookmark();
   288 	extra.Close();
   289 //
   290 	test.Next(_L("Alien bookmark"));
   291 	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
   292 	TRAPD(r,TheTable.GotoL(alien));
   293 	test (r==KErrNotFound);
   294 	test (TheTable.SetIndex(KIndexInt)==KErrNone);
   295 	TRAP(r,TheTable.GotoL(alien));
   296 	test (r==KErrNotFound);
   297 	test (TheTable.SetIndex(KIndexText)==KErrNone);
   298 	TRAP(r,TheTable.GotoL(alien));
   299 	test (r==KErrNotFound);
   300 //
   301 	test.Next(_L("Cross-view bookmarks"));
   302 	TheTable.LastL();	// indexed view
   303 	TheTable.PreviousL();
   304 	TDbBookmark mark=TheTable.Bookmark();
   305 	test (extra.Open(TheDatabase,KTableName)==KErrNone);
   306 	TRAP(r,extra.GotoL(mark));
   307 	test (r==KErrNone);
   308 	test (extra.PreviousL());
   309 	TRAP(r,TheTable.GotoL(extra.Bookmark()));
   310 	test (r==KErrNone);
   311 	extra.Close();
   312 //
   313 	test.Next(_L("Bookmark persistence"));
   314 	TheTable.Close();
   315 	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
   316 	TRAP(r,TheTable.GotoL(mark));
   317 	test (r==KErrNone);
   318 	TheTable.Close();
   319 //
   320 	test.Next(_L("Delete alien record"));
   321 	test (extra.Open(TheDatabase,KOtherTable)==KErrNone);
   322 	TRAP(r, extra.GotoL(mark));
   323 	test (r==KErrNotFound);
   324 	TRAP(r,extra.GotoL(alien));
   325 	test (r==KErrNone);
   326 	extra.DeleteL();
   327 	TRAP(r,extra.GotoL(alien));
   328 	test (r==KErrNotFound);
   329 	extra.Close();
   330 //
   331 	test.Next(_L("Delete extra table"));
   332 	test (TheDatabase.DropTable(KOtherTable)==KErrNone);
   333 	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
   334 	TRAP(r,TheTable.GotoL(alien));
   335 	test (r==KErrNotFound);
   336 	TheTable.Close();
   337 //
   338 	test.End();
   339 	}
   340 
   341 /**
   342 @SYMTestCaseID          SYSLIB-DBMS-CT-1314
   343 @SYMTestCaseDesc        Discarding indexes belonging to the table on database 
   344 @SYMTestPriority        Medium
   345 @SYMTestActions        	Tests for RDbIncremental::DropTable(),RDbIncremental::Next() function.
   346 @SYMTestExpectedResults Test must not fail
   347 @SYMREQ                 REQ0000
   348 */
   349 LOCAL_C void BreakIndex()
   350 	{
   351 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1314 "));
   352 #ifndef __TOOLS2__
   353 	TheTimer.Start(_L("break"));
   354 #endif
   355 	TInt step;
   356 	RDbIncremental drop;
   357 	test(drop.DropTable(TheDatabase,KTableName,step)==KErrNone);
   358 	test(drop.Next(step)==KErrNone);
   359 	test(step>0);
   360 	drop.Close();	// abort the drop
   361 	test(TheDatabase.IsDamaged());
   362 #ifndef __TOOLS2__
   363 	TheTimer.Stop();
   364 #endif
   365 	}
   366 
   367 /**
   368 @SYMTestCaseID          SYSLIB-DBMS-CT-1315
   369 @SYMTestCaseDesc        Database recovery test 
   370 @SYMTestPriority        Medium
   371 @SYMTestActions        	Calls up RDbStoreDatabase::Recover() function 
   372 @SYMTestExpectedResults Test must not fail
   373 @SYMREQ                 REQ0000
   374 */
   375 LOCAL_C void Recover()
   376 	{
   377 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1315 "));
   378 #ifndef __TOOLS2__
   379 	TheTimer.Start(_L("recover"));
   380 #endif
   381 	test(TheDatabase.Recover()==KErrNone);
   382 #ifndef __TOOLS2__
   383 	TheTimer.Stop();
   384 #endif
   385 	test(!TheDatabase.IsDamaged());
   386 	}
   387 
   388 /**
   389 @SYMTestCaseID          SYSLIB-DBMS-CT-1316
   390 @SYMTestCaseDesc        Tests for dropping an index
   391 @SYMTestPriority        Medium
   392 @SYMTestActions        	Drop an integer and text index from the table. Test for damage of database
   393 @SYMTestExpectedResults Test must not fail
   394 @SYMREQ                 REQ0000
   395 */
   396 LOCAL_C void DropIndexes()
   397 	{
   398 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1316 "));
   399 #ifndef __TOOLS2__
   400 	TheTimer.Start(_L("drop Int[32]"));
   401 #endif
   402 	test(TheDatabase.DropIndex(KIndexInt,KTableName)==KErrNone);
   403 #ifndef __TOOLS2__
   404 	TheTimer.Stop();
   405 	TheTimer.Start(_L("drop Text[200]"));
   406 #endif
   407 	test(TheDatabase.DropIndex(KIndexText,KTableName)==KErrNone);
   408 #ifndef __TOOLS2__
   409 	TheTimer.Stop();
   410 #endif
   411 	test(!TheDatabase.IsDamaged());
   412 	}
   413 
   414 /**
   415 @SYMTestCaseID          SYSLIB-DBMS-CT-1317
   416 @SYMTestCaseDesc        Deleting a table from the database 
   417 @SYMTestPriority        Medium
   418 @SYMTestActions        	Delete the rows from the rowset.Check for empty rows in the rowset.
   419 @SYMTestExpectedResults Test must not fail
   420 @SYMREQ                 REQ0000
   421 */
   422 LOCAL_C void DeleteTable()
   423 	{
   424 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1317 "));
   425 	const TInt KTenthRecords=KRecords/10;
   426 
   427 	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
   428 	TheDatabase.Begin();
   429 	TInt ii;
   430 	for (ii=0;ii<15;++ii)
   431 		{
   432 		TheTable.NextL();
   433 		TheTable.DeleteL();
   434 		}
   435 	TheTable.NextL();
   436 	TDbBookmark mark=TheTable.Bookmark();
   437 	TheTable.Close();
   438 	TheDatabase.Commit();
   439 	CloseDatabaseL();
   440 	OpenDatabaseL();
   441 #ifndef __TOOLS2__
   442 	TheTimer.Start(_L("delete table"));
   443 #endif
   444 	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
   445 	TheDatabase.Begin();
   446 	TheTable.GotoL(mark);
   447 	TheTable.DeleteL();
   448 	for (ii=0;ii<KTenthRecords*2-16;++ii)
   449 		{
   450 		TheTable.NextL();
   451 		TheTable.DeleteL();
   452 		}
   453 	TheTable.EndL();
   454 	for (ii=0;ii<KTenthRecords*2;++ii)
   455 		{
   456 		TheTable.PreviousL();
   457 		TheTable.DeleteL();
   458 		}
   459 	TheTable.BeginningL();
   460 	for (ii=0;ii<KTenthRecords*3;++ii)
   461 		TheTable.NextL();
   462 	for (ii=0;ii<KTenthRecords*2;++ii)
   463 		{
   464 		TheTable.NextL();
   465 		TheTable.DeleteL();
   466 		}
   467 	for (ii=0;ii<KTenthRecords*2;++ii)
   468 		{
   469 		TheTable.PreviousL();
   470 		TheTable.DeleteL();
   471 		}
   472 	for (ii=0;ii<KTenthRecords;++ii)
   473 		{
   474 		TheTable.NextL();
   475 		TheTable.DeleteL();
   476 		}
   477 	for (ii=0;ii<KTenthRecords;++ii)
   478 		{
   479 		TheTable.PreviousL();
   480 		TheTable.DeleteL();
   481 		}
   482 	test (TheTable.CountL()==0);
   483 	test (!TheTable.NextL());
   484 	test (!TheTable.PreviousL());
   485 	test (TheDatabase.Commit()==KErrNone);
   486 	TheTable.Close();
   487 #ifndef __TOOLS2__
   488 	TheTimer.Stop();
   489 #endif
   490 	}
   491 
   492 /**
   493 @SYMTestCaseID          SYSLIB-DBMS-CT-0579
   494 @SYMTestCaseDesc        Tests the database definition and enquiry functions
   495 @SYMTestPriority        Medium
   496 @SYMTestActions        	Executes the index and bookmark tests
   497 @SYMTestExpectedResults Test must not fail
   498 @SYMREQ                 REQ0000
   499 */
   500 LOCAL_C void BigTestL()
   501 	{
   502 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0579 Table "));
   503 	CreateDatabaseL();
   504 	BuildTable(KRecords);
   505 	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
   506 	TheTable.EndL();
   507 	IterateL(TheTable.EPrevious);
   508 	TheTable.BeginningL();
   509 	IterateL(TheTable.ENext);
   510 	TheTable.EndL();
   511 	IterateL(TheTable.EPrevious);
   512 	TheTable.Close();
   513 	test.Next(_L("Int32 Index"));
   514 	CDbKey *key=CDbKey::NewLC();
   515 	key->AddL(KColumnInt);
   516 	key->MakeUnique();
   517 	TestIndex(KIndexInt,*key);
   518 	test.Next(_L("Text[200] Index"));
   519 	key->Clear();
   520 	key->AddL(KColumnText);
   521 	key->MakeUnique();
   522 	TestIndex(KIndexText,*key);
   523 	test.Next(_L("Bookmarks"));
   524 	TestBookmark();
   525 	test.Next(_L("Int32 Index"));
   526 #ifndef __TOOLS2__
   527 	TheTimer.Start(_L("drop"));
   528 #endif
   529 	test(TheDatabase.DropIndex(KIndexInt,KTableName)==KErrNone);
   530 #ifndef __TOOLS2__
   531 	TheTimer.Stop();
   532 #endif
   533 	key->Clear();
   534 	key->AddL(KColumnInt);
   535 	key->MakeUnique();
   536 	TestIndex(KIndexInt,*key);
   537 	CleanupStack::PopAndDestroy();
   538 	test.Next(_L("Break & Recover"));
   539 	BreakIndex();
   540 	Recover();
   541 	test.Next(_L("Drop Indexes"));
   542 	DropIndexes();
   543 	test.Next(_L("Delete all records"));
   544 	DeleteTable();
   545 	CloseDatabaseL();
   546 	test.End();
   547 	}
   548 
   549 //
   550 // Prepare the test directory.
   551 //
   552 LOCAL_C void setupTestDirectory()
   553     {
   554 	TInt r=TheFs.Connect();
   555 	test(r==KErrNone);
   556 	r=TheFs.MkDir(KTestDir);
   557 	test(r==KErrNone || r==KErrAlreadyExists);
   558 	r=TheFs.SetSessionPath(KTestDir);
   559 	test(r==KErrNone);
   560 	
   561 // On TOOLS2 - RFs::SetSessionPath() will affect all RFs Sessions, 
   562 // the two RFs need same session path anyway
   563 #ifdef __WINSCW__
   564 	r=TheCrcChecker.SetSessionPath(KTestDir);
   565 	test(r==KErrNone);
   566 #endif
   567 	}
   568 
   569 //
   570 // Initialise the cleanup stack.
   571 //
   572 LOCAL_C void setupCleanup()
   573     {
   574 	TheTrapCleanup=CTrapCleanup::New();
   575 	test(TheTrapCleanup!=NULL);
   576 	TRAPD(r,\
   577 		{\
   578 		for (TInt i=KTestCleanupStack;i>0;i--)\
   579 			CleanupStack::PushL((TAny*)0);\
   580 		CleanupStack::Pop(KTestCleanupStack);\
   581 		});
   582 	test(r==KErrNone);
   583 	}
   584 
   585 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
   586 	{
   587 	RFs fsSession;
   588 	TInt err = fsSession.Connect();
   589 	if(err == KErrNone)
   590 		{
   591 		TEntry entry;
   592 		if(fsSession.Entry(aFullName, entry) == KErrNone)
   593 			{
   594 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
   595 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
   596 			if(err != KErrNone) 
   597 				{
   598 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
   599 				}
   600 			err = fsSession.Delete(aFullName);
   601 			if(err != KErrNone) 
   602 				{
   603 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
   604 				}
   605 			}
   606 		fsSession.Close();
   607 		}
   608 	else
   609 		{
   610 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
   611 		}
   612 	}
   613 
   614 GLDEF_C TInt E32Main()
   615     {
   616 	test.Title();
   617 	setupTestDirectory();
   618 	setupCleanup();
   619 	__UHEAP_MARK;
   620 //
   621 	test.Start(_L("Standard database"));
   622 	TRAPD(r,BigTestL();)
   623 	test(r==KErrNone);
   624 	test.Next(_L("Secure database"));
   625 	TRAP(r,BigTestL();)
   626 	test(r==KErrNone);
   627     
   628 	// clean up data files used by this test - must be done before call to End() - DEF047652
   629 #ifndef __TOOLS2__
   630 	_LIT(KTestDbName, "C:\\dbms-tst\\T_BIG.DB");
   631 #else
   632 	_LIT(KTestDbName, "T_BIG.DB");
   633 #endif
   634 	::DeleteDataFile(KTestDbName);	
   635 	
   636 #ifndef __linux__
   637 	TInt err;
   638 #ifndef __TOOLS2__
   639 	TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
   640 	test(err==KErrNone);
   641 	test(lc==KErrNone);
   642 #else
   643 	TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
   644 	TPtrC errmsg;
   645 	TheCrcChecker.ErrorReportL(err, errmsg);
   646 	RDebug::Print(errmsg);
   647 	test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
   648 #endif
   649 #endif
   650 
   651 	test.End();
   652 
   653 	__UHEAP_MARKEND;
   654 	delete TheTrapCleanup;
   655 
   656 	TheFs.Close();
   657 	test.Close();
   658 	return 0;
   659     }