os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_dbms.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_dbms.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1889 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <d32dbms.h>
    1.20 +#include <s32file.h>
    1.21 +#include <e32test.h>
    1.22 +#include <e32math.h>
    1.23 +
    1.24 +#include "crccheck.h"
    1.25 +
    1.26 +#undef __UHEAP_MARK
    1.27 +#define __UHEAP_MARK
    1.28 +#undef __UHEAP_MARKEND
    1.29 +#define __UHEAP_MARKEND
    1.30 +
    1.31 +LOCAL_D TDBMS_CRCChecks TheCrcChecker;
    1.32 +
    1.33 +#ifndef __linux__ //No CRC test on LINUX
    1.34 +#ifdef __TOOLS2__
    1.35 +const TPtrC	KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_DBMS.CRC");
    1.36 +#else
    1.37 +const TPtrC	KCrcRecord=_L("C:\\dbms-tst\\T_DBMS.CRC");
    1.38 +#endif
    1.39 +#endif
    1.40 +
    1.41 +#if defined(__VC32__) && !defined(_DEBUG)
    1.42 +#pragma warning(disable : 4710)			// function not expanded. MSVC 4.0 is stupid
    1.43 +#endif
    1.44 +
    1.45 +LOCAL_D RTest test(_L("T_DBMS : Test DBMS API"));
    1.46 +LOCAL_D CTrapCleanup* TheTrapCleanup;
    1.47 +LOCAL_D RDbs TheDbs;
    1.48 +LOCAL_D RDbNamedDatabase TheDatabase;
    1.49 +LOCAL_D RDbTable TheTable;
    1.50 +LOCAL_D RDbView TheView;
    1.51 +LOCAL_D RFs TheFs;
    1.52 +LOCAL_D TBuf8<0x200> TheBuf8;
    1.53 +LOCAL_D TBuf16<0x100> TheBuf16;
    1.54 +
    1.55 +const TInt KTestCleanupStack=0x40;
    1.56 +
    1.57 +#ifdef __TOOLS2__
    1.58 +const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_DBMS.DB");
    1.59 +#else
    1.60 +const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_DBMS.DB");
    1.61 +#endif
    1.62 +
    1.63 +const TPtrC8 KTestText8(_S8("Text used for test columns when testing"));
    1.64 +const TPtrC8 KTestShortText8(_S8("a"));
    1.65 +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............." \
    1.66 +							"Text which is used to set Long ASCII Text columns and ensure they are not inlined, and therefore needs to be very long indeed............."));
    1.67 +const TPtrC16 KTestText16(_S16("Text used for test columns when testing"));
    1.68 +const TPtrC16 KTestShortText16(_S16("a"));
    1.69 +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............."));
    1.70 +const TPtrC KTableName(_S("TestTable"));
    1.71 +const TPtrC KTableName2(_S("TestTable2"));
    1.72 +const TPtrC KTestViewTable(_L("TestViewTable"));
    1.73 +const TPtrC KTestTypesTable(_L("TestTypesTable"));
    1.74 +const TPtrC KTestFindTable(_L("TestFindTable"));
    1.75 +const TPtrC KTestMultiTable(_L("TestMultiTable"));
    1.76 +const TPtrC KIndexName(_S("Index1"));
    1.77 +const TPtrC KIndexName2(_S("Index2"));
    1.78 +const TPtrC KIndexName3(_S("Index3"));
    1.79 +const TInt KBlobItems=1000;
    1.80 +
    1.81 +const TPtrC KNull=TPtrC();
    1.82 +const TPtrC KPass1(_S("wibble"));
    1.83 +const TPtrC KPass2(_S("wobble"));
    1.84 +
    1.85 +const TTime KMinTTime=Time::MinTTime();
    1.86 +const TTime KMaxTTime=Time::MaxTTime();
    1.87 +
    1.88 +struct SColDef
    1.89 +	{
    1.90 +	const TText* iName;
    1.91 +	TDbColType iType;
    1.92 +	TInt iAttributes;
    1.93 +	};
    1.94 +LOCAL_D SColDef const SingleColumn[]=
    1.95 +	{
    1.96 +	{_S("Column1"),EDbColInt32,0},
    1.97 +	{0}
    1.98 +	};
    1.99 +LOCAL_D SColDef const DoubleColumn[]=
   1.100 +	{
   1.101 +	{_S("Column1"),EDbColInt32,0},
   1.102 +	{_S("c2"),EDbColInt64,0},
   1.103 +	{0}
   1.104 +	};
   1.105 +LOCAL_D SColDef const ViewTestColumns[]=
   1.106 +	{
   1.107 +	{_S("Int"),EDbColInt32,0},
   1.108 +	{_S("Long1"),EDbColLongText8,0},
   1.109 +	{_S("Long2"),EDbColLongText8,0},
   1.110 +	{_S("Long3"),EDbColLongText8,0},
   1.111 +	{_S("Long4"),EDbColLongText8,0},
   1.112 +	{_S("Long5"),EDbColLongText8,0},
   1.113 +	{0}
   1.114 +	};
   1.115 +LOCAL_D SColDef const AllColumns[]=
   1.116 +	{
   1.117 +	{_S("counter"),EDbColInt32,TDbCol::ENotNull|TDbCol::EAutoIncrement},
   1.118 +	{_S("bit"),EDbColBit,TDbCol::ENotNull},
   1.119 +	{_S("int8"),EDbColInt8,TDbCol::ENotNull},
   1.120 +	{_S("uint8"),EDbColUint8,TDbCol::ENotNull},
   1.121 +	{_S("int16"),EDbColInt16,TDbCol::ENotNull},
   1.122 +	{_S("uint16"),EDbColUint16,TDbCol::ENotNull},
   1.123 +	{_S("int32"),EDbColInt32,TDbCol::ENotNull},
   1.124 +	{_S("uint32"),EDbColUint32,TDbCol::ENotNull},
   1.125 +	{_S("int64"),EDbColInt64,TDbCol::ENotNull},
   1.126 +	{_S("real32"),EDbColReal32,TDbCol::ENotNull},
   1.127 +	{_S("real64"),EDbColReal64,TDbCol::ENotNull},
   1.128 +	{_S("date_time"),EDbColDateTime,TDbCol::ENotNull},
   1.129 +	{_S("text8"),EDbColText8,TDbCol::ENotNull},
   1.130 +	{_S("text16"),EDbColText16,TDbCol::ENotNull},
   1.131 +	{_S("binary"),EDbColBinary,TDbCol::ENotNull},
   1.132 +	{_S("longtext8"),EDbColLongText8,TDbCol::ENotNull},
   1.133 +	{_S("longtext16"),EDbColLongText16,TDbCol::ENotNull},
   1.134 +	{_S("longbinary"),EDbColLongBinary,TDbCol::ENotNull},
   1.135 +	{_S("bit_null"),EDbColBit,0},
   1.136 +	{_S("int8_null"),EDbColInt8,0},
   1.137 +	{_S("uint8_null"),EDbColUint8,0},
   1.138 +	{_S("int16_null"),EDbColInt16,0},
   1.139 +	{_S("uint16_null"),EDbColUint16,0},
   1.140 +	{_S("int32_null"),EDbColInt32,0},
   1.141 +	{_S("uint32_null"),EDbColUint32,0},
   1.142 +	{_S("int64_null"),EDbColInt64,0},
   1.143 +	{_S("real32_null"),EDbColReal32,0},
   1.144 +	{_S("real64_null"),EDbColReal64,0},
   1.145 +	{_S("date_time_null"),EDbColDateTime,0},
   1.146 +	{_S("text8_null"),EDbColText8,0},
   1.147 +	{_S("text16_null"),EDbColText16,0},
   1.148 +	{_S("binary_null"),EDbColBinary,0},
   1.149 +	{_S("longtext8_null"),EDbColLongText8,0},
   1.150 +	{_S("longtext16_null"),EDbColLongText16,0},
   1.151 +	{_S("longbinary_null"),EDbColLongBinary,0},
   1.152 +	{_S("force_null"),EDbColInt32,0},
   1.153 +	{0}
   1.154 +	};
   1.155 +const TInt KColumns=sizeof(AllColumns)/sizeof(AllColumns[0])-1;
   1.156 +enum TColumns
   1.157 +	{
   1.158 +	ECounter,
   1.159 +	EBit,EInt8,EUint8,EInt16,EUint16,EInt32,EUint32,EInt64,
   1.160 +	EReal32,EReal64,ETime,EText8,EText16,ETBinary,
   1.161 +	ELongText8,ELongText16,ELongBinary,
   1.162 +	EBitNull,EInt8Null,EUint8Null,EInt16Null,EUint16Null,EInt32Null,EUint32Null,EInt64Null,
   1.163 +	EReal32Null,EReal64Null,ETimeNull,EText8Null,EText16Null,ETBinaryNull,
   1.164 +	ELongText8Null,ELongText16Null,ELongBinaryNull,EForceNull
   1.165 +	};
   1.166 +LOCAL_D TDbColNo TheMap[KColumns];
   1.167 +
   1.168 +CDbColSet* ColumnSetL(const SColDef* aDef)
   1.169 +	{
   1.170 +	CDbColSet *set=CDbColSet::NewLC();
   1.171 +	for (;aDef->iName;++aDef)
   1.172 +		{
   1.173 +		TDbCol col(TPtrC(aDef->iName),aDef->iType);
   1.174 +		col.iAttributes=aDef->iAttributes;
   1.175 +		set->AddL(col);
   1.176 +		}
   1.177 +	CleanupStack::Pop();
   1.178 +	return set;
   1.179 +	}
   1.180 +
   1.181 +enum TColSet {EAllTypes,ESingleColumn,EDoubleColumn,EViewTestTable};
   1.182 +LOCAL_D const SColDef* const ColSetDef[]=
   1.183 +	{
   1.184 +	AllColumns,
   1.185 +	SingleColumn,
   1.186 +	DoubleColumn,
   1.187 +	ViewTestColumns
   1.188 +	};
   1.189 +LOCAL_C CDbColSet* CreateColSetL(TColSet aType)
   1.190 +	{
   1.191 +	return ColumnSetL(ColSetDef[aType]);
   1.192 +	}
   1.193 +
   1.194 +inline TPtrC ColName(const SColDef* aSet,TInt aColumn)
   1.195 +	{return TPtrC(aSet[aColumn].iName);}
   1.196 +
   1.197 +enum TKeySet {EKeyAsc,EKeyDesc,EKeyMulti,EKeySingle};
   1.198 +LOCAL_C CDbKey* CreateKeyL(TKeySet aType)
   1.199 +	{
   1.200 +	CDbKey *k=CDbKey::NewLC();
   1.201 +	switch(aType)
   1.202 +		{
   1.203 +	case EKeyAsc:
   1.204 +		k->AddL(ColName(AllColumns,EInt32));
   1.205 +		break;
   1.206 +	case EKeyDesc:
   1.207 +		k->AddL(TDbKeyCol(ColName(AllColumns,EInt32),TDbKeyCol::EDesc));
   1.208 +		k->MakeUnique();
   1.209 +		break;
   1.210 +	case EKeyMulti:
   1.211 +		k->AddL(ColName(AllColumns,EInt32)).AddL(ColName(AllColumns,EText8));
   1.212 +		k->SetComparison(EDbCompareFolded);
   1.213 +		break;
   1.214 +	case EKeySingle:
   1.215 +		k->AddL(ColName(SingleColumn,0));
   1.216 +		break;
   1.217 +		}
   1.218 +	CleanupStack::Pop();
   1.219 +	return k;
   1.220 +	}
   1.221 +
   1.222 +LOCAL_C void CloseDatabase()
   1.223 +	{
   1.224 +	TheDatabase.Close();
   1.225 +	TheCrcChecker.GenerateCrcL(KTestDatabase);
   1.226 +	}
   1.227 +
   1.228 +
   1.229 +//
   1.230 +// Open a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   1.231 +//
   1.232 +LOCAL_C TInt OpenSharedDatabase()
   1.233 +	{
   1.234 +	return TheDatabase.Open(TheDbs,KTestDatabase);
   1.235 +	}
   1.236 +
   1.237 +//
   1.238 +// Create a local database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   1.239 +//
   1.240 +LOCAL_C void CreateClientDatabase()
   1.241 +	{
   1.242 +	TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
   1.243 +	test (r==KErrNone);
   1.244 +	}
   1.245 +
   1.246 +//
   1.247 +// Create a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   1.248 +//
   1.249 +LOCAL_C void CreateSharedDatabase()
   1.250 +	{
   1.251 +	CreateClientDatabase();
   1.252 +	CloseDatabase();
   1.253 +	TInt r=OpenSharedDatabase();
   1.254 +	test (r==KErrNone);
   1.255 +	}
   1.256 +
   1.257 +//
   1.258 +// Open a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   1.259 +//
   1.260 +LOCAL_C void OpenDatabase()
   1.261 +	{
   1.262 +	TInt r=OpenSharedDatabase();
   1.263 +	test (r==KErrNone);
   1.264 +	}
   1.265 +
   1.266 +//
   1.267 +// Create a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
   1.268 +//
   1.269 +LOCAL_C void CreateDatabase()
   1.270 +	{
   1.271 +	CreateSharedDatabase();
   1.272 +	}
   1.273 +
   1.274 +
   1.275 +LOCAL_C void DestroyDatabase()
   1.276 +	{
   1.277 +	TInt r=TheDatabase.Destroy();
   1.278 +	test (r==KErrNone);
   1.279 +	}
   1.280 +
   1.281 +//
   1.282 +// Check the database has this many tables
   1.283 +//
   1.284 +LOCAL_C void CountTables(TInt aCount)
   1.285 +	{
   1.286 +	CDbNames* names=TheDatabase.TableNamesL();
   1.287 +	test (names->Count()==aCount);
   1.288 +	delete names;
   1.289 +	}
   1.290 +
   1.291 +//
   1.292 +// Compare two column sets
   1.293 +//
   1.294 +LOCAL_C void Compare(const TDesC& aTable,const CDbColSet& aSet)
   1.295 +	{
   1.296 +	CDbColSet* set=TheDatabase.ColSetL(aTable);
   1.297 +	test(set->Count()==aSet.Count());
   1.298 +	for (TDbColSetIter iter(*set);iter;++iter)
   1.299 +		{
   1.300 +		const TDbCol* pRight=aSet.Col(iter->iName);
   1.301 +		test(pRight!=NULL);
   1.302 +		test(iter->iType==pRight->iType);
   1.303 +		test(iter->iMaxLength==KDbUndefinedLength || pRight->iMaxLength==KDbUndefinedLength || iter->iMaxLength==pRight->iMaxLength);
   1.304 +		test((iter->iAttributes&pRight->iAttributes)==iter->iAttributes);
   1.305 +		}
   1.306 +	delete set;
   1.307 +	}
   1.308 +
   1.309 +//
   1.310 +// Check the database has this many tables
   1.311 +//
   1.312 +LOCAL_C void CountIndexes(const TDesC& aTable,TInt aCount)
   1.313 +	{
   1.314 +	CDbNames* names=TheDatabase.IndexNamesL(aTable);
   1.315 +	test (names->Count()==aCount);
   1.316 +	delete names;
   1.317 +	}
   1.318 +
   1.319 +//
   1.320 +// Compare index definition
   1.321 +//
   1.322 +LOCAL_C void Compare(const TDesC& aIndex,const TDesC& aTable,const CDbKey& aKey)
   1.323 +	{
   1.324 +	CDbKey* key=TheDatabase.KeyL(aIndex,aTable);
   1.325 +	test(key->Count()==aKey.Count());
   1.326 +	test(key->Comparison()==aKey.Comparison());
   1.327 +	test(key->IsUnique()==aKey.IsUnique());
   1.328 +	for (TInt ii=aKey.Count();--ii>=0;)
   1.329 +		{
   1.330 +		const TDbKeyCol& left=(*key)[ii];
   1.331 +		const TDbKeyCol& right=aKey[ii];
   1.332 +		test (left.iName==right.iName);
   1.333 +		test (left.iOrder==right.iOrder);
   1.334 +		test (left.iLength==right.iLength || right.iLength==KDbUndefinedLength);
   1.335 +		}
   1.336 +	delete key;
   1.337 +	}
   1.338 +
   1.339 +/**
   1.340 +@SYMTestCaseID          SYSLIB-DBMS-CT-0594
   1.341 +@SYMTestCaseDesc        Tests the database definition and enquiry functions
   1.342 +@SYMTestPriority        Medium
   1.343 +@SYMTestActions         Tests for creation and opening of a database,creation of a table 
   1.344 +                        Tests for comparing column and table column sets
   1.345 +						Tests for altering a table and creation of an index.
   1.346 +@SYMTestExpectedResults Test must not fail
   1.347 +@SYMREQ                 REQ0000
   1.348 +*/
   1.349 +LOCAL_C void TestDDL()
   1.350 +	{
   1.351 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0594 Create Database "));
   1.352 +	CreateDatabase();
   1.353 +	CountTables(0);
   1.354 +	CloseDatabase();
   1.355 +	test.Next(_L("Open Database"));
   1.356 +	OpenDatabase();
   1.357 +	CountTables(0);
   1.358 +	test.Next(_L("CreateTable"));
   1.359 +	CDbColSet* cs=CreateColSetL(EAllTypes);
   1.360 +	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
   1.361 +	CountTables(1);
   1.362 +	test.Next(_L("Compare column sets"));
   1.363 +	Compare(KTableName,*cs);
   1.364 +	CloseDatabase();
   1.365 +	test.Next(_L("Re-open database"));
   1.366 +	OpenDatabase();
   1.367 +	CountTables(1);
   1.368 +	test.Next(_L("Compare table column sets"));
   1.369 +	Compare(KTableName,*cs);
   1.370 +	delete cs;
   1.371 +	test.Next(_L("Add another table"));
   1.372 +	cs=CreateColSetL(ESingleColumn);
   1.373 +	test(TheDatabase.CreateTable(KTableName2,*cs)==KErrNone);
   1.374 +	Compare(KTableName2,*cs);
   1.375 +	delete cs;
   1.376 +	CountTables(2);
   1.377 +//
   1.378 +	test.Next(_L("Alter table"));
   1.379 +	cs=CreateColSetL(EDoubleColumn);
   1.380 +	test(TheDatabase.AlterTable(KTableName2,*cs)==KErrNone);
   1.381 +	Compare(KTableName2,*cs);
   1.382 +	delete cs;
   1.383 +	CountTables(2);
   1.384 +//
   1.385 +	test.Next(_L("Test index creation"));
   1.386 +	CountIndexes(KTableName,0);
   1.387 +	CountIndexes(KTableName2,0);
   1.388 +	CDbKey* key=CreateKeyL(EKeyAsc);
   1.389 +	test (TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
   1.390 +	Compare(KIndexName,KTableName,*key);
   1.391 +	delete key;
   1.392 +	key=CreateKeyL(EKeyDesc);
   1.393 +	test (TheDatabase.CreateIndex(KIndexName2,KTableName,*key)==KErrNone);
   1.394 +	Compare(KIndexName2,KTableName,*key);
   1.395 +	delete key;
   1.396 +	key=CreateKeyL(EKeySingle);
   1.397 +	test (TheDatabase.CreateIndex(KIndexName,KTableName2,*key)==KErrNone);
   1.398 +	Compare(KIndexName,KTableName2,*key);
   1.399 +	delete key;
   1.400 +	key=CreateKeyL(EKeyMulti);
   1.401 +	test (TheDatabase.CreateIndex(KIndexName3,KTableName,*key)==KErrNone);
   1.402 +	Compare(KIndexName3,KTableName,*key);
   1.403 +	CountIndexes(KTableName,3);
   1.404 +	CountIndexes(KTableName2,1);
   1.405 +	CloseDatabase();
   1.406 +	OpenDatabase();
   1.407 +	CountIndexes(KTableName,3);
   1.408 +	CountIndexes(KTableName2,1);
   1.409 +	Compare(KIndexName3,KTableName,*key);
   1.410 +	delete key;
   1.411 +	test.Next(_L("Drop indexes"));
   1.412 +	test (TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
   1.413 +	CountIndexes(KTableName,2);
   1.414 +	test (TheDatabase.DropIndex(KIndexName2,KTableName)==KErrNone);
   1.415 +	CountIndexes(KTableName,1);
   1.416 +	test (TheDatabase.DropIndex(KIndexName,KTableName2)==KErrNone);
   1.417 +	CountIndexes(KTableName2,0);
   1.418 +	test.Next(_L("Drop table"));
   1.419 +	test(TheDatabase.DropTable(KTableName)==KErrNone);
   1.420 +	CountTables(1);
   1.421 +	test(TheDatabase.DropTable(KTableName2)==KErrNone);
   1.422 +	CountTables(0);
   1.423 +	CloseDatabase();
   1.424 +	OpenDatabase();
   1.425 +	CountTables(0);
   1.426 +	DestroyDatabase();
   1.427 +	test.End();
   1.428 +	}
   1.429 +
   1.430 +
   1.431 +LOCAL_C void AddRow()
   1.432 +	{
   1.433 +	test(TheView.Prepare(TheDatabase,_L("select * from testviewtable"))==KErrNone);
   1.434 +	test(TheView.EvaluateAll()==KErrNone);
   1.435 +	TheView.InsertL();
   1.436 +	TheView.SetColL(1,(TInt32)12345);
   1.437 +	TheView.PutL();
   1.438 +	TheView.InsertL();
   1.439 +	TheView.Cancel();
   1.440 +	TheView.FirstL();
   1.441 +	TheView.NextL();
   1.442 +	test(TheView.AtEnd());		// should be only 1 row as second insert was cancelled
   1.443 +	TheView.Close();
   1.444 +	}
   1.445 +
   1.446 +/**
   1.447 +@SYMTestCaseID          SYSLIB-DBMS-CT-1318
   1.448 +@SYMTestCaseDesc        Tests for RDbView class
   1.449 +@SYMTestPriority        Medium
   1.450 +@SYMTestActions         Tests for navigation of the cursor in the generated row sets.
   1.451 +@SYMTestExpectedResults Test must not fail
   1.452 +@SYMREQ                 REQ0000
   1.453 +*/
   1.454 +LOCAL_C void TestEmptyNavigation(const TDesC& aQuery)
   1.455 +	{
   1.456 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1318 Test navigation states "));
   1.457 +	test(TheView.Prepare(TheDatabase,aQuery,TheView.EReadOnly)==KErrNone);
   1.458 +	test(TheView.EvaluateAll()==KErrNone);
   1.459 +	TheView.FirstL();
   1.460 +	test(!TheView.AtBeginning());
   1.461 +	test(!TheView.AtRow());
   1.462 +	test(TheView.AtEnd());
   1.463 +	TheView.PreviousL();
   1.464 +	test(TheView.AtBeginning());
   1.465 +	test(!TheView.AtRow());
   1.466 +	test(!TheView.AtEnd());
   1.467 +	TheView.NextL();
   1.468 +	test(!TheView.AtBeginning());
   1.469 +	test(!TheView.AtRow());
   1.470 +	test(TheView.AtEnd());
   1.471 +	TheView.LastL();
   1.472 +	test(TheView.AtBeginning());
   1.473 +	test(!TheView.AtRow());
   1.474 +	test(!TheView.AtEnd());
   1.475 +	TheView.NextL();
   1.476 +	test(TheView.AtEnd());
   1.477 +	TheView.Close();
   1.478 +	}
   1.479 +
   1.480 +/**
   1.481 +@SYMTestCaseID          SYSLIB-DBMS-CT-1319
   1.482 +@SYMTestCaseDesc        Tests for RDbView class
   1.483 +@SYMTestPriority        Medium
   1.484 +@SYMTestActions         Tests for navigation of the cursor in the generated row sets.
   1.485 +@SYMTestExpectedResults Test must not fail
   1.486 +@SYMREQ                 REQ0000
   1.487 +*/
   1.488 +LOCAL_C void TestNavigation(const TDesC& aQuery)
   1.489 +	{
   1.490 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1319 Test navigation states "));
   1.491 +	test(TheView.Prepare(TheDatabase,aQuery,TheView.EReadOnly)==KErrNone);
   1.492 +	test(TheView.EvaluateAll()==KErrNone);
   1.493 +	TheView.FirstL();
   1.494 +	test(!TheView.AtBeginning());
   1.495 +	test(TheView.AtRow());
   1.496 +	test(!TheView.AtEnd());
   1.497 +	TheView.GetL();
   1.498 +	test(TheView.ColInt32(1)==12345);
   1.499 +	TheView.PreviousL();
   1.500 +	test(TheView.AtBeginning());
   1.501 +	test(!TheView.AtRow());
   1.502 +	test(!TheView.AtEnd());
   1.503 +	TheView.NextL();
   1.504 +	test(!TheView.AtBeginning());
   1.505 +	test(TheView.AtRow());
   1.506 +	test(!TheView.AtEnd());
   1.507 +	TheView.NextL();
   1.508 +	test(!TheView.AtBeginning());
   1.509 +	test(!TheView.AtRow());
   1.510 +	test(TheView.AtEnd());
   1.511 +	TheView.PreviousL();
   1.512 +	test(!TheView.AtBeginning());
   1.513 +	test(TheView.AtRow());
   1.514 +	test(!TheView.AtEnd());
   1.515 +	TheView.LastL();
   1.516 +	test(!TheView.AtBeginning());
   1.517 +	test(TheView.AtRow());
   1.518 +	test(!TheView.AtEnd());
   1.519 +	TheView.NextL();
   1.520 +	test(TheView.AtEnd());
   1.521 +	TheView.Close();
   1.522 +	}
   1.523 +
   1.524 +/**
   1.525 +@SYMTestCaseID          SYSLIB-DBMS-CT-1320
   1.526 +@SYMTestCaseDesc        RDbView updation test
   1.527 +@SYMTestPriority        Medium
   1.528 +@SYMTestActions         Tests for updation of row sets 
   1.529 +@SYMTestExpectedResults Test must not fail
   1.530 +@SYMREQ                 REQ0000
   1.531 +*/
   1.532 +static void TestUpdate()
   1.533 +	{
   1.534 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1320 Update and delete the row "));
   1.535 +	test(TheView.Prepare(TheDatabase,_L("select * from TestViewTable"))==KErrNone);
   1.536 +	test(TheView.EvaluateAll()==KErrNone);
   1.537 +	TheView.FirstL();
   1.538 +	TheView.UpdateL();
   1.539 +	TheView.SetColL(1,(TInt32)54321);
   1.540 +	TheView.PutL();
   1.541 +	TheView.FirstL();
   1.542 +	TheView.GetL();
   1.543 +	test(TheView.ColInt32(1)==54321);
   1.544 +	TheView.UpdateL();
   1.545 +	TheView.SetColL(1,(TInt32)12345);
   1.546 +	TheView.Cancel();
   1.547 +	TheView.FirstL();
   1.548 +	TheView.GetL();
   1.549 +	test(TheView.ColInt32(1)==54321);
   1.550 +	TheView.DeleteL();
   1.551 +	TheView.PreviousL();
   1.552 +	test(TheView.AtBeginning());
   1.553 +	TheView.NextL();
   1.554 +	test(TheView.AtEnd());
   1.555 +	TheView.Close();
   1.556 +	}
   1.557 +
   1.558 +#include <s32mem.h>
   1.559 +
   1.560 +void writeBLOB(TDbColNo aCol,const TDesC8& aDes)
   1.561 +	{
   1.562 +	CBufSeg* buf=CBufSeg::NewL(128);
   1.563 +	CleanupStack::PushL(buf);
   1.564 +	buf->InsertL(0,aDes);
   1.565 +	RBufReadStream read(*buf);
   1.566 +	RDbColWriteStream blob;
   1.567 +	blob.OpenLC(TheView,aCol);
   1.568 +//	blob.WriteL(aDes);
   1.569 +	blob.WriteL(read,aDes.Length());
   1.570 +	blob.CommitL();
   1.571 +	CleanupStack::PopAndDestroy();
   1.572 +	CleanupStack::PopAndDestroy();	// buf
   1.573 +	test (TheView.ColLength(aCol)==aDes.Length());
   1.574 +	test (TheView.ColSize(aCol)==aDes.Size());
   1.575 +	}
   1.576 +
   1.577 +void checkBLOB(TDbColNo aCol,const TDesC8& aDes)
   1.578 +	{
   1.579 +	RDbColReadStream blob;
   1.580 +	blob.OpenLC(TheView,aCol);
   1.581 +	blob.ReadL(TheBuf8,TheView.ColLength(aCol));
   1.582 +	CleanupStack::PopAndDestroy();
   1.583 +	test(TheBuf8==aDes);
   1.584 +	}
   1.585 +
   1.586 +/**
   1.587 +@SYMTestCaseID          SYSLIB-DBMS-CT-1321
   1.588 +@SYMTestCaseDesc        BLOB tests
   1.589 +@SYMTestPriority        Medium
   1.590 +@SYMTestActions         Test long column tracking through insert/put/update/cancel
   1.591 +@SYMTestExpectedResults Test must not fail
   1.592 +@SYMREQ                 REQ0000
   1.593 +*/
   1.594 +void TestBLOB()
   1.595 +	{
   1.596 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1321 Long column tracking "));
   1.597 +	test(TheView.Prepare(TheDatabase,_L("select * from TestViewTable"))==KErrNone);
   1.598 +	test(TheView.EvaluateAll()==KErrNone);
   1.599 +	TheView.InsertL();
   1.600 +	writeBLOB(2,KTestShortText8);
   1.601 +	writeBLOB(3,KTestShortText8);
   1.602 +	TheView.PutL();
   1.603 +	TheView.InsertL();
   1.604 +	writeBLOB(4,KTestShortText8);
   1.605 +	writeBLOB(5,KTestShortText8);
   1.606 +	TheView.Cancel();
   1.607 +// change in behaviour--writing BLOBs forces a true rollback here. So reset
   1.608 +	TheView.Reset();
   1.609 +	test(TheView.EvaluateAll()==KErrNone);
   1.610 +// check the one row we should have
   1.611 +	TheView.FirstL();
   1.612 +	TheView.GetL();
   1.613 +	checkBLOB(2,KTestShortText8);
   1.614 +	checkBLOB(3,KTestShortText8);
   1.615 +	test(TheView.IsColNull(4));
   1.616 +	test(TheView.IsColNull(5));
   1.617 +	test(TheView.IsColNull(6));
   1.618 +	TheView.NextL();
   1.619 +	test(TheView.AtEnd());
   1.620 +// update/cancel the row
   1.621 +	TheView.FirstL();
   1.622 +	TheView.UpdateL();
   1.623 +	TheView.SetColNullL(3);
   1.624 +	writeBLOB(4,KTestLongText8);
   1.625 +	writeBLOB(5,KTestLongText8);
   1.626 +// check pre-cancel
   1.627 +	checkBLOB(2,KTestShortText8);
   1.628 +	test(TheView.IsColNull(3));
   1.629 +	checkBLOB(4,KTestLongText8);
   1.630 +	checkBLOB(5,KTestLongText8);
   1.631 +	test(TheView.IsColNull(6));
   1.632 +// cancel and check
   1.633 +	TheView.Cancel();
   1.634 +// change in behaviour--writing BLOBs forces a true rollback here. So reset
   1.635 +	TheView.Reset();
   1.636 +	test(TheView.EvaluateAll()==KErrNone);
   1.637 +	TheView.FirstL();
   1.638 +	TheView.GetL();
   1.639 +	checkBLOB(2,KTestShortText8);
   1.640 +	checkBLOB(3,KTestShortText8);
   1.641 +	test(TheView.IsColNull(4));
   1.642 +	test(TheView.IsColNull(5));
   1.643 +	test(TheView.IsColNull(6));
   1.644 +	TheView.NextL();
   1.645 +	test(TheView.AtEnd());
   1.646 +// update/put the row
   1.647 +	TheView.FirstL();
   1.648 +	TheView.UpdateL();
   1.649 +	TheView.SetColNullL(3);
   1.650 +	writeBLOB(4,KTestLongText8);
   1.651 +	writeBLOB(5,KTestLongText8);
   1.652 +// check pre-put
   1.653 +	checkBLOB(2,KTestShortText8);
   1.654 +	test(TheView.IsColNull(3));
   1.655 +	checkBLOB(4,KTestLongText8);
   1.656 +	checkBLOB(5,KTestLongText8);
   1.657 +	test(TheView.IsColNull(6));
   1.658 +// put and check
   1.659 +	TheView.PutL();
   1.660 +	TheView.FirstL();
   1.661 +	TheView.GetL();
   1.662 +	checkBLOB(2,KTestShortText8);
   1.663 +	test(TheView.IsColNull(3));
   1.664 +	checkBLOB(4,KTestLongText8);
   1.665 +	checkBLOB(5,KTestLongText8);
   1.666 +	test(TheView.IsColNull(6));
   1.667 +	TheView.NextL();
   1.668 +	test(TheView.AtEnd());
   1.669 +// update/put the row again
   1.670 +	TheView.FirstL();
   1.671 +	TheView.UpdateL();
   1.672 +	TheView.SetColNullL(2);
   1.673 +	writeBLOB(3,KTestShortText8);
   1.674 +	writeBLOB(4,KTestShortText8);
   1.675 +	writeBLOB(5,KTestShortText8);
   1.676 +// check
   1.677 +	test(TheView.IsColNull(2));
   1.678 +	checkBLOB(3,KTestShortText8);
   1.679 +	checkBLOB(4,KTestShortText8);
   1.680 +	checkBLOB(5,KTestShortText8);
   1.681 +	test(TheView.IsColNull(6));
   1.682 +// modify again
   1.683 +	writeBLOB(2,KTestLongText8);
   1.684 +	TheView.SetColNullL(3);
   1.685 +	TheView.SetColNullL(4);
   1.686 +	writeBLOB(5,KTestLongText8);
   1.687 +// check pre-put
   1.688 +	checkBLOB(2,KTestLongText8);
   1.689 +	test(TheView.IsColNull(3));
   1.690 +	test(TheView.IsColNull(4));
   1.691 +	checkBLOB(5,KTestLongText8);
   1.692 +	test(TheView.IsColNull(6));
   1.693 +// put and check
   1.694 +	TheView.PutL();
   1.695 +	TheView.FirstL();
   1.696 +	TheView.GetL();
   1.697 +	checkBLOB(2,KTestLongText8);
   1.698 +	test(TheView.IsColNull(3));
   1.699 +	test(TheView.IsColNull(4));
   1.700 +	checkBLOB(5,KTestLongText8);
   1.701 +	test(TheView.IsColNull(6));
   1.702 +	TheView.NextL();
   1.703 +	test(TheView.AtEnd());
   1.704 +// insert copy
   1.705 +	TheView.LastL();
   1.706 +	TheView.InsertCopyL();
   1.707 +	TheView.SetColNullL(2);
   1.708 +	writeBLOB(3,KTestLongText8);
   1.709 +// check pre-put
   1.710 +	test(TheView.IsColNull(2));
   1.711 +	checkBLOB(3,KTestLongText8);
   1.712 +	test(TheView.IsColNull(4));
   1.713 +	checkBLOB(5,KTestLongText8);
   1.714 +	test(TheView.IsColNull(6));
   1.715 +// put and check
   1.716 +	TheView.PutL();
   1.717 +	TheView.LastL();
   1.718 +	TheView.GetL();
   1.719 +	test(TheView.IsColNull(2));
   1.720 +	checkBLOB(3,KTestLongText8);
   1.721 +	test(TheView.IsColNull(4));
   1.722 +	checkBLOB(5,KTestLongText8);
   1.723 +	test(TheView.IsColNull(6));
   1.724 +// delete previous one and check
   1.725 +	TheView.PreviousL();
   1.726 +	TheView.DeleteL();
   1.727 +	TheView.NextL();
   1.728 +	TheView.GetL();
   1.729 +	test(TheView.IsColNull(2));
   1.730 +	checkBLOB(3,KTestLongText8);
   1.731 +	test(TheView.IsColNull(4));
   1.732 +	checkBLOB(5,KTestLongText8);
   1.733 +	test(TheView.IsColNull(6));
   1.734 +	TheView.NextL();
   1.735 +	test(TheView.AtEnd());
   1.736 +// delete
   1.737 +	TheView.FirstL();
   1.738 +	TheView.DeleteL();
   1.739 +// finish
   1.740 +	TheView.Close();
   1.741 +	}
   1.742 +
   1.743 +/**
   1.744 +@SYMTestCaseID          SYSLIB-DBMS-CT-0596
   1.745 +@SYMTestCaseDesc        Tests for navigation states
   1.746 +@SYMTestPriority        Medium
   1.747 +@SYMTestActions         Tests for view state cycle, navigation, Insert/Update/Delete 
   1.748 +@SYMTestExpectedResults Test must not fail
   1.749 +@SYMREQ                 REQ0000
   1.750 +*/
   1.751 +void TestView()
   1.752 +	{
   1.753 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0596 Create the Test table "));
   1.754 +	CreateDatabase();
   1.755 +	CDbColSet* cs=CreateColSetL(EViewTestTable);
   1.756 +	test(TheDatabase.CreateTable(KTestViewTable,*cs)==KErrNone);
   1.757 +	delete cs;
   1.758 +	test.Next(_L("Test navigation states"));
   1.759 +	TestEmptyNavigation(_L("select * from TestViewTable"));
   1.760 +	test.Next(_L("Insert and Put/Cancel"));
   1.761 +	AddRow();
   1.762 +	test.Next(_L("Test navigation states"));
   1.763 +	TestNavigation(_L("select * from TestViewTable"));
   1.764 +	TestNavigation(_L("select * from TestViewTable where Int is not null"));
   1.765 +	TestEmptyNavigation(_L("select * from TestViewTable where Int is null"));
   1.766 +	test.Next(_L("Update and delete the row"));
   1.767 +	TestUpdate();
   1.768 +	test.Next(_L("Long column tracking"));
   1.769 +	TestBLOB();
   1.770 +	test.Next(_L("Close"));
   1.771 +	CloseDatabase();
   1.772 +	test.End();
   1.773 +	}
   1.774 +
   1.775 +//
   1.776 +// Check the integral set/get functions for different width types
   1.777 +//
   1.778 +LOCAL_C void CheckIntAccessors()
   1.779 +	{
   1.780 +	TheView.InsertL();
   1.781 +// bit column
   1.782 +	TDbColNo ord=TheMap[EBit];
   1.783 +	TheView.SetColL(ord,TUint32(1));
   1.784 +	test (TheView.ColUint(ord)==1);
   1.785 +	TheView.SetColL(ord,TInt32(0));
   1.786 +	test (TheView.ColUint(ord)==0);
   1.787 +	TheView.SetColL(ord,TInt64(1));
   1.788 +	test (TheView.ColUint(ord)==1);
   1.789 +	test (TheView.ColUint8(ord)==1);
   1.790 +	test (TheView.ColUint16(ord)==1);
   1.791 +	test (TheView.ColUint32(ord)==1);
   1.792 +	test (TheView.ColInt8(ord)==1);
   1.793 +	test (TheView.ColInt16(ord)==1);
   1.794 +	test (TheView.ColInt32(ord)==1);
   1.795 +	test (TheView.ColInt64(ord)==1);
   1.796 +// uint8 column
   1.797 +	ord=TheMap[EUint8];
   1.798 +	TheView.SetColL(ord,TUint32(255));
   1.799 +	test (TheView.ColUint(ord)==255);
   1.800 +	TheView.SetColL(ord,TInt32(0));
   1.801 +	test (TheView.ColUint(ord)==0);
   1.802 +	TheView.SetColL(ord,TInt64(1));
   1.803 +	test (TheView.ColUint(ord)==1);
   1.804 +	test (TheView.ColUint8(ord)==1);
   1.805 +	test (TheView.ColUint16(ord)==1);
   1.806 +	test (TheView.ColUint32(ord)==1);
   1.807 +	test (TheView.ColInt16(ord)==1);
   1.808 +	test (TheView.ColInt32(ord)==1);
   1.809 +	test (TheView.ColInt64(ord)==1);
   1.810 +// uint16 column
   1.811 +	ord=TheMap[EUint16];
   1.812 +	TheView.SetColL(ord,TUint32(65535));
   1.813 +	test (TheView.ColUint(ord)==65535);
   1.814 +	TheView.SetColL(ord,TInt32(0));
   1.815 +	test (TheView.ColUint(ord)==0);
   1.816 +	TheView.SetColL(ord,TInt64(1));
   1.817 +	test (TheView.ColUint(ord)==1);
   1.818 +	test (TheView.ColUint16(ord)==1);
   1.819 +	test (TheView.ColUint32(ord)==1);
   1.820 +	test (TheView.ColInt32(ord)==1);
   1.821 +	test (TheView.ColInt64(ord)==1);
   1.822 +// uint32 column
   1.823 +	ord=TheMap[EUint32];
   1.824 +	TheView.SetColL(ord,TUint32(0));
   1.825 +	test (TheView.ColUint(ord)==0);
   1.826 +	TheView.SetColL(ord,TInt32(KMaxTInt));
   1.827 +	test (TInt(TheView.ColUint(ord))==KMaxTInt);
   1.828 +	TheView.SetColL(ord,TInt64(KMaxTUint));
   1.829 +	test (TheView.ColUint(ord)==KMaxTUint);
   1.830 +	test (TheView.ColUint32(ord)==KMaxTUint);
   1.831 +	test (TheView.ColInt64(ord)==KMaxTUint);
   1.832 +// int8 column
   1.833 +	ord=TheMap[EInt8];
   1.834 +	TheView.SetColL(ord,TUint32(127));
   1.835 +	test (TheView.ColInt(ord)==127);
   1.836 +	TheView.SetColL(ord,TInt32(0));
   1.837 +	test (TheView.ColInt(ord)==0);
   1.838 +	TheView.SetColL(ord,TInt64(-128));
   1.839 +	test (TheView.ColInt(ord)==-128);
   1.840 +	test (TheView.ColInt8(ord)==-128);
   1.841 +	test (TheView.ColInt16(ord)==-128);
   1.842 +	test (TheView.ColInt32(ord)==-128);
   1.843 +	test (TheView.ColInt64(ord)==-128);
   1.844 +// int16 column
   1.845 +	ord=TheMap[EInt16];
   1.846 +	TheView.SetColL(ord,TUint32(32767));
   1.847 +	test (TheView.ColInt(ord)==32767);
   1.848 +	TheView.SetColL(ord,TInt32(0));
   1.849 +	test (TheView.ColInt(ord)==0);
   1.850 +	TheView.SetColL(ord,TInt64(-32768));
   1.851 +	test (TheView.ColInt(ord)==-32768);
   1.852 +	test (TheView.ColInt16(ord)==-32768);
   1.853 +	test (TheView.ColInt32(ord)==-32768);
   1.854 +	test (TheView.ColInt64(ord)==-32768);
   1.855 +// int32 column
   1.856 +	ord=TheMap[EInt32];
   1.857 +	TheView.SetColL(ord,TUint32(KMaxTInt));
   1.858 +	test (TheView.ColInt(ord)==KMaxTInt);
   1.859 +	TheView.SetColL(ord,TInt32(0));
   1.860 +	test (TheView.ColInt(ord)==0);
   1.861 +	TheView.SetColL(ord,TInt64(KMinTInt));
   1.862 +	test (TheView.ColInt(ord)==KMinTInt);
   1.863 +	test (TheView.ColInt32(ord)==KMinTInt);
   1.864 +	test (TheView.ColInt64(ord)==KMinTInt);
   1.865 +//
   1.866 +	TheView.Cancel();
   1.867 +	}
   1.868 +
   1.869 +//
   1.870 +// Write the values to nullable column types
   1.871 +//
   1.872 +LOCAL_C void WriteMinValues(TInt anOffset)
   1.873 +	{
   1.874 +	TheView.SetColL(TheMap[anOffset+EBit],TUint(0));
   1.875 +	TheView.SetColL(TheMap[anOffset+EInt8],KMinTInt8);
   1.876 +	TheView.SetColL(TheMap[anOffset+EUint8],TUint(0));
   1.877 +	TheView.SetColL(TheMap[anOffset+EInt16],KMinTInt16);
   1.878 +	TheView.SetColL(TheMap[anOffset+EUint16],TUint(0));
   1.879 +	TheView.SetColL(TheMap[anOffset+EInt32],KMinTInt32);
   1.880 +	TheView.SetColL(TheMap[anOffset+EUint32],TUint(0));
   1.881 +	TheView.SetColL(TheMap[anOffset+EInt64],KMinTInt64);
   1.882 +	TheView.SetColL(TheMap[anOffset+EReal32],KMinTReal32);
   1.883 +	TheView.SetColL(TheMap[anOffset+EReal64],KMinTReal64);
   1.884 +	TheView.SetColL(TheMap[anOffset+ETime],KMinTTime);
   1.885 +	TheView.SetColL(TheMap[anOffset+EText8],KTestShortText8);
   1.886 +	TheView.SetColL(TheMap[anOffset+EText16],KTestShortText16);
   1.887 +	{
   1.888 +	TUint8 val=0;
   1.889 +	TheView.SetColL(TheMap[anOffset+ETBinary],TPtrC8(&val,sizeof(val)));
   1.890 +	}
   1.891 +	TheView.SetColL(TheMap[anOffset+ELongText8],KTestShortText8);
   1.892 +	TheView.SetColL(TheMap[anOffset+ELongText16],KTestShortText16);
   1.893 +	RDbColWriteStream out;
   1.894 +	out.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
   1.895 +	out.WriteUint8L(0);
   1.896 +	out.CommitL();
   1.897 +	CleanupStack::PopAndDestroy();
   1.898 +	}
   1.899 +
   1.900 +//
   1.901 +// Write a row with the minimum (or small) column values
   1.902 +// return the value in the counter column
   1.903 +//
   1.904 +LOCAL_C TInt WriteMinimum()
   1.905 +	{
   1.906 +	TheView.InsertL();
   1.907 +	WriteMinValues(0);
   1.908 +	WriteMinValues(EBitNull-EBit);
   1.909 +	test(!TheView.IsColNull(TheMap[ECounter]));
   1.910 +	TInt cc=TheView.ColInt(TheMap[ECounter]);
   1.911 +	TheView.PutL();
   1.912 +	return cc;
   1.913 +	}
   1.914 +
   1.915 +LOCAL_C void CheckMinValues(TInt anOffset)
   1.916 +	{
   1.917 +	test(TheView.ColUint8(TheMap[anOffset+EBit])==0);
   1.918 +	test(TheView.ColUint16(TheMap[anOffset+EBit])==0);
   1.919 +	test(TheView.ColUint32(TheMap[anOffset+EBit])==0);
   1.920 +	test(TheView.ColUint(TheMap[anOffset+EBit])==0);
   1.921 +	test(TheView.ColInt8(TheMap[anOffset+EInt8])==KMinTInt8);
   1.922 +	test(TheView.ColInt16(TheMap[anOffset+EInt8])==KMinTInt8);
   1.923 +	test(TheView.ColInt32(TheMap[anOffset+EInt8])==KMinTInt8);
   1.924 +	test(TheView.ColInt(TheMap[anOffset+EInt8])==KMinTInt8);
   1.925 +	test(TheView.ColUint8(TheMap[anOffset+EUint8])==0);
   1.926 +	test(TheView.ColUint16(TheMap[anOffset+EUint8])==0);
   1.927 +	test(TheView.ColUint32(TheMap[anOffset+EUint8])==0);
   1.928 +	test(TheView.ColUint(TheMap[anOffset+EUint8])==0);
   1.929 +	test(TheView.ColInt16(TheMap[anOffset+EInt16])==KMinTInt16);
   1.930 +	test(TheView.ColInt32(TheMap[anOffset+EInt16])==KMinTInt16);
   1.931 +	test(TheView.ColInt(TheMap[anOffset+EInt16])==KMinTInt16);
   1.932 +	test(TheView.ColUint16(TheMap[anOffset+EUint16])==0);
   1.933 +	test(TheView.ColUint32(TheMap[anOffset+EUint16])==0);
   1.934 +	test(TheView.ColUint(TheMap[anOffset+EUint16])==0);
   1.935 +	test(TheView.ColInt32(TheMap[anOffset+EInt32])==KMinTInt32);
   1.936 +	test(TheView.ColInt(TheMap[anOffset+EInt32])==KMinTInt32);
   1.937 +	test(TheView.ColUint32(TheMap[anOffset+EUint32])==0);
   1.938 +	test(TheView.ColUint(TheMap[anOffset+EUint32])==0);
   1.939 +	test(TheView.ColInt64(TheMap[anOffset+EInt64])==KMinTInt64);
   1.940 +	test(TheView.ColReal32(TheMap[anOffset+EReal32])==KMinTReal32);
   1.941 +	test(TheView.ColReal64(TheMap[anOffset+EReal64])==KMinTReal64);
   1.942 +	test(TheView.ColReal(TheMap[anOffset+EReal64])==KMinTReal64);
   1.943 +	test(TheView.ColTime(TheMap[anOffset+ETime])==KMinTTime);
   1.944 +	test(TheView.ColDes8(TheMap[anOffset+EText8])==KTestShortText8);
   1.945 +	test(TheView.ColSize(TheMap[anOffset+EText8])==KTestShortText8.Size());
   1.946 +	test(TheView.ColLength(TheMap[anOffset+EText8])==KTestShortText8.Length());
   1.947 +	test(TheView.ColDes16(TheMap[anOffset+EText16])==KTestShortText16);
   1.948 +	test(TheView.ColSize(TheMap[anOffset+EText16])==KTestShortText16.Size());
   1.949 +	test(TheView.ColLength(TheMap[anOffset+EText16])==KTestShortText16.Length());
   1.950 +	{
   1.951 +	TUint8 val=0;
   1.952 +	test(TheView.ColDes8(TheMap[anOffset+ETBinary])==TPtrC8(&val,sizeof(val)));
   1.953 +	}
   1.954 +	test(TheView.ColSize(TheMap[anOffset+ETBinary])==1);
   1.955 +	test(TheView.ColLength(TheMap[anOffset+ETBinary])==1);
   1.956 +//
   1.957 +	test(TheView.ColSize(TheMap[anOffset+ELongText8])==KTestShortText8.Size());
   1.958 +	test(TheView.ColLength(TheMap[anOffset+ELongText8])==KTestShortText8.Length());
   1.959 +	RDbColReadStream in;
   1.960 +	in.OpenLC(TheView,TheMap[anOffset+ELongText8]);
   1.961 +	in.ReadL(TheBuf8,TheView.ColLength(TheMap[anOffset+ELongText8]));
   1.962 +	CleanupStack::PopAndDestroy();
   1.963 +	test(TheBuf8==KTestShortText8);
   1.964 +//
   1.965 +	test(TheView.ColSize(TheMap[anOffset+ELongText16])==KTestShortText16.Size());
   1.966 +	test(TheView.ColLength(TheMap[anOffset+ELongText16])==KTestShortText16.Length());
   1.967 +	in.OpenLC(TheView,TheMap[anOffset+ELongText16]);
   1.968 +	in.ReadL(TheBuf16,TheView.ColLength(TheMap[anOffset+ELongText16]));
   1.969 +	CleanupStack::PopAndDestroy();
   1.970 +	test(TheBuf16==KTestShortText16);
   1.971 +//
   1.972 +	test(TheView.ColSize(TheMap[anOffset+ELongBinary])==1);
   1.973 +	test(TheView.ColLength(TheMap[anOffset+ELongBinary])==1);
   1.974 +	in.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
   1.975 +	test(in.ReadUint8L()==0);
   1.976 +	CleanupStack::PopAndDestroy();
   1.977 +	}
   1.978 +
   1.979 +//
   1.980 +// Check the row is the same as was written
   1.981 +//
   1.982 +LOCAL_C void CheckMinimum(TInt aCounter)
   1.983 +	{
   1.984 +	TheView.GetL();
   1.985 +	test(TheView.ColInt32(TheMap[ECounter])==aCounter);
   1.986 +	CheckMinValues(0);
   1.987 +	CheckMinValues(EBitNull-EBit);
   1.988 +	}
   1.989 +
   1.990 +LOCAL_C void WriteMaxValues(TInt anOffset)
   1.991 +	{
   1.992 +	TheView.SetColL(TheMap[anOffset+EBit],TUint(1));
   1.993 +	TheView.SetColL(TheMap[anOffset+EInt8],KMaxTInt8);
   1.994 +	TheView.SetColL(TheMap[anOffset+EUint8],TUint(KMaxTUint8));
   1.995 +	TheView.SetColL(TheMap[anOffset+EInt16],KMaxTInt16);
   1.996 +	TheView.SetColL(TheMap[anOffset+EUint16],TUint(KMaxTUint16));
   1.997 +	TheView.SetColL(TheMap[anOffset+EInt32],KMaxTInt32);
   1.998 +	TheView.SetColL(TheMap[anOffset+EUint32],KMaxTUint32);
   1.999 +	TheView.SetColL(TheMap[anOffset+EInt64],KMaxTInt64);
  1.1000 +	TheView.SetColL(TheMap[anOffset+EReal32],KMaxTReal32);
  1.1001 +	TheView.SetColL(TheMap[anOffset+EReal64],KMaxTReal64);
  1.1002 +	TheView.SetColL(TheMap[anOffset+ETime],KMaxTTime);
  1.1003 +	TheView.SetColL(TheMap[anOffset+EText8],KTestText8);
  1.1004 +	TheView.SetColL(TheMap[anOffset+EText16],KTestText16);
  1.1005 +	TheView.SetColL(TheMap[anOffset+ETBinary],TPtrC8((TUint8*)&TheMap[0],sizeof(TheMap)));
  1.1006 +	TheView.SetColL(TheMap[anOffset+ELongText8],KTestLongText8);
  1.1007 +	TheView.SetColL(TheMap[anOffset+ELongText16],KTestLongText16);
  1.1008 +	RDbColWriteStream out;
  1.1009 +	out.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
  1.1010 +	for (TInt ii=0;ii<KBlobItems;++ii)
  1.1011 +		out.WriteInt32L(ii);
  1.1012 +	out.CommitL();
  1.1013 +	CleanupStack::PopAndDestroy();
  1.1014 +	}
  1.1015 +
  1.1016 +//
  1.1017 +// Write a row with the maximum (or longer) column values
  1.1018 +// return the value in the counter column
  1.1019 +//
  1.1020 +LOCAL_C TInt WriteMaximum()
  1.1021 +	{
  1.1022 +	TheView.InsertL();
  1.1023 +	WriteMaxValues(0);
  1.1024 +	WriteMaxValues(EBitNull-EBit);
  1.1025 +	test(!TheView.IsColNull(TheMap[ECounter]));
  1.1026 +	TInt cc=TheView.ColInt(TheMap[ECounter]);
  1.1027 +	TheView.PutL();
  1.1028 +	return cc;
  1.1029 +	}
  1.1030 +
  1.1031 +LOCAL_C void CheckMaxValues(TInt anOffset)
  1.1032 +	{
  1.1033 +	test(TheView.ColUint8(TheMap[anOffset+EBit])==1);
  1.1034 +	test(TheView.ColUint16(TheMap[anOffset+EBit])==1);
  1.1035 +	test(TheView.ColUint32(TheMap[anOffset+EBit])==1);
  1.1036 +	test(TheView.ColUint(TheMap[anOffset+EBit])==1);
  1.1037 +	test(TheView.ColInt8(TheMap[anOffset+EInt8])==KMaxTInt8);
  1.1038 +	test(TheView.ColInt16(TheMap[anOffset+EInt8])==KMaxTInt8);
  1.1039 +	test(TheView.ColInt32(TheMap[anOffset+EInt8])==KMaxTInt8);
  1.1040 +	test(TheView.ColInt(TheMap[anOffset+EInt8])==KMaxTInt8);
  1.1041 +	test(TheView.ColUint8(TheMap[anOffset+EUint8])==KMaxTUint8);
  1.1042 +	test(TheView.ColUint16(TheMap[anOffset+EUint8])==KMaxTUint8);
  1.1043 +	test(TheView.ColUint32(TheMap[anOffset+EUint8])==KMaxTUint8);
  1.1044 +	test(TheView.ColUint(TheMap[anOffset+EUint8])==KMaxTUint8);
  1.1045 +	test(TheView.ColInt16(TheMap[anOffset+EInt16])==KMaxTInt16);
  1.1046 +	test(TheView.ColInt32(TheMap[anOffset+EInt16])==KMaxTInt16);
  1.1047 +	test(TheView.ColInt(TheMap[anOffset+EInt16])==KMaxTInt16);
  1.1048 +	test(TheView.ColUint16(TheMap[anOffset+EUint16])==KMaxTUint16);
  1.1049 +	test(TheView.ColUint32(TheMap[anOffset+EUint16])==KMaxTUint16);
  1.1050 +	test(TheView.ColUint(TheMap[anOffset+EUint16])==KMaxTUint16);
  1.1051 +	test(TheView.ColInt32(TheMap[anOffset+EInt32])==KMaxTInt32);
  1.1052 +	test(TheView.ColInt(TheMap[anOffset+EInt32])==KMaxTInt32);
  1.1053 +	test(TheView.ColUint32(TheMap[anOffset+EUint32])==KMaxTUint32);
  1.1054 +	test(TheView.ColUint(TheMap[anOffset+EUint32])==KMaxTUint32);
  1.1055 +	test(TheView.ColInt64(TheMap[anOffset+EInt64])==KMaxTInt64);
  1.1056 +	test(TheView.ColReal32(TheMap[anOffset+EReal32])==KMaxTReal32);
  1.1057 +	test(TheView.ColReal64(TheMap[anOffset+EReal64])==KMaxTReal64);
  1.1058 +	test(TheView.ColReal(TheMap[anOffset+EReal64])==KMaxTReal64);
  1.1059 +	test(TheView.ColTime(TheMap[anOffset+ETime])==KMaxTTime);
  1.1060 +	test(TheView.ColDes8(TheMap[anOffset+EText8])==KTestText8);
  1.1061 +	test(TheView.ColSize(TheMap[anOffset+EText8])==KTestText8.Size());
  1.1062 +	test(TheView.ColLength(TheMap[anOffset+EText8])==KTestText8.Length());
  1.1063 +	test(TheView.ColDes16(TheMap[anOffset+EText16])==KTestText16);
  1.1064 +	test(TheView.ColSize(TheMap[anOffset+EText16])==KTestText16.Size());
  1.1065 +	test(TheView.ColLength(TheMap[anOffset+EText16])==KTestText16.Length());
  1.1066 +	test(TheView.ColDes8(TheMap[anOffset+ETBinary])==TPtrC8((TUint8*)&TheMap[0],sizeof(TheMap)));
  1.1067 +	test(TheView.ColSize(TheMap[anOffset+ETBinary])==sizeof(TheMap));
  1.1068 +	test(TheView.ColLength(TheMap[anOffset+ETBinary])==sizeof(TheMap));
  1.1069 +//
  1.1070 +	test(TheView.ColSize(TheMap[anOffset+ELongText8])==KTestLongText8.Size());
  1.1071 +	test(TheView.ColLength(TheMap[anOffset+ELongText8])==KTestLongText8.Length());
  1.1072 +	RDbColReadStream in;
  1.1073 +	in.OpenLC(TheView,TheMap[anOffset+ELongText8]);
  1.1074 +	in.ReadL(TheBuf8,TheView.ColLength(TheMap[anOffset+ELongText8]));
  1.1075 +	CleanupStack::PopAndDestroy();
  1.1076 +	test(TheBuf8==KTestLongText8);
  1.1077 +//
  1.1078 +	test(TheView.ColSize(TheMap[anOffset+ELongText16])==KTestLongText16.Size());
  1.1079 +	test(TheView.ColLength(TheMap[anOffset+ELongText16])==KTestLongText16.Length());
  1.1080 +	in.OpenLC(TheView,TheMap[anOffset+ELongText16]);
  1.1081 +	in.ReadL(TheBuf16,TheView.ColLength(TheMap[anOffset+ELongText16]));
  1.1082 +	CleanupStack::PopAndDestroy();
  1.1083 +	test(TheBuf16==KTestLongText16);
  1.1084 +//
  1.1085 +	test(TheView.ColSize(TheMap[anOffset+ELongBinary])==KBlobItems*sizeof(TUint32));
  1.1086 +	test(TheView.ColLength(TheMap[anOffset+ELongBinary])==KBlobItems*sizeof(TUint32));
  1.1087 +	in.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
  1.1088 +	for (TInt ii=0;ii<KBlobItems;++ii)
  1.1089 +		test(in.ReadInt32L()==ii);
  1.1090 +	CleanupStack::PopAndDestroy();
  1.1091 +	}
  1.1092 +
  1.1093 +//
  1.1094 +// Check the row is the same as was written
  1.1095 +//
  1.1096 +LOCAL_C void CheckMaximum(TInt aCounter)
  1.1097 +	{
  1.1098 +	TheView.GetL();
  1.1099 +	test(TheView.ColInt32(TheMap[ECounter])==aCounter);
  1.1100 +	CheckMaxValues(0);
  1.1101 +	CheckMaxValues(EBitNull-EBit);
  1.1102 +	}
  1.1103 +
  1.1104 +//
  1.1105 +// Write a row with null column values in the nullable columns
  1.1106 +// return the value in the counter column
  1.1107 +//
  1.1108 +LOCAL_C TInt WriteNull()
  1.1109 +	{
  1.1110 +	TheView.InsertL();
  1.1111 +	WriteMinValues(0);
  1.1112 +	test(!TheView.IsColNull(TheMap[ECounter]));
  1.1113 +	TInt cc=TheView.ColInt(TheMap[ECounter]);
  1.1114 +	TheView.PutL();
  1.1115 +	return cc;
  1.1116 +	}
  1.1117 +
  1.1118 +//
  1.1119 +// Check the row is the same as was written
  1.1120 +//
  1.1121 +LOCAL_C void CheckNull(TInt aCounter)
  1.1122 +	{
  1.1123 +	TheView.GetL();
  1.1124 +	test(TheView.ColInt32(TheMap[ECounter])==aCounter);
  1.1125 +	TInt ii;
  1.1126 +	for (ii=ECounter;ii<EBitNull;ii++)
  1.1127 +		{	// not null columns
  1.1128 +		TDbColNo col=TheMap[ii];
  1.1129 +		test(!TheView.IsColNull(col));
  1.1130 +		test(TheView.ColSize(col)!=0);
  1.1131 +		test(TheView.ColLength(col)!=0);
  1.1132 +		if (ii<ELongText8)
  1.1133 +			test(TheView.ColDes8(col).Length()!=0);
  1.1134 +		}
  1.1135 +	CheckMinValues(0);
  1.1136 +	for (;ii<EForceNull-1;++ii)
  1.1137 +		{	// null columns
  1.1138 +		TDbColNo col=TheMap[ii];
  1.1139 +		test(TheView.IsColNull(col));
  1.1140 +		test(TheView.ColSize(col)==0);
  1.1141 +		test(TheView.ColLength(col)==0);
  1.1142 +		if (ii<ELongText8Null)
  1.1143 +			test(TheView.ColDes8(col).Length()==0);
  1.1144 +		}
  1.1145 +	test(TheView.ColUint(TheMap[EBitNull])==0);
  1.1146 +	test(TheView.ColInt(TheMap[EInt8Null])==0);
  1.1147 +	test(TheView.ColUint(TheMap[EUint8Null])==0);
  1.1148 +	test(TheView.ColInt(TheMap[EInt16Null])==0);
  1.1149 +	test(TheView.ColUint(TheMap[EUint16Null])==0);
  1.1150 +	test(TheView.ColInt(TheMap[EInt32Null])==0);
  1.1151 +	test(TheView.ColUint(TheMap[EUint32Null])==0);
  1.1152 +	test(TheView.ColInt64(TheMap[EInt64Null])==0);
  1.1153 +	test(TheView.ColReal32(TheMap[EReal32Null])==0);
  1.1154 +	test(TheView.ColReal64(TheMap[EReal64Null])==0);
  1.1155 +	test(TheView.ColTime(TheMap[ETimeNull])==TTime(0));
  1.1156 +	}
  1.1157 +
  1.1158 +//
  1.1159 +// Copy the last row (should have a different auto-inc value)
  1.1160 +//
  1.1161 +LOCAL_C TInt WriteCopy()
  1.1162 +	{
  1.1163 +	TheView.LastL();
  1.1164 +	TheView.InsertCopyL();
  1.1165 +	TheView.SetColL(TheMap[EForceNull],1234567);
  1.1166 +	test(!TheView.IsColNull(TheMap[ECounter]));
  1.1167 +	TInt cc=TheView.ColInt(TheMap[ECounter]);
  1.1168 +	TheView.PutL();
  1.1169 +	return cc;
  1.1170 +	}
  1.1171 +
  1.1172 +template <class T>
  1.1173 +void TestOverflow(TDbColNo aCol,const T& aValue)
  1.1174 +	{
  1.1175 +	TheView.UpdateL();
  1.1176 +	TheView.SetColL(aCol,aValue);
  1.1177 +	TRAPD(r,TheView.PutL());
  1.1178 +	test(r==KErrOverflow);
  1.1179 +	TheView.Cancel();
  1.1180 +	}
  1.1181 +
  1.1182 +LOCAL_C void TestWriteNull(TDbColNo aCol)
  1.1183 +	{
  1.1184 +	TheView.UpdateL();
  1.1185 +	TheView.SetColNullL(aCol);
  1.1186 +	TRAPD(r,TheView.PutL());
  1.1187 +	test(r==KErrNotFound);
  1.1188 +	TheView.Cancel();
  1.1189 +	}
  1.1190 +
  1.1191 +LOCAL_C void TestValidation()
  1.1192 +	{
  1.1193 +	TheView.InsertL();
  1.1194 +	WriteMinValues(0);
  1.1195 +	TheView.PutL();
  1.1196 +	TestOverflow(TheMap[EBit],TUint(2));
  1.1197 +	TestOverflow(TheMap[EBit],TUint(0xffffffffu));
  1.1198 +	TestOverflow(TheMap[EInt8],TInt(-129));
  1.1199 +	TestOverflow(TheMap[EInt8],TInt(128));
  1.1200 +	TestOverflow(TheMap[EUint8],TUint(0xffffffffu));
  1.1201 +	TestOverflow(TheMap[EUint8],TUint(256));
  1.1202 +	TestOverflow(TheMap[EInt16],TInt(-32769));
  1.1203 +	TestOverflow(TheMap[EInt16],TInt(32768));
  1.1204 +	TestOverflow(TheMap[EUint16],TUint(0xffffffffu));
  1.1205 +	TestOverflow(TheMap[EUint16],TUint(65536));
  1.1206 +	{
  1.1207 +	TBuf8<KDbDefaultTextColLength+1> buf;
  1.1208 +	buf.SetMax();
  1.1209 +	buf.Fill('x');
  1.1210 +	TestOverflow(TheMap[EText8],buf);
  1.1211 +	}
  1.1212 +	{
  1.1213 +	TBuf16<KDbDefaultTextColLength+1> buf;
  1.1214 +	buf.SetMax();
  1.1215 +	buf.Fill('x');
  1.1216 +	TestOverflow(TheMap[EText16],buf);
  1.1217 +	}
  1.1218 +	for (TInt ii=EBit;ii<EBitNull;++ii)
  1.1219 +		TestWriteNull(TheMap[ii]);
  1.1220 +	}
  1.1221 +
  1.1222 +/**
  1.1223 +@SYMTestCaseID          SYSLIB-DBMS-CT-0597
  1.1224 +@SYMTestCaseDesc        Tests the range and values of all columns types
  1.1225 +@SYMTestPriority        Medium
  1.1226 +@SYMTestActions         Tests for integral accessors 
  1.1227 +@SYMTestExpectedResults Test must not fail
  1.1228 +@SYMREQ                 REQ0000
  1.1229 +*/
  1.1230 +LOCAL_C void TestTypes()
  1.1231 +	{
  1.1232 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0597 Create table of all types "));
  1.1233 +	OpenDatabase();
  1.1234 +	CDbColSet* cs=CreateColSetL(EAllTypes);
  1.1235 +	test(TheDatabase.CreateTable(KTestTypesTable,*cs)==KErrNone);
  1.1236 +	delete cs;
  1.1237 +	test(TheView.Prepare(TheDatabase,_L("select * from TestTypesTable"))==KErrNone);
  1.1238 +	test(TheView.EvaluateAll()==KErrNone);
  1.1239 +	cs=TheView.ColSetL();
  1.1240 +	for (TInt ii=0;ii<KColumns;ii++)
  1.1241 +		TheMap[ii]=cs->ColNo(TPtrC(AllColumns[ii].iName));
  1.1242 +	delete cs;
  1.1243 +	test.Next(_L("Test integral accessors"));
  1.1244 +	CheckIntAccessors();
  1.1245 +	test.Next(_L("Add row of minimum values"));
  1.1246 +	TInt c1=WriteMinimum();
  1.1247 +	test.Next(_L("Add row of maximum values"));
  1.1248 +	TInt c2=WriteMaximum();
  1.1249 +	test(c2>c1);
  1.1250 +	test.Next(_L("Add row of Null values"));
  1.1251 +	TInt c3=WriteNull();
  1.1252 +	test(c3>c2);
  1.1253 +	test.Next(_L("Add a copy of the last row"));
  1.1254 +	TInt c4=WriteCopy();
  1.1255 +	test(c4>c3);
  1.1256 +	test.Next(_L("Check minimum values"));
  1.1257 +	TheView.FirstL();
  1.1258 +	CheckMinimum(c1);
  1.1259 +	test.Next(_L("Check maximum values"));
  1.1260 +	TheView.NextL();
  1.1261 +	CheckMaximum(c2);
  1.1262 +	test.Next(_L("Check Null values"));
  1.1263 +	TheView.NextL();
  1.1264 +	CheckNull(c3);
  1.1265 +	TheView.NextL();
  1.1266 +	CheckNull(c4);
  1.1267 +	test.Next(_L("Test column value Validation"));
  1.1268 +	TestValidation();
  1.1269 +	TheView.Close();
  1.1270 +	CloseDatabase();
  1.1271 +	test.End();
  1.1272 +	}
  1.1273 +
  1.1274 +const TPtrC KColumnID(_S("id"));
  1.1275 +const TPtrC KColumnText(_S("txt"));
  1.1276 +const TPtrC KColumnOther(_S("other"));
  1.1277 +const TPtrC KBlobText(_S("text"));
  1.1278 +const TPtrC KFind1(_S("id=1"));
  1.1279 +const TPtrC KFind2(_S("id is null"));
  1.1280 +
  1.1281 +// records will be:
  1.1282 +// 0: "text"
  1.1283 +// 1: "aaa...aaatext"
  1.1284 +// 2: "textaaa...aaa"
  1.1285 +// 3: "aaa...aaa"
  1.1286 +// 4: "aaa...aaatextaaa...aaa"
  1.1287 +// 5: ""
  1.1288 +
  1.1289 +struct STest
  1.1290 +	{
  1.1291 +	const TText* iText;
  1.1292 +	TUint iRecs;
  1.1293 +	};
  1.1294 +
  1.1295 +LOCAL_D STest const Tests[]=
  1.1296 +	{
  1.1297 +		{_S("txt like 'a*'"),0x010110},
  1.1298 +		{_S("txt like 'a*' or other like 'a*'"),0x111111},
  1.1299 +		{_S("txt like 'a*' and other like 'a*'"),0x010110},
  1.1300 +		{_S("txt < 'text'"),0x010111},
  1.1301 +		{_S("txt > 'text'"),0x001000},
  1.1302 +		{_S("txt > ''"),0x111110},
  1.1303 +		{_S("txt like 'text'"),0x100000},
  1.1304 +		{_S("txt like '*TEXT'"),0x110000},
  1.1305 +		{_S("txt like 'text*'"),0x101000},
  1.1306 +		{_S("txt like '*text*'"),0x111010},
  1.1307 +		{_S("txt like '*'"),0x111111},
  1.1308 +		{_S("txt like '?*'"),0x111110},
  1.1309 +		{_S("txt like '*t*t*'"),0x111010},
  1.1310 +		{_S("txt like '*a??t*'"),0x010010},
  1.1311 +		{_S("txt like 'aA*aa'"),0x000110},
  1.1312 +		{_S("txt like 'teXT'"),0x100000},
  1.1313 +		{_S("txt like '*text'"),0x110000},
  1.1314 +		{_S("txt like '*tExt*'"),0x111010},
  1.1315 +		{_S("txt like ''"),0x000001},
  1.1316 +		{_S("txt is null"),0x000001}
  1.1317 +	};
  1.1318 +
  1.1319 +LOCAL_C void CreateFindTable()
  1.1320 +	{
  1.1321 +	CDbColSet *pC=CDbColSet::NewL();
  1.1322 +	CleanupStack::PushL(pC);
  1.1323 +	pC->AddL(TDbCol(KColumnID,EDbColUint32));
  1.1324 +	pC->AddL(TDbCol(KColumnText,EDbColLongText,200));
  1.1325 +	pC->AddL(TDbCol(KColumnOther,EDbColText,200));
  1.1326 +	test(TheDatabase.CreateTable(KTestFindTable,*pC)==KErrNone);
  1.1327 +	CleanupStack::PopAndDestroy();
  1.1328 +	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EInsertOnly)==KErrNone);
  1.1329 +	TBuf<0x40> garbage;
  1.1330 +	garbage.SetMax();
  1.1331 +	garbage.Fill('a');
  1.1332 +	TBuf<0xff> col;
  1.1333 +	for (TUint ii=0;ii<6;++ii)
  1.1334 +		{
  1.1335 +		TheTable.InsertL();
  1.1336 +		TheTable.SetColL(1,ii);
  1.1337 +		TheTable.SetColL(3,_L("abcdef"));
  1.1338 +
  1.1339 +		switch (ii)
  1.1340 +			{
  1.1341 +		case 0:
  1.1342 +			TheTable.SetColL(2,KBlobText);
  1.1343 +			break;
  1.1344 +		case 1:
  1.1345 +			col=garbage;
  1.1346 +			col+=KBlobText;
  1.1347 +			TheTable.SetColL(2,col);
  1.1348 +			break;
  1.1349 +		case 2:
  1.1350 +			col=KBlobText;
  1.1351 +			col+=garbage;
  1.1352 +			TheTable.SetColL(2,col);
  1.1353 +			break;
  1.1354 +		case 3:
  1.1355 +			TheTable.SetColL(2,garbage);
  1.1356 +			break;
  1.1357 +		case 4:
  1.1358 +			col=garbage;
  1.1359 +			col+=KBlobText;
  1.1360 +			col+=garbage;
  1.1361 +			TheTable.SetColL(2,col);
  1.1362 +			break;
  1.1363 +		case 5:
  1.1364 +			break;
  1.1365 +			}
  1.1366 +		TheTable.PutL();
  1.1367 +		}
  1.1368 +	TheTable.Close();
  1.1369 +	CDbKey* key=CDbKey::NewLC();
  1.1370 +	key->AddL(KColumnID);
  1.1371 +	key->MakeUnique();
  1.1372 +	test(TheDatabase.CreateIndex(KIndexName,KTestFindTable,*key)==KErrNone);
  1.1373 +	key->Clear();
  1.1374 +	key->AddL(TDbKeyCol(KColumnText,100));
  1.1375 +	key->MakeUnique();
  1.1376 +	key->SetComparison(EDbCompareFolded);
  1.1377 +	test(TheDatabase.CreateIndex(KIndexName2,KTestFindTable,*key)==KErrNone);
  1.1378 +	CleanupStack::PopAndDestroy(); //key
  1.1379 +	}
  1.1380 +
  1.1381 +/**
  1.1382 +@SYMTestCaseID          SYSLIB-DBMS-CT-0598
  1.1383 +@SYMTestCaseDesc        Tests for RDbRowConstraint::Open() function
  1.1384 +@SYMTestPriority        Medium
  1.1385 +@SYMTestActions         Tests for the specified SQL search-condition for matching against rows in the specified rowset
  1.1386 +@SYMTestExpectedResults Test must not fail
  1.1387 +@SYMREQ                 REQ0000
  1.1388 +*/
  1.1389 +LOCAL_C void TestMatch()
  1.1390 +	{
  1.1391 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0598 Match "));
  1.1392 +	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1.1393 +	for (TInt ii=0;ii<TInt(sizeof(Tests)/sizeof(Tests[0]));++ii)
  1.1394 +		{
  1.1395 +		RDbRowConstraint match;
  1.1396 +		test(match.Open(TheTable,TDbQuery(TPtrC(Tests[ii].iText),EDbCompareFolded))==KErrNone);
  1.1397 +		TUint mask=0;
  1.1398 +		TheTable.BeginningL();
  1.1399 +		while (TheTable.NextL())
  1.1400 +			{
  1.1401 +			if (TheTable.MatchL(match))
  1.1402 +				{
  1.1403 +				TheTable.GetL();
  1.1404 +				TUint bit=0x100000>>(TheTable.ColUint32(1)*4);
  1.1405 +				test((bit&mask)==0);
  1.1406 +				mask|=bit;
  1.1407 +				}
  1.1408 +			}
  1.1409 +		match.Close();
  1.1410 +		test(mask==Tests[ii].iRecs);
  1.1411 +		}
  1.1412 +	TheTable.Close();
  1.1413 +	}
  1.1414 +
  1.1415 +/**
  1.1416 +@SYMTestCaseID          SYSLIB-DBMS-CT-0599
  1.1417 +@SYMTestCaseDesc        Tests for RDbRowSet::FindL(),RDbRowSet::GetL() functions
  1.1418 +@SYMTestPriority        Medium
  1.1419 +@SYMTestActions         Tests for finding a match through a rowset 
  1.1420 +@SYMTestExpectedResults Test must not fail
  1.1421 +@SYMREQ                 REQ0000
  1.1422 +*/
  1.1423 +LOCAL_C void TestFind(RDbRowSet& aSet)
  1.1424 +	{
  1.1425 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0599 "));
  1.1426 +	CDbColSet* cs=aSet.ColSetL();
  1.1427 +	test(cs!=0);
  1.1428 +	TDbColNo col=cs->ColNo(KColumnID);
  1.1429 +	test(col!=KDbNullColNo);
  1.1430 +	delete cs;
  1.1431 +	aSet.FirstL();
  1.1432 +	TInt p1=aSet.FindL(aSet.EForwards,KFind1);
  1.1433 +	test(p1>=0);
  1.1434 +	aSet.GetL();
  1.1435 +	test(aSet.ColUint(col)==1);
  1.1436 +	test(aSet.FindL(aSet.EForwards,KFind1)==0);
  1.1437 +	aSet.GetL();
  1.1438 +	test(aSet.ColUint(col)==1);
  1.1439 +	if (aSet.NextL())
  1.1440 +		test(aSet.FindL(aSet.EForwards,KFind1)==KErrNotFound);
  1.1441 +	aSet.FirstL();
  1.1442 +	test(aSet.FindL(aSet.EForwards,KFind2)==KErrNotFound);
  1.1443 +	aSet.LastL();
  1.1444 +	TInt p2=aSet.FindL(aSet.EBackwards,KFind1);
  1.1445 +	test(p2>=0);
  1.1446 +	aSet.GetL();
  1.1447 +	test(aSet.ColUint(col)==1);
  1.1448 +	test(aSet.FindL(aSet.EBackwards,KFind1)==0);
  1.1449 +	aSet.GetL();
  1.1450 +	test(aSet.ColUint(col)==1);
  1.1451 +	if (aSet.PreviousL())
  1.1452 +		test(aSet.FindL(aSet.EBackwards,KFind1)==KErrNotFound);
  1.1453 +	aSet.LastL();
  1.1454 +	test(aSet.FindL(aSet.EBackwards,KFind2)==KErrNotFound);
  1.1455 +	test(p1+p2+1==aSet.CountL());
  1.1456 +	}
  1.1457 +
  1.1458 +/**
  1.1459 +@SYMTestCaseID          SYSLIB-DBMS-CT-0600
  1.1460 +@SYMTestCaseDesc        Tests for SQL find
  1.1461 +@SYMTestPriority        Medium
  1.1462 +@SYMTestActions         Tests for SQL querying a table
  1.1463 +@SYMTestExpectedResults Test must not fail
  1.1464 +@SYMREQ                 REQ0000
  1.1465 +*/
  1.1466 +LOCAL_C void TestSQLFind(const TText* aSql)
  1.1467 +	{
  1.1468 +    test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0600 "));
  1.1469 +	test(TheView.Prepare(TheDatabase,TDbQuery(TPtrC(aSql),EDbCompareFolded),TheView.EReadOnly)==KErrNone);
  1.1470 +	test(TheView.EvaluateAll()==KErrNone);
  1.1471 +	TestFind(TheView);
  1.1472 +	TheView.Close();
  1.1473 +	}
  1.1474 +
  1.1475 +/**
  1.1476 +@SYMTestCaseID          SYSLIB-DBMS-CT-0601
  1.1477 +@SYMTestCaseDesc        Tests for DBMS limits
  1.1478 +@SYMTestPriority        Medium
  1.1479 +@SYMTestActions         Tests for maximum length boundaries
  1.1480 +@SYMTestExpectedResults Test must not fail
  1.1481 +@SYMREQ                 REQ0000
  1.1482 +*/
  1.1483 +LOCAL_C void TestDbmsBoundaries()
  1.1484 +	{
  1.1485 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0601 "));
  1.1486 +	// Test KMaxSegmentLength boundary
  1.1487 +
  1.1488 +	_LIT(KMaxSegmentLengthMinusOne,"txt like \
  1.1489 +		'*01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567@0.com*' \
  1.1490 +		  or other like \
  1.1491 +		'*01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567@0.com*'");
  1.1492 +	_LIT(KMaxSegmentLengthExact,"txt like \
  1.1493 +		'*012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@0.com*' \
  1.1494 +		  or other like \
  1.1495 +		'*012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@0.com*'");
  1.1496 +	_LIT(KMaxSegmentLengthPlusOne,"txt like \
  1.1497 +		'*0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@0.com*' \
  1.1498 +		  or other like \
  1.1499 +		'*0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@0.com*'");
  1.1500 +
  1.1501 +	TInt ret=KErrNone;
  1.1502 +	RDbRowConstraint match;
  1.1503 +
  1.1504 +	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1.1505 +
  1.1506 +	// Test one less than the boundary
  1.1507 +	ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthMinusOne,EDbCompareFolded));
  1.1508 +	match.Close();
  1.1509 +	test(ret==KErrNone);
  1.1510 +
  1.1511 +	// Test the boundary
  1.1512 +	ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthExact,EDbCompareFolded));
  1.1513 +	match.Close();
  1.1514 +	test(ret==KErrNone);
  1.1515 +
  1.1516 +	// Test one more than the boundary
  1.1517 +	ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthPlusOne,EDbCompareFolded));
  1.1518 +	match.Close();
  1.1519 +	test(ret==KErrArgument);
  1.1520 +
  1.1521 +	TheTable.Close();
  1.1522 +	}
  1.1523 +
  1.1524 +/**
  1.1525 +@SYMTestCaseID          SYSLIB-DBMS-CT-0602
  1.1526 +@SYMTestCaseDesc        Tests for table order,SQL query,
  1.1527 +@SYMTestPriority        Medium
  1.1528 +@SYMTestActions         Tests for finding a row in a rowset,dbms boundaries,SQL querying
  1.1529 +@SYMTestExpectedResults Test must not fail
  1.1530 +@SYMREQ                 REQ0000
  1.1531 +*/
  1.1532 +LOCAL_C void TestFind()
  1.1533 +	{
  1.1534 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0602 Table order "));
  1.1535 +	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1.1536 +	TestFind(TheTable);
  1.1537 +	test.Next(_L("Index order"));
  1.1538 +	test(TheTable.SetIndex(KIndexName)==KErrNone);
  1.1539 +	TestFind(TheTable);
  1.1540 +	test(TheTable.SetIndex(KIndexName2)==KErrNone);
  1.1541 +	TestFind(TheTable);
  1.1542 +	TheTable.Close();
  1.1543 +
  1.1544 +	test.Next(_L("SQL query test boundary"));
  1.1545 +	TestDbmsBoundaries();
  1.1546 +
  1.1547 +	test.Next(_L("SQL query"));
  1.1548 +	TestSQLFind(_S("select id from TestFindTable where id=1"));
  1.1549 +	TestSQLFind(_S("select * from TestFindTable where id<=2"));
  1.1550 +	TestSQLFind(_S("select txt,id from TestFindTable order by id desc"));
  1.1551 +	TestSQLFind(_S("select id,txt from TestFindTable where id=1 or txt like '*text*'"));
  1.1552 +	TestSQLFind(_S("select * from TestFindTable where id=1 or txt is not null order by id"));
  1.1553 +	TestSQLFind(_S("select id from TestFindTable where id<>3 order by txt"));
  1.1554 +	test.End();
  1.1555 +	}
  1.1556 +
  1.1557 +LOCAL_C void TestBookmark(RDbRowSet& aSet)
  1.1558 +	{
  1.1559 +	aSet.BeginningL();
  1.1560 +	while (aSet.NextL())
  1.1561 +		{
  1.1562 +		aSet.GetL();
  1.1563 +		TUint id=aSet.ColUint(1);
  1.1564 +		TDbBookmark mark=aSet.Bookmark();
  1.1565 +		aSet.BeginningL();
  1.1566 +		aSet.GotoL(mark);
  1.1567 +		aSet.GetL();
  1.1568 +		test(aSet.ColUint(1)==id);
  1.1569 +		aSet.NextL();
  1.1570 +		aSet.PreviousL();
  1.1571 +		aSet.PreviousL();
  1.1572 +		aSet.NextL();
  1.1573 +		aSet.GetL();
  1.1574 +		test(aSet.ColUint(1)==id);
  1.1575 +		aSet.GotoL(mark);
  1.1576 +		};
  1.1577 +	}
  1.1578 +
  1.1579 +LOCAL_C void TestSQLBookmark(const TText* aSql)
  1.1580 +	{
  1.1581 +	test(TheView.Prepare(TheDatabase,TDbQuery(TPtrC(aSql),EDbCompareFolded),TheView.EReadOnly)==KErrNone);
  1.1582 +	test(TheView.EvaluateAll()==KErrNone);
  1.1583 +	TestBookmark(TheView);
  1.1584 +	TheView.Close();
  1.1585 +	}
  1.1586 +
  1.1587 +LOCAL_C void TestBookmark()
  1.1588 +	{
  1.1589 +	test.Start(_L("Table order"));
  1.1590 +	test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
  1.1591 +	TestBookmark(TheTable);
  1.1592 +	test.Next(_L("Index order"));
  1.1593 +	test(TheTable.SetIndex(KIndexName)==KErrNone);
  1.1594 +	TestBookmark(TheTable);
  1.1595 +	test(TheTable.SetIndex(KIndexName2)==KErrNone);
  1.1596 +	TestBookmark(TheTable);
  1.1597 +	TheTable.Close();
  1.1598 +	test.Next(_L("SQL query"));
  1.1599 +	TestSQLBookmark(_S("select * from TestFindTable where id=1"));
  1.1600 +	TestSQLBookmark(_S("select * from TestFindTable where id>2"));
  1.1601 +	TestSQLBookmark(_S("select * from TestFindTable order by id desc"));
  1.1602 +	TestSQLBookmark(_S("select * from TestFindTable where txt like '*text*'"));
  1.1603 +	TestSQLBookmark(_S("select * from TestFindTable where txt is not null order by id"));
  1.1604 +	TestSQLBookmark(_S("select * from TestFindTable where id <> 3 order by txt"));
  1.1605 +	test.End();
  1.1606 +	}
  1.1607 +
  1.1608 +/**
  1.1609 +@SYMTestCaseID          SYSLIB-DBMS-CT-0603
  1.1610 +@SYMTestCaseDesc        Tests for find and bookmark
  1.1611 +@SYMTestPriority        Medium
  1.1612 +@SYMTestActions         Executes Match,Find,Bookmarks tests 
  1.1613 +@SYMTestExpectedResults Test must not fail
  1.1614 +@SYMREQ                 REQ0000
  1.1615 +*/
  1.1616 +LOCAL_C void TestFindAndBookmark()
  1.1617 +	{
  1.1618 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0603 Create Table "));
  1.1619 +	OpenDatabase();
  1.1620 +	CreateFindTable();
  1.1621 +	test.Next(_L("Match"));
  1.1622 +	TestMatch();
  1.1623 +	test.Next(_L("Find"));
  1.1624 +	TestFind();
  1.1625 +	test.Next(_L("Bookmarks"));
  1.1626 +	TestBookmark();
  1.1627 +	test.Next(_L("Close"));
  1.1628 +	CloseDatabase();
  1.1629 +	test.End();
  1.1630 +	}
  1.1631 +
  1.1632 +/**
  1.1633 +@SYMTestCaseID          SYSLIB-DBMS-CT-0604
  1.1634 +@SYMTestCaseDesc        Tests for multi view
  1.1635 +@SYMTestPriority        Medium
  1.1636 +@SYMTestActions         Tests for adding and deleting rows 
  1.1637 +@SYMTestExpectedResults Test must not fail
  1.1638 +@SYMREQ                 REQ0000
  1.1639 +*/
  1.1640 +LOCAL_C void TestMultiView()
  1.1641 +	{
  1.1642 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0604 Create Table "));
  1.1643 +	OpenDatabase();
  1.1644 +	CDbColSet* set=CreateColSetL(ESingleColumn);
  1.1645 +	test(TheDatabase.CreateTable(KTestMultiTable,*set)==KErrNone);
  1.1646 +	delete set;
  1.1647 +	test.Next(_L("Add and modify rows"));
  1.1648 +	test(TheTable.Open(TheDatabase,KTestMultiTable)==KErrNone);
  1.1649 +	test(TheView.Prepare(TheDatabase,_L("select * from TestMultiTable"))==KErrNone);
  1.1650 +	test(TheView.EvaluateAll()==KErrNone);
  1.1651 +	for (TInt ii=1;ii<=10;++ii)
  1.1652 +		{
  1.1653 +		TheTable.InsertL();
  1.1654 +		TheTable.SetColL(1,ii);
  1.1655 +		TheTable.PutL();
  1.1656 +		TheView.NextL();
  1.1657 +		TheView.GetL();
  1.1658 +		test(TheView.ColInt(1)==ii);
  1.1659 +		TheView.UpdateL();
  1.1660 +		TheView.SetColL(1,ii+100);
  1.1661 +		TheView.PutL();
  1.1662 +		test(TheTable.ColInt(1)==ii);
  1.1663 +		TheTable.GetL();
  1.1664 +		test(TheTable.ColInt(1)==ii+100);
  1.1665 +		}
  1.1666 +	test.Next(_L("delete rows"));
  1.1667 +	TheView.FirstL();
  1.1668 +	TheTable.FirstL();
  1.1669 +	TheView.GetL();
  1.1670 +	test (TheView.ColInt(1)==1+100);
  1.1671 +	TheTable.DeleteL();
  1.1672 +	TRAPD(r,TheView.GetL());
  1.1673 +	test(r!=KErrNone);
  1.1674 +	TheView.NextL();
  1.1675 +	TheView.GetL();
  1.1676 +	test (TheView.ColInt(1)==2+100);
  1.1677 +	TheView.DeleteL();
  1.1678 +	test(!TheView.PreviousL());
  1.1679 +	TheTable.NextL();
  1.1680 +	test(!TheTable.PreviousL());
  1.1681 +	test.End();
  1.1682 +	TheView.Close();
  1.1683 +	TheTable.Close();
  1.1684 +	CloseDatabase();
  1.1685 +	}
  1.1686 +	
  1.1687 +LOCAL_C void ValidateUID3(const TDesC& aDbName, const TUid& aUid)
  1.1688 +	{
  1.1689 +	test.Next(_L("Read DB header"));
  1.1690 +	RFile dbFile;
  1.1691 +	TInt err = dbFile.Open(TheFs, aDbName, EFileRead);
  1.1692 +	test(err==KErrNone);
  1.1693 +	TBuf8<100> contents; // header of a new DB is approx 77 bytes
  1.1694 +	err = dbFile.Read(contents);
  1.1695 +	dbFile.Close();
  1.1696 +	test(err==KErrNone);
  1.1697 +	
  1.1698 +	test.Next(_L("Check UID3"));
  1.1699 +	const TPtrC8 ptr((const TUint8*) &aUid.iUid, sizeof(aUid.iUid));
  1.1700 +	TInt pos = contents.Find(ptr);
  1.1701 +	test(pos==8); // UID3 begins at byte pos 8
  1.1702 +	}
  1.1703 +
  1.1704 +/**
  1.1705 +@SYMTestCaseID          SYSLIB-DBMS-CT-1372
  1.1706 +@SYMTestCaseDesc        Tests for UID3 being set in DB header
  1.1707 +@SYMTestPriority        Medium
  1.1708 +@SYMTestActions         Creates a new DB and checks UID3
  1.1709 +@SYMTestExpectedResults Test must not fail
  1.1710 +@SYMREQ                 REQ0000
  1.1711 +*/
  1.1712 +LOCAL_C void TestDbUID3()
  1.1713 +	{
  1.1714 +	const TUid KOrigUid = {0x19768253}; // random UID
  1.1715 +	const TUid KReplaceUid = {0x24731264}; // different random UID
  1.1716 +#ifndef __TOOLS2__
  1.1717 +	const TPtrC KTempDbName(_S("C:\\dbms-tst\\T_DBMS_UID3.DB"));
  1.1718 +#else
  1.1719 +	const TPtrC KTempDbName(_S(".\\dbms-tst\\T_DBMS_UID3.DB"));
  1.1720 +#endif
  1.1721 +	
  1.1722 +	(void)TheFs.Delete(KTempDbName);
  1.1723 +	
  1.1724 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1372 Create Database "));
  1.1725 +	RDbNamedDatabase tempDb;
  1.1726 +	TInt err = tempDb.Create(TheFs, KTempDbName, KOrigUid.Name());
  1.1727 +	test(err==KErrNone);
  1.1728 +	tempDb.Close();
  1.1729 +	
  1.1730 +	ValidateUID3(KTempDbName, KOrigUid);
  1.1731 +	
  1.1732 +	test.Next(_L("Replace Database"));
  1.1733 +	err = tempDb.Replace(TheFs, KTempDbName, KReplaceUid.Name());
  1.1734 +	test(err==KErrNone);
  1.1735 +	tempDb.Close();
  1.1736 +	
  1.1737 +	ValidateUID3(KTempDbName, KReplaceUid);
  1.1738 +	
  1.1739 +	test.Next(_L("Replace Database using default UID3"));
  1.1740 +	err = tempDb.Replace(TheFs, KTempDbName);
  1.1741 +	test(err==KErrNone);
  1.1742 +	tempDb.Close();
  1.1743 +	
  1.1744 +	ValidateUID3(KTempDbName, KNullUid);
  1.1745 +	
  1.1746 +	(void)TheFs.Delete(KTempDbName);
  1.1747 +	test.End();
  1.1748 +	}
  1.1749 +
  1.1750 +LOCAL_C void Test()
  1.1751 +	{
  1.1752 +	__UHEAP_MARK;
  1.1753 +	test.Start(_L("DDL"));
  1.1754 +	TRAPD(r,TestDDL();)
  1.1755 +	test(r==KErrNone);
  1.1756 +	__UHEAP_MARKEND;
  1.1757 +	__UHEAP_MARK;
  1.1758 +	test.Next(_L("Navigation/Edit"));
  1.1759 +	TRAP(r,TestView();)
  1.1760 +	test(r==KErrNone);
  1.1761 +	__UHEAP_MARKEND;
  1.1762 +	__UHEAP_MARK;
  1.1763 +	test.Next(_L("Column Types"));
  1.1764 +	TRAP(r,TestTypes();)
  1.1765 +	test(r==KErrNone);
  1.1766 +	__UHEAP_MARKEND;
  1.1767 +	__UHEAP_MARK;
  1.1768 +	test.Next(_L("Find, Match & Bookmarks"));
  1.1769 +	TRAP(r,TestFindAndBookmark();)
  1.1770 +	test(r==KErrNone);
  1.1771 +	__UHEAP_MARKEND;
  1.1772 +	__UHEAP_MARK;
  1.1773 +	test.Next(_L("Multiple view updates"));
  1.1774 +	TRAP(r,TestMultiView();)
  1.1775 +	test(r==KErrNone);
  1.1776 +	__UHEAP_MARKEND;
  1.1777 +	__UHEAP_MARK;
  1.1778 +	test.Next(_L("Database UID3"));
  1.1779 +	TRAP(r,TestDbUID3();)
  1.1780 +	test(r==KErrNone);
  1.1781 +	test.End();
  1.1782 +	__UHEAP_MARKEND;
  1.1783 +	}
  1.1784 +
  1.1785 +//
  1.1786 +// Prepare the test directory.
  1.1787 +//
  1.1788 +LOCAL_C void setupTestDirectory()
  1.1789 +    {
  1.1790 +	TInt r=TheFs.Connect();
  1.1791 +	test(r==KErrNone);
  1.1792 +//
  1.1793 +	r=TheFs.MkDir(KTestDatabase);
  1.1794 +	test(r==KErrNone || r==KErrAlreadyExists);
  1.1795 +	}
  1.1796 +
  1.1797 +//
  1.1798 +// Initialise the cleanup stack.
  1.1799 +//
  1.1800 +LOCAL_C void setupCleanup()
  1.1801 +    {
  1.1802 +	TheTrapCleanup=CTrapCleanup::New();
  1.1803 +	test(TheTrapCleanup!=NULL);
  1.1804 +	TRAPD(r,\
  1.1805 +		{\
  1.1806 +		for (TInt i=KTestCleanupStack;i>0;i--)\
  1.1807 +			CleanupStack::PushL((TAny*)0);\
  1.1808 +		CleanupStack::Pop(KTestCleanupStack);\
  1.1809 +		});
  1.1810 +	test(r==KErrNone);
  1.1811 +	}
  1.1812 +
  1.1813 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
  1.1814 +	{
  1.1815 +	RFs fsSession;
  1.1816 +	TInt err = fsSession.Connect();
  1.1817 +	if(err == KErrNone)
  1.1818 +		{
  1.1819 +		TEntry entry;
  1.1820 +		if(fsSession.Entry(aFullName, entry) == KErrNone)
  1.1821 +			{
  1.1822 +			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
  1.1823 +			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
  1.1824 +			if(err != KErrNone) 
  1.1825 +				{
  1.1826 +				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
  1.1827 +				}
  1.1828 +			err = fsSession.Delete(aFullName);
  1.1829 +			if(err != KErrNone) 
  1.1830 +				{
  1.1831 +				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
  1.1832 +				}
  1.1833 +			}
  1.1834 +		fsSession.Close();
  1.1835 +		}
  1.1836 +	else
  1.1837 +		{
  1.1838 +		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
  1.1839 +		}
  1.1840 +	}
  1.1841 +
  1.1842 +//
  1.1843 +// Test streaming conversions.
  1.1844 +//
  1.1845 +GLDEF_C TInt E32Main()
  1.1846 +    {
  1.1847 +	test.Title();
  1.1848 +	setupTestDirectory();
  1.1849 +	setupCleanup();
  1.1850 +	__UHEAP_MARK;
  1.1851 +//
  1.1852 +#ifndef __TOOLS2__
  1.1853 +	TInt r=TheDbs.Connect();
  1.1854 +	test (r==KErrNone);
  1.1855 +#endif
  1.1856 +	test.Start(_L("Standard database"));
  1.1857 +	Test();
  1.1858 +	test.Next(_L("Secure database"));
  1.1859 +	Test();
  1.1860 +#ifndef __TOOLS2__
  1.1861 +	TheDbs.Close();
  1.1862 +#endif
  1.1863 +
  1.1864 +#ifndef __linux__
  1.1865 +	TInt err;
  1.1866 +#ifndef __TOOLS2__
  1.1867 +	TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
  1.1868 +	test(err==KErrNone);
  1.1869 +	test(lc==KErrNone);
  1.1870 +#else
  1.1871 +	TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
  1.1872 +	TPtrC errmsg;
  1.1873 +	TheCrcChecker.ErrorReportL(err, errmsg);
  1.1874 +	RDebug::Print(errmsg);
  1.1875 +	test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
  1.1876 +#endif // TOOLS2
  1.1877 +#endif // linux
  1.1878 +
  1.1879 +	test.Next(_L("Waiting for server exit"));
  1.1880 +	const TUint KExitDelay=6*0x100000;	// ~6 seconds
  1.1881 +	User::After(KExitDelay);
  1.1882 +	test.End();
  1.1883 +//
  1.1884 +	__UHEAP_MARKEND;
  1.1885 +	delete TheTrapCleanup;
  1.1886 +
  1.1887 +	::DeleteDataFile(KTestDatabase);
  1.1888 +
  1.1889 +	TheFs.Close();
  1.1890 +	test.Close();
  1.1891 +	return 0;
  1.1892 +    }