1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/tdbms/t_dbindex.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1295 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <d32dbms.h>
1.20 +#include <s32file.h>
1.21 +#include <e32test.h>
1.22 +#include <e32math.h>
1.23 +#include "D32TABLE.H"
1.24 +
1.25 +// MSVC++ up to 5.0 has problems with expanding inline functions
1.26 +// This disables the mad warnings for the whole project
1.27 +#if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
1.28 +#pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
1.29 +#endif
1.30 +
1.31 +LOCAL_D RTest test(_L("t_dbindex - Test DBMS indexing and ordering"));
1.32 +LOCAL_D CTrapCleanup* TheTrapCleanup;
1.33 +LOCAL_D RDbs TheDbs;
1.34 +LOCAL_D RDbNamedDatabase TheDatabase;
1.35 +LOCAL_D RDbTable TheTable;
1.36 +LOCAL_D RDbView TheView;
1.37 +LOCAL_D RFs TheFs;
1.38 +LOCAL_D TBuf<0x200> TheBuf;
1.39 +
1.40 +const TInt KTestCleanupStack=0x20;
1.41 +const TPtrC KTestDatabase=_L("C:\\DBMS-TST\\T_INDEX.DB");
1.42 +const TPtrC KTableName(_S("Table"));
1.43 +const TPtrC KIndexName(_S("index"));
1.44 +const TPtrC KIndexTwo(_S("index_two"));
1.45 +const TPtrC KColumnName(_S("column"));
1.46 +const TPtrC KColumnTwo(_S("column2"));
1.47 +
1.48 +const TPtrC KTableName1(_S("Table1"));
1.49 +const TPtrC KColumnName1(_S("column1"));
1.50 +const TPtrC KIndexName1(_S("index1"));
1.51 +
1.52 +const TPtrC KSelectOrdered(_L("select column from table order by column"));
1.53 +
1.54 +#define elementsof(array) (sizeof(array)/sizeof(array[0]))
1.55 +
1.56 +void Check(TInt aValue,TInt aExpected,TInt aLine)
1.57 + {
1.58 + if (aValue!=aExpected)
1.59 + {
1.60 + test.Printf(_L("*** Expected %d: got %d\r\n"),aExpected,aValue);
1.61 + test.operator()(EFalse,aLine);
1.62 + }
1.63 + }
1.64 +#define test2(a,b) Check(a,b,__LINE__)
1.65 +
1.66 +//
1.67 +// Open the database (shared access) (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
1.68 +//
1.69 +LOCAL_C void OpenDatabase()
1.70 + {
1.71 + TInt r=TheDatabase.Open(TheDbs,KTestDatabase);
1.72 + test (r==KErrNone);
1.73 + }
1.74 +
1.75 +//
1.76 +// Create the database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
1.77 +//
1.78 +LOCAL_C void CreateDatabase()
1.79 + {
1.80 + TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
1.81 + test (r==KErrNone);
1.82 + TheDatabase.Close();
1.83 + OpenDatabase();
1.84 + }
1.85 +
1.86 +
1.87 +LOCAL_C void CloseDatabase()
1.88 + {
1.89 + TheDatabase.Close();
1.90 + }
1.91 +
1.92 +/**
1.93 +@SYMTestCaseID SYSLIB-DBMS-CT-0618
1.94 +@SYMTestCaseDesc Tests for RDbNamedDatabase functionality
1.95 +@SYMTestPriority Medium
1.96 +@SYMTestActions Tests for RDbNamedDatabase::CreateIndex()
1.97 +@SYMTestExpectedResults Test must not fail
1.98 +@SYMREQ REQ0000
1.99 +*/
1.100 +LOCAL_C void TestIndexBuildL()
1.101 + {
1.102 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0618 Create table "));
1.103 + TheDatabase.Begin();
1.104 + CDbColSet *cs=CDbColSet::NewLC();
1.105 + cs->AddL(TDbCol(KColumnName,EDbColInt32));
1.106 + cs->AddL(TDbCol(KColumnTwo,EDbColInt32));
1.107 + test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1.108 + CleanupStack::PopAndDestroy();
1.109 + test.Next(_L("create indices"));
1.110 + CDbKey *key=CDbKey::NewLC();
1.111 + key->AddL(TDbKeyCol(KColumnName));
1.112 + key->MakeUnique();
1.113 + test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1.114 + key->Clear();
1.115 + key->AddL(TDbKeyCol(KColumnTwo));
1.116 + key->MakeUnique();
1.117 + test(TheDatabase.CreateIndex(KIndexTwo,KTableName,*key)==KErrNone);
1.118 + CleanupStack::PopAndDestroy();
1.119 + test.Next(_L("Populate table"));
1.120 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.121 + TheTable.InsertL();
1.122 + TheTable.SetColL(1,1);
1.123 + TheTable.SetColL(2,-1);
1.124 + TheTable.PutL();
1.125 + TheTable.InsertL();
1.126 + TheTable.SetColL(1,2);
1.127 + TheTable.SetColL(2,-2);
1.128 + TheTable.PutL();
1.129 + test(TheDatabase.Commit()==KErrNone);
1.130 + test.Next(_L("Check order"));
1.131 + test(TheTable.SetNoIndex()==KErrNone);
1.132 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.133 + test(TheTable.CountL()==2);
1.134 + test(TheTable.NextL());
1.135 + TheTable.GetL();
1.136 + test(TheTable.ColInt(1)==1);
1.137 + test(TheTable.NextL());
1.138 + TheTable.GetL();
1.139 + test(TheTable.ColInt(1)==2);
1.140 + test(!TheTable.NextL());
1.141 + test(TheTable.SetIndex(KIndexTwo)==KErrNone);
1.142 + test(TheTable.CountL()==2);
1.143 + test(TheTable.NextL());
1.144 + TheTable.GetL();
1.145 + test(TheTable.ColInt(1)==2);
1.146 + test(TheTable.NextL());
1.147 + TheTable.GetL();
1.148 + test(TheTable.ColInt(1)==1);
1.149 + test(!TheTable.NextL());
1.150 + test(TheTable.SetNoIndex()==KErrNone);
1.151 + test(TheTable.CountL()==2);
1.152 + test(TheTable.NextL());
1.153 + test(TheTable.NextL());
1.154 + test(!TheTable.NextL());
1.155 + TheTable.Close();
1.156 + test.Next(_L("Drop indices"));
1.157 + test(TheDatabase.DropIndex(KIndexTwo,KTableName)==KErrNone);
1.158 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.159 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.160 + test(TheTable.SetIndex(KIndexTwo)!=KErrNone);
1.161 + TheTable.Close();
1.162 + test(TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
1.163 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.164 + test(TheTable.SetIndex(KIndexName)!=KErrNone);
1.165 + test(TheTable.SetIndex(KIndexTwo)!=KErrNone);
1.166 + TheTable.Close();
1.167 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.168 + test.End();
1.169 + }
1.170 +
1.171 +LOCAL_C TInt CountRowsL()
1.172 + {
1.173 + TInt count=0;
1.174 + while (TheTable.NextL())
1.175 + ++count;
1.176 + return count;
1.177 + }
1.178 +
1.179 +/**
1.180 +@SYMTestCaseID SYSLIB-DBMS-CT-0619
1.181 +@SYMTestCaseDesc RDbNamedDatabase::Execute() function test
1.182 +@SYMTestPriority Medium
1.183 +@SYMTestActions Tests for CREATE TABLE,CREATE INDEX and CREATE UNIQUE INDEX query
1.184 +@SYMTestExpectedResults Test must not fail
1.185 +@SYMREQ REQ0000
1.186 +*/
1.187 +LOCAL_C void TestPersistenceL()
1.188 + {
1.189 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0619 Create table "));
1.190 + TheDatabase.Begin();
1.191 + test(TheDatabase.Execute(_L("CREATE TABLE Table (column CHAR(120) NOT NULL)"))==KErrNone);
1.192 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.193 + TheTable.InsertL();
1.194 + TheTable.SetColL(1,_L("a"));
1.195 + TheTable.PutL();
1.196 + TheTable.InsertL();
1.197 + TheTable.SetColL(1,_L("b"));
1.198 + TheTable.PutL();
1.199 + TheTable.InsertL();
1.200 + TheTable.SetColL(1,_L("c"));
1.201 + TheTable.PutL();
1.202 + TheTable.InsertL();
1.203 + TheTable.SetColL(1,_L("d"));
1.204 + TheTable.PutL();
1.205 + TheTable.InsertL();
1.206 + TheTable.SetColL(1,_L("e"));
1.207 + TheTable.PutL();
1.208 + TheTable.Close();
1.209 + test(TheDatabase.Commit()==KErrNone);
1.210 + test.Next(_L("Build indices"));
1.211 + test (TheDatabase.Execute(_L("CREATE INDEX index ON table (column ASC)"))==KErrNone);
1.212 + test (TheDatabase.Execute(_L("CREATE UNIQUE INDEX index_two ON table (column DESC)"))==KErrNone);
1.213 + test.Next(_L("Close and re-open database"));
1.214 + CloseDatabase();
1.215 + OpenDatabase();
1.216 + test.Next(_L("Check indices"));
1.217 + CDbKey* key=TheDatabase.KeyL(KIndexName,KTableName);
1.218 + test (key->Count()==1);
1.219 + test (key->Comparison()==EDbCompareNormal);
1.220 + test (!key->IsUnique());
1.221 + test ((*key)[0].iName.CompareF(KColumnName)==0);
1.222 + test ((*key)[0].iOrder==TDbKeyCol::EAsc);
1.223 + delete key;
1.224 + key=TheDatabase.KeyL(KIndexTwo,KTableName);
1.225 + test (key->Count()==1);
1.226 + test (key->Comparison()==EDbCompareNormal);
1.227 + test (key->IsUnique());
1.228 + test ((*key)[0].iName.CompareF(KColumnName)==0);
1.229 + test ((*key)[0].iOrder==TDbKeyCol::EDesc);
1.230 + delete key;
1.231 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.232 + test(TheTable.SetNoIndex()==KErrNone);
1.233 + test(CountRowsL()==5);
1.234 + test(TheTable.CountL()==5);
1.235 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.236 + test(TheTable.CountL()==5);
1.237 + test(CountRowsL()==5);
1.238 + test(TheTable.SetIndex(KIndexTwo)==KErrNone);
1.239 + test(TheTable.CountL()==5);
1.240 + test(CountRowsL()==5);
1.241 + TheTable.Close();
1.242 + test.Next(_L("Drop indices"));
1.243 + TheDatabase.Begin();
1.244 + test (TheDatabase.Execute(_L("DROP INDEX index_two FROM table"))==KErrNone);
1.245 + test (TheDatabase.Execute(_L("DROP INDEX index FROM table"))==KErrNone);
1.246 + test (TheDatabase.Execute(_L("DROP TABLE table"))==KErrNone);
1.247 + test(TheDatabase.Commit()==KErrNone);
1.248 + test.End();
1.249 + }
1.250 +
1.251 +LOCAL_C void BuildTablePrologL(TDbColType aType,TInt aAttribs=0)
1.252 + {
1.253 + TheDatabase.Begin();
1.254 + CDbColSet *cs=CDbColSet::NewLC();
1.255 + TDbCol col(KColumnName,aType);
1.256 + col.iAttributes=aAttribs;
1.257 + cs->AddL(col);
1.258 + test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1.259 + CleanupStack::PopAndDestroy();
1.260 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.261 + }
1.262 +
1.263 +inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TInt& aValue)
1.264 + {aSet.SetColL(col,aValue);}
1.265 +inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TUint& aValue)
1.266 + {aSet.SetColL(col,aValue);}
1.267 +inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TInt64& aValue)
1.268 + {aSet.SetColL(col,aValue);}
1.269 +inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TReal32& aValue)
1.270 + {aSet.SetColL(col,aValue);}
1.271 +inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TReal64& aValue)
1.272 + {aSet.SetColL(col,aValue);}
1.273 +inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TTime& aValue)
1.274 + {aSet.SetColL(col,aValue);}
1.275 +inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TPtrC& aValue)
1.276 + {aSet.SetColL(col,aValue);}
1.277 +
1.278 +template <class T>
1.279 +void BuildTableL(TDbColType aType,TInt aAttribs,T aValues[],TInt aCount)
1.280 + {
1.281 + BuildTablePrologL(aType,aAttribs);
1.282 + for (TInt ii=0;ii<aCount;++ii)
1.283 + {
1.284 + TheTable.InsertL();
1.285 + SetColL(TheTable,1,aValues[ii]);
1.286 + TheTable.PutL();
1.287 + }
1.288 + test(TheDatabase.Commit()==KErrNone);
1.289 + test (TheTable.CountL()==aCount);
1.290 + TheTable.Close();
1.291 + }
1.292 +
1.293 +/**
1.294 +@SYMTestCaseID SYSLIB-DBMS-CT-0620
1.295 +@SYMTestCaseDesc Setting the specified index as the active index for a table test
1.296 +@SYMTestPriority Medium
1.297 +@SYMTestActions Create an index and set as active index for the table.
1.298 + Tests for RDbNamedDatabase::CreateIndex(),RDbNamedDatabase::Commit()
1.299 + RDbTable::Open(),RDbTable::SetIndex() functions.
1.300 +@SYMTestExpectedResults Test must not fail
1.301 +@SYMREQ REQ0000
1.302 +*/
1.303 +LOCAL_C void BuildIndexL(TDbTextComparison aComparison=EDbCompareNormal,TInt aLength=KDbUndefinedLength)
1.304 + {
1.305 + test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0620 Test index order "));
1.306 + TheDatabase.Begin();
1.307 + CDbKey *key=CDbKey::NewLC();
1.308 + key->AddL(TDbKeyCol(KColumnName,aLength));
1.309 + key->MakeUnique();
1.310 + key->SetComparison(aComparison);
1.311 + test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1.312 + CleanupStack::PopAndDestroy();
1.313 + test (TheDatabase.Commit()==KErrNone);
1.314 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.315 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.316 + }
1.317 +
1.318 +inline void GetCol(RDbRowSet& aSet,TDbColNo col,TInt& aValue)
1.319 + {aValue=aSet.ColInt(col);}
1.320 +inline void GetCol(RDbRowSet& aSet,TDbColNo col,TUint& aValue)
1.321 + {aValue=aSet.ColUint(col);}
1.322 +inline void GetCol(RDbRowSet& aSet,TDbColNo col,TInt64& aValue)
1.323 + {aValue=aSet.ColInt64(col);}
1.324 +inline void GetCol(RDbRowSet& aSet,TDbColNo col,TReal32& aValue)
1.325 + {aValue=aSet.ColReal32(col);}
1.326 +inline void GetCol(RDbRowSet& aSet,TDbColNo col,TReal64& aValue)
1.327 + {aValue=aSet.ColReal64(col);}
1.328 +inline void GetCol(RDbRowSet& aSet,TDbColNo col,TTime& aValue)
1.329 + {aValue=aSet.ColTime(col);}
1.330 +
1.331 +/**
1.332 +@SYMTestCaseID SYSLIB-DBMS-CT-0621
1.333 +@SYMTestCaseDesc RDbRowSet ordering test
1.334 +@SYMTestPriority Medium
1.335 +@SYMTestActions Reorder the row set data with RDbRowSet::GetL(),SetL() functions.
1.336 +@SYMTestExpectedResults Test must not fail
1.337 +@SYMREQ REQ0000
1.338 +*/
1.339 +template <class T>
1.340 +void TestOrderingL(RDbRowSet& aSet,T,TInt aCount)
1.341 + {
1.342 + test.Next( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0621 " ) );
1.343 + test(aSet.CountL()==aCount);
1.344 + TInt count=0;
1.345 + if (aSet.FirstL())
1.346 + {
1.347 + ++count;
1.348 + aSet.GetL();
1.349 + T last;
1.350 + GetCol(aSet,1,last);
1.351 + while (aSet.NextL())
1.352 + {
1.353 + ++count;
1.354 + aSet.GetL();
1.355 + T current;
1.356 + GetCol(aSet,1,current);
1.357 + test(last<current);
1.358 + last=current;
1.359 + }
1.360 + }
1.361 + test(count==aCount);
1.362 + }
1.363 +
1.364 +/**
1.365 +@SYMTestCaseID SYSLIB-DBMS-CT-0622
1.366 +@SYMTestCaseDesc RDbTable::SeekL() function test
1.367 +@SYMTestPriority Medium
1.368 +@SYMTestActions Tests for the retrieved column value
1.369 +@SYMTestExpectedResults Test must not fail
1.370 +@SYMREQ REQ0000
1.371 +*/
1.372 +template <class T>
1.373 +void TestSeekL(RDbTable& aTable,T,const T aValues[],TInt aCount)
1.374 + {
1.375 + test.Next( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0622 Test index seeking " ) );
1.376 + for (TInt ii=0;ii<aCount;++ii)
1.377 + {
1.378 + test(aTable.SeekL(aValues[ii]));
1.379 + aTable.GetL();
1.380 + T val;
1.381 + GetCol(aTable,1,val);
1.382 + test(aValues[ii]==val);
1.383 + }
1.384 + }
1.385 +
1.386 +/**
1.387 +aVal argument is used in the test functions (TestType & TestOrdering) and has no meaning outside them.
1.388 +It is used only to avoid some compiler varnings and to determine the correct template type
1.389 +
1.390 +@SYMTestCaseID SYSLIB-DBMS-CT-0623
1.391 +@SYMTestCaseDesc Tests for RDbTable,RDbRowSet classes
1.392 +@SYMTestPriority Medium
1.393 +@SYMTestActions Call up Test for table ordering and index seeking functions
1.394 +@SYMTestExpectedResults Test must not fail
1.395 +@SYMREQ REQ0000
1.396 +*/
1.397 +template <class T>
1.398 +void TestTypeL( TDbColType aType, TInt aAttribs, const T aValues[], TInt aCount )
1.399 + {
1.400 + test.Start( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0623 Build table " ) );
1.401 + BuildTableL( aType, aAttribs, aValues, aCount );
1.402 + T t(0);
1.403 +//
1.404 + test.Next( _L( "Test ORDER BY ordering" ) );
1.405 + test( TheView.Prepare( TheDatabase, KSelectOrdered ) == KErrNone );
1.406 + test( TheView.EvaluateAll() == KErrNone );
1.407 + TestOrderingL( TheView, t, aCount );
1.408 + TheView.Close();
1.409 +//
1.410 + BuildIndexL();
1.411 + TestOrderingL( TheTable, t, aCount );
1.412 +//
1.413 + TestSeekL( TheTable, t, aValues, aCount );
1.414 + TheTable.Close();
1.415 +//
1.416 + test( TheDatabase.DropTable( KTableName ) == KErrNone );
1.417 + test.End();
1.418 + }
1.419 +/**
1.420 +@SYMTestCaseID SYSLIB-DBMS-CT-1322
1.421 +@SYMTestCaseDesc Text ordering test
1.422 +@SYMTestPriority Medium
1.423 +@SYMTestActions Tests for RDbRowSet::Next(),RDbRowSet::GetL(),RDbRowSet::ColDes() functions
1.424 +@SYMTestExpectedResults Test must not fail
1.425 +@SYMREQ REQ0000
1.426 +*/
1.427 +void TestTextOrderingL(RDbRowSet& aSet,TInt aCount,const TTextOps& aComp)
1.428 + {
1.429 + test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1322 "));
1.430 + test(aSet.CountL()==aCount);
1.431 + TInt count=0;
1.432 + while (aSet.NextL())
1.433 + {
1.434 + aSet.GetL();
1.435 + TPtrC current=aSet.ColDes(1);
1.436 + if (count++>0)
1.437 + test(aComp.Compare(TheBuf,current)<0);
1.438 + TheBuf=current;
1.439 + }
1.440 + test(count==aCount);
1.441 + }
1.442 +
1.443 +/**
1.444 +@SYMTestCaseID SYSLIB-DBMS-CT-1323
1.445 +@SYMTestCaseDesc Tests for RDbView,RDbTable classes
1.446 +@SYMTestPriority Medium
1.447 +@SYMTestActions Wrapper function to call up for text ordering and text indexing tests
1.448 +@SYMTestExpectedResults Test must not fail
1.449 +@SYMREQ REQ0000
1.450 +*/
1.451 +void TestTextL(const TPtrC aValues[],TInt aCount,TDbTextComparison aComparison,TInt aLength=KDbUndefinedLength)
1.452 + {
1.453 + const TTextOps& comp=TTextOps::Ops(aComparison);
1.454 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1323 Build table "));
1.455 + BuildTableL(EDbColText,0,aValues,aCount);
1.456 +//
1.457 + test.Next(_L("Test ORDER BY ordering"));
1.458 + test (TheView.Prepare(TheDatabase,TDbQuery(KSelectOrdered,aComparison))==KErrNone);
1.459 + test (TheView.EvaluateAll()==KErrNone);
1.460 + TestTextOrderingL(TheView,aCount,comp);
1.461 + TheView.Close();
1.462 +//
1.463 + BuildIndexL(aComparison,aLength);
1.464 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.465 + TestTextOrderingL(TheTable,aCount,comp);
1.466 +//
1.467 + test.Next(_L("Test index seeking"));
1.468 + for (TInt ii=0;ii<aCount;++ii)
1.469 + {
1.470 + test(TheTable.SeekL(aValues[ii]));
1.471 + TheTable.GetL();
1.472 + test(comp.Compare(aValues[ii],TheTable.ColDes(1))==0);
1.473 + }
1.474 +//
1.475 + TheTable.Close();
1.476 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.477 + test.End();
1.478 + }
1.479 +
1.480 +void TestLongTextOrderingL(RDbRowSet& aSet,TInt aCount,const TTextOps& aComp)
1.481 + {
1.482 + test(aSet.CountL()==aCount);
1.483 + TInt count=0;
1.484 + HBufC* prev=0;
1.485 + while (aSet.NextL())
1.486 + {
1.487 + aSet.GetL();
1.488 + TInt len=aSet.ColLength(1);
1.489 + HBufC* buf=HBufC::NewL(len);
1.490 + RDbColReadStream s;
1.491 + s.OpenLC(aSet,1);
1.492 + TPtr des(buf->Des());
1.493 + s.ReadL(des,len);
1.494 + CleanupStack::PopAndDestroy();
1.495 + if (count++)
1.496 + test (aComp.Compare(*buf,*prev)>=0);
1.497 + delete prev;
1.498 + prev=buf;
1.499 + }
1.500 + delete prev;
1.501 + test(count==aCount);
1.502 + }
1.503 +
1.504 +LOCAL_C void OrderByLongTextL(TInt aCount,TDbTextComparison aComparison)
1.505 + {
1.506 + test (TheView.Prepare(TheDatabase,TDbQuery(KSelectOrdered,aComparison))==KErrNone);
1.507 + test (TheView.EvaluateAll()==KErrNone);
1.508 + TestLongTextOrderingL(TheView,aCount,TTextOps::Ops(aComparison));
1.509 + TheView.Close();
1.510 + }
1.511 +
1.512 +LOCAL_C void TestLongTextL(const TPtrC aValues[],TInt aCount,TDbTextComparison aComparison,TInt aLength=KDbUndefinedLength)
1.513 + {
1.514 + const TTextOps& comp=TTextOps::Ops(aComparison);
1.515 + test.Start(_L("Build table"));
1.516 + BuildTableL(EDbColLongText,0,aValues,aCount);
1.517 +//
1.518 + test.Next(_L("Test ORDER BY ordering"));
1.519 + OrderByLongTextL(aCount,aComparison);
1.520 +//
1.521 + BuildIndexL(aComparison,aLength);
1.522 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.523 + TestLongTextOrderingL(TheTable,aCount,comp);
1.524 +//
1.525 + test.Next(_L("Test index seeking"));
1.526 + for (TInt ii=0;ii<aCount;++ii)
1.527 + {
1.528 + test(TheTable.SeekL(aValues[ii]));
1.529 + TheTable.GetL();
1.530 + RDbColReadStream strm;
1.531 + strm.OpenLC(TheTable,1);
1.532 + strm.ReadL(TheBuf,TheTable.ColLength(1));
1.533 + CleanupStack::PopAndDestroy();
1.534 + test(comp.Compare(aValues[ii],TheBuf)==0);
1.535 + }
1.536 + TheTable.Close();
1.537 +//
1.538 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.539 + test.End();
1.540 + }
1.541 +
1.542 +TUint const KBitValues[]={0,1};
1.543 +TInt const KInt8Values[]={0,KMinTInt8+1,1,KMaxTInt8,2,-3,-1,KMaxTInt8-1,KMinTInt8,-40};
1.544 +TInt const KInt16Values[]={0,KMinTInt16+1,1,KMaxTInt16,2,-3,-1,KMaxTInt16-1,KMinTInt16,-4000};
1.545 +TInt const KInt32Values[]={0,KMinTInt32+1,1,KMaxTInt32,2,-3,-1,KMaxTInt32-1,KMinTInt32,-40000000};
1.546 +TInt const KInt32Count=sizeof(KInt32Values)/sizeof(KInt32Values[0]);
1.547 +TUint const KUint8Values[]={0,1,KMaxTUint8,2,(KMaxTUint8+1)/2,(KMaxTUint8-1)/2,KMaxTUint8-1,40};
1.548 +TUint const KUint16Values[]={0,1,KMaxTUint16,2,(KMaxTUint16+1)/2,(KMaxTUint16-1)/2,KMaxTUint16-1,4000};
1.549 +TUint const KUint32Values[]={0,1,KMaxTUint32,2,KMaxTUint32/2+1,KMaxTUint32/2,KMaxTUint32-1,40000000};
1.550 +//TReal32 const KReal32Values[]={0.0f,1.0f,KMaxTReal32,KMinTReal32,-1.0f,-KMaxTReal32,-4e20f,-KMinTReal32};
1.551 +//TReal64 const KReal64Values[]={0.0,1.0,KMaxTReal64,KMinTReal64,-1.0,-KMaxTReal64,-4e200,-KMinTReal64};
1.552 +TReal32 const KReal32Values[]={0.0f,1.0f,1e37f,1e-37f,-1.0f,-1e37f,-4e20f,-1e-37f};
1.553 +TReal64 const KReal64Values[]={0.0,1.0,KMaxTReal64,KMinTReal64,-1.0,-KMaxTReal64,-4e200,-KMinTReal64};
1.554 +TInt64 const KInt64Values[]=
1.555 + {
1.556 + 0,
1.557 + MAKE_TINT64(0x80000000u,0x1u),
1.558 + 1,
1.559 + MAKE_TINT64(0x7fffffffu,0xffffffffu),
1.560 + 2,
1.561 + -3,
1.562 + -1,
1.563 + MAKE_TINT64(0x7fffffffu,0xfffffffeu),
1.564 + MAKE_TINT64(0x80000000u,0x0u),
1.565 + -40
1.566 + };
1.567 +TTime const KTimeValues[]=
1.568 + {
1.569 + Time::MaxTTime(),
1.570 + TInt64(0),
1.571 + TDateTime(1970,EJanuary,0,0,0,0,0),
1.572 + Time::MinTTime(),
1.573 + TDateTime(2049,EDecember,30,23,59,59,999999),
1.574 + TDateTime(1996,EJuly,8,17,45,0,0)
1.575 + };
1.576 +TPtrC const KTextValues[]=
1.577 + {
1.578 + _S(""),
1.579 + _S("10"),
1.580 + _S("zyx"),
1.581 + _S("0"),
1.582 + _S("abcd"),
1.583 + _S("abcdefg"),
1.584 + _S("ABCDE"),
1.585 + _S("Z")
1.586 + };
1.587 +TPtrC const KLongTextValues[]=
1.588 + {
1.589 + _S("this blob will be inlined"),
1.590 + _S(""),
1.591 + _S("that blob was null"),
1.592 + _S("An example of an out-of-line blob in an index! LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8")
1.593 + };
1.594 +const TInt KLongTextLimit=30;
1.595 +
1.596 +/**
1.597 +@SYMTestCaseID SYSLIB-DBMS-CT-0624
1.598 +@SYMTestCaseDesc Wrapper function testing for Indexing with different integer sizes and Text .
1.599 +@SYMTestPriority Medium
1.600 +@SYMTestActions Tests for indexing
1.601 +@SYMTestExpectedResults Test must not fail
1.602 +@SYMREQ REQ0000
1.603 +*/
1.604 +LOCAL_C void TestTypesL()
1.605 + {
1.606 + #define ARRAY_SIZE(a) TInt(sizeof(a)/sizeof(a[0]))
1.607 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0624 Indexing Bit "));
1.608 + TestTypeL(EDbColBit,TDbCol::ENotNull,KBitValues,ARRAY_SIZE(KBitValues));
1.609 + test.Next(_L("Indexing Int8"));
1.610 + TestTypeL(EDbColInt8,TDbCol::ENotNull,KInt8Values,ARRAY_SIZE(KInt8Values));
1.611 + test.Next(_L("Indexing Int16"));
1.612 + TestTypeL(EDbColInt16,TDbCol::ENotNull,KInt16Values,ARRAY_SIZE(KInt16Values));
1.613 + test.Next(_L("Indexing Int32"));
1.614 + TestTypeL(EDbColInt32,TDbCol::ENotNull,KInt32Values,ARRAY_SIZE(KInt32Values));
1.615 + test.Next(_L("Indexing Uint8"));
1.616 + TestTypeL(EDbColUint8,TDbCol::ENotNull,KUint8Values,ARRAY_SIZE(KUint8Values));
1.617 + test.Next(_L("Indexing Uint16"));
1.618 + TestTypeL(EDbColUint16,TDbCol::ENotNull,KUint16Values,ARRAY_SIZE(KUint16Values));
1.619 + test.Next(_L("Indexing Uint32"));
1.620 + TestTypeL(EDbColUint32,TDbCol::ENotNull,KUint32Values,ARRAY_SIZE(KUint32Values));
1.621 + test.Next(_L("Indexing Real32"));
1.622 + TestTypeL(EDbColReal32,TDbCol::ENotNull,KReal32Values,ARRAY_SIZE(KReal32Values));
1.623 + test.Next(_L("Indexing Real64"));
1.624 + TestTypeL(EDbColReal64,TDbCol::ENotNull,KReal64Values,ARRAY_SIZE(KReal64Values));
1.625 + test.Next(_L("Indexing Int64"));
1.626 + TestTypeL(EDbColInt64,TDbCol::ENotNull,KInt64Values,ARRAY_SIZE(KInt64Values));
1.627 + test.Next(_L("Indexing Time"));
1.628 + TestTypeL(EDbColDateTime,TDbCol::ENotNull,KTimeValues,ARRAY_SIZE(KTimeValues));
1.629 + test.Next(_L("Indexing Text (Normal)"));
1.630 + TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareNormal);
1.631 + test.Next(_L("Indexing Text (Folded)"));
1.632 + TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareFolded);
1.633 + test.Next(_L("Indexing Text (Collated)"));
1.634 + TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareCollated);
1.635 + test.Next(_L("Indexing Text (Normal, truncated)"));
1.636 + TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareNormal,5);
1.637 + test.Next(_L("Indexing LongText (Normal)"));
1.638 + TestLongTextL(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareNormal,KLongTextLimit);
1.639 + test.Next(_L("Indexing LongText (Folded)"));
1.640 + TestLongTextL(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareFolded,KLongTextLimit);
1.641 + test.Next(_L("Indexing LongText (Collated)"));
1.642 + TestLongTextL(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareCollated,KLongTextLimit);
1.643 + test.End();
1.644 + }
1.645 +
1.646 +const TInt KBlobKeyTruncated=32/sizeof(TText);
1.647 +const TInt KBlobKeyMaxInline=255/sizeof(TText);
1.648 +const TInt KBlobKeyCompare=512/sizeof(TText);
1.649 +
1.650 +const TInt KMemoTestLengths[]=
1.651 + {
1.652 + 0,
1.653 + 1,
1.654 + KBlobKeyTruncated-1,
1.655 + KBlobKeyTruncated,
1.656 + KBlobKeyTruncated+1,
1.657 + KBlobKeyMaxInline,
1.658 + KBlobKeyMaxInline+1,
1.659 + KBlobKeyCompare-1,
1.660 + KBlobKeyCompare,
1.661 + KBlobKeyCompare+1,
1.662 + 5000
1.663 + };
1.664 +
1.665 +void TestMemoTableL(CDbColSet& aBaseSet)
1.666 + {
1.667 + test.Start(_L("create the table"));
1.668 + aBaseSet.AddL(TDbCol(KColumnName,EDbColLongText));
1.669 + TheDatabase.Begin();
1.670 + TInt r=TheDatabase.CreateTable(KTableName,aBaseSet);
1.671 + test (r==KErrNone);
1.672 +//
1.673 + test.Next(_L("add the rows"));
1.674 + r=TheView.Prepare(TheDatabase,KSelectOrdered,RDbView::EInsertOnly);
1.675 + test (r==KErrNone);
1.676 + r=TheView.EvaluateAll();
1.677 + test (r==KErrNone);
1.678 + HBufC* prev=0;
1.679 + TInt count=0;
1.680 + for (TUint ii=0;ii<elementsof(KMemoTestLengths);++ii)
1.681 + {
1.682 + TInt size=KMemoTestLengths[ii];
1.683 + HBufC* buf=HBufC::NewL(size);
1.684 + if (size>0)
1.685 + {
1.686 + TPtr des(buf->Des());
1.687 + des.Copy(*prev);
1.688 + des.AppendFill('b',size-prev->Length());
1.689 + delete prev;
1.690 + TheView.InsertL();
1.691 + TheView.SetColL(1,*buf);
1.692 + TheView.PutL();
1.693 + ++count;
1.694 + des[size-1]='a';
1.695 + }
1.696 + TheView.InsertL();
1.697 + TheView.SetColL(1,*buf);
1.698 + TheView.PutL();
1.699 + ++count;
1.700 + prev=buf;
1.701 + }
1.702 + delete prev;
1.703 + TheView.Close();
1.704 + r=TheDatabase.Commit();
1.705 + test (r==KErrNone);
1.706 +//
1.707 + test.Next(_L("Normal order"));
1.708 + OrderByLongTextL(count,EDbCompareNormal);
1.709 + test.Next(_L("Folded order"));
1.710 + OrderByLongTextL(count,EDbCompareFolded);
1.711 + test.Next(_L("Collated order"));
1.712 + OrderByLongTextL(count,EDbCompareCollated);
1.713 +//
1.714 + r=TheDatabase.DropTable(KTableName);
1.715 + test (r==KErrNone);
1.716 + test.End();
1.717 + }
1.718 +
1.719 +/**
1.720 +@SYMTestCaseID SYSLIB-DBMS-CT-0625
1.721 +@SYMTestCaseDesc Tests for ordering by longtext
1.722 +@SYMTestPriority Medium
1.723 +@SYMTestActions Tests for CDbColSet
1.724 +@SYMTestExpectedResults Test must not fail
1.725 +@SYMREQ REQ0000
1.726 +*/
1.727 +LOCAL_C void TestOrderByLongTextL()
1.728 + {
1.729 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0625 Maximum Inline Limit "));
1.730 + CDbColSet* set=CDbColSet::NewLC();
1.731 + TestMemoTableL(*set);
1.732 +//
1.733 + test.Next(_L("Reduced Inline limit [<32]"));
1.734 + set->Clear();
1.735 + TDbCol col;
1.736 + col.iType=EDbColText8;
1.737 + col.iMaxLength=255;
1.738 + col.iAttributes=0;
1.739 + TDbColName name;
1.740 + for (TInt ii=0;ii<32;++ii)
1.741 + {
1.742 + name.Format(_L("col%d"),ii);
1.743 + col.iName=name;
1.744 + if (ii==31)
1.745 + col.iMaxLength=255-20;
1.746 + set->AddL(col);
1.747 + }
1.748 + TestMemoTableL(*set);
1.749 + CleanupStack::PopAndDestroy();
1.750 + test.End();
1.751 + }
1.752 +
1.753 +/**
1.754 +@SYMTestCaseID SYSLIB-DBMS-CT-0626
1.755 +@SYMTestCaseDesc Tests for reverse ordering in indexes
1.756 +@SYMTestPriority Medium
1.757 +@SYMTestActions Tests for reversing the indexes
1.758 +@SYMTestExpectedResults Test must not fail
1.759 +@SYMREQ REQ0000
1.760 +*/
1.761 +LOCAL_C void TestReverseL()
1.762 + {
1.763 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0626 Create table and index "));
1.764 + TheDatabase.Begin();
1.765 + CDbColSet *cs=CDbColSet::NewLC();
1.766 + cs->AddL(TDbCol(KColumnName,EDbColInt32));
1.767 + test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1.768 + CleanupStack::PopAndDestroy();
1.769 + CDbKey *key=CDbKey::NewLC();
1.770 + key->AddL(TDbKeyCol(KColumnName,TDbKeyCol::EDesc));
1.771 + key->MakeUnique();
1.772 + test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1.773 + CleanupStack::PopAndDestroy();
1.774 + test(TheDatabase.Commit()==KErrNone);
1.775 + test.Next(_L("Add records"));
1.776 + TheDatabase.Begin();
1.777 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.778 + for (TInt ii=0;ii<KInt32Count;++ii)
1.779 + {
1.780 + TheTable.InsertL();
1.781 + TheTable.SetColL(1,KInt32Values[ii]);
1.782 + TheTable.PutL();
1.783 + }
1.784 + test(TheDatabase.Commit()==KErrNone);
1.785 + test(TheTable.CountL()==KInt32Count);
1.786 + test.Next(_L("Check order"));
1.787 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.788 + test(TheTable.CountL()==KInt32Count);
1.789 + TInt count=0;
1.790 + if (TheTable.FirstL())
1.791 + {
1.792 + ++count;
1.793 + TheTable.GetL();
1.794 + TInt32 last=TheTable.ColInt(1);
1.795 + while (TheTable.NextL())
1.796 + {
1.797 + ++count;
1.798 + TheTable.GetL();
1.799 + TInt32 current=TheTable.ColInt(1);
1.800 + test(last>current);
1.801 + last=current;
1.802 + }
1.803 + }
1.804 + test(count==KInt32Count);
1.805 + TheTable.Close();
1.806 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.807 + test.End();
1.808 + }
1.809 +
1.810 +/**
1.811 +@SYMTestCaseID SYSLIB-DBMS-CT-0627
1.812 +@SYMTestCaseDesc Tests for multi-column keys
1.813 +@SYMTestPriority Medium
1.814 +@SYMTestActions Tests for mutliple column keys
1.815 +@SYMTestExpectedResults Test must not fail
1.816 +@SYMREQ REQ0000
1.817 +*/
1.818 +LOCAL_C void TestMultiL()
1.819 + {
1.820 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0627 Create table and index "));
1.821 + TheDatabase.Begin();
1.822 + CDbColSet *cs=CDbColSet::NewLC();
1.823 + TDbCol col(KColumnName,EDbColInt32);
1.824 + col.iAttributes=TDbCol::ENotNull;
1.825 + cs->AddL(col);
1.826 + col.iName=KColumnTwo;
1.827 + cs->AddL(col);
1.828 + test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1.829 + CleanupStack::PopAndDestroy();
1.830 + CDbKey *key=CDbKey::NewLC();
1.831 + key->AddL(TDbKeyCol(KColumnTwo));
1.832 + key->AddL(TDbKeyCol(KColumnName,TDbKeyCol::EDesc));
1.833 + key->MakeUnique();
1.834 + test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1.835 + CleanupStack::PopAndDestroy();
1.836 + test(TheDatabase.Commit()==KErrNone);
1.837 + test.Next(_L("Add records"));
1.838 + TheDatabase.Begin();
1.839 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.840 + for (TInt ii=0;ii<KInt32Count;++ii)
1.841 + {
1.842 + for (TInt jj=0;jj<KInt32Count;++jj)
1.843 + {
1.844 + TheTable.InsertL();
1.845 + TheTable.SetColL(1,KInt32Values[ii]);
1.846 + TheTable.SetColL(2,KInt32Values[jj]);
1.847 + TheTable.PutL();
1.848 + }
1.849 + }
1.850 + test(TheDatabase.Commit()==KErrNone);
1.851 + test.Next(_L("Check order"));
1.852 + test(TheTable.CountL()==KInt32Count*KInt32Count);
1.853 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.854 + test(TheTable.CountL()==KInt32Count*KInt32Count);
1.855 + TInt count=0;
1.856 + if (TheTable.FirstL())
1.857 + {
1.858 + ++count;
1.859 + TheTable.GetL();
1.860 + TInt32 lastOne=TheTable.ColInt(1);
1.861 + TInt32 lastTwo=TheTable.ColInt(2);
1.862 + while (TheTable.NextL())
1.863 + {
1.864 + ++count;
1.865 + TheTable.GetL();
1.866 + TInt32 currentOne=TheTable.ColInt(1);
1.867 + TInt32 currentTwo=TheTable.ColInt(2);
1.868 + test(lastTwo<currentTwo||(lastTwo==currentTwo&&lastOne>currentOne));
1.869 + lastOne=currentOne;
1.870 + lastTwo=currentTwo;
1.871 + }
1.872 + }
1.873 + test(count==KInt32Count*KInt32Count);
1.874 + TheTable.Close();
1.875 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.876 + test.End();
1.877 + }
1.878 +
1.879 +/**
1.880 +@SYMTestCaseID SYSLIB-DBMS-CT-0628
1.881 +@SYMTestCaseDesc Tests duplicates/unique constraints
1.882 +@SYMTestPriority Medium
1.883 +@SYMTestActions Tests for adding duplicate entries
1.884 +@SYMTestExpectedResults Test must not fail
1.885 +@SYMREQ REQ0000
1.886 +*/
1.887 +LOCAL_C void TestDuplicatesL()
1.888 + {
1.889 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0628 Create table and indices "));
1.890 + BuildTableL(EDbColInt32,TDbCol::ENotNull,KInt32Values,KInt32Count);
1.891 + BuildIndexL();
1.892 + TheTable.Close();
1.893 + CDbKey* key=CDbKey::NewLC();
1.894 + key->AddL(KColumnName);
1.895 + test(TheDatabase.CreateIndex(KIndexTwo,KTableName,*key)==KErrNone);
1.896 + CleanupStack::PopAndDestroy();
1.897 + test.Next(_L("Attempt to add/update duplicate entry"));
1.898 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.899 + TheTable.InsertL();
1.900 + TheTable.SetColL(1,0);
1.901 + TRAPD(r,TheTable.PutL());
1.902 + test(r!=KErrNone);
1.903 + TheTable.Cancel();
1.904 + TheTable.LastL();
1.905 + TheTable.UpdateL();
1.906 + TheTable.SetColL(1,0);
1.907 + TRAP(r,TheTable.PutL());
1.908 + test(r!=KErrNone);
1.909 + TheTable.Cancel();
1.910 + test.Next(_L("Remove unique index"));
1.911 + TheTable.Close();
1.912 + test(TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
1.913 + test.Next(_L("Attempt to update/add duplicate entry"));
1.914 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.915 + TheTable.LastL();
1.916 + TheTable.UpdateL();
1.917 + TheTable.SetColL(1,0);
1.918 + TRAP(r,TheTable.PutL());
1.919 + test(r==KErrNone);
1.920 + TheTable.InsertL();
1.921 + TheTable.SetColL(1,0);
1.922 + TRAP(r,TheTable.PutL());
1.923 + test(r==KErrNone);
1.924 + test.Next(_L("Check order"));
1.925 + test(TheTable.CountL()==KInt32Count+1);
1.926 + test(TheTable.SetIndex(KIndexTwo)==KErrNone);
1.927 + test(TheTable.CountL()==KInt32Count+1);
1.928 + TInt count=0;
1.929 + if (TheTable.FirstL())
1.930 + {
1.931 + ++count;
1.932 + TheTable.GetL();
1.933 + TInt32 last=TheTable.ColInt(1);
1.934 + while (TheTable.NextL())
1.935 + {
1.936 + ++count;
1.937 + TheTable.GetL();
1.938 + TInt32 current=TheTable.ColInt(1);
1.939 + test(last<=current); // duplicates present
1.940 + last=current;
1.941 + }
1.942 + }
1.943 + test(count==KInt32Count+1);
1.944 + test.Next(_L("Try to create unique index"));
1.945 + TheTable.Close();
1.946 + key=CDbKey::NewLC();
1.947 + key->AddL(KColumnName);
1.948 + key->MakeUnique();
1.949 + test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)!=KErrNone);
1.950 + CleanupStack::PopAndDestroy();
1.951 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.952 + test.End();
1.953 + }
1.954 +
1.955 +struct Pair { TInt i1,i2; };
1.956 +struct TSeekingTest
1.957 + {
1.958 + Pair iSeek;
1.959 + Pair iResults[5];
1.960 + };
1.961 +
1.962 +// seek pair: results for <,<=,=,>=,>
1.963 +static TSeekingTest const SeekingTests[]=
1.964 + {
1.965 + {{0,0},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
1.966 + {{0,-1},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
1.967 + {{100,0},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
1.968 + {{100,10},{{-1,-1},{100,10},{100,10},{100,10},{100,20}}},
1.969 + {{100,55},{{100,50},{100,50},{-1,-1},{100,60},{100,60}}},
1.970 + {{100,60},{{100,50},{100,60},{100,60},{100,60},{100,70}}},
1.971 + {{100,100},{{100,90},{100,100},{100,100},{100,100},{200,10}}},
1.972 + {{100,110},{{100,100},{100,100},{-1,-1},{200,10},{200,10}}},
1.973 + {{100,-1},{{-1,-1},{100,100},{100,10},{100,10},{200,10}}},
1.974 + {{500,-1},{{400,100},{500,100},{500,10},{500,10},{600,10}}},
1.975 + {{550,50},{{500,100},{500,100},{-1,-1},{600,10},{600,10}}},
1.976 + {{550,-1},{{500,100},{500,100},{-1,-1},{600,10},{600,10}}},
1.977 + {{1000,0},{{900,100},{900,100},{-1,-1},{1000,10},{1000,10}}},
1.978 + {{1000,10},{{900,100},{1000,10},{1000,10},{1000,10},{1000,20}}},
1.979 + {{1000,100},{{1000,90},{1000,100},{1000,100},{1000,100},{-1,-1}}},
1.980 + {{1000,110},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}},
1.981 + {{1000,-1},{{900,100},{1000,100},{1000,10},{1000,10},{-1,-1}}},
1.982 + {{1100,0},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}},
1.983 + {{1100,-1},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}}
1.984 + };
1.985 +
1.986 +/**
1.987 +@SYMTestCaseID SYSLIB-DBMS-CT-0629
1.988 +@SYMTestCaseDesc Tests for seeking on indexes
1.989 +@SYMTestPriority Medium
1.990 +@SYMTestActions Tests for SeekL and GetL functions
1.991 +@SYMTestExpectedResults Test must not fail
1.992 +@SYMREQ REQ0000
1.993 +*/
1.994 +LOCAL_C void TestSeekingL()
1.995 + {
1.996 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0629 Create table and index "));
1.997 + TheDatabase.Begin();
1.998 + CDbColSet *cs=CDbColSet::NewLC();
1.999 + TDbCol col(KColumnName,EDbColInt32);
1.1000 + col.iAttributes=TDbCol::ENotNull;
1.1001 + cs->AddL(col);
1.1002 + col.iName=KColumnTwo;
1.1003 + cs->AddL(col);
1.1004 + test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1.1005 + CleanupStack::PopAndDestroy();
1.1006 + CDbKey *key=CDbKey::NewLC();
1.1007 + key->AddL(KColumnName).AddL(KColumnTwo);
1.1008 + key->MakeUnique();
1.1009 + test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1.1010 + CleanupStack::PopAndDestroy();
1.1011 + test(TheDatabase.Commit()==KErrNone);
1.1012 + test.Next(_L("Add records"));
1.1013 + TheDatabase.Begin();
1.1014 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.1015 + for (TInt ii=100;ii<=1000;ii+=100)
1.1016 + {
1.1017 + for (TInt jj=10;jj<=100;jj+=10)
1.1018 + {
1.1019 + TheTable.InsertL();
1.1020 + TheTable.SetColL(1,ii);
1.1021 + TheTable.SetColL(2,jj);
1.1022 + TheTable.PutL();
1.1023 + }
1.1024 + }
1.1025 + test(TheDatabase.Commit()==KErrNone);
1.1026 + test(TheTable.CountL()==100);
1.1027 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.1028 + test(TheTable.CountL()==100);
1.1029 + test.Next(_L("Seeking"));
1.1030 + const TSeekingTest* stest=SeekingTests;
1.1031 + const TSeekingTest* const end=stest+sizeof(SeekingTests)/sizeof(SeekingTests[0])-1;
1.1032 + for (;stest<=end;++stest)
1.1033 + {
1.1034 + TDbSeekMultiKey<2> key;
1.1035 + key.Add(stest->iSeek.i1);
1.1036 + if (stest->iSeek.i2>=0)
1.1037 + key.Add(stest->iSeek.i2);
1.1038 + const Pair* results=stest->iResults;
1.1039 + for (TInt ii=RDbTable::ELessThan;ii<=RDbTable::EGreaterThan;++results,++ii)
1.1040 + {
1.1041 + if (TheTable.SeekL(key,RDbTable::TComparison(ii)))
1.1042 + {
1.1043 + test(results->i1>=0);
1.1044 + TRAPD(errCode, TheTable.GetL());
1.1045 + test(errCode==KErrNone);
1.1046 + test(TheTable.ColInt(1)==results->i1);
1.1047 + test(TheTable.ColInt(2)==results->i2);
1.1048 + }
1.1049 + else
1.1050 + test(results->i1<0);
1.1051 + }
1.1052 + }
1.1053 + TheTable.Close();
1.1054 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.1055 + test.End();
1.1056 + }
1.1057 +
1.1058 +/**
1.1059 +@SYMTestCaseID SYSLIB-DBMS-CT-0630
1.1060 +@SYMTestCaseDesc Tests for defect,index creation and set index operations
1.1061 +@SYMTestPriority Medium
1.1062 +@SYMTestActions Tests for creating and setting index operations
1.1063 +@SYMTestExpectedResults Test must not fail
1.1064 +@SYMREQ REQ0000
1.1065 +*/
1.1066 +LOCAL_C void TestInequalityErrorL()
1.1067 + {
1.1068 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0630 Create table "));
1.1069 + TheDatabase.Begin();
1.1070 + CDbColSet *cs=CDbColSet::NewLC();
1.1071 + cs->AddL(TDbCol(KColumnName,EDbColInt32));
1.1072 + test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1.1073 + CleanupStack::PopAndDestroy();
1.1074 +//
1.1075 + test.Next(_L("create indices"));
1.1076 + CDbKey *key=CDbKey::NewLC();
1.1077 + key->AddL(TDbKeyCol(KColumnName));
1.1078 + test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1.1079 + CleanupStack::PopAndDestroy();
1.1080 +//
1.1081 + test.Next(_L("Populate table"));
1.1082 + test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.1083 + for(TInt ii=0; ii<=130;++ii)
1.1084 + {
1.1085 + TheTable.InsertL();
1.1086 + TheTable.SetColL(1,ii);
1.1087 + TheTable.PutL();
1.1088 + }
1.1089 +//
1.1090 + test.Next(_L("Checks"));
1.1091 + test(TheTable.SetIndex(KIndexName)==KErrNone);
1.1092 +//
1.1093 +// We need to delete a row in this node to get to the correct inequality condition
1.1094 + test.Next(_L("Delete row 90"));
1.1095 + test(TheTable.SeekL(TDbSeekKey(90)));
1.1096 + TheTable.GetL();
1.1097 + TheTable.DeleteL();
1.1098 +// Now delete last row on node which should be 94
1.1099 + test.Next(_L("Delete row 94"));
1.1100 + test(TheTable.SeekL(TDbSeekKey(94)));
1.1101 + TheTable.GetL();
1.1102 + TheTable.DeleteL();
1.1103 + TheTable.EndL();
1.1104 + test(!TheTable.SeekL(TDbSeekKey(94)));
1.1105 +//
1.1106 + test.Next(_L("Insert row 94"));
1.1107 + TheTable.InsertL();
1.1108 + TheTable.SetColL(1,94);
1.1109 + TheTable.PutL();
1.1110 +//
1.1111 + test.Next(_L("now try and find it"));
1.1112 + test(TheTable.SeekL(TDbSeekKey(94))); //prior to defect fix this line failed.
1.1113 +//
1.1114 + TheDatabase.Commit();
1.1115 + TheTable.Close();
1.1116 + test(TheDatabase.DropTable(KTableName)==KErrNone);
1.1117 + test.End();
1.1118 + }
1.1119 +
1.1120 +/**
1.1121 +@SYMTestCaseID PDS-DBMS-CT-4006
1.1122 +@SYMTestCaseDesc Tests for add dbseekkey operations
1.1123 +@SYMTestPriority High
1.1124 +@SYMTestActions Create a DbSeekKey then add an index to it
1.1125 +@SYMTestExpectedResults Verify that seeking with key works
1.1126 +@SYMDEF DEF135710
1.1127 +*/
1.1128 +LOCAL_C void TestAddSeekKeyL()
1.1129 + {
1.1130 + test.Start(_L(" @SYMTestCaseID:PDS-DBMS-CT-4006 Tests for add dbseekkey operations"));
1.1131 +
1.1132 + CreateDatabase();
1.1133 + TInt err = TheDatabase.Begin();
1.1134 + test2(err, KErrNone);
1.1135 +
1.1136 + CDbColSet *cs=CDbColSet::NewLC();
1.1137 + cs->AddL(TDbCol(KColumnName1,EDbColText8));
1.1138 + err = TheDatabase.CreateTable(KTableName1,*cs);
1.1139 + test2(err , KErrNone);
1.1140 + CleanupStack::PopAndDestroy();
1.1141 +
1.1142 + test.Next(_L("Create Indices"));
1.1143 + CDbKey *key=CDbKey::NewLC();
1.1144 + key->AddL(TDbKeyCol(KColumnName1));
1.1145 + err = TheDatabase.CreateIndex(KIndexName1,KTableName1,*key);
1.1146 + test2(err, KErrNone);
1.1147 + CleanupStack::PopAndDestroy();
1.1148 +
1.1149 + test.Next(_L("Populate Table"));
1.1150 + TBuf8<7> buf(_L8("testKey"));
1.1151 + err = TheTable.Open(TheDatabase,KTableName1);
1.1152 + test2(err, KErrNone);
1.1153 + for(TInt i = 0; i <= 10; ++i)
1.1154 + {
1.1155 + TheTable.InsertL();
1.1156 + TheTable.SetColL(1,buf);
1.1157 + TheTable.PutL();
1.1158 + }
1.1159 +
1.1160 + test.Next(_L("Set Index"));
1.1161 + err = TheTable.SetIndex(KIndexName1);
1.1162 + test2(err, KErrNone);
1.1163 +
1.1164 + test.Next(_L("Testing Add Function"));
1.1165 + TDbSeekKey testkey;
1.1166 + testkey.Add(buf);
1.1167 + TBool r = TheTable.SeekL(testkey);
1.1168 + test2(r, ETrue);
1.1169 +
1.1170 + err = TheDatabase.Commit();
1.1171 + test2(err, KErrNone);
1.1172 +
1.1173 + TheTable.Close();
1.1174 + test.End();
1.1175 + }
1.1176 +
1.1177 +//
1.1178 +// Test the database definition and enquiry functions
1.1179 +//
1.1180 +LOCAL_C void TestIndexesL()
1.1181 + {
1.1182 + test.Start(_L("Create Database"));
1.1183 + CreateDatabase();
1.1184 + test.Next(_L("Test index build and drop"));
1.1185 + TestIndexBuildL();
1.1186 + test.Next(_L("Test index persistence"));
1.1187 + TestPersistenceL();
1.1188 + test.Next(_L("Testing index key types"));
1.1189 + TestTypesL();
1.1190 + test.Next(_L("Testing LongText ORDER BY"));
1.1191 + TestOrderByLongTextL();
1.1192 + test.Next(_L("Testing reverse ordering"));
1.1193 + TestReverseL();
1.1194 + test.Next(_L("Testing multi column keys"));
1.1195 + TestMultiL();
1.1196 + test.Next(_L("Testing duplicate/unqiue"));
1.1197 + TestDuplicatesL();
1.1198 + test.Next(_L("Testing seeking"));
1.1199 + TestSeekingL();
1.1200 + test.Next(_L("Testing incorrect inequaltiy condition in store btree"));
1.1201 + TestInequalityErrorL();
1.1202 + CloseDatabase();
1.1203 + test.End();
1.1204 + }
1.1205 +
1.1206 +//
1.1207 +// Prepare the test directory.
1.1208 +//
1.1209 +LOCAL_C void setupTestDirectory()
1.1210 + {
1.1211 + TInt r=TheFs.Connect();
1.1212 + test(r==KErrNone);
1.1213 +//
1.1214 + r=TheFs.MkDir(KTestDatabase);
1.1215 + test(r==KErrNone || r==KErrAlreadyExists);
1.1216 + }
1.1217 +
1.1218 +//
1.1219 +// Initialise the cleanup stack.
1.1220 +//
1.1221 +LOCAL_C void setupCleanup()
1.1222 + {
1.1223 + TheTrapCleanup=CTrapCleanup::New();
1.1224 + test(TheTrapCleanup!=NULL);
1.1225 + TRAPD(r,\
1.1226 + {\
1.1227 + for (TInt i=KTestCleanupStack;i>0;i--)\
1.1228 + CleanupStack::PushL((TAny*)0);\
1.1229 + CleanupStack::Pop(KTestCleanupStack);\
1.1230 + });
1.1231 + test(r==KErrNone);
1.1232 + }
1.1233 +
1.1234 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
1.1235 + {
1.1236 + RFs fsSession;
1.1237 + TInt err = fsSession.Connect();
1.1238 + if(err == KErrNone)
1.1239 + {
1.1240 + TEntry entry;
1.1241 + if(fsSession.Entry(aFullName, entry) == KErrNone)
1.1242 + {
1.1243 + RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
1.1244 + err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
1.1245 + if(err != KErrNone)
1.1246 + {
1.1247 + RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
1.1248 + }
1.1249 + err = fsSession.Delete(aFullName);
1.1250 + if(err != KErrNone)
1.1251 + {
1.1252 + RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
1.1253 + }
1.1254 + }
1.1255 + fsSession.Close();
1.1256 + }
1.1257 + else
1.1258 + {
1.1259 + RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
1.1260 + }
1.1261 + }
1.1262 +
1.1263 +//
1.1264 +// Test streaming conversions.
1.1265 +//
1.1266 +GLDEF_C TInt E32Main()
1.1267 + {
1.1268 + test.Title();
1.1269 + setupTestDirectory();
1.1270 + setupCleanup();
1.1271 + __UHEAP_MARK;
1.1272 +//
1.1273 + TInt r=TheDbs.Connect();
1.1274 + test (r==KErrNone);
1.1275 + TheDbs.ResourceMark();
1.1276 + test.Start(_L("Standard database"));
1.1277 + TRAP(r,TestIndexesL();)
1.1278 + test(r==KErrNone);
1.1279 + test.Next(_L("Secure database"));
1.1280 + TRAP(r,TestIndexesL();)
1.1281 + test(r==KErrNone);
1.1282 + TRAP(r, TestAddSeekKeyL());
1.1283 + test(r==KErrNone);
1.1284 + CloseDatabase();
1.1285 +
1.1286 + ::DeleteDataFile(KTestDatabase); //deletion of data files must be before call to end - DEF047652
1.1287 +
1.1288 + test.End();
1.1289 + TheDbs.ResourceCheck();
1.1290 + TheDbs.Close();
1.1291 +
1.1292 + __UHEAP_MARKEND;
1.1293 + delete TheTrapCleanup;
1.1294 +
1.1295 + TheFs.Close();
1.1296 + test.Close();
1.1297 + return 0;
1.1298 + }