os/persistentdata/persistentstorage/dbms/tdbms/t_dbapi.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <d32dbms.h>
    17 #include <s32file.h>
    18 #include <e32test.h>
    19 
    20 #if defined(__VC32__) && !defined(_DEBUG)
    21 #pragma warning(disable : 4710)			// function not expanded. MSVC 4.0 is stupid
    22 #endif
    23 
    24 LOCAL_D RTest test(_L("t_dbapi : Test DBMS API"));
    25 LOCAL_D CTrapCleanup* TheTrapCleanup;
    26 LOCAL_D RDbs TheDbs;
    27 LOCAL_D RDbNamedDatabase TheDatabase;
    28 LOCAL_D RDbTable TheTable;
    29 LOCAL_D RDbView TheView;
    30 LOCAL_D RFs TheFs;
    31 LOCAL_D TBuf8<0x200> TheBuf8;
    32 LOCAL_D TBuf16<0x100> TheBuf16;
    33 
    34 const TInt KTestCleanupStack=0x40;
    35 const TPtrC KTestDatabase=_L("C:\\DBMS-TST\\T_DBMS.DB");
    36 const TPtrC8 KTestText8(_S8("Text used for test columns when testing"));
    37 const TPtrC8 KTestShortText8(_S8("a"));
    38 const TPtrC8 KTestLongText8(_S8("Text which is used to set Long ASCII Text columns and ensure they are not inlined, and therefore needs to be very long indeed............." \
    39 							"Text which is used to set Long ASCII Text columns and ensure they are not inlined, and therefore needs to be very long indeed............."));
    40 const TPtrC16 KTestText16(_S16("Text used for test columns when testing"));
    41 const TPtrC16 KTestShortText16(_S16("a"));
    42 const TPtrC16 KTestLongText16(_S16("Text which is used to set Long UNICODE Text columns and ensure they are not inlined, and therefore needs to be very long indeed............."));
    43 const TPtrC KTableName(_S("TestTable"));
    44 const TPtrC KTableName2(_S("TestTable2"));
    45 const TPtrC KTestViewTable(_L("TestViewTable"));
    46 const TPtrC KTestTypesTable(_L("TestTypesTable"));
    47 const TPtrC KTestFindTable(_L("TestFindTable"));
    48 const TPtrC KTestMultiTable(_L("TestMultiTable"));
    49 const TPtrC KIndexName(_S("Index1"));
    50 const TPtrC KIndexName2(_S("Index2"));
    51 const TPtrC KIndexName3(_S("Index3"));
    52 const TInt KBlobItems=1000;
    53 
    54 const TPtrC KNull=TPtrC();
    55 const TPtrC KPass1(_S("wibble"));
    56 const TPtrC KPass2(_S("wobble"));
    57 
    58 const TReal32 KMinTReal32=(TReal32)1.2345e-37;
    59 const TReal32 KMaxTReal32=(TReal32)9.8765e37;
    60 const TReal64 KMinTReal64=1.23456789e-300;
    61 const TReal64 KMaxTReal64=9.87654321e300;
    62 
    63 const TTime KMinTTime=Time::MinTTime();
    64 const TTime KMaxTTime=Time::MaxTTime();
    65 
    66 struct SColDef
    67 	{
    68 	const TText* iName;
    69 	TDbColType iType;
    70 	TInt iAttributes;
    71 	};
    72 LOCAL_D SColDef const SingleColumn[]=
    73 	{
    74 	{_S("Column1"),EDbColInt32,0},
    75 	{0}
    76 	};
    77 LOCAL_D SColDef const DoubleColumn[]=
    78 	{
    79 	{_S("Column1"),EDbColInt32,0},
    80 	{_S("c2"),EDbColInt64,0},
    81 	{0}
    82 	};
    83 LOCAL_D SColDef const ViewTestColumns[]=
    84 	{
    85 	{_S("Int"),EDbColInt32,0},
    86 	{_S("Long1"),EDbColLongText8,0},
    87 	{_S("Long2"),EDbColLongText8,0},
    88 	{_S("Long3"),EDbColLongText8,0},
    89 	{_S("Long4"),EDbColLongText8,0},
    90 	{_S("Long5"),EDbColLongText8,0},
    91 	{0}
    92 	};
    93 LOCAL_D SColDef const AllColumns[]=
    94 	{
    95 	{_S("counter"),EDbColInt32,TDbCol::ENotNull|TDbCol::EAutoIncrement},
    96 	{_S("bit"),EDbColBit,TDbCol::ENotNull},
    97 	{_S("int8"),EDbColInt8,TDbCol::ENotNull},
    98 	{_S("uint8"),EDbColUint8,TDbCol::ENotNull},
    99 	{_S("int16"),EDbColInt16,TDbCol::ENotNull},
   100 	{_S("uint16"),EDbColUint16,TDbCol::ENotNull},
   101 	{_S("int32"),EDbColInt32,TDbCol::ENotNull},
   102 	{_S("uint32"),EDbColUint32,TDbCol::ENotNull},
   103 	{_S("int64"),EDbColInt64,TDbCol::ENotNull},
   104 	{_S("real32"),EDbColReal32,TDbCol::ENotNull},
   105 	{_S("real64"),EDbColReal64,TDbCol::ENotNull},
   106 	{_S("date_time"),EDbColDateTime,TDbCol::ENotNull},
   107 	{_S("text8"),EDbColText8,TDbCol::ENotNull},
   108 	{_S("text16"),EDbColText16,TDbCol::ENotNull},
   109 	{_S("binary"),EDbColBinary,TDbCol::ENotNull},
   110 	{_S("longtext8"),EDbColLongText8,TDbCol::ENotNull},
   111 	{_S("longtext16"),EDbColLongText16,TDbCol::ENotNull},
   112 	{_S("longbinary"),EDbColLongBinary,TDbCol::ENotNull},
   113 	{_S("bit_null"),EDbColBit,0},
   114 	{_S("int8_null"),EDbColInt8,0},
   115 	{_S("uint8_null"),EDbColUint8,0},
   116 	{_S("int16_null"),EDbColInt16,0},
   117 	{_S("uint16_null"),EDbColUint16,0},
   118 	{_S("int32_null"),EDbColInt32,0},
   119 	{_S("uint32_null"),EDbColUint32,0},
   120 	{_S("int64_null"),EDbColInt64,0},
   121 	{_S("real32_null"),EDbColReal32,0},
   122 	{_S("real64_null"),EDbColReal64,0},
   123 	{_S("date_time_null"),EDbColDateTime,0},
   124 	{_S("text8_null"),EDbColText8,0},
   125 	{_S("text16_null"),EDbColText16,0},
   126 	{_S("binary_null"),EDbColBinary,0},
   127 	{_S("longtext8_null"),EDbColLongText8,0},
   128 	{_S("longtext16_null"),EDbColLongText16,0},
   129 	{_S("longbinary_null"),EDbColLongBinary,0},
   130 	{_S("force_null"),EDbColInt32,0},
   131 	{0}
   132 	};
   133 const TInt KColumns=sizeof(AllColumns)/sizeof(AllColumns[0])-1;
   134 enum TColumns
   135 	{
   136 	ECounter,
   137 	EBit,EInt8,EUint8,EInt16,EUint16,EInt32,EUint32,EInt64,
   138 	EReal32,EReal64,ETime,EText8,EText16,ETBinary,
   139 	ELongText8,ELongText16,ELongBinary,
   140 	EBitNull,EInt8Null,EUint8Null,EInt16Null,EUint16Null,EInt32Null,EUint32Null,EInt64Null,
   141 	EReal32Null,EReal64Null,ETimeNull,EText8Null,EText16Null,ETBinaryNull,
   142 	ELongText8Null,ELongText16Null,ELongBinaryNull,EForceNull
   143 	};
   144 LOCAL_D TDbColNo TheMap[KColumns];
   145 
   146 CDbColSet* ColumnSetL(const SColDef* aDef)
   147 	{
   148 	CDbColSet *set=CDbColSet::NewLC();
   149 	for (;aDef->iName;++aDef)
   150 		{
   151 		TDbCol col(TPtrC(aDef->iName),aDef->iType);
   152 		col.iAttributes=aDef->iAttributes;
   153 		set->AddL(col);
   154 		}
   155 	CleanupStack::Pop();
   156 	return set;
   157 	}
   158 
   159 enum TColSet {EAllTypes,ESingleColumn,EDoubleColumn,EViewTestTable};
   160 LOCAL_D const SColDef* const ColSetDef[]=
   161 	{
   162 	AllColumns,
   163 	SingleColumn,
   164 	DoubleColumn,
   165 	ViewTestColumns
   166 	};
   167 LOCAL_C CDbColSet* CreateColSetL(TColSet aType)
   168 	{
   169 	return ColumnSetL(ColSetDef[aType]);
   170 	}
   171 
   172 inline TPtrC ColName(const SColDef* aSet,TInt aColumn)
   173 	{return TPtrC(aSet[aColumn].iName);}
   174 
   175 enum TKeySet {EKeyAsc,EKeyDesc,EKeyMulti,EKeySingle};
   176 LOCAL_C CDbKey* CreateKeyL(TKeySet aType)
   177 	{
   178 	CDbKey *k=CDbKey::NewLC();
   179 	switch(aType)
   180 		{
   181 	case EKeyAsc:
   182 		k->AddL(ColName(AllColumns,EInt32));
   183 		break;
   184 	case EKeyDesc:
   185 		k->AddL(TDbKeyCol(ColName(AllColumns,EInt32),TDbKeyCol::EDesc));
   186 		k->MakeUnique();
   187 		break;
   188 	case EKeyMulti:
   189 		k->AddL(ColName(AllColumns,EInt32)).AddL(ColName(AllColumns,EText8));
   190 		k->SetComparison(EDbCompareFolded);
   191 		break;
   192 	case EKeySingle:
   193 		k->AddL(ColName(SingleColumn,0));
   194 		break;
   195 		}
   196 	CleanupStack::Pop();
   197 	return k;
   198 	}
   199 
   200 LOCAL_C void CloseDatabase()
   201 	{
   202 	TheDatabase.Close();
   203 	}
   204 
   205 
   206 //
   207 // Open a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   208 //
   209 LOCAL_C TInt OpenSharedDatabase()
   210 	{
   211 	return TheDatabase.Open(TheDbs,KTestDatabase);
   212 	}
   213 
   214 //
   215 // Create a local database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   216 //
   217 LOCAL_C void CreateClientDatabase()
   218 	{
   219 	TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
   220 	test (r==KErrNone);
   221 	}
   222 
   223 //
   224 // Create a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   225 //
   226 LOCAL_C void CreateSharedDatabase()
   227 	{
   228 	CreateClientDatabase();
   229 	CloseDatabase();
   230 	TInt r=OpenSharedDatabase();
   231 	test (r==KErrNone);
   232 	}
   233 
   234 //
   235 // Open a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   236 //
   237 LOCAL_C void OpenDatabase()
   238 	{
   239 	TInt r=OpenSharedDatabase();
   240 	test (r==KErrNone);
   241 	}
   242 
   243 //
   244 // Create a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   245 //
   246 LOCAL_C void CreateDatabase()
   247 	{
   248 	CreateSharedDatabase();
   249 	}
   250 
   251 
   252 LOCAL_C void DestroyDatabase()
   253 	{
   254 	TInt r=TheDatabase.Destroy();
   255 	test (r==KErrNone);
   256 	}
   257 
   258 //
   259 // Check the database has this many tables
   260 //
   261 LOCAL_C void CountTablesL(TInt aCount)
   262 	{
   263 	CDbNames* names=TheDatabase.TableNamesL();
   264 	test (names->Count()==aCount);
   265 	delete names;
   266 	}
   267 
   268 //
   269 // Compare two column sets
   270 //
   271 LOCAL_C void CompareL(const TDesC& aTable,const CDbColSet& aSet)
   272 	{
   273 	CDbColSet* set=TheDatabase.ColSetL(aTable);
   274 	test(set->Count()==aSet.Count());
   275 	for (TDbColSetIter iter(*set);iter;++iter)
   276 		{
   277 		const TDbCol* pRight=aSet.Col(iter->iName);
   278 		test(pRight!=NULL);
   279 		test(iter->iType==pRight->iType);
   280 		test(iter->iMaxLength==KDbUndefinedLength || pRight->iMaxLength==KDbUndefinedLength || iter->iMaxLength==pRight->iMaxLength);
   281 		test((iter->iAttributes&pRight->iAttributes)==iter->iAttributes);
   282 		}
   283 	delete set;
   284 	}
   285 
   286 //
   287 // Check the database has this many tables
   288 //
   289 LOCAL_C void CountIndexesL(const TDesC& aTable,TInt aCount)
   290 	{
   291 	CDbNames* names=TheDatabase.IndexNamesL(aTable);
   292 	test (names->Count()==aCount);
   293 	delete names;
   294 	}
   295 
   296 //
   297 // Compare index definition
   298 //
   299 LOCAL_C void CompareL(const TDesC& aIndex,const TDesC& aTable,const CDbKey& aKey)
   300 	{
   301 	CDbKey* key=TheDatabase.KeyL(aIndex,aTable);
   302 	test(key->Count()==aKey.Count());
   303 	test(key->Comparison()==aKey.Comparison());
   304 	test(key->IsUnique()==aKey.IsUnique());
   305 	for (TInt ii=aKey.Count();--ii>=0;)
   306 		{
   307 		const TDbKeyCol& left=(*key)[ii];
   308 		const TDbKeyCol& right=aKey[ii];
   309 		test (left.iName==right.iName);
   310 		test (left.iOrder==right.iOrder);
   311 		test (left.iLength==right.iLength || right.iLength==KDbUndefinedLength);
   312 		}
   313 	delete key;
   314 	}
   315 
   316 /**
   317 @SYMTestCaseID          SYSLIB-DBMS-CT-0594
   318 @SYMTestCaseDesc        Tests the database definition and enquiry functions
   319 @SYMTestPriority        Medium
   320 @SYMTestActions         Tests for creation and opening of a database,creation of a table
   321                         Tests for comparing column and table column sets
   322 						Tests for altering a table and creation of an index.
   323 @SYMTestExpectedResults Test must not fail
   324 @SYMREQ                 REQ0000
   325 */
   326 LOCAL_C void TestDDL()
   327 	{
   328 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0594 Create Database "));
   329 	CreateDatabase();
   330 	CountTablesL(0);
   331 	CloseDatabase();
   332 	test.Next(_L("Open Database"));
   333 	OpenDatabase();
   334 	CountTablesL(0);
   335 	test.Next(_L("CreateTable"));
   336 	CDbColSet* cs=CreateColSetL(EAllTypes);
   337 	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
   338 	CountTablesL(1);
   339 	test.Next(_L("Compare column sets"));
   340 	CompareL(KTableName,*cs);
   341 	CloseDatabase();
   342 	test.Next(_L("Re-open database"));
   343 	OpenDatabase();
   344 	CountTablesL(1);
   345 	test.Next(_L("Compare table column sets"));
   346 	CompareL(KTableName,*cs);
   347 	delete cs;
   348 	test.Next(_L("Add another table"));
   349 	cs=CreateColSetL(ESingleColumn);
   350 	test(TheDatabase.CreateTable(KTableName2,*cs)==KErrNone);
   351 	CompareL(KTableName2,*cs);
   352 	delete cs;
   353 	CountTablesL(2);
   354 //
   355 	test.Next(_L("Alter table"));
   356 	cs=CreateColSetL(EDoubleColumn);
   357 	test(TheDatabase.AlterTable(KTableName2,*cs)==KErrNone);
   358 	CompareL(KTableName2,*cs);
   359 	delete cs;
   360 	CountTablesL(2);
   361 //
   362 	test.Next(_L("Test index creation"));
   363 	CountIndexesL(KTableName,0);
   364 	CountIndexesL(KTableName2,0);
   365 	CDbKey* key=CreateKeyL(EKeyAsc);
   366 	test (TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
   367 	CompareL(KIndexName,KTableName,*key);
   368 	delete key;
   369 	key=CreateKeyL(EKeyDesc);
   370 	test (TheDatabase.CreateIndex(KIndexName2,KTableName,*key)==KErrNone);
   371 	CompareL(KIndexName2,KTableName,*key);
   372 	delete key;
   373 	key=CreateKeyL(EKeySingle);
   374 	test (TheDatabase.CreateIndex(KIndexName,KTableName2,*key)==KErrNone);
   375 	CompareL(KIndexName,KTableName2,*key);
   376 	delete key;
   377 	key=CreateKeyL(EKeyMulti);
   378 	test (TheDatabase.CreateIndex(KIndexName3,KTableName,*key)==KErrNone);
   379 	CompareL(KIndexName3,KTableName,*key);
   380 	CountIndexesL(KTableName,3);
   381 	CountIndexesL(KTableName2,1);
   382 	CloseDatabase();
   383 	OpenDatabase();
   384 	CountIndexesL(KTableName,3);
   385 	CountIndexesL(KTableName2,1);
   386 	CompareL(KIndexName3,KTableName,*key);
   387 	delete key;
   388 	test.Next(_L("Drop indexes"));
   389 	test (TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
   390 	CountIndexesL(KTableName,2);
   391 	test (TheDatabase.DropIndex(KIndexName2,KTableName)==KErrNone);
   392 	CountIndexesL(KTableName,1);
   393 	test (TheDatabase.DropIndex(KIndexName,KTableName2)==KErrNone);
   394 	CountIndexesL(KTableName2,0);
   395 	test.Next(_L("Drop table"));
   396 	test(TheDatabase.DropTable(KTableName)==KErrNone);
   397 	CountTablesL(1);
   398 	test(TheDatabase.DropTable(KTableName2)==KErrNone);
   399 	CountTablesL(0);
   400 	CloseDatabase();
   401 	OpenDatabase();
   402 	CountTablesL(0);
   403 	DestroyDatabase();
   404 	test.End();
   405 	}
   406 
   407 
   408 LOCAL_C void AddRowL()
   409 	{
   410 	test(TheView.Prepare(TheDatabase,_L("select * from testviewtable"))==KErrNone);
   411 	test(TheView.EvaluateAll()==KErrNone);
   412 	TheView.InsertL();
   413 	TheView.SetColL(1,(TInt32)12345);
   414 	TheView.PutL();
   415 	TheView.InsertL();
   416 	TheView.Cancel();
   417 	TheView.FirstL();
   418 	TheView.NextL();
   419 	test(TheView.AtEnd());		// should be only 1 row as second insert was cancelled
   420 	TheView.Close();
   421 	}
   422 
   423 /**
   424 @SYMTestCaseID          SYSLIB-DBMS-CT-1318
   425 @SYMTestCaseDesc        Tests for RDbView class
   426 @SYMTestPriority        Medium
   427 @SYMTestActions         Tests for navigation of the cursor in the generated row sets.
   428 @SYMTestExpectedResults Test must not fail
   429 @SYMREQ                 REQ0000
   430 */
   431 LOCAL_C void TestEmptyNavigationL(const TDesC& aQuery)
   432 	{
   433 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1318 Test navigation states "));
   434 	test(TheView.Prepare(TheDatabase,aQuery,TheView.EReadOnly)==KErrNone);
   435 	test(TheView.EvaluateAll()==KErrNone);
   436 	TheView.FirstL();
   437 	test(!TheView.AtBeginning());
   438 	test(!TheView.AtRow());
   439 	test(TheView.AtEnd());
   440 	TheView.PreviousL();
   441 	test(TheView.AtBeginning());
   442 	test(!TheView.AtRow());
   443 	test(!TheView.AtEnd());
   444 	TheView.NextL();
   445 	test(!TheView.AtBeginning());
   446 	test(!TheView.AtRow());
   447 	test(TheView.AtEnd());
   448 	TheView.LastL();
   449 	test(TheView.AtBeginning());
   450 	test(!TheView.AtRow());
   451 	test(!TheView.AtEnd());
   452 	TheView.NextL();
   453 	test(TheView.AtEnd());
   454 	TheView.Close();
   455 	}
   456 
   457 /**
   458 @SYMTestCaseID          SYSLIB-DBMS-CT-1319
   459 @SYMTestCaseDesc        Tests for RDbView class
   460 @SYMTestPriority        Medium
   461 @SYMTestActions         Tests for navigation of the cursor in the generated row sets.
   462 @SYMTestExpectedResults Test must not fail
   463 @SYMREQ                 REQ0000
   464 */
   465 LOCAL_C void TestNavigationL(const TDesC& aQuery)
   466 	{
   467 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1319 Test navigation states "));
   468 	test(TheView.Prepare(TheDatabase,aQuery,TheView.EReadOnly)==KErrNone);
   469 	test(TheView.EvaluateAll()==KErrNone);
   470 	TheView.FirstL();
   471 	test(!TheView.AtBeginning());
   472 	test(TheView.AtRow());
   473 	test(!TheView.AtEnd());
   474 	TheView.GetL();
   475 	test(TheView.ColInt32(1)==12345);
   476 	TheView.PreviousL();
   477 	test(TheView.AtBeginning());
   478 	test(!TheView.AtRow());
   479 	test(!TheView.AtEnd());
   480 	TheView.NextL();
   481 	test(!TheView.AtBeginning());
   482 	test(TheView.AtRow());
   483 	test(!TheView.AtEnd());
   484 	TheView.NextL();
   485 	test(!TheView.AtBeginning());
   486 	test(!TheView.AtRow());
   487 	test(TheView.AtEnd());
   488 	TheView.PreviousL();
   489 	test(!TheView.AtBeginning());
   490 	test(TheView.AtRow());
   491 	test(!TheView.AtEnd());
   492 	TheView.LastL();
   493 	test(!TheView.AtBeginning());
   494 	test(TheView.AtRow());
   495 	test(!TheView.AtEnd());
   496 	TheView.NextL();
   497 	test(TheView.AtEnd());
   498 	TheView.Close();
   499 	}
   500 
   501 /**
   502 @SYMTestCaseID          SYSLIB-DBMS-CT-1320
   503 @SYMTestCaseDesc        RDbView updation test
   504 @SYMTestPriority        Medium
   505 @SYMTestActions         Tests for updation of row sets
   506 @SYMTestExpectedResults Test must not fail
   507 @SYMREQ                 REQ0000
   508 */
   509 static void TestUpdateL()
   510 	{
   511 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1320 Update and delete the row "));
   512 	test(TheView.Prepare(TheDatabase,_L("select * from TestViewTable"))==KErrNone);
   513 	test(TheView.EvaluateAll()==KErrNone);
   514 	TheView.FirstL();
   515 	TheView.UpdateL();
   516 	TheView.SetColL(1,(TInt32)54321);
   517 	TheView.PutL();
   518 	TheView.FirstL();
   519 	TheView.GetL();
   520 	test(TheView.ColInt32(1)==54321);
   521 	TheView.UpdateL();
   522 	TheView.SetColL(1,(TInt32)12345);
   523 	TheView.Cancel();
   524 	TheView.FirstL();
   525 	TheView.GetL();
   526 	test(TheView.ColInt32(1)==54321);
   527 	TheView.DeleteL();
   528 	TheView.PreviousL();
   529 	test(TheView.AtBeginning());
   530 	TheView.NextL();
   531 	test(TheView.AtEnd());
   532 	TheView.Close();
   533 	}
   534 
   535 #include <s32mem.h>
   536 
   537 void writeBLOBL(TDbColNo aCol,const TDesC8& aDes)
   538 	{
   539 	CBufSeg* buf=CBufSeg::NewL(128);
   540 	CleanupStack::PushL(buf);
   541 	buf->InsertL(0,aDes);
   542 	RBufReadStream read(*buf);
   543 	RDbColWriteStream blob;
   544 	blob.OpenLC(TheView,aCol);
   545 //	blob.WriteL(aDes);
   546 	blob.WriteL(read,aDes.Length());
   547 	blob.CommitL();
   548 	CleanupStack::PopAndDestroy();
   549 	CleanupStack::PopAndDestroy();	// buf
   550 	test (TheView.ColLength(aCol)==aDes.Length());
   551 	test (TheView.ColSize(aCol)==aDes.Size());
   552 	}
   553 
   554 void checkBLOBL(TDbColNo aCol,const TDesC8& aDes)
   555 	{
   556 	RDbColReadStream blob;
   557 	blob.OpenLC(TheView,aCol);
   558 	blob.ReadL(TheBuf8,TheView.ColLength(aCol));
   559 	CleanupStack::PopAndDestroy();
   560 	test(TheBuf8==aDes);
   561 	}
   562 
   563 /**
   564 @SYMTestCaseID          SYSLIB-DBMS-CT-1321
   565 @SYMTestCaseDesc        BLOB tests
   566 @SYMTestPriority        Medium
   567 @SYMTestActions         Test long column tracking through insert/put/update/cancel
   568 @SYMTestExpectedResults Test must not fail
   569 @SYMREQ                 REQ0000
   570 */
   571 void TestBLOBL()
   572 	{
   573 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1321 Long column tracking "));
   574 	test(TheView.Prepare(TheDatabase,_L("select * from TestViewTable"))==KErrNone);
   575 	test(TheView.EvaluateAll()==KErrNone);
   576 	TheView.InsertL();
   577 	writeBLOBL(2,KTestShortText8);
   578 	writeBLOBL(3,KTestShortText8);
   579 	TheView.PutL();
   580 	TheView.InsertL();
   581 	writeBLOBL(4,KTestShortText8);
   582 	writeBLOBL(5,KTestShortText8);
   583 	TheView.Cancel();
   584 // change in behaviour--writing BLOBs forces a true rollback here. So reset
   585 	TheView.Reset();
   586 	test(TheView.EvaluateAll()==KErrNone);
   587 // check the one row we should have
   588 	TheView.FirstL();
   589 	TheView.GetL();
   590 	checkBLOBL(2,KTestShortText8);
   591 	checkBLOBL(3,KTestShortText8);
   592 	test(TheView.IsColNull(4));
   593 	test(TheView.IsColNull(5));
   594 	test(TheView.IsColNull(6));
   595 	TheView.NextL();
   596 	test(TheView.AtEnd());
   597 // update/cancel the row
   598 	TheView.FirstL();
   599 	TheView.UpdateL();
   600 	TheView.SetColNullL(3);
   601 	writeBLOBL(4,KTestLongText8);
   602 	writeBLOBL(5,KTestLongText8);
   603 // check pre-cancel
   604 	checkBLOBL(2,KTestShortText8);
   605 	test(TheView.IsColNull(3));
   606 	checkBLOBL(4,KTestLongText8);
   607 	checkBLOBL(5,KTestLongText8);
   608 	test(TheView.IsColNull(6));
   609 // cancel and check
   610 	TheView.Cancel();
   611 // change in behaviour--writing BLOBs forces a true rollback here. So reset
   612 	TheView.Reset();
   613 	test(TheView.EvaluateAll()==KErrNone);
   614 	TheView.FirstL();
   615 	TheView.GetL();
   616 	checkBLOBL(2,KTestShortText8);
   617 	checkBLOBL(3,KTestShortText8);
   618 	test(TheView.IsColNull(4));
   619 	test(TheView.IsColNull(5));
   620 	test(TheView.IsColNull(6));
   621 	TheView.NextL();
   622 	test(TheView.AtEnd());
   623 // update/put the row
   624 	TheView.FirstL();
   625 	TheView.UpdateL();
   626 	TheView.SetColNullL(3);
   627 	writeBLOBL(4,KTestLongText8);
   628 	writeBLOBL(5,KTestLongText8);
   629 // check pre-put
   630 	checkBLOBL(2,KTestShortText8);
   631 	test(TheView.IsColNull(3));
   632 	checkBLOBL(4,KTestLongText8);
   633 	checkBLOBL(5,KTestLongText8);
   634 	test(TheView.IsColNull(6));
   635 // put and check
   636 	TheView.PutL();
   637 	TheView.FirstL();
   638 	TheView.GetL();
   639 	checkBLOBL(2,KTestShortText8);
   640 	test(TheView.IsColNull(3));
   641 	checkBLOBL(4,KTestLongText8);
   642 	checkBLOBL(5,KTestLongText8);
   643 	test(TheView.IsColNull(6));
   644 	TheView.NextL();
   645 	test(TheView.AtEnd());
   646 // update/put the row again
   647 	TheView.FirstL();
   648 	TheView.UpdateL();
   649 	TheView.SetColNullL(2);
   650 	writeBLOBL(3,KTestShortText8);
   651 	writeBLOBL(4,KTestShortText8);
   652 	writeBLOBL(5,KTestShortText8);
   653 // check
   654 	test(TheView.IsColNull(2));
   655 	checkBLOBL(3,KTestShortText8);
   656 	checkBLOBL(4,KTestShortText8);
   657 	checkBLOBL(5,KTestShortText8);
   658 	test(TheView.IsColNull(6));
   659 // modify again
   660 	writeBLOBL(2,KTestLongText8);
   661 	TheView.SetColNullL(3);
   662 	TheView.SetColNullL(4);
   663 	writeBLOBL(5,KTestLongText8);
   664 // check pre-put
   665 	checkBLOBL(2,KTestLongText8);
   666 	test(TheView.IsColNull(3));
   667 	test(TheView.IsColNull(4));
   668 	checkBLOBL(5,KTestLongText8);
   669 	test(TheView.IsColNull(6));
   670 // put and check
   671 	TheView.PutL();
   672 	TheView.FirstL();
   673 	TheView.GetL();
   674 	checkBLOBL(2,KTestLongText8);
   675 	test(TheView.IsColNull(3));
   676 	test(TheView.IsColNull(4));
   677 	checkBLOBL(5,KTestLongText8);
   678 	test(TheView.IsColNull(6));
   679 	TheView.NextL();
   680 	test(TheView.AtEnd());
   681 // insert copy
   682 	TheView.LastL();
   683 	TheView.InsertCopyL();
   684 	TheView.SetColNullL(2);
   685 	writeBLOBL(3,KTestLongText8);
   686 // check pre-put
   687 	test(TheView.IsColNull(2));
   688 	checkBLOBL(3,KTestLongText8);
   689 	test(TheView.IsColNull(4));
   690 	checkBLOBL(5,KTestLongText8);
   691 	test(TheView.IsColNull(6));
   692 // put and check
   693 	TheView.PutL();
   694 	TheView.LastL();
   695 	TheView.GetL();
   696 	test(TheView.IsColNull(2));
   697 	checkBLOBL(3,KTestLongText8);
   698 	test(TheView.IsColNull(4));
   699 	checkBLOBL(5,KTestLongText8);
   700 	test(TheView.IsColNull(6));
   701 // delete previous one and check
   702 	TheView.PreviousL();
   703 	TheView.DeleteL();
   704 	TheView.NextL();
   705 	TheView.GetL();
   706 	test(TheView.IsColNull(2));
   707 	checkBLOBL(3,KTestLongText8);
   708 	test(TheView.IsColNull(4));
   709 	checkBLOBL(5,KTestLongText8);
   710 	test(TheView.IsColNull(6));
   711 	TheView.NextL();
   712 	test(TheView.AtEnd());
   713 // delete
   714 	TheView.FirstL();
   715 	TheView.DeleteL();
   716 // finish
   717 	TheView.Close();
   718 	}
   719 
   720 /**
   721 @SYMTestCaseID          SYSLIB-DBMS-CT-0596
   722 @SYMTestCaseDesc        Tests for navigation states
   723 @SYMTestPriority        Medium
   724 @SYMTestActions         Tests for view state cycle, navigation, Insert/Update/Delete
   725 @SYMTestExpectedResults Test must not fail
   726 @SYMREQ                 REQ0000
   727 */
   728 void TestViewL()
   729 	{
   730 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0596 Create the Test table "));
   731 	CreateDatabase();
   732 	CDbColSet* cs=CreateColSetL(EViewTestTable);
   733 	test(TheDatabase.CreateTable(KTestViewTable,*cs)==KErrNone);
   734 	delete cs;
   735 	TestEmptyNavigationL(_L("select * from TestViewTable"));
   736 	test.Next(_L("Insert and Put/Cancel"));
   737 	AddRowL();
   738 	TestNavigationL(_L("select * from TestViewTable"));
   739 	TestNavigationL(_L("select * from TestViewTable where Int is not null"));
   740 	TestEmptyNavigationL(_L("select * from TestViewTable where Int is null"));
   741 	TestUpdateL();
   742 	TestBLOBL();
   743 	test.Next(_L("Close"));
   744 	CloseDatabase();
   745 	test.End();
   746 	}
   747 
   748 //
   749 // Check the integral set/get functions for different width types
   750 //
   751 LOCAL_C void CheckIntAccessorsL()
   752 	{
   753 	TheView.InsertL();
   754 // bit column
   755 	TDbColNo ord=TheMap[EBit];
   756 	TheView.SetColL(ord,TUint32(1));
   757 	test (TheView.ColUint(ord)==1);
   758 	TheView.SetColL(ord,TInt32(0));
   759 	test (TheView.ColUint(ord)==0);
   760 	TheView.SetColL(ord,TInt64(1));
   761 	test (TheView.ColUint(ord)==1);
   762 	test (TheView.ColUint8(ord)==1);
   763 	test (TheView.ColUint16(ord)==1);
   764 	test (TheView.ColUint32(ord)==1);
   765 	test (TheView.ColInt8(ord)==1);
   766 	test (TheView.ColInt16(ord)==1);
   767 	test (TheView.ColInt32(ord)==1);
   768 	test (TheView.ColInt64(ord)==1);
   769 // uint8 column
   770 	ord=TheMap[EUint8];
   771 	TheView.SetColL(ord,TUint32(255));
   772 	test (TheView.ColUint(ord)==255);
   773 	TheView.SetColL(ord,TInt32(0));
   774 	test (TheView.ColUint(ord)==0);
   775 	TheView.SetColL(ord,TInt64(1));
   776 	test (TheView.ColUint(ord)==1);
   777 	test (TheView.ColUint8(ord)==1);
   778 	test (TheView.ColUint16(ord)==1);
   779 	test (TheView.ColUint32(ord)==1);
   780 	test (TheView.ColInt16(ord)==1);
   781 	test (TheView.ColInt32(ord)==1);
   782 	test (TheView.ColInt64(ord)==1);
   783 // uint16 column
   784 	ord=TheMap[EUint16];
   785 	TheView.SetColL(ord,TUint32(65535));
   786 	test (TheView.ColUint(ord)==65535);
   787 	TheView.SetColL(ord,TInt32(0));
   788 	test (TheView.ColUint(ord)==0);
   789 	TheView.SetColL(ord,TInt64(1));
   790 	test (TheView.ColUint(ord)==1);
   791 	test (TheView.ColUint16(ord)==1);
   792 	test (TheView.ColUint32(ord)==1);
   793 	test (TheView.ColInt32(ord)==1);
   794 	test (TheView.ColInt64(ord)==1);
   795 // uint32 column
   796 	ord=TheMap[EUint32];
   797 	TheView.SetColL(ord,TUint32(0));
   798 	test (TheView.ColUint(ord)==0);
   799 	TheView.SetColL(ord,TInt32(KMaxTInt));
   800 	test (TInt(TheView.ColUint(ord))==KMaxTInt);
   801 	TheView.SetColL(ord,TInt64(KMaxTUint));
   802 	test (TheView.ColUint(ord)==KMaxTUint);
   803 	test (TheView.ColUint32(ord)==KMaxTUint);
   804 	test (TheView.ColInt64(ord)==KMaxTUint);
   805 // int8 column
   806 	ord=TheMap[EInt8];
   807 	TheView.SetColL(ord,TUint32(127));
   808 	test (TheView.ColInt(ord)==127);
   809 	TheView.SetColL(ord,TInt32(0));
   810 	test (TheView.ColInt(ord)==0);
   811 	TheView.SetColL(ord,TInt64(-128));
   812 	test (TheView.ColInt(ord)==-128);
   813 	test (TheView.ColInt8(ord)==-128);
   814 	test (TheView.ColInt16(ord)==-128);
   815 	test (TheView.ColInt32(ord)==-128);
   816 	test (TheView.ColInt64(ord)==-128);
   817 // int16 column
   818 	ord=TheMap[EInt16];
   819 	TheView.SetColL(ord,TUint32(32767));
   820 	test (TheView.ColInt(ord)==32767);
   821 	TheView.SetColL(ord,TInt32(0));
   822 	test (TheView.ColInt(ord)==0);
   823 	TheView.SetColL(ord,TInt64(-32768));
   824 	test (TheView.ColInt(ord)==-32768);
   825 	test (TheView.ColInt16(ord)==-32768);
   826 	test (TheView.ColInt32(ord)==-32768);
   827 	test (TheView.ColInt64(ord)==-32768);
   828 // int32 column
   829 	ord=TheMap[EInt32];
   830 	TheView.SetColL(ord,TUint32(KMaxTInt));
   831 	test (TheView.ColInt(ord)==KMaxTInt);
   832 	TheView.SetColL(ord,TInt32(0));
   833 	test (TheView.ColInt(ord)==0);
   834 	TheView.SetColL(ord,TInt64(KMinTInt));
   835 	test (TheView.ColInt(ord)==KMinTInt);
   836 	test (TheView.ColInt32(ord)==KMinTInt);
   837 	test (TheView.ColInt64(ord)==KMinTInt);
   838 //
   839 	TheView.Cancel();
   840 	}
   841 
   842 //
   843 // Write the values to nullable column types
   844 //
   845 LOCAL_C void WriteMinValuesL(TInt anOffset)
   846 	{
   847 	TheView.SetColL(TheMap[anOffset+EBit],TUint(0));
   848 	TheView.SetColL(TheMap[anOffset+EInt8],KMinTInt8);
   849 	TheView.SetColL(TheMap[anOffset+EUint8],TUint(0));
   850 	TheView.SetColL(TheMap[anOffset+EInt16],KMinTInt16);
   851 	TheView.SetColL(TheMap[anOffset+EUint16],TUint(0));
   852 	TheView.SetColL(TheMap[anOffset+EInt32],KMinTInt32);
   853 	TheView.SetColL(TheMap[anOffset+EUint32],TUint(0));
   854 	TheView.SetColL(TheMap[anOffset+EInt64],KMinTInt64);
   855 	TheView.SetColL(TheMap[anOffset+EReal32],KMinTReal32);
   856 	TheView.SetColL(TheMap[anOffset+EReal64],KMinTReal64);
   857 	TheView.SetColL(TheMap[anOffset+ETime],KMinTTime);
   858 	TheView.SetColL(TheMap[anOffset+EText8],KTestShortText8);
   859 	TheView.SetColL(TheMap[anOffset+EText16],KTestShortText16);
   860 	{
   861 	TUint8 val=0;
   862 	TheView.SetColL(TheMap[anOffset+ETBinary],TPtrC8(&val,sizeof(val)));
   863 	}
   864 	TheView.SetColL(TheMap[anOffset+ELongText8],KTestShortText8);
   865 	TheView.SetColL(TheMap[anOffset+ELongText16],KTestShortText16);
   866 	RDbColWriteStream out;
   867 	out.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
   868 	out.WriteUint8L(0);
   869 	out.CommitL();
   870 	CleanupStack::PopAndDestroy();
   871 	}
   872 
   873 //
   874 // Write a row with the minimum (or small) column values
   875 // return the value in the counter column
   876 //
   877 LOCAL_C TInt WriteMinimumL()
   878 	{
   879 	TheView.InsertL();
   880 	WriteMinValuesL(0);
   881 	WriteMinValuesL(EBitNull-EBit);
   882 	test(!TheView.IsColNull(TheMap[ECounter]));
   883 	TInt cc=TheView.ColInt(TheMap[ECounter]);
   884 	TheView.PutL();
   885 	return cc;
   886 	}
   887 
   888 LOCAL_C void CheckMinValuesL(TInt anOffset)
   889 	{
   890 	test(TheView.ColUint8(TheMap[anOffset+EBit])==0);
   891 	test(TheView.ColUint16(TheMap[anOffset+EBit])==0);
   892 	test(TheView.ColUint32(TheMap[anOffset+EBit])==0);
   893 	test(TheView.ColUint(TheMap[anOffset+EBit])==0);
   894 	test(TheView.ColInt8(TheMap[anOffset+EInt8])==KMinTInt8);
   895 	test(TheView.ColInt16(TheMap[anOffset+EInt8])==KMinTInt8);
   896 	test(TheView.ColInt32(TheMap[anOffset+EInt8])==KMinTInt8);
   897 	test(TheView.ColInt(TheMap[anOffset+EInt8])==KMinTInt8);
   898 	test(TheView.ColUint8(TheMap[anOffset+EUint8])==0);
   899 	test(TheView.ColUint16(TheMap[anOffset+EUint8])==0);
   900 	test(TheView.ColUint32(TheMap[anOffset+EUint8])==0);
   901 	test(TheView.ColUint(TheMap[anOffset+EUint8])==0);
   902 	test(TheView.ColInt16(TheMap[anOffset+EInt16])==KMinTInt16);
   903 	test(TheView.ColInt32(TheMap[anOffset+EInt16])==KMinTInt16);
   904 	test(TheView.ColInt(TheMap[anOffset+EInt16])==KMinTInt16);
   905 	test(TheView.ColUint16(TheMap[anOffset+EUint16])==0);
   906 	test(TheView.ColUint32(TheMap[anOffset+EUint16])==0);
   907 	test(TheView.ColUint(TheMap[anOffset+EUint16])==0);
   908 	test(TheView.ColInt32(TheMap[anOffset+EInt32])==KMinTInt32);
   909 	test(TheView.ColInt(TheMap[anOffset+EInt32])==KMinTInt32);
   910 	test(TheView.ColUint32(TheMap[anOffset+EUint32])==0);
   911 	test(TheView.ColUint(TheMap[anOffset+EUint32])==0);
   912 	test(TheView.ColInt64(TheMap[anOffset+EInt64])==KMinTInt64);
   913 	test(TheView.ColReal32(TheMap[anOffset+EReal32])==KMinTReal32);
   914 	test(TheView.ColReal64(TheMap[anOffset+EReal64])==KMinTReal64);
   915 	test(TheView.ColReal(TheMap[anOffset+EReal64])==KMinTReal64);
   916 	test(TheView.ColTime(TheMap[anOffset+ETime])==KMinTTime);
   917 	test(TheView.ColDes8(TheMap[anOffset+EText8])==KTestShortText8);
   918 	test(TheView.ColSize(TheMap[anOffset+EText8])==KTestShortText8.Size());
   919 	test(TheView.ColLength(TheMap[anOffset+EText8])==KTestShortText8.Length());
   920 	test(TheView.ColDes16(TheMap[anOffset+EText16])==KTestShortText16);
   921 	test(TheView.ColSize(TheMap[anOffset+EText16])==KTestShortText16.Size());
   922 	test(TheView.ColLength(TheMap[anOffset+EText16])==KTestShortText16.Length());
   923 	{
   924 	TUint8 val=0;
   925 	test(TheView.ColDes8(TheMap[anOffset+ETBinary])==TPtrC8(&val,sizeof(val)));
   926 	}
   927 	test(TheView.ColSize(TheMap[anOffset+ETBinary])==1);
   928 	test(TheView.ColLength(TheMap[anOffset+ETBinary])==1);
   929 //
   930 	test(TheView.ColSize(TheMap[anOffset+ELongText8])==KTestShortText8.Size());
   931 	test(TheView.ColLength(TheMap[anOffset+ELongText8])==KTestShortText8.Length());
   932 	RDbColReadStream in;
   933 	in.OpenLC(TheView,TheMap[anOffset+ELongText8]);
   934 	in.ReadL(TheBuf8,TheView.ColLength(TheMap[anOffset+ELongText8]));
   935 	CleanupStack::PopAndDestroy();
   936 	test(TheBuf8==KTestShortText8);
   937 //
   938 	test(TheView.ColSize(TheMap[anOffset+ELongText16])==KTestShortText16.Size());
   939 	test(TheView.ColLength(TheMap[anOffset+ELongText16])==KTestShortText16.Length());
   940 	in.OpenLC(TheView,TheMap[anOffset+ELongText16]);
   941 	in.ReadL(TheBuf16,TheView.ColLength(TheMap[anOffset+ELongText16]));
   942 	CleanupStack::PopAndDestroy();
   943 	test(TheBuf16==KTestShortText16);
   944 //
   945 	test(TheView.ColSize(TheMap[anOffset+ELongBinary])==1);
   946 	test(TheView.ColLength(TheMap[anOffset+ELongBinary])==1);
   947 	in.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
   948 	test(in.ReadUint8L()==0);
   949 	CleanupStack::PopAndDestroy();
   950 	}
   951 
   952 //
   953 // Check the row is the same as was written
   954 //
   955 LOCAL_C void CheckMinimumL(TInt aCounter)
   956 	{
   957 	TheView.GetL();
   958 	test(TheView.ColInt32(TheMap[ECounter])==aCounter);
   959 	CheckMinValuesL(0);
   960 	CheckMinValuesL(EBitNull-EBit);
   961 	}
   962 
   963 LOCAL_C void WriteMaxValuesL(TInt anOffset)
   964 	{
   965 	TheView.SetColL(TheMap[anOffset+EBit],TUint(1));
   966 	TheView.SetColL(TheMap[anOffset+EInt8],KMaxTInt8);
   967 	TheView.SetColL(TheMap[anOffset+EUint8],TUint(KMaxTUint8));
   968 	TheView.SetColL(TheMap[anOffset+EInt16],KMaxTInt16);
   969 	TheView.SetColL(TheMap[anOffset+EUint16],TUint(KMaxTUint16));
   970 	TheView.SetColL(TheMap[anOffset+EInt32],KMaxTInt32);
   971 	TheView.SetColL(TheMap[anOffset+EUint32],KMaxTUint32);
   972 	TheView.SetColL(TheMap[anOffset+EInt64],KMaxTInt64);
   973 	TheView.SetColL(TheMap[anOffset+EReal32],KMaxTReal32);
   974 	TheView.SetColL(TheMap[anOffset+EReal64],KMaxTReal64);
   975 	TheView.SetColL(TheMap[anOffset+ETime],KMaxTTime);
   976 	TheView.SetColL(TheMap[anOffset+EText8],KTestText8);
   977 	TheView.SetColL(TheMap[anOffset+EText16],KTestText16);
   978 	TheView.SetColL(TheMap[anOffset+ETBinary],TPtrC8((TUint8*)&TheMap[0],sizeof(TheMap)));
   979 	TheView.SetColL(TheMap[anOffset+ELongText8],KTestLongText8);
   980 	TheView.SetColL(TheMap[anOffset+ELongText16],KTestLongText16);
   981 	RDbColWriteStream out;
   982 	out.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
   983 	for (TInt ii=0;ii<KBlobItems;++ii)
   984 		out.WriteInt32L(ii);
   985 	out.CommitL();
   986 	CleanupStack::PopAndDestroy();
   987 	}
   988 
   989 //
   990 // Write a row with the maximum (or longer) column values
   991 // return the value in the counter column
   992 //
   993 LOCAL_C TInt WriteMaximumL()
   994 	{
   995 	TheView.InsertL();
   996 	WriteMaxValuesL(0);
   997 	WriteMaxValuesL(EBitNull-EBit);
   998 	test(!TheView.IsColNull(TheMap[ECounter]));
   999 	TInt cc=TheView.ColInt(TheMap[ECounter]);
  1000 	TheView.PutL();
  1001 	return cc;
  1002 	}
  1003 
  1004 LOCAL_C void CheckMaxValuesL(TInt anOffset)
  1005 	{
  1006 	test(TheView.ColUint8(TheMap[anOffset+EBit])==1);
  1007 	test(TheView.ColUint16(TheMap[anOffset+EBit])==1);
  1008 	test(TheView.ColUint32(TheMap[anOffset+EBit])==1);
  1009 	test(TheView.ColUint(TheMap[anOffset+EBit])==1);
  1010 	test(TheView.ColInt8(TheMap[anOffset+EInt8])==KMaxTInt8);
  1011 	test(TheView.ColInt16(TheMap[anOffset+EInt8])==KMaxTInt8);
  1012 	test(TheView.ColInt32(TheMap[anOffset+EInt8])==KMaxTInt8);
  1013 	test(TheView.ColInt(TheMap[anOffset+EInt8])==KMaxTInt8);
  1014 	test(TheView.ColUint8(TheMap[anOffset+EUint8])==KMaxTUint8);
  1015 	test(TheView.ColUint16(TheMap[anOffset+EUint8])==KMaxTUint8);
  1016 	test(TheView.ColUint32(TheMap[anOffset+EUint8])==KMaxTUint8);
  1017 	test(TheView.ColUint(TheMap[anOffset+EUint8])==KMaxTUint8);
  1018 	test(TheView.ColInt16(TheMap[anOffset+EInt16])==KMaxTInt16);
  1019 	test(TheView.ColInt32(TheMap[anOffset+EInt16])==KMaxTInt16);
  1020 	test(TheView.ColInt(TheMap[anOffset+EInt16])==KMaxTInt16);
  1021 	test(TheView.ColUint16(TheMap[anOffset+EUint16])==KMaxTUint16);
  1022 	test(TheView.ColUint32(TheMap[anOffset+EUint16])==KMaxTUint16);
  1023 	test(TheView.ColUint(TheMap[anOffset+EUint16])==KMaxTUint16);
  1024 	test(TheView.ColInt32(TheMap[anOffset+EInt32])==KMaxTInt32);
  1025 	test(TheView.ColInt(TheMap[anOffset+EInt32])==KMaxTInt32);
  1026 	test(TheView.ColUint32(TheMap[anOffset+EUint32])==KMaxTUint32);
  1027 	test(TheView.ColUint(TheMap[anOffset+EUint32])==KMaxTUint32);
  1028 	test(TheView.ColInt64(TheMap[anOffset+EInt64])==KMaxTInt64);
  1029 	test(TheView.ColReal32(TheMap[anOffset+EReal32])==KMaxTReal32);
  1030 	test(TheView.ColReal64(TheMap[anOffset+EReal64])==KMaxTReal64);
  1031 	test(TheView.ColReal(TheMap[anOffset+EReal64])==KMaxTReal64);
  1032 	test(TheView.ColTime(TheMap[anOffset+ETime])==KMaxTTime);
  1033 	test(TheView.ColDes8(TheMap[anOffset+EText8])==KTestText8);
  1034 	test(TheView.ColSize(TheMap[anOffset+EText8])==KTestText8.Size());
  1035 	test(TheView.ColLength(TheMap[anOffset+EText8])==KTestText8.Length());
  1036 	test(TheView.ColDes16(TheMap[anOffset+EText16])==KTestText16);
  1037 	test(TheView.ColSize(TheMap[anOffset+EText16])==KTestText16.Size());
  1038 	test(TheView.ColLength(TheMap[anOffset+EText16])==KTestText16.Length());
  1039 	test(TheView.ColDes8(TheMap[anOffset+ETBinary])==TPtrC8((TUint8*)&TheMap[0],sizeof(TheMap)));
  1040 	test(TheView.ColSize(TheMap[anOffset+ETBinary])==sizeof(TheMap));
  1041 	test(TheView.ColLength(TheMap[anOffset+ETBinary])==sizeof(TheMap));
  1042 //
  1043 	test(TheView.ColSize(TheMap[anOffset+ELongText8])==KTestLongText8.Size());
  1044 	test(TheView.ColLength(TheMap[anOffset+ELongText8])==KTestLongText8.Length());
  1045 	RDbColReadStream in;
  1046 	in.OpenLC(TheView,TheMap[anOffset+ELongText8]);
  1047 	in.ReadL(TheBuf8,TheView.ColLength(TheMap[anOffset+ELongText8]));
  1048 	CleanupStack::PopAndDestroy();
  1049 	test(TheBuf8==KTestLongText8);
  1050 //
  1051 	test(TheView.ColSize(TheMap[anOffset+ELongText16])==KTestLongText16.Size());
  1052 	test(TheView.ColLength(TheMap[anOffset+ELongText16])==KTestLongText16.Length());
  1053 	in.OpenLC(TheView,TheMap[anOffset+ELongText16]);
  1054 	in.ReadL(TheBuf16,TheView.ColLength(TheMap[anOffset+ELongText16]));
  1055 	CleanupStack::PopAndDestroy();
  1056 	test(TheBuf16==KTestLongText16);
  1057 //
  1058 	test(TheView.ColSize(TheMap[anOffset+ELongBinary])==KBlobItems*sizeof(TUint32));
  1059 	test(TheView.ColLength(TheMap[anOffset+ELongBinary])==KBlobItems*sizeof(TUint32));
  1060 	in.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
  1061 	for (TInt ii=0;ii<KBlobItems;++ii)
  1062 		test(in.ReadInt32L()==ii);
  1063 	CleanupStack::PopAndDestroy();
  1064 	}
  1065 
  1066 //
  1067 // Check the row is the same as was written
  1068 //
  1069 LOCAL_C void CheckMaximumL(TInt aCounter)
  1070 	{
  1071 	TheView.GetL();
  1072 	test(TheView.ColInt32(TheMap[ECounter])==aCounter);
  1073 	CheckMaxValuesL(0);
  1074 	CheckMaxValuesL(EBitNull-EBit);
  1075 	}
  1076 
  1077 //
  1078 // Write a row with null column values in the nullable columns
  1079 // return the value in the counter column
  1080 //
  1081 LOCAL_C TInt WriteNullL()
  1082 	{
  1083 	TheView.InsertL();
  1084 	WriteMinValuesL(0);
  1085 	test(!TheView.IsColNull(TheMap[ECounter]));
  1086 	TInt cc=TheView.ColInt(TheMap[ECounter]);
  1087 	TheView.PutL();
  1088 	return cc;
  1089 	}
  1090 
  1091 //
  1092 // Check the row is the same as was written
  1093 //
  1094 LOCAL_C void CheckNullL(TInt aCounter)
  1095 	{
  1096 	TheView.GetL();
  1097 	test(TheView.ColInt32(TheMap[ECounter])==aCounter);
  1098 	TInt ii;
  1099 	for (ii=ECounter;ii<EBitNull;ii++)
  1100 		{	// not null columns
  1101 		TDbColNo col=TheMap[ii];
  1102 		test(!TheView.IsColNull(col));
  1103 		test(TheView.ColSize(col)!=0);
  1104 		test(TheView.ColLength(col)!=0);
  1105 		if (ii<ELongText8)
  1106 			test(TheView.ColDes8(col).Length()!=0);
  1107 		}
  1108 	CheckMinValuesL(0);
  1109 	for (;ii<EForceNull-1;++ii)
  1110 		{	// null columns
  1111 		TDbColNo col=TheMap[ii];
  1112 		test(TheView.IsColNull(col));
  1113 		test(TheView.ColSize(col)==0);
  1114 		test(TheView.ColLength(col)==0);
  1115 		if (ii<ELongText8Null)
  1116 			test(TheView.ColDes8(col).Length()==0);
  1117 		}
  1118 	test(TheView.ColUint(TheMap[EBitNull])==0);
  1119 	test(TheView.ColInt(TheMap[EInt8Null])==0);
  1120 	test(TheView.ColUint(TheMap[EUint8Null])==0);
  1121 	test(TheView.ColInt(TheMap[EInt16Null])==0);
  1122 	test(TheView.ColUint(TheMap[EUint16Null])==0);
  1123 	test(TheView.ColInt(TheMap[EInt32Null])==0);
  1124 	test(TheView.ColUint(TheMap[EUint32Null])==0);
  1125 	test(TheView.ColInt64(TheMap[EInt64Null])==0);
  1126 	test(TheView.ColReal32(TheMap[EReal32Null])==0);
  1127 	test(TheView.ColReal64(TheMap[EReal64Null])==0);
  1128 	test(TheView.ColTime(TheMap[ETimeNull])==TTime(0));
  1129 	}
  1130 
  1131 //
  1132 // Copy the last row (should have a different auto-inc value)
  1133 //
  1134 LOCAL_C TInt WriteCopyL()
  1135 	{
  1136 	TheView.LastL();
  1137 	TheView.InsertCopyL();
  1138 	TheView.SetColL(TheMap[EForceNull],1234567);
  1139 	test(!TheView.IsColNull(TheMap[ECounter]));
  1140 	TInt cc=TheView.ColInt(TheMap[ECounter]);
  1141 	TheView.PutL();
  1142 	return cc;
  1143 	}
  1144 
  1145 template <class T>
  1146 void TestOverflowL(TDbColNo aCol,const T& aValue)
  1147 	{
  1148 	TheView.UpdateL();
  1149 	TheView.SetColL(aCol,aValue);
  1150 	TRAPD(r,TheView.PutL());
  1151 	test(r==KErrOverflow);
  1152 	TheView.Cancel();
  1153 	}
  1154 
  1155 LOCAL_C void TestWriteNullL(TDbColNo aCol)
  1156 	{
  1157 	TheView.UpdateL();
  1158 	TheView.SetColNullL(aCol);
  1159 	TRAPD(r,TheView.PutL());
  1160 	test(r==KErrNotFound);
  1161 	TheView.Cancel();
  1162 	}
  1163 
  1164 LOCAL_C void TestValidationL()
  1165 	{
  1166 	TheView.InsertL();
  1167 	WriteMinValuesL(0);
  1168 	TheView.PutL();
  1169 	TestOverflowL(TheMap[EBit],TUint(2));
  1170 	TestOverflowL(TheMap[EBit],TUint(0xffffffffu));
  1171 	TestOverflowL(TheMap[EInt8],TInt(-129));
  1172 	TestOverflowL(TheMap[EInt8],TInt(128));
  1173 	TestOverflowL(TheMap[EUint8],TUint(0xffffffffu));
  1174 	TestOverflowL(TheMap[EUint8],TUint(256));
  1175 	TestOverflowL(TheMap[EInt16],TInt(-32769));
  1176 	TestOverflowL(TheMap[EInt16],TInt(32768));
  1177 	TestOverflowL(TheMap[EUint16],TUint(0xffffffffu));
  1178 	TestOverflowL(TheMap[EUint16],TUint(65536));
  1179 	{
  1180 	TBuf8<KDbDefaultTextColLength+1> buf;
  1181 	buf.SetMax();
  1182 	buf.Fill('x');
  1183 	TestOverflowL(TheMap[EText8],buf);
  1184 	}
  1185 	{
  1186 	TBuf16<KDbDefaultTextColLength+1> buf;
  1187 	buf.SetMax();
  1188 	buf.Fill('x');
  1189 	TestOverflowL(TheMap[EText16],buf);
  1190 	}
  1191 	for (TInt ii=EBit;ii<EBitNull;++ii)
  1192 		TestWriteNullL(TheMap[ii]);
  1193 	}
  1194 
  1195 /**
  1196 @SYMTestCaseID          SYSLIB-DBMS-CT-0597
  1197 @SYMTestCaseDesc        Tests the range and values of all columns types
  1198 @SYMTestPriority        Medium
  1199 @SYMTestActions         Tests for integral accessors
  1200 @SYMTestExpectedResults Test must not fail
  1201 @SYMREQ                 REQ0000
  1202 */
  1203 LOCAL_C void TestTypesL()
  1204 	{
  1205 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0597 Create table of all types "));
  1206 	OpenDatabase();
  1207 	CDbColSet* cs=CreateColSetL(EAllTypes);
  1208 	test(TheDatabase.CreateTable(KTestTypesTable,*cs)==KErrNone);
  1209 	delete cs;
  1210 	test(TheView.Prepare(TheDatabase,_L("select * from TestTypesTable"))==KErrNone);
  1211 	test(TheView.EvaluateAll()==KErrNone);
  1212 	cs=TheView.ColSetL();
  1213 	for (TInt ii=0;ii<KColumns;ii++)
  1214 		TheMap[ii]=cs->ColNo(TPtrC(AllColumns[ii].iName));
  1215 	delete cs;
  1216 	test.Next(_L("Test integral accessors"));
  1217 	CheckIntAccessorsL();
  1218 	test.Next(_L("Add row of minimum values"));
  1219 	TInt c1=WriteMinimumL();
  1220 	test.Next(_L("Add row of maximum values"));
  1221 	TInt c2=WriteMaximumL();
  1222 	test(c2>c1);
  1223 	test.Next(_L("Add row of Null values"));
  1224 	TInt c3=WriteNullL();
  1225 	test(c3>c2);
  1226 	test.Next(_L("Add a copy of the last row"));
  1227 	TInt c4=WriteCopyL();
  1228 	test(c4>c3);
  1229 	test.Next(_L("Check minimum values"));
  1230 	TheView.FirstL();
  1231 	CheckMinimumL(c1);
  1232 	test.Next(_L("Check maximum values"));
  1233 	TheView.NextL();
  1234 	CheckMaximumL(c2);
  1235 	test.Next(_L("Check Null values"));
  1236 	TheView.NextL();
  1237 	CheckNullL(c3);
  1238 	TheView.NextL();
  1239 	CheckNullL(c4);
  1240 	test.Next(_L("Test column value Validation"));
  1241 	TestValidationL();
  1242 	TheView.Close();
  1243 	CloseDatabase();
  1244 	test.End();
  1245 	}
  1246 
  1247 const TPtrC KColumnID(_S("id"));
  1248 const TPtrC KColumnText(_S("txt"));
  1249 const TPtrC KColumnOther(_S("other"));
  1250 const TPtrC KBlobText(_S("text"));
  1251 const TPtrC KFind1(_S("id=1"));
  1252 const TPtrC KFind2(_S("id is null"));
  1253 
  1254 // records will be:
  1255 // 0: "text"
  1256 // 1: "aaa...aaatext"
  1257 // 2: "textaaa...aaa"
  1258 // 3: "aaa...aaa"
  1259 // 4: "aaa...aaatextaaa...aaa"
  1260 // 5: ""
  1261 
  1262 struct STest
  1263 	{
  1264 	const TText* iText;
  1265 	TUint iRecs;
  1266 	};
  1267 
  1268 LOCAL_D STest const Tests[]=
  1269 	{
  1270 		{_S("txt like 'a*'"),0x010110},
  1271 		{_S("txt like 'a*' or other like 'a*'"),0x111111},
  1272 		{_S("txt like 'a*' and other like 'a*'"),0x010110},
  1273 		{_S("txt < 'text'"),0x010111},
  1274 		{_S("txt > 'text'"),0x001000},
  1275 		{_S("txt > ''"),0x111110},
  1276 		{_S("txt like 'text'"),0x100000},
  1277 		{_S("txt like '*TEXT'"),0x110000},
  1278 		{_S("txt like 'text*'"),0x101000},
  1279 		{_S("txt like '*text*'"),0x111010},
  1280 		{_S("txt like '*'"),0x111111},
  1281 		{_S("txt like '?*'"),0x111110},
  1282 		{_S("txt like '*t*t*'"),0x111010},
  1283 		{_S("txt like '*a??t*'"),0x010010},
  1284 		{_S("txt like 'aA*aa'"),0x000110},
  1285 		{_S("txt like 'teXT'"),0x100000},
  1286 		{_S("txt like '*text'"),0x110000},
  1287 		{_S("txt like '*tExt*'"),0x111010},
  1288 		{_S("txt like ''"),0x000001},
  1289 		{_S("txt is null"),0x000001}
  1290 	};
  1291 
  1292 LOCAL_C void CreateFindTableL()
  1293 	{
  1294 	CDbColSet *pC=CDbColSet::NewL();
  1295 	CleanupStack::PushL(pC);
  1296 	pC->AddL(TDbCol(KColumnID,EDbColUint32));
  1297 	pC->AddL(TDbCol(KColumnText,EDbColLongText,200));
  1298 	pC->AddL(TDbCol(KColumnOther,EDbColText,200));
  1299 	test(TheDatabase.CreateTable(KTestFindTable,*pC)==KErrNone);
  1300 	CleanupStack::PopAndDestroy();
  1301 	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EInsertOnly)==KErrNone);
  1302 	TBuf<0x40> garbage;
  1303 	garbage.SetMax();
  1304 	garbage.Fill('a');
  1305 	TBuf<0xff> col;
  1306 	for (TUint ii=0;ii<6;++ii)
  1307 		{
  1308 		TheTable.InsertL();
  1309 		TheTable.SetColL(1,ii);
  1310 		TheTable.SetColL(3,_L("abcdef"));
  1311 
  1312 		switch (ii)
  1313 			{
  1314 		case 0:
  1315 			TheTable.SetColL(2,KBlobText);
  1316 			break;
  1317 		case 1:
  1318 			col=garbage;
  1319 			col+=KBlobText;
  1320 			TheTable.SetColL(2,col);
  1321 			break;
  1322 		case 2:
  1323 			col=KBlobText;
  1324 			col+=garbage;
  1325 			TheTable.SetColL(2,col);
  1326 			break;
  1327 		case 3:
  1328 			TheTable.SetColL(2,garbage);
  1329 			break;
  1330 		case 4:
  1331 			col=garbage;
  1332 			col+=KBlobText;
  1333 			col+=garbage;
  1334 			TheTable.SetColL(2,col);
  1335 			break;
  1336 		case 5:
  1337 			break;
  1338 			}
  1339 		TheTable.PutL();
  1340 		}
  1341 	TheTable.Close();
  1342 	CDbKey* key=CDbKey::NewLC();
  1343 	key->AddL(KColumnID);
  1344 	key->MakeUnique();
  1345 	test(TheDatabase.CreateIndex(KIndexName,KTestFindTable,*key)==KErrNone);
  1346 	key->Clear();
  1347 	key->AddL(TDbKeyCol(KColumnText,100));
  1348 	key->MakeUnique();
  1349 	key->SetComparison(EDbCompareFolded);
  1350 	test(TheDatabase.CreateIndex(KIndexName2,KTestFindTable,*key)==KErrNone);
  1351 	CleanupStack::PopAndDestroy(); //key
  1352 	}
  1353 
  1354 /**
  1355 @SYMTestCaseID          SYSLIB-DBMS-CT-0598
  1356 @SYMTestCaseDesc        Tests for RDbRowConstraint::Open() function
  1357 @SYMTestPriority        Medium
  1358 @SYMTestActions         Tests for the specified SQL search-condition for matching against rows in the specified rowset
  1359 @SYMTestExpectedResults Test must not fail
  1360 @SYMREQ                 REQ0000
  1361 */
  1362 LOCAL_C void TestMatchL()
  1363 	{
  1364 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0598 Match "));
  1365 	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1366 	for (TInt ii=0;ii<TInt(sizeof(Tests)/sizeof(Tests[0]));++ii)
  1367 		{
  1368 		RDbRowConstraint match;
  1369 		test(match.Open(TheTable,TDbQuery(TPtrC(Tests[ii].iText),EDbCompareFolded))==KErrNone);
  1370 		TUint mask=0;
  1371 		TheTable.BeginningL();
  1372 		while (TheTable.NextL())
  1373 			{
  1374 			if (TheTable.MatchL(match))
  1375 				{
  1376 				TheTable.GetL();
  1377 				TUint bit=0x100000>>(TheTable.ColUint32(1)*4);
  1378 				test((bit&mask)==0);
  1379 				mask|=bit;
  1380 				}
  1381 			}
  1382 		match.Close();
  1383 		test(mask==Tests[ii].iRecs);
  1384 		}
  1385 	TheTable.Close();
  1386 	}
  1387 
  1388 /**
  1389 @SYMTestCaseID          SYSLIB-DBMS-CT-0599
  1390 @SYMTestCaseDesc        Tests for RDbRowSet::FindL(),RDbRowSet::GetL() functions
  1391 @SYMTestPriority        Medium
  1392 @SYMTestActions         Tests for finding a match through a rowset
  1393 @SYMTestExpectedResults Test must not fail
  1394 @SYMREQ                 REQ0000
  1395 */
  1396 LOCAL_C void TestFindL(RDbRowSet& aSet)
  1397 	{
  1398 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0599 "));
  1399 	CDbColSet* cs=aSet.ColSetL();
  1400 	test(cs!=0);
  1401 	TDbColNo col=cs->ColNo(KColumnID);
  1402 	test(col!=KDbNullColNo);
  1403 	delete cs;
  1404 	aSet.FirstL();
  1405 	TInt p1=aSet.FindL(aSet.EForwards,KFind1);
  1406 	test(p1>=0);
  1407 	aSet.GetL();
  1408 	test(aSet.ColUint(col)==1);
  1409 	test(aSet.FindL(aSet.EForwards,KFind1)==0);
  1410 	aSet.GetL();
  1411 	test(aSet.ColUint(col)==1);
  1412 	if (aSet.NextL())
  1413 		test(aSet.FindL(aSet.EForwards,KFind1)==KErrNotFound);
  1414 	aSet.FirstL();
  1415 	test(aSet.FindL(aSet.EForwards,KFind2)==KErrNotFound);
  1416 	aSet.LastL();
  1417 	TInt p2=aSet.FindL(aSet.EBackwards,KFind1);
  1418 	test(p2>=0);
  1419 	aSet.GetL();
  1420 	test(aSet.ColUint(col)==1);
  1421 	test(aSet.FindL(aSet.EBackwards,KFind1)==0);
  1422 	aSet.GetL();
  1423 	test(aSet.ColUint(col)==1);
  1424 	if (aSet.PreviousL())
  1425 		test(aSet.FindL(aSet.EBackwards,KFind1)==KErrNotFound);
  1426 	aSet.LastL();
  1427 	test(aSet.FindL(aSet.EBackwards,KFind2)==KErrNotFound);
  1428 	test(p1+p2+1==aSet.CountL());
  1429 	}
  1430 
  1431 /**
  1432 @SYMTestCaseID          SYSLIB-DBMS-CT-0600
  1433 @SYMTestCaseDesc        Tests for SQL find
  1434 @SYMTestPriority        Medium
  1435 @SYMTestActions         Tests for SQL querying a table
  1436 @SYMTestExpectedResults Test must not fail
  1437 @SYMREQ                 REQ0000
  1438 */
  1439 LOCAL_C void TestSQLFindL(const TText* aSql)
  1440 	{
  1441     test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0600 "));
  1442 	test(TheView.Prepare(TheDatabase,TDbQuery(TPtrC(aSql),EDbCompareFolded),TheView.EReadOnly)==KErrNone);
  1443 	test(TheView.EvaluateAll()==KErrNone);
  1444 	TestFindL(TheView);
  1445 	TheView.Close();
  1446 	}
  1447 
  1448 /**
  1449 @SYMTestCaseID          SYSLIB-DBMS-CT-0601
  1450 @SYMTestCaseDesc        Tests for DBMS limits
  1451 @SYMTestPriority        Medium
  1452 @SYMTestActions         Tests for maximum length boundaries
  1453 @SYMTestExpectedResults Test must not fail
  1454 @SYMREQ                 REQ0000
  1455 */
  1456 LOCAL_C void TestDbmsBoundaries()
  1457 	{
  1458 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0601 "));
  1459 	// Test KMaxSegmentLength boundary
  1460 
  1461 	_LIT(KMaxSegmentLengthMinusOne,"txt like \
  1462 		'*01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567@0.com*' \
  1463 		  or other like \
  1464 		'*01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567@0.com*'");
  1465 	_LIT(KMaxSegmentLengthExact,"txt like \
  1466 		'*012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@0.com*' \
  1467 		  or other like \
  1468 		'*012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@0.com*'");
  1469 	_LIT(KMaxSegmentLengthPlusOne,"txt like \
  1470 		'*0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@0.com*' \
  1471 		  or other like \
  1472 		'*0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@0.com*'");
  1473 
  1474 	TInt ret=KErrNone;
  1475 	RDbRowConstraint match;
  1476 
  1477 	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1478 
  1479 	// Test one less than the boundary
  1480 	ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthMinusOne,EDbCompareFolded));
  1481 	match.Close();
  1482 	test(ret==KErrNone);
  1483 
  1484 	// Test the boundary
  1485 	ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthExact,EDbCompareFolded));
  1486 	match.Close();
  1487 	test(ret==KErrNone);
  1488 
  1489 	// Test one more than the boundary
  1490 	ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthPlusOne,EDbCompareFolded));
  1491 	match.Close();
  1492 	test(ret==KErrArgument);
  1493 
  1494 	TheTable.Close();
  1495 	}
  1496 
  1497 /**
  1498 @SYMTestCaseID          SYSLIB-DBMS-CT-0602
  1499 @SYMTestCaseDesc        Tests for table order,SQL query,
  1500 @SYMTestPriority        Medium
  1501 @SYMTestActions         Tests for finding a row in a rowset,dbms boundaries,SQL querying
  1502 @SYMTestExpectedResults Test must not fail
  1503 @SYMREQ                 REQ0000
  1504 */
  1505 LOCAL_C void TestFindL()
  1506 	{
  1507 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0602 Table order "));
  1508 	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1509 	TestFindL(TheTable);
  1510 	test.Next(_L("Index order"));
  1511 	test(TheTable.SetIndex(KIndexName)==KErrNone);
  1512 	TestFindL(TheTable);
  1513 	test(TheTable.SetIndex(KIndexName2)==KErrNone);
  1514 	TestFindL(TheTable);
  1515 	TheTable.Close();
  1516 
  1517 	test.Next(_L("SQL query test boundary"));
  1518 	TestDbmsBoundaries();
  1519 
  1520 	test.Next(_L("SQL query"));
  1521 	TestSQLFindL(_S("select id from TestFindTable where id=1"));
  1522 	TestSQLFindL(_S("select * from TestFindTable where id<=2"));
  1523 	TestSQLFindL(_S("select txt,id from TestFindTable order by id desc"));
  1524 	TestSQLFindL(_S("select id,txt from TestFindTable where id=1 or txt like '*text*'"));
  1525 	TestSQLFindL(_S("select * from TestFindTable where id=1 or txt is not null order by id"));
  1526 	TestSQLFindL(_S("select id from TestFindTable where id<>3 order by txt"));
  1527 	test.End();
  1528 	}
  1529 
  1530 LOCAL_C void TestBookmarkL(RDbRowSet& aSet)
  1531 	{
  1532 	aSet.BeginningL();
  1533 	while (aSet.NextL())
  1534 		{
  1535 		aSet.GetL();
  1536 		TUint id=aSet.ColUint(1);
  1537 		TDbBookmark mark=aSet.Bookmark();
  1538 		aSet.BeginningL();
  1539 		aSet.GotoL(mark);
  1540 		aSet.GetL();
  1541 		test(aSet.ColUint(1)==id);
  1542 		aSet.NextL();
  1543 		aSet.PreviousL();
  1544 		aSet.PreviousL();
  1545 		aSet.NextL();
  1546 		aSet.GetL();
  1547 		test(aSet.ColUint(1)==id);
  1548 		aSet.GotoL(mark);
  1549 		};
  1550 	}
  1551 
  1552 LOCAL_C void TestSQLBookmarkL(const TText* aSql)
  1553 	{
  1554 	test(TheView.Prepare(TheDatabase,TDbQuery(TPtrC(aSql),EDbCompareFolded),TheView.EReadOnly)==KErrNone);
  1555 	test(TheView.EvaluateAll()==KErrNone);
  1556 	TestBookmarkL(TheView);
  1557 	TheView.Close();
  1558 	}
  1559 
  1560 LOCAL_C void TestBookmarkL()
  1561 	{
  1562 	test.Start(_L("Table order"));
  1563 	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1564 	TestBookmarkL(TheTable);
  1565 	test.Next(_L("Index order"));
  1566 	test(TheTable.SetIndex(KIndexName)==KErrNone);
  1567 	TestBookmarkL(TheTable);
  1568 	test(TheTable.SetIndex(KIndexName2)==KErrNone);
  1569 	TestBookmarkL(TheTable);
  1570 	TheTable.Close();
  1571 	test.Next(_L("SQL query"));
  1572 	TestSQLBookmarkL(_S("select * from TestFindTable where id=1"));
  1573 	TestSQLBookmarkL(_S("select * from TestFindTable where id>2"));
  1574 	TestSQLBookmarkL(_S("select * from TestFindTable order by id desc"));
  1575 	TestSQLBookmarkL(_S("select * from TestFindTable where txt like '*text*'"));
  1576 	TestSQLBookmarkL(_S("select * from TestFindTable where txt is not null order by id"));
  1577 	TestSQLBookmarkL(_S("select * from TestFindTable where id <> 3 order by txt"));
  1578 	test.End();
  1579 	}
  1580 
  1581 /**
  1582 @SYMTestCaseID          SYSLIB-DBMS-CT-0603
  1583 @SYMTestCaseDesc        Tests for find and bookmark
  1584 @SYMTestPriority        Medium
  1585 @SYMTestActions         Executes Match,Find,Bookmarks tests
  1586 @SYMTestExpectedResults Test must not fail
  1587 @SYMREQ                 REQ0000
  1588 */
  1589 LOCAL_C void TestFindAndBookmarkL()
  1590 	{
  1591 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0603 Create Table "));
  1592 	OpenDatabase();
  1593 	CreateFindTableL();
  1594 	TestMatchL();
  1595 	test.Next(_L("Find"));
  1596 	TestFindL();
  1597 	test.Next(_L("Bookmarks"));
  1598 	TestBookmarkL();
  1599 	test.Next(_L("Close"));
  1600 	CloseDatabase();
  1601 	test.End();
  1602 	}
  1603 
  1604 /**
  1605 @SYMTestCaseID          SYSLIB-DBMS-CT-0604
  1606 @SYMTestCaseDesc        Tests for multi view
  1607 @SYMTestPriority        Medium
  1608 @SYMTestActions         Tests for adding and deleting rows
  1609 @SYMTestExpectedResults Test must not fail
  1610 @SYMREQ                 REQ0000
  1611 */
  1612 LOCAL_C void TestMultiViewL()
  1613 	{
  1614 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0604 Create Table "));
  1615 	OpenDatabase();
  1616 	CDbColSet* set=CreateColSetL(ESingleColumn);
  1617 	test(TheDatabase.CreateTable(KTestMultiTable,*set)==KErrNone);
  1618 	delete set;
  1619 	test.Next(_L("Add and modify rows"));
  1620 	test(TheTable.Open(TheDatabase,KTestMultiTable)==KErrNone);
  1621 	test(TheView.Prepare(TheDatabase,_L("select * from TestMultiTable"))==KErrNone);
  1622 	test(TheView.EvaluateAll()==KErrNone);
  1623 	for (TInt ii=1;ii<=10;++ii)
  1624 		{
  1625 		TheTable.InsertL();
  1626 		TheTable.SetColL(1,ii);
  1627 		TheTable.PutL();
  1628 		TheView.NextL();
  1629 		TheView.GetL();
  1630 		test(TheView.ColInt(1)==ii);
  1631 		TheView.UpdateL();
  1632 		TheView.SetColL(1,ii+100);
  1633 		TheView.PutL();
  1634 		test(TheTable.ColInt(1)==ii);
  1635 		TheTable.GetL();
  1636 		test(TheTable.ColInt(1)==ii+100);
  1637 		}
  1638 	test.Next(_L("delete rows"));
  1639 	TheView.FirstL();
  1640 	TheTable.FirstL();
  1641 	TheView.GetL();
  1642 	test (TheView.ColInt(1)==1+100);
  1643 	TheTable.DeleteL();
  1644 	TRAPD(r,TheView.GetL());
  1645 	test(r!=KErrNone);
  1646 	TheView.NextL();
  1647 	TheView.GetL();
  1648 	test (TheView.ColInt(1)==2+100);
  1649 	TheView.DeleteL();
  1650 	test(!TheView.PreviousL());
  1651 	TheTable.NextL();
  1652 	test(!TheTable.PreviousL());
  1653 	test.End();
  1654 	TheView.Close();
  1655 	TheTable.Close();
  1656 	CloseDatabase();
  1657 	}
  1658 
  1659 LOCAL_C void ValidateUID3(const TDesC& aDbName, const TUid& aUid)
  1660 	{
  1661 	test.Next(_L("Read DB header"));
  1662 	RFile dbFile;
  1663 	TInt err = dbFile.Open(TheFs, aDbName, EFileRead);
  1664 	test(err==KErrNone);
  1665 	TBuf8<100> contents; // header of a new DB is approx 77 bytes
  1666 	err = dbFile.Read(contents);
  1667 	dbFile.Close();
  1668 	test(err==KErrNone);
  1669 
  1670 	test.Next(_L("Check UID3"));
  1671 	const TPtrC8 ptr((const TUint8*) &aUid.iUid, sizeof(aUid.iUid));
  1672 	TInt pos = contents.Find(ptr);
  1673 	test(pos==8); // UID3 begins at byte pos 8
  1674 	}
  1675 
  1676 /**
  1677 @SYMTestCaseID          SYSLIB-DBMS-CT-1372
  1678 @SYMTestCaseDesc        Tests for UID3 being set in DB header
  1679 @SYMTestPriority        Medium
  1680 @SYMTestActions         Creates a new DB and checks UID3
  1681 @SYMTestExpectedResults Test must not fail
  1682 @SYMREQ                 REQ0000
  1683 */
  1684 LOCAL_C void TestDbUID3()
  1685 	{
  1686 	const TUid KOrigUid = {0x19768253}; // random UID
  1687 	const TUid KReplaceUid = {0x24731264}; // different random UID
  1688 	const TPtrC KTempDbName(_S("C:\\DBMS-TST\\T_DBMS_UID3.DB"));
  1689 
  1690 	(void)TheFs.Delete(KTempDbName);
  1691 
  1692 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1372 Create Database "));
  1693 	RDbNamedDatabase tempDb;
  1694 	TInt err = tempDb.Create(TheFs, KTempDbName, KOrigUid.Name());
  1695 	test(err==KErrNone);
  1696 	tempDb.Close();
  1697 
  1698 	ValidateUID3(KTempDbName, KOrigUid);
  1699 
  1700 	test.Next(_L("Replace Database"));
  1701 	err = tempDb.Replace(TheFs, KTempDbName, KReplaceUid.Name());
  1702 	test(err==KErrNone);
  1703 	tempDb.Close();
  1704 
  1705 	ValidateUID3(KTempDbName, KReplaceUid);
  1706 
  1707 	test.Next(_L("Replace Database using default UID3"));
  1708 	err = tempDb.Replace(TheFs, KTempDbName);
  1709 	test(err==KErrNone);
  1710 	tempDb.Close();
  1711 
  1712 	ValidateUID3(KTempDbName, KNullUid);
  1713 
  1714 	(void)TheFs.Delete(KTempDbName);
  1715 	test.End();
  1716 	}
  1717 
  1718 LOCAL_C void Test()
  1719 	{
  1720 	__UHEAP_MARK;
  1721 	test.Start(_L("DDL"));
  1722 	TRAPD(r,TestDDL();)
  1723 	test(r==KErrNone);
  1724 	__UHEAP_MARKEND;
  1725 	__UHEAP_MARK;
  1726 	test.Next(_L("Navigation/Edit"));
  1727 	TRAP(r,TestViewL();)
  1728 	test(r==KErrNone);
  1729 	__UHEAP_MARKEND;
  1730 	__UHEAP_MARK;
  1731 	test.Next(_L("Column Types"));
  1732 	TRAP(r,TestTypesL();)
  1733 	test(r==KErrNone);
  1734 	__UHEAP_MARKEND;
  1735 	__UHEAP_MARK;
  1736 	test.Next(_L("Find, Match & Bookmarks"));
  1737 	TRAP(r,TestFindAndBookmarkL();)
  1738 	test(r==KErrNone);
  1739 	__UHEAP_MARKEND;
  1740 	__UHEAP_MARK;
  1741 	test.Next(_L("Multiple view updates"));
  1742 	TRAP(r,TestMultiViewL();)
  1743 	test(r==KErrNone);
  1744 	__UHEAP_MARKEND;
  1745 	__UHEAP_MARK;
  1746 	test.Next(_L("Database UID3"));
  1747 	TRAP(r,TestDbUID3();)
  1748 	test(r==KErrNone);
  1749 	test.End();
  1750 	__UHEAP_MARKEND;
  1751 	}
  1752 
  1753 //
  1754 // Prepare the test directory.
  1755 //
  1756 LOCAL_C void setupTestDirectory()
  1757     {
  1758 	TInt r=TheFs.Connect();
  1759 	test(r==KErrNone);
  1760 //
  1761 	r=TheFs.MkDir(KTestDatabase);
  1762 	test(r==KErrNone || r==KErrAlreadyExists);
  1763 	}
  1764 
  1765 //
  1766 // Initialise the cleanup stack.
  1767 //
  1768 LOCAL_C void setupCleanup()
  1769     {
  1770 	TheTrapCleanup=CTrapCleanup::New();
  1771 	test(TheTrapCleanup!=NULL);
  1772 	TRAPD(r,\
  1773 		{\
  1774 		for (TInt i=KTestCleanupStack;i>0;i--)\
  1775 			CleanupStack::PushL((TAny*)0);\
  1776 		CleanupStack::Pop(KTestCleanupStack);\
  1777 		});
  1778 	test(r==KErrNone);
  1779 	}
  1780 
  1781 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
  1782 	{
  1783 	RFs fsSession;
  1784 	TInt err = fsSession.Connect();
  1785 	if(err == KErrNone)
  1786 		{
  1787 		TEntry entry;
  1788 		if(fsSession.Entry(aFullName, entry) == KErrNone)
  1789 			{
  1790 			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
  1791 			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
  1792 			if(err != KErrNone)
  1793 				{
  1794 				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
  1795 				}
  1796 			err = fsSession.Delete(aFullName);
  1797 			if(err != KErrNone)
  1798 				{
  1799 				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
  1800 				}
  1801 			}
  1802 		fsSession.Close();
  1803 		}
  1804 	else
  1805 		{
  1806 		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
  1807 		}
  1808 	}
  1809 
  1810 //
  1811 // Test streaming conversions.
  1812 //
  1813 GLDEF_C TInt E32Main()
  1814     {
  1815 	test.Title();
  1816 	setupTestDirectory();
  1817 	setupCleanup();
  1818 	__UHEAP_MARK;
  1819 //
  1820 	TInt r=TheDbs.Connect();
  1821 	test (r==KErrNone);
  1822 	test.Start(_L("Standard database"));
  1823 	Test();
  1824 	test.Next(_L("Secure database"));
  1825 	Test();
  1826 	TheDbs.Close();
  1827 	test.End();
  1828 //
  1829 	__UHEAP_MARKEND;
  1830 	delete TheTrapCleanup;
  1831 
  1832 	::DeleteDataFile(KTestDatabase);
  1833 
  1834 	TheFs.Close();
  1835 	test.Close();
  1836 	return 0;
  1837     }