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