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