First public contribution.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
24 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
26 #ifndef __linux__ //No CRC test on LINUX
28 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_PANIC.CRC");
30 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_PANIC.CRC");
35 LOCAL_D RTest test(_L("T_PANIC - Panic test when cancelling two blobs transactions"));
36 LOCAL_D CTrapCleanup* TheTrapCleanup;
37 LOCAL_D RDbTable TheTables[2];
42 LOCAL_D RDbNamedDatabase TheDatabase;
45 const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_PANIC.DB");
47 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_PANIC.DB");
52 @SYMTestCaseID SYSLIB-DBMS-CT-0641
53 @SYMTestCaseDesc Tests for creating the database and tables
54 @SYMTestPriority Medium
55 @SYMTestActions Tests for creating the tables.Leave on error.
56 @SYMTestExpectedResults Test must not fail
59 LOCAL_C void PreTestL()
61 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0641 "));
62 // Create the database:
63 User::LeaveIfError(TheDatabase.Replace(TheFs,KTestDatabase));
64 CleanupClosePushL(TheDatabase);
66 // Create tables in the database:
67 User::LeaveIfError(TheDatabase.Execute(_L("create table ta (a integer, b Long Varbinary)")));
68 User::LeaveIfError(TheDatabase.Execute(_L("create table tb (a integer, b Long Varbinary)")));
71 User::LeaveIfError(TheTables[0].Open(TheDatabase, _L("ta")));
72 CleanupClosePushL(TheTables[0]);
73 User::LeaveIfError(TheTables[1].Open(TheDatabase, _L("tb")));
74 CleanupClosePushL(TheTables[1]);
78 @SYMTestCaseID SYSLIB-DBMS-CT-0642
79 @SYMTestCaseDesc Tests for transaction of large data
80 @SYMTestPriority Medium
81 @SYMTestActions Tests for streaming of blob data
82 @SYMTestExpectedResults Test must not fail
87 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0642 "));
88 // Start a transaction:
91 // Create a new row on each table:
92 TheTables[0].InsertL();
93 TheTables[1].InsertL();
95 for(TInt i = 0; i < 2; ++i)
97 // Setting to null sets the dirty flag:
98 TheTables[i].SetColNullL(1);
100 // Create a blob of data:
101 _LIT8(blobdata, "abcdefghijklmnopqrstuvwxyz");
102 CBufFlat * blobbuff = CBufFlat::NewL(32);
103 CleanupStack::PushL(blobbuff);
104 blobbuff->InsertL(0, blobdata());
106 // Open a read stream on the blob:
107 RBufReadStream blobstream;
108 blobstream.Open(*blobbuff, 0);
109 CleanupClosePushL(blobstream);
111 // Open a write stream on the table:
112 RDbColWriteStream blobwrite;
113 blobwrite.OpenLC(TheTables[i], 2);
115 // Stream data from the read stream to the write stream:
116 blobwrite.WriteL(blobstream);
119 // Close the write stream:
120 CleanupStack::PopAndDestroy();
121 // Close the read stream:
122 CleanupStack::PopAndDestroy();
123 // Delete the blob of data:
124 CleanupStack::PopAndDestroy(blobbuff);
127 TheTables[0].Cancel();
128 TheTables[1].Cancel(); //This call to cancel panics.
131 // End the transaction:
132 TheDatabase.Commit();
136 @SYMTestCaseID SYSLIB-DBMS-CT-0643
137 @SYMTestCaseDesc Tests for closing of tables
138 @SYMTestPriority Medium
139 @SYMTestActions Tests for closing of tables and database
140 @SYMTestExpectedResults Test must not fail
143 LOCAL_C void PostTestL()
145 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0643 "));
147 TheTables[0].Close();
148 CleanupStack::Pop(); // Table close
149 TheTables[1].Close();
150 CleanupStack::Pop(); // Table close
152 // Close the database:
153 CleanupStack::PopAndDestroy();
156 TRAPD(lc, err = TheCrcChecker.GenerateCrcL(KTestDatabase));
161 test.Start(_L("bang"));
163 // Open a connection to the DBMS server:
165 User::LeaveIfError(TheDbs.Connect());
166 CleanupClosePushL(TheDbs);
174 CleanupStack::PopAndDestroy(); // TheDbs close
178 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
181 TInt err = fsSession.Connect();
185 if(fsSession.Entry(aFullName, entry) == KErrNone)
187 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
188 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
191 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
193 err = fsSession.Delete(aFullName);
196 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
203 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
208 // Test streaming conversions.
210 GLDEF_C TInt E32Main()
213 TheTrapCleanup=CTrapCleanup::New();
215 User::LeaveIfError(TheFs.Connect());
216 TInt r=TheFs.MkDir(KTestDatabase);
217 test(r==KErrNone || r==KErrAlreadyExists);
222 test.Printf(_L("Waiting for server exit\n"));
223 const TUint KExitDelay=6*0x100000; // ~6 seconds
224 User::After(KExitDelay);
226 ::DeleteDataFile(KTestDatabase);
231 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
235 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
237 TheCrcChecker.ErrorReportL(err, errmsg);
238 RDebug::Print(errmsg);
239 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
245 delete TheTrapCleanup;