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.
22 _LIT(KTestTitle,"t_dbfail: DBMS Failure mode test");
23 GLDEF_D RTest test(KTestTitle);
25 GLDEF_D RDbNamedDatabase TheDatabase;
26 GLDEF_D TClientHeap KClientHeap;
27 GLDEF_D TServerHeap KServerHeap;
30 LOCAL_D CTrapCleanup* TheTrapCleanup;
32 LOCAL_D RDbView TheView;
33 LOCAL_D RDbTable TheTable;
34 LOCAL_D RDbRowSet::TAccess Access;
35 LOCAL_D CDbColSet* TheColSet;
36 LOCAL_D CDbKey* TheKey;
37 LOCAL_D const TDesC* TheSql;
38 LOCAL_D TBuf<64> TheFormat;
40 const TInt KTestCleanupStack=0x20;
41 _LIT(KTestDatabase,"C:\\DBMS-TST\\t_fail.db");
42 _LIT(TableName,"Table1");
43 _LIT(TableName2,"Table_two");
44 _LIT(TableNameX,"Bad Table Name");
45 _LIT(IndexName,"Index1");
46 _LIT(IndexName2,"Index2");
47 _LIT(Column1,"column_one");
48 _LIT(Column1Fold,"COLUMN_ONE");
49 _LIT(Column2,"column_2");
50 _LIT(Column2X,"column_2%");
51 _LIT(SimpleSql,"select * from Table1");
52 _LIT(UpdateSql,"update Table1 SET column_2='hello'");
54 //const TPtrC ComplexSql(_S("select * from Table1 where column_one<0 and not column_one is null or column_2 not like '*fred*' and column_2>'m' order by column_one desc"));
55 const TPtrC ComplexSql[]=
57 _S("select * from Table1 where column_one<0 and column_one is null"),
58 _S("select * from Table1 where column_one<0 and (column_one is null and column_2 like '')"),
59 _S("select * from Table1 where (column_one<0 and column_one is null) and column_2 like ''"),
60 _S("select * from Table1 where (column_one<0 and column_one is null) and (column_2 like '' and column_one>0)"),
61 _S("select * from Table1 where (column_one<0 and column_one is null) and (column_2 like '' and column_one>0 and column_one is null)"),
62 _S("select * from Table1 where (column_one<0 and column_one is null and column_one = 10) and (column_2 like '' and column_one>0 and column_one is null)"),
63 _S("select * from Table1 where column_one<0 and column_one is null and column_one = 10 and column_2 like '' and column_one>0 and column_one is null")
72 LOCAL_D SSqlErrors const BadSql[]=
74 {_S("sponge"),KErrArgument},
75 {_S("select * from widget"),KErrNotFound},
76 {_S("select * from Table1 where x = 0"),KErrNotFound},
77 {_S("select * from Table1 where x 0 like"),KErrArgument},
78 {_S("select * from Table1 where column_2>'a' and column_one<'z'"),KErrGeneral},
79 {_S("select from Table1"),KErrArgument},
80 {_S("select x, from Table1"),KErrArgument},
81 {_S("select x from Table1"),KErrNotFound},
82 {_S("select column_2 column_one from Table1"),KErrArgument},
83 {_S("select * from Table1 order by x"),KErrNotFound},
84 {_S("select * from Table1 order column_one"),KErrArgument},
85 {_S("select * from Table1 order by column_one down"),KErrArgument}
88 GLDEF_C void Connect()
90 TInt r=TheDbs.Connect();
92 TheDbs.ResourceMark();
95 GLDEF_C void Disconnect()
97 TheDbs.ResourceCheck();
102 //SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version
103 LOCAL_C void DbCreateL()
105 User::LeaveIfError(TheDatabase.Replace(TheFs,KTestDatabase,TheFormat));
108 //SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version
109 LOCAL_C void DbOpenL()
111 User::LeaveIfError(TheDatabase.Open(TheFs,KTestDatabase,TheFormat));
112 CleanupClosePushL(TheDatabase);
113 delete TheDatabase.TableNamesL(); // force a schema load
117 //SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version
118 LOCAL_C void DbShareL()
120 User::LeaveIfError(TheDatabase.Open(TheDbs,KTestDatabase,TheFormat));
121 CleanupClosePushL(TheDatabase);
122 delete TheDatabase.TableNamesL(); // force a schema load
128 @SYMTestCaseID SYSLIB-DBMS-CT-0612
129 @SYMTestCaseDesc Database validity test
130 @SYMTestPriority Medium
131 @SYMTestActions Tests for opening and closing of database
132 @SYMTestExpectedResults Test must not fail
135 LOCAL_C void TestOpenL()
137 _LIT(KFileNotFound,"not a database");
138 TInt r=TheDatabase.Open(TheFs,KFileNotFound);
139 test (r==KErrNotFound || r==KErrPathNotFound);
141 _LIT(KPathNotFound,"C:\\not a path\\database.db");
142 r=TheDatabase.Open(TheFs,KPathNotFound);
143 test (r==KErrPathNotFound);
145 _LIT(KNotFormat,"not.a.dbx");
146 r=TheDatabase.Open(TheFs,KFileNotFound,KNotFormat);
147 test (r==KErrNotFound || r==KErrPathNotFound);
151 r=TheDatabase.Open(TheFs,KTestDatabase,TUid::Uid(0x01234567).Name());
152 test (r==KErrNone); // New code has no loadable drivers, it is irrelevant to expect error here
153 TheDatabase.Close(); // We have added it here because previous statement does not return error anymore
156 r=f.Replace(TheFs,KTestDatabase,EFileWrite);
158 TCheckedUid type(KDirectFileStoreLayoutUid);
159 r=f.Write(type.Des());
162 r=TheDatabase.Open(TheFs,KTestDatabase);
163 test (r==KErrNotSupported);
165 _LIT(KDefaultFormat,"epoc");
166 r=TheDatabase.Open(TheFs,KTestDatabase,KDefaultFormat);
167 test (r==KErrNotSupported); // We expect not supported db here
170 class TClient : public TContext
178 class TServer : public TContext
187 const TClient KClient;
188 const TServer KServer;
190 void TFail::Test(const THeapFail& aHeap,const TContext* aContext)
198 TRAP(errCode, aContext->OpenDbL());
199 if(errCode != KErrNone)
208 test(r==KErrNoMemory);
219 class TFailCreateDatabase : public TFail
224 {TheDatabase.Close();}
227 class TFailOpenDatabase : public TFail
232 {TheDatabase.Close();}
235 class TFailShareDatabase : public TFail
240 {TheDatabase.Close();}
244 @SYMTestCaseID SYSLIB-DBMS-CT-0613
245 @SYMTestCaseDesc Tests for allocation failures on creating a database
246 @SYMTestPriority Medium
247 @SYMTestActions Tests for allocation failure for differently sourced databases
248 @SYMTestExpectedResults Test must not fail
251 LOCAL_C void OriginsL()
253 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0613 Allocation failures on Creating a database "));
254 TFailCreateDatabase t1;
255 t1.Test(KClientHeap);
257 test.Next(_L("Fail to create existing database"));
259 TInt r=TheFs.Att(KTestDatabase,att);
261 r=TheDatabase.Create(TheFs,KTestDatabase,TheFormat);
262 test (r==KErrAlreadyExists);
263 r=TheFs.Att(KTestDatabase,att);
266 test.Next(_L("Allocation failures on Open"));
267 TFailOpenDatabase t2;
268 t2.Test(KClientHeap);
270 test.Next(_L("Allocation failures on 1st Share"));
272 TFailShareDatabase t3;
273 t3.Test(KClientHeap);
274 t3.Test(KServerHeap);
276 test.Next(_L("Allocation failures on 2nd Share"));
278 RDbNamedDatabase temp=TheDatabase;TheDatabase=RDbNamedDatabase();
279 t3.Test(KClientHeap);
280 t3.Test(KServerHeap);
287 class TFailCreateTable : public TFail
290 {User::LeaveIfError(TheDatabase.CreateTable(TableName,*TheColSet));}
293 class TFailAlterTable : public TFail
296 {User::LeaveIfError(TheDatabase.AlterTable(TableName,*TheColSet));}
299 class TFailDropTable : public TFail
302 {User::LeaveIfError(TheDatabase.DropTable(TableName));}
305 class TFailCreateIndex : public TFail
308 {User::LeaveIfError(TheDatabase.CreateIndex(IndexName,TableName,*TheKey));}
311 class TFailDropIndex : public TFail
314 {User::LeaveIfError(TheDatabase.DropIndex(IndexName,TableName));}
317 class TFailGetObject : public TFail
326 class TFailDatabaseTables : public TFailGetObject
329 {iObject=TheDatabase.TableNamesL();}
332 class TFailDatabaseColSet : public TFailGetObject
335 {iObject=TheDatabase.ColSetL(TableName);}
338 class TFailDatabaseIndexes : public TFailGetObject
341 {iObject=TheDatabase.IndexNamesL(TableName);}
344 class TFailDatabaseKeys : public TFailGetObject
347 {iObject=TheDatabase.KeyL(IndexName,TableName);}
350 const TInt KRowCount=60;
352 LOCAL_C void WriteTableL()
355 TInt r=TheTable.Open(TheDatabase,TableName);
358 for (TInt ii=0;ii<KRowCount;++ii)
361 TheTable.SetColL(1,TUint((ii*17)%KRowCount));
364 r=TheDatabase.Commit();
370 LOCAL_C void DatabaseL()
372 test.Start(_L("Adding and dropping tables"));
374 // ensure the database locking list has been allocated
376 TheDatabase.Commit();
378 CDbColSet *col=CDbColSet::NewLC();
380 test.Next(_L("Empty Column Set"));
382 test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
385 test.Next(_L("Invalid table name"));
386 col->AddL(TDbCol(Column1,EDbColInt32));
388 test(TheDatabase.CreateTable(TableNameX,*col)!=KErrNone);
391 test.Next(_L("Invalid column name"));
392 col->AddL(TDbCol(Column2X,EDbColBit));
394 test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
397 test.Next(_L("Duplicate column name"));
398 col->Remove(Column2X);
399 col->AddL(TDbCol(Column1Fold,EDbColBit));
401 test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
404 test.Next(_L("Invalid column type"));
405 col->Remove(Column1);
406 col->AddL(TDbCol(Column2,TDbColType(-1)));
408 test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
411 test.Next(_L("Invalid maximum length"));
412 col->Remove(Column2);
413 col->AddL(TDbCol(Column2,EDbColInt32,0));
415 test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
418 test.Next(_L("Invalid attributes"));
419 col->Remove(Column2);
420 TDbCol cc(Column2,EDbColInt32);
424 test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
427 test.Next(_L("Adding/dropping a table name twice"));
428 col->Remove(Column2);
429 col->AddL(TDbCol(Column2,EDbColText8));
431 test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
432 test(TheDatabase.CreateTable(TableName,*col)==KErrAlreadyExists);
433 test(TheDatabase.DropTable(TableNameX)!=KErrNone);
434 test(TheDatabase.DropTable(TableName)==KErrNone);
435 test(TheDatabase.DropTable(TableName)==KErrNotFound);
438 test.Next(_L("Adding and dropping indexes"));
439 test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
441 CDbKey *key=CDbKey::NewLC();
444 test(TheDatabase.CreateIndex(IndexName,TableName,*key)!=KErrNone);
447 key->AddL(Column2X());
450 test(TheDatabase.CreateIndex(IndexName,TableName,*key)!=KErrNone);
454 key->AddL(Column1());
457 test(TheDatabase.CreateIndex(TableNameX,TableName,*key)!=KErrNone);
461 test(TheDatabase.CreateIndex(IndexName,TableNameX,*key)!=KErrNone);
466 test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrNone);
467 test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrAlreadyExists);
468 test(TheDatabase.DropIndex(TableNameX,TableName)!=KErrNone);
469 test(TheDatabase.DropIndex(IndexName,TableNameX)!=KErrNone);
470 test(TheDatabase.DropIndex(IndexName,TableName)==KErrNone);
471 test(TheDatabase.DropIndex(IndexName,TableName)==KErrNotFound);
472 test(TheDatabase.DropTable(TableName)==KErrNone);
473 test(TheDatabase.DropIndex(IndexName,TableName)==KErrNotFound);
477 test.Next(_L("Allocation failure during DDL"));
478 TFailCreateTable fct;
481 TFailCreateIndex fci;
483 TheColSet=CDbColSet::NewL();
484 TheColSet->AddL(TDbCol(Column1,EDbColUint16));
485 TheKey=CDbKey::NewL();
486 TheKey->AddL(Column1());
487 fct.Test(KClientHeap,KClient);
489 TheColSet->AddL(TDbCol(Column2,EDbColText));
490 fat.Test(KClientHeap,KClient);
491 fci.Test(KClientHeap,KClient);
492 fdi.Test(KClientHeap,KClient);
493 fdt.Test(KClientHeap,KClient);
495 test.Next(_L("Allocation failure during server DDL"));
497 TheColSet->Remove(Column2);
498 fct.Test(KClientHeap,KServer);
500 TheColSet->AddL(TDbCol(Column2,EDbColText));
501 fat.Test(KClientHeap,KServer);
502 fci.Test(KClientHeap,KServer);
503 fdi.Test(KClientHeap,KServer);
504 fdt.Test(KClientHeap,KServer);
506 TheColSet->Remove(Column2);
507 fct.Test(KServerHeap,KServer);
509 TheColSet->AddL(TDbCol(Column2,EDbColText));
510 fat.Test(KServerHeap,KServer);
511 fci.Test(KServerHeap,KServer);
512 fdi.Test(KServerHeap,KServer);
513 fdt.Test(KServerHeap,KServer);
520 test.Next(_L("Allocation failure on schema enquiry"));
522 test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
523 test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrNone);
524 CleanupStack::PopAndDestroy(2); // columns set and key
526 TFailDatabaseTables t4;
527 TFailDatabaseColSet t5;
528 TFailDatabaseIndexes t6;
529 TFailDatabaseKeys t7;
530 t4.Test(KClientHeap,KClient);
531 t5.Test(KClientHeap,KClient);
532 t6.Test(KClientHeap,KClient);
533 t7.Test(KClientHeap,KClient);
535 test.Next(_L("Allocation failure on server schema enquiry"));
537 t4.Test(KClientHeap,KServer);
538 t4.Test(KServerHeap,KServer);
539 t5.Test(KClientHeap,KServer);
540 t5.Test(KServerHeap,KServer);
541 t6.Test(KClientHeap,KServer);
542 t6.Test(KServerHeap,KServer);
543 t7.Test(KClientHeap,KServer);
544 t7.Test(KServerHeap,KServer);
549 class TFailOpenTable : public TFail
552 {User::LeaveIfError(TheTable.Open(TheDatabase,TableName,Access));}
558 @SYMTestCaseID SYSLIB-DBMS-CT-0614
559 @SYMTestCaseDesc Tests for allocation failure on opening and closing of database
560 @SYMTestPriority Medium
561 @SYMTestActions Tests for opening and closing of database
562 @SYMTestExpectedResults Test must not fail
565 LOCAL_C void TestTableL(const THeapFail& aHeap,const TContext& aContext)
567 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0614 Allocation failure on Open "));
569 Access=RDbRowSet::EUpdatable;
570 fot.Test(aHeap,aContext);
571 Access=RDbRowSet::EReadOnly;
572 fot.Test(aHeap,aContext);
573 Access=RDbRowSet::EInsertOnly;
574 fot.Test(aHeap,aContext);
576 test.Next(_L("Open invalid table"));
579 TInt r=TheTable.Open(TheDatabase,TableNameX);
583 test.Next(_L("Set invalid index"));
584 r=TheTable.Open(TheDatabase,TableName);
587 r=TheTable.SetIndex(IndexName2);
591 test.Next(_L("Allocation failure on 2nd Open"));
592 RDbTable table(TheTable);
593 Access=RDbRowSet::EUpdatable;
595 Access=RDbRowSet::EReadOnly;
597 Access=RDbRowSet::EInsertOnly;
604 LOCAL_C void TestTableDDL(const TContext& aContext)
606 test.Start(_L("DDL while open"));
608 TInt r=TheTable.Open(TheDatabase,TableName);
610 CDbColSet* set=CDbColSet::NewLC();
611 set->AddL(TDbCol(Column1,EDbColText));
612 r=TheDatabase.CreateTable(TableName2,*set);
614 TRAP(r,TheTable.CountL(TheTable.EQuick));
617 r=TheTable.Open(TheDatabase,TableName2);
620 set->AddL(TDbCol(Column2,EDbColUint32));
621 r=TheDatabase.AlterTable(TableName2,*set);
623 CleanupStack::PopAndDestroy(); // set
624 TRAP(r,TheTable.CountL(TheTable.EQuick));
625 test (r==KErrDisconnected);
627 TRAP(r,TheTable.CountL(TheTable.EQuick));
628 test (r==KErrDisconnected);
630 r=TheTable.Open(TheDatabase,TableName2);
633 CDbKey* key=CDbKey::NewLC();
634 key->AddL(Column2());
635 r=TheDatabase.CreateIndex(IndexName2,TableName,*key);
637 TRAP(r,TheTable.CountL(TheTable.EQuick));
639 r=TheDatabase.DropIndex(IndexName2,TableName);
641 TRAP(r,TheTable.CountL(TheTable.EQuick));
644 r=TheDatabase.CreateIndex(IndexName,TableName2,*key);
646 CleanupStack::PopAndDestroy(); // key
647 TRAP(r,TheTable.CountL(TheTable.EQuick));
648 test (r==KErrDisconnected);
650 r=TheTable.Open(TheDatabase,TableName2);
653 r=TheDatabase.DropIndex(IndexName,TableName2);
655 TRAP(r,TheTable.CountL(TheTable.EQuick));
656 test (r==KErrDisconnected);
658 r=TheTable.Open(TheDatabase,TableName2);
661 r=TheDatabase.DropTable(TableName2);
663 TRAP(r,TheTable.CountL(TheTable.EQuick));
664 test (r==KErrDisconnected);
670 LOCAL_C void TableL()
672 test.Start(_L("Testing Client-side"));
673 TestTableL(KClientHeap,KClient);
674 TestTableDDL(KClient);
675 test.Next(_L("Testing Client-Server"));
677 TestTableL(KClientHeap,KServer);
678 TestTableL(KServerHeap,KServer);
679 TestTableDDL(KServer);
684 class TFailExecuteSQL : public TFail
687 {User::LeaveIfError(TheDatabase.Execute(*TheSql));}
692 class TFailPrepareView : public TFail
695 {User::LeaveIfError(TheView.Prepare(TheDatabase,*TheSql,Access));}
701 @SYMTestCaseID SYSLIB-DBMS-CT-0615
702 @SYMTestCaseDesc Tests for allocation failure on prepare
703 @SYMTestPriority Medium
704 @SYMTestActions Tests for error on updating a row set data
705 @SYMTestExpectedResults Test must not fail
708 LOCAL_C void TestView(const THeapFail& aHeap,const TContext& aContext)
710 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0615 Allocation failure on Prepare "));
711 TFailPrepareView fpv;
713 Access=RDbRowSet::EUpdatable;
714 fpv.Test(aHeap,aContext);
715 Access=RDbRowSet::EReadOnly;
716 fpv.Test(aHeap,aContext);
717 Access=RDbRowSet::EInsertOnly;
718 fpv.Test(aHeap,aContext);
720 test.Next(_L("Allocation failure on Prepare (complex SQL)"));
721 for (TUint ii=0;ii<sizeof(ComplexSql)/sizeof(ComplexSql[0]);++ii)
723 TheSql=&ComplexSql[ii];
724 Access=RDbRowSet::EUpdatable;
725 fpv.Test(aHeap,aContext);
731 @SYMTestCaseID SYSLIB-DBMS-CT-0616
732 @SYMTestCaseDesc Bad SQL query test
733 @SYMTestPriority Medium
734 @SYMTestActions Test for bad query
735 @SYMTestExpectedResults Test must not fail
738 LOCAL_C void TestSQLL(const TContext& aContext)
740 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0616 Bad SQL "));
742 for (TUint ii=0;ii<sizeof(BadSql)/sizeof(BadSql[0]);++ii)
743 test(TheView.Prepare(TheDatabase,TPtrC(BadSql[ii].iSql))==BadSql[ii].iError);
749 @SYMTestCaseID SYSLIB-DBMS-CT-0617
750 @SYMTestCaseDesc Tests for updation of an SQL statement
751 @SYMTestPriority Medium
752 @SYMTestActions Tests for update SQL statement
753 @SYMTestExpectedResults Test must not fail
756 LOCAL_C void TestUpdateSQL(const THeapFail& aHeap,const TContext& aContext)
758 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0617 Test for UPDATE SQL statement "));
759 TFailExecuteSQL fsql;
761 fsql.Test(aHeap,aContext);
767 test.Start(_L("Client side"));
768 TestView(KClientHeap,KClient);
770 test.Next(_L("Client-Server"));
772 TestView(KClientHeap,KServer);
773 TestView(KServerHeap,KServer);
775 TestUpdateSQL(KClientHeap,KClient);
776 TestUpdateSQL(KServerHeap,KClient);
781 //TFailIncrementalUpdate implements the base class' virtual methods - RunL() and End().
782 //TFailIncrementalUpdate::RunL() is called by the base class' Test() method, which simulates
783 //OOM failures and checks the behaviour of the "incremental update" statement used by RunL().
784 class TFailIncrementalUpdate : public TFail
789 CleanupClosePushL(dbUpdate);
790 User::LeaveIfError(dbUpdate.Execute(TheDatabase, _L("UPDATE A SET Name = 'ModifiedNameString' WHERE Id2 > 10")));
792 for(TInt err=1;err>0;++step)
794 err = dbUpdate.Next();
795 User::LeaveIfError(err);
797 test(step > 1);//just to be sure that the test executes dbUpdate.Next() more than once
798 CleanupStack::PopAndDestroy(&dbUpdate);
807 @SYMTestCaseID SYSLIB-DBMS-UT-3414
808 @SYMTestCaseDesc "Incremental update" operations - OOM test.
809 @SYMTestPriority High
810 @SYMTestActions Create a test database with one table and insert some records there (> 100).
811 Run an "incremental update" operation in OOM loop.
812 @SYMTestExpectedResults The test should not fail or panic.
815 LOCAL_C void IncrementalUpdateTest(const THeapFail& aHeap)
817 //Create a test shared database with a table
820 TInt err = TheDbs.Connect();
821 test(err == KErrNone);
822 err = TheDatabase.Replace(TheFs, KTestDatabase);
823 test(err == KErrNone);
825 err = TheDatabase.Open(TheDbs, KTestDatabase);
826 test(err == KErrNone);
827 //Create a test table and fill the table with enough test records (> 100)
828 err = TheDatabase.Execute(_L("CREATE TABLE A(Id COUNTER, Id2 INTEGER, Name LONG VARCHAR)"));
829 test(err == KErrNone);
830 const TInt KTestRecCount = 110;
831 err = TheDatabase.Begin();
832 test(err == KErrNone);
833 for(TInt i=0;i<KTestRecCount;++i)
835 _LIT(KSqlFmtStr, "INSERT INTO A(Id2, Name) VALUES(%d, 'TestNameString')");
837 TUint32 id = Math::Random() % KTestRecCount;
838 sql.Format(KSqlFmtStr, id + 1);
839 err = TheDatabase.Execute(sql);
842 err = TheDatabase.Commit();
843 test(err == KErrNone);
845 TFailIncrementalUpdate testObj;
853 // Testing the DBMS for failure modes
855 LOCAL_C void doMainL()
857 test.Start(_L("Class RDbNamedDatabase"));
864 test.Next(_L("Class RDbDatabase"));
867 test.Next(_L("Class RDbTable"));
870 test.Next(_L("Class RDbView"));
877 // Prepare the test directory.
879 LOCAL_C void setupTestDirectory()
881 TInt r=TheFs.Connect();
884 r=TheFs.MkDir(KTestDatabase);
885 test(r==KErrNone || r==KErrAlreadyExists);
889 // Initialise the cleanup stack.
891 LOCAL_C void setupCleanup()
893 TheTrapCleanup=CTrapCleanup::New();
894 test(TheTrapCleanup!=NULL);
897 for (TInt i=KTestCleanupStack;i>0;i--)\
898 CleanupStack::PushL((TAny*)0);\
899 CleanupStack::Pop(KTestCleanupStack);\
904 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
907 TInt err = fsSession.Connect();
911 if(fsSession.Entry(aFullName, entry) == KErrNone)
913 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
914 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
917 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
919 err = fsSession.Delete(aFullName);
922 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
929 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
933 GLDEF_C TInt E32Main()
936 setupTestDirectory();
940 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0612 Locating a database "));
941 TRAPD(r,TestOpenL());
943 PrepareDbFmtString();
946 test.Next(_L("Standard database"));
949 test.Next(_L("Secure database"));
952 test.Next(_L("ISAM database"));
953 TheFormat=_S("epoc[12345678]");
958 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3414 \"Incremental update\" - client test "));
959 IncrementalUpdateTest(KClientHeap);
961 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3414 \"Incremental update\" - client-server test "));
962 IncrementalUpdateTest(KServerHeap);
965 ::DeleteDataFile(KTestDatabase); // clean up data file used by this test - must be done before call to End() - DEF047652
970 delete TheTrapCleanup;