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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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
31 #undef __UHEAP_MARKEND
32 #define __UHEAP_MARKEND
34 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
36 #ifndef __linux__ //No CRC test on LINUX
38 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_TRANS.CRC");
40 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_TRANS.CRC");
44 LOCAL_D RTest test(_L("T_TRANS - Test DBMS transactions"));
45 LOCAL_D CTrapCleanup* TheTrapCleanup;
46 LOCAL_D RDbTable TheTable;
51 LOCAL_D RDbNamedDatabase TheDatabase;
53 const TInt KTestCleanupStack=0x20;
56 const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_TRANS.DB");
58 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_TRANS.DB");
61 const TPtrC KTableName(_S("table"));
62 const TPtrC KIndexInt=_S("int");
63 const TPtrC KIndexText=_S("text");
64 const TPtrC KColumnInt=_S("int");
65 const TPtrC KColumnText=_S("text");
66 const TPtrC KColumnComment=_S("comment");
67 const TPtrC KCommentValue=_S("abcdefghijklmnopqrstuvwxyz");
68 const TInt KRecords=2000;
74 Progress(TInt aCount);
75 void Next(TInt aStep);
81 Progress::Progress(TInt aCount)
82 : iCount(aCount),iPos(0)
85 void Progress::Next(TInt aStep)
87 TInt next=(ETotal*(iCount-aStep))/iCount;
94 test.Printf(_L("\n"));
97 LOCAL_C void ProgressInc(RDbIncremental& inc,TInt aCount)
99 Progress progress(aCount);
103 progress.Next(aCount);
108 LOCAL_C void CreateDatabaseL()
110 // Create the database
113 TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
117 LOCAL_C void OpenDatabase()
119 // Create the database
122 TInt r=TheDatabase.Open(TheFs,KTestDatabase);
126 LOCAL_C void CloseDatabaseL()
129 TheCrcChecker.GenerateCrcL(KTestDatabase);
132 LOCAL_C void CreateTable()
134 TInt r=TheDatabase.Execute(_L("create table table (int integer,text varchar(8),comment varchar)"));
138 LOCAL_C void WriteRecords(TInt aCount)
140 Progress write(aCount);
141 TDbColNo cInt,cText,cComment;
142 CDbColSet* set=TheTable.ColSetL();
143 cInt=set->ColNo(KColumnInt);
144 cText=set->ColNo(KColumnText);
145 cComment=set->ColNo(KColumnComment);
149 for (TInt ii=0;ii<aCount;++ii)
155 TheTable.SetColL(cInt,jj);
157 TheTable.SetColL(cText,text);
158 TheTable.SetColL(cComment,KCommentValue);
160 write.Next(aCount-ii-1);
164 LOCAL_C TUint FileSize()
168 test(TheFs.Entry(KTestDatabase,entry)==KErrNone);
172 test(myfile.Open(TheFs, KTestDatabase, EFileRead) == KErrNone);
174 test(myfile.Size(size) == KErrNone);
180 LOCAL_C void BuildTable(TInt aCount,TBool aTransactions,TUint& aTime,TUint& aSize)
182 TUint size=FileSize();
183 TUint time=User::TickCount();
187 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
188 WriteRecords(aCount);
190 test(TheDatabase.Commit()==KErrNone);
192 aTime=User::TickCount()-time;
193 aSize=FileSize()-size;
196 LOCAL_C void Execute(const TDesC& aSql)
200 test(inc.Execute(TheDatabase,aSql,step)==KErrNone);
201 ProgressInc(inc,step);
204 LOCAL_C void BreakIndex()
207 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
209 TheTable.SetColL(1,-1);
212 TheDatabase.Rollback();
213 test(TheDatabase.IsDamaged());
216 LOCAL_C void Recover()
220 test(rec.Recover(TheDatabase,step)==KErrNone);
221 ProgressInc(rec,step);
222 test(!TheDatabase.IsDamaged());
226 @SYMTestCaseID SYSLIB-DBMS-CT-0637
227 @SYMTestCaseDesc Streaming conversions test
228 @SYMTestPriority Medium
229 @SYMTestActions Test the database definition and enquiry functions
230 @SYMTestExpectedResults Test must not fail
235 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0637 Build without transactions "));
238 BuildTable(KRecords,EFalse,time1,size1);
240 test.Next(_L("Build with transactions"));
243 BuildTable(KRecords,ETrue,time2,size2);
244 test.Printf(_L("Transaction performance: time %4.2f, size %4.2f\n"),TReal(time1)/TReal(time2),TReal(size1)/TReal(size2));
245 test.Next(_L("Build Int index"));
246 Execute(_L("create unique index int on table (int)"));
247 test.Next(_L("Break index"));
249 test.Next(_L("Build Text index"));
250 Execute(_L("create unique index text on table (text)"));
251 test.Next(_L("Recover"));
252 test (TheDatabase.IsDamaged());
255 test (TheDatabase.IsDamaged());
257 test.Next(_L("Drop table"));
258 Execute(_L("drop table table"));
262 LOCAL_C void setupTestDirectory()
264 // Prepare the test directory.
267 TInt r=TheFs.Connect();
270 r=TheFs.MkDir(KTestDatabase);
271 test(r==KErrNone || r==KErrAlreadyExists);
274 LOCAL_C void setupCleanup()
276 // Initialise the cleanup stack.
279 TheTrapCleanup=CTrapCleanup::New();
280 test(TheTrapCleanup!=NULL);
283 for (TInt i=KTestCleanupStack;i>0;i--)\
284 CleanupStack::PushL((TAny*)0);\
285 CleanupStack::Pop(KTestCleanupStack);\
290 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
293 TInt err = fsSession.Connect();
297 if(fsSession.Entry(aFullName, entry) == KErrNone)
299 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
300 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
303 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
305 err = fsSession.Delete(aFullName);
308 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
315 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
320 GLDEF_C TInt E32Main()
323 setupTestDirectory();
330 test.Printf(_L("Waiting for server exit\n"));
331 const TUint KExitDelay=6*0x100000; // ~6 seconds
332 User::After(KExitDelay);
334 //deletion of data files must be done before call to End() - DEF047652
335 ::DeleteDataFile(KTestDatabase);
340 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
344 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
346 TheCrcChecker.ErrorReportL(err, errmsg);
347 RDebug::Print(errmsg);
348 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
356 delete TheTrapCleanup;