os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_panic.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) 2003-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
#include <e32math.h>
sl@0
    20
#include <s32mem.h>
sl@0
    21
sl@0
    22
#include "crccheck.h"
sl@0
    23
sl@0
    24
LOCAL_D TDBMS_CRCChecks TheCrcChecker;
sl@0
    25
sl@0
    26
#ifndef __linux__ //No CRC test on LINUX
sl@0
    27
#ifdef __TOOLS2__
sl@0
    28
const TPtrC	KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_PANIC.CRC");
sl@0
    29
#else
sl@0
    30
const TPtrC	KCrcRecord=_L("C:\\dbms-tst\\T_PANIC.CRC");
sl@0
    31
#endif
sl@0
    32
#endif
sl@0
    33
sl@0
    34
sl@0
    35
LOCAL_D RTest test(_L("T_PANIC - Panic test when cancelling two blobs transactions"));
sl@0
    36
LOCAL_D CTrapCleanup* TheTrapCleanup;
sl@0
    37
LOCAL_D RDbTable TheTables[2];
sl@0
    38
LOCAL_D RFs TheFs;
sl@0
    39
#ifndef __TOOLS2__
sl@0
    40
LOCAL_D RDbs TheDbs;
sl@0
    41
#endif
sl@0
    42
LOCAL_D RDbNamedDatabase TheDatabase;
sl@0
    43
sl@0
    44
#ifdef __TOOLS2__
sl@0
    45
const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_PANIC.DB");
sl@0
    46
#else
sl@0
    47
const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_PANIC.DB");
sl@0
    48
#endif
sl@0
    49
sl@0
    50
sl@0
    51
/**
sl@0
    52
@SYMTestCaseID          SYSLIB-DBMS-CT-0641
sl@0
    53
@SYMTestCaseDesc        Tests for creating the database and tables
sl@0
    54
@SYMTestPriority        Medium
sl@0
    55
@SYMTestActions         Tests for creating the tables.Leave on error.
sl@0
    56
@SYMTestExpectedResults Test must not fail
sl@0
    57
@SYMREQ                 REQ0000
sl@0
    58
*/
sl@0
    59
LOCAL_C void PreTestL()
sl@0
    60
	{
sl@0
    61
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0641 "));
sl@0
    62
	// Create the database:
sl@0
    63
	User::LeaveIfError(TheDatabase.Replace(TheFs,KTestDatabase));
sl@0
    64
	CleanupClosePushL(TheDatabase);
sl@0
    65
sl@0
    66
	// Create tables in the database:
sl@0
    67
	User::LeaveIfError(TheDatabase.Execute(_L("create table ta (a integer, b Long Varbinary)")));
sl@0
    68
	User::LeaveIfError(TheDatabase.Execute(_L("create table tb (a integer, b Long Varbinary)")));
sl@0
    69
sl@0
    70
	// Open the tables:
sl@0
    71
	User::LeaveIfError(TheTables[0].Open(TheDatabase, _L("ta")));
sl@0
    72
	CleanupClosePushL(TheTables[0]);
sl@0
    73
	User::LeaveIfError(TheTables[1].Open(TheDatabase, _L("tb")));
sl@0
    74
	CleanupClosePushL(TheTables[1]);
sl@0
    75
	}
sl@0
    76
sl@0
    77
/**
sl@0
    78
@SYMTestCaseID          SYSLIB-DBMS-CT-0642
sl@0
    79
@SYMTestCaseDesc        Tests for transaction of large data
sl@0
    80
@SYMTestPriority        Medium
sl@0
    81
@SYMTestActions         Tests for streaming of blob data
sl@0
    82
@SYMTestExpectedResults Test must not fail
sl@0
    83
@SYMREQ                 REQ0000
sl@0
    84
*/
sl@0
    85
LOCAL_C void TestL()
sl@0
    86
	{
sl@0
    87
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0642 "));
sl@0
    88
	// Start a transaction:
sl@0
    89
	TheDatabase.Begin();
sl@0
    90
sl@0
    91
	// Create a new row on each table:
sl@0
    92
	TheTables[0].InsertL();
sl@0
    93
	TheTables[1].InsertL();
sl@0
    94
sl@0
    95
	for(TInt i = 0; i < 2; ++i)
sl@0
    96
		{
sl@0
    97
		// Setting to null sets the dirty flag:
sl@0
    98
		TheTables[i].SetColNullL(1);
sl@0
    99
sl@0
   100
		// Create a blob of data:
sl@0
   101
		_LIT8(blobdata, "abcdefghijklmnopqrstuvwxyz");
sl@0
   102
		CBufFlat * blobbuff = CBufFlat::NewL(32);
sl@0
   103
		CleanupStack::PushL(blobbuff);
sl@0
   104
		blobbuff->InsertL(0, blobdata());
sl@0
   105
sl@0
   106
		// Open a read stream on the blob:
sl@0
   107
		RBufReadStream blobstream;
sl@0
   108
		blobstream.Open(*blobbuff, 0);
sl@0
   109
		CleanupClosePushL(blobstream);
sl@0
   110
sl@0
   111
		// Open a write stream on the table:
sl@0
   112
		RDbColWriteStream blobwrite;
sl@0
   113
		blobwrite.OpenLC(TheTables[i], 2);
sl@0
   114
sl@0
   115
		// Stream data from the read stream to the write stream:
sl@0
   116
		blobwrite.WriteL(blobstream);
sl@0
   117
		blobwrite.CommitL();
sl@0
   118
sl@0
   119
		// Close the write stream:
sl@0
   120
		CleanupStack::PopAndDestroy();
sl@0
   121
		// Close the read stream:
sl@0
   122
		CleanupStack::PopAndDestroy();
sl@0
   123
		// Delete the blob of data:
sl@0
   124
		CleanupStack::PopAndDestroy(blobbuff);
sl@0
   125
		}
sl@0
   126
	
sl@0
   127
	TheTables[0].Cancel();
sl@0
   128
	TheTables[1].Cancel(); //This call to cancel panics.
sl@0
   129
	
sl@0
   130
sl@0
   131
	// End the transaction:
sl@0
   132
	TheDatabase.Commit();
sl@0
   133
	}
sl@0
   134
sl@0
   135
/**
sl@0
   136
@SYMTestCaseID          SYSLIB-DBMS-CT-0643
sl@0
   137
@SYMTestCaseDesc        Tests for closing of tables
sl@0
   138
@SYMTestPriority        Medium
sl@0
   139
@SYMTestActions         Tests for closing of tables and database
sl@0
   140
@SYMTestExpectedResults Test must not fail
sl@0
   141
@SYMREQ                 REQ0000
sl@0
   142
*/
sl@0
   143
LOCAL_C void PostTestL()
sl@0
   144
	{
sl@0
   145
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0643 "));
sl@0
   146
	// Close the tables:
sl@0
   147
	TheTables[0].Close();
sl@0
   148
	CleanupStack::Pop(); // Table close
sl@0
   149
	TheTables[1].Close();
sl@0
   150
	CleanupStack::Pop(); // Table close
sl@0
   151
sl@0
   152
	// Close the database:
sl@0
   153
	CleanupStack::PopAndDestroy();
sl@0
   154
sl@0
   155
	TInt err;
sl@0
   156
	TRAPD(lc, err = TheCrcChecker.GenerateCrcL(KTestDatabase));
sl@0
   157
	}
sl@0
   158
sl@0
   159
void doTest()
sl@0
   160
	{
sl@0
   161
	test.Start(_L("bang"));
sl@0
   162
sl@0
   163
	// Open a connection to the DBMS server:
sl@0
   164
#ifndef __TOOLS2__
sl@0
   165
	User::LeaveIfError(TheDbs.Connect());
sl@0
   166
	CleanupClosePushL(TheDbs);
sl@0
   167
#endif
sl@0
   168
sl@0
   169
	PreTestL();
sl@0
   170
	TestL();
sl@0
   171
	PostTestL();
sl@0
   172
		
sl@0
   173
#ifndef __TOOLS2__
sl@0
   174
	CleanupStack::PopAndDestroy(); // TheDbs close
sl@0
   175
#endif
sl@0
   176
	}
sl@0
   177
sl@0
   178
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
   179
	{
sl@0
   180
	RFs fsSession;
sl@0
   181
	TInt err = fsSession.Connect();
sl@0
   182
	if(err == KErrNone)
sl@0
   183
		{
sl@0
   184
		TEntry entry;
sl@0
   185
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   186
			{
sl@0
   187
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0
   188
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   189
			if(err != KErrNone) 
sl@0
   190
				{
sl@0
   191
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   192
				}
sl@0
   193
			err = fsSession.Delete(aFullName);
sl@0
   194
			if(err != KErrNone) 
sl@0
   195
				{
sl@0
   196
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   197
				}
sl@0
   198
			}
sl@0
   199
		fsSession.Close();
sl@0
   200
		}
sl@0
   201
	else
sl@0
   202
		{
sl@0
   203
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   204
		}
sl@0
   205
	}
sl@0
   206
sl@0
   207
//
sl@0
   208
// Test streaming conversions.
sl@0
   209
//
sl@0
   210
GLDEF_C TInt E32Main()
sl@0
   211
    {
sl@0
   212
	test.Title();
sl@0
   213
	TheTrapCleanup=CTrapCleanup::New();
sl@0
   214
sl@0
   215
	User::LeaveIfError(TheFs.Connect());
sl@0
   216
	TInt r=TheFs.MkDir(KTestDatabase);
sl@0
   217
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   218
sl@0
   219
	TRAP(r, doTest());
sl@0
   220
	test(r == KErrNone);
sl@0
   221
sl@0
   222
	test.Printf(_L("Waiting for server exit\n"));
sl@0
   223
	const TUint KExitDelay=6*0x100000;	// ~6 seconds
sl@0
   224
	User::After(KExitDelay);
sl@0
   225
sl@0
   226
	::DeleteDataFile(KTestDatabase);
sl@0
   227
	
sl@0
   228
#ifndef __linux__
sl@0
   229
	TInt err;
sl@0
   230
#ifndef __TOOLS2__
sl@0
   231
	TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
sl@0
   232
	test(err==KErrNone);
sl@0
   233
	test(lc==KErrNone);
sl@0
   234
#else
sl@0
   235
	TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
sl@0
   236
	TPtrC errmsg;
sl@0
   237
	TheCrcChecker.ErrorReportL(err, errmsg);
sl@0
   238
	RDebug::Print(errmsg);
sl@0
   239
	test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
sl@0
   240
#endif
sl@0
   241
#endif
sl@0
   242
	test.End();
sl@0
   243
	
sl@0
   244
	TheFs.Close();
sl@0
   245
	delete TheTrapCleanup;
sl@0
   246
	test.Close();
sl@0
   247
	return r;
sl@0
   248
    }