1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_panic.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,248 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <d32dbms.h>
1.20 +#include <s32file.h>
1.21 +#include <e32test.h>
1.22 +#include <e32math.h>
1.23 +#include <s32mem.h>
1.24 +
1.25 +#include "crccheck.h"
1.26 +
1.27 +LOCAL_D TDBMS_CRCChecks TheCrcChecker;
1.28 +
1.29 +#ifndef __linux__ //No CRC test on LINUX
1.30 +#ifdef __TOOLS2__
1.31 +const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_PANIC.CRC");
1.32 +#else
1.33 +const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_PANIC.CRC");
1.34 +#endif
1.35 +#endif
1.36 +
1.37 +
1.38 +LOCAL_D RTest test(_L("T_PANIC - Panic test when cancelling two blobs transactions"));
1.39 +LOCAL_D CTrapCleanup* TheTrapCleanup;
1.40 +LOCAL_D RDbTable TheTables[2];
1.41 +LOCAL_D RFs TheFs;
1.42 +#ifndef __TOOLS2__
1.43 +LOCAL_D RDbs TheDbs;
1.44 +#endif
1.45 +LOCAL_D RDbNamedDatabase TheDatabase;
1.46 +
1.47 +#ifdef __TOOLS2__
1.48 +const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_PANIC.DB");
1.49 +#else
1.50 +const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_PANIC.DB");
1.51 +#endif
1.52 +
1.53 +
1.54 +/**
1.55 +@SYMTestCaseID SYSLIB-DBMS-CT-0641
1.56 +@SYMTestCaseDesc Tests for creating the database and tables
1.57 +@SYMTestPriority Medium
1.58 +@SYMTestActions Tests for creating the tables.Leave on error.
1.59 +@SYMTestExpectedResults Test must not fail
1.60 +@SYMREQ REQ0000
1.61 +*/
1.62 +LOCAL_C void PreTestL()
1.63 + {
1.64 + test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0641 "));
1.65 + // Create the database:
1.66 + User::LeaveIfError(TheDatabase.Replace(TheFs,KTestDatabase));
1.67 + CleanupClosePushL(TheDatabase);
1.68 +
1.69 + // Create tables in the database:
1.70 + User::LeaveIfError(TheDatabase.Execute(_L("create table ta (a integer, b Long Varbinary)")));
1.71 + User::LeaveIfError(TheDatabase.Execute(_L("create table tb (a integer, b Long Varbinary)")));
1.72 +
1.73 + // Open the tables:
1.74 + User::LeaveIfError(TheTables[0].Open(TheDatabase, _L("ta")));
1.75 + CleanupClosePushL(TheTables[0]);
1.76 + User::LeaveIfError(TheTables[1].Open(TheDatabase, _L("tb")));
1.77 + CleanupClosePushL(TheTables[1]);
1.78 + }
1.79 +
1.80 +/**
1.81 +@SYMTestCaseID SYSLIB-DBMS-CT-0642
1.82 +@SYMTestCaseDesc Tests for transaction of large data
1.83 +@SYMTestPriority Medium
1.84 +@SYMTestActions Tests for streaming of blob data
1.85 +@SYMTestExpectedResults Test must not fail
1.86 +@SYMREQ REQ0000
1.87 +*/
1.88 +LOCAL_C void TestL()
1.89 + {
1.90 + test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0642 "));
1.91 + // Start a transaction:
1.92 + TheDatabase.Begin();
1.93 +
1.94 + // Create a new row on each table:
1.95 + TheTables[0].InsertL();
1.96 + TheTables[1].InsertL();
1.97 +
1.98 + for(TInt i = 0; i < 2; ++i)
1.99 + {
1.100 + // Setting to null sets the dirty flag:
1.101 + TheTables[i].SetColNullL(1);
1.102 +
1.103 + // Create a blob of data:
1.104 + _LIT8(blobdata, "abcdefghijklmnopqrstuvwxyz");
1.105 + CBufFlat * blobbuff = CBufFlat::NewL(32);
1.106 + CleanupStack::PushL(blobbuff);
1.107 + blobbuff->InsertL(0, blobdata());
1.108 +
1.109 + // Open a read stream on the blob:
1.110 + RBufReadStream blobstream;
1.111 + blobstream.Open(*blobbuff, 0);
1.112 + CleanupClosePushL(blobstream);
1.113 +
1.114 + // Open a write stream on the table:
1.115 + RDbColWriteStream blobwrite;
1.116 + blobwrite.OpenLC(TheTables[i], 2);
1.117 +
1.118 + // Stream data from the read stream to the write stream:
1.119 + blobwrite.WriteL(blobstream);
1.120 + blobwrite.CommitL();
1.121 +
1.122 + // Close the write stream:
1.123 + CleanupStack::PopAndDestroy();
1.124 + // Close the read stream:
1.125 + CleanupStack::PopAndDestroy();
1.126 + // Delete the blob of data:
1.127 + CleanupStack::PopAndDestroy(blobbuff);
1.128 + }
1.129 +
1.130 + TheTables[0].Cancel();
1.131 + TheTables[1].Cancel(); //This call to cancel panics.
1.132 +
1.133 +
1.134 + // End the transaction:
1.135 + TheDatabase.Commit();
1.136 + }
1.137 +
1.138 +/**
1.139 +@SYMTestCaseID SYSLIB-DBMS-CT-0643
1.140 +@SYMTestCaseDesc Tests for closing of tables
1.141 +@SYMTestPriority Medium
1.142 +@SYMTestActions Tests for closing of tables and database
1.143 +@SYMTestExpectedResults Test must not fail
1.144 +@SYMREQ REQ0000
1.145 +*/
1.146 +LOCAL_C void PostTestL()
1.147 + {
1.148 + test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0643 "));
1.149 + // Close the tables:
1.150 + TheTables[0].Close();
1.151 + CleanupStack::Pop(); // Table close
1.152 + TheTables[1].Close();
1.153 + CleanupStack::Pop(); // Table close
1.154 +
1.155 + // Close the database:
1.156 + CleanupStack::PopAndDestroy();
1.157 +
1.158 + TInt err;
1.159 + TRAPD(lc, err = TheCrcChecker.GenerateCrcL(KTestDatabase));
1.160 + }
1.161 +
1.162 +void doTest()
1.163 + {
1.164 + test.Start(_L("bang"));
1.165 +
1.166 + // Open a connection to the DBMS server:
1.167 +#ifndef __TOOLS2__
1.168 + User::LeaveIfError(TheDbs.Connect());
1.169 + CleanupClosePushL(TheDbs);
1.170 +#endif
1.171 +
1.172 + PreTestL();
1.173 + TestL();
1.174 + PostTestL();
1.175 +
1.176 +#ifndef __TOOLS2__
1.177 + CleanupStack::PopAndDestroy(); // TheDbs close
1.178 +#endif
1.179 + }
1.180 +
1.181 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
1.182 + {
1.183 + RFs fsSession;
1.184 + TInt err = fsSession.Connect();
1.185 + if(err == KErrNone)
1.186 + {
1.187 + TEntry entry;
1.188 + if(fsSession.Entry(aFullName, entry) == KErrNone)
1.189 + {
1.190 + RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
1.191 + err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
1.192 + if(err != KErrNone)
1.193 + {
1.194 + RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
1.195 + }
1.196 + err = fsSession.Delete(aFullName);
1.197 + if(err != KErrNone)
1.198 + {
1.199 + RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
1.200 + }
1.201 + }
1.202 + fsSession.Close();
1.203 + }
1.204 + else
1.205 + {
1.206 + RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
1.207 + }
1.208 + }
1.209 +
1.210 +//
1.211 +// Test streaming conversions.
1.212 +//
1.213 +GLDEF_C TInt E32Main()
1.214 + {
1.215 + test.Title();
1.216 + TheTrapCleanup=CTrapCleanup::New();
1.217 +
1.218 + User::LeaveIfError(TheFs.Connect());
1.219 + TInt r=TheFs.MkDir(KTestDatabase);
1.220 + test(r==KErrNone || r==KErrAlreadyExists);
1.221 +
1.222 + TRAP(r, doTest());
1.223 + test(r == KErrNone);
1.224 +
1.225 + test.Printf(_L("Waiting for server exit\n"));
1.226 + const TUint KExitDelay=6*0x100000; // ~6 seconds
1.227 + User::After(KExitDelay);
1.228 +
1.229 + ::DeleteDataFile(KTestDatabase);
1.230 +
1.231 +#ifndef __linux__
1.232 + TInt err;
1.233 +#ifndef __TOOLS2__
1.234 + TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
1.235 + test(err==KErrNone);
1.236 + test(lc==KErrNone);
1.237 +#else
1.238 + TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
1.239 + TPtrC errmsg;
1.240 + TheCrcChecker.ErrorReportL(err, errmsg);
1.241 + RDebug::Print(errmsg);
1.242 + test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
1.243 +#endif
1.244 +#endif
1.245 + test.End();
1.246 +
1.247 + TheFs.Close();
1.248 + delete TheTrapCleanup;
1.249 + test.Close();
1.250 + return r;
1.251 + }