sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Testing DBMS ordering and searching functionality when the key field is unicode string.
|
sl@0
|
15 |
// The idea is to verify that collation level 0 is used when doing string based searching
|
sl@0
|
16 |
// and collation level > 0 is used when doing string based ordering.
|
sl@0
|
17 |
//
|
sl@0
|
18 |
//
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <e32test.h>
|
sl@0
|
21 |
#include <f32file.h>
|
sl@0
|
22 |
#include <d32dbms.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
/////////////////////////////////////////////////////////////////
|
sl@0
|
25 |
//Globals
|
sl@0
|
26 |
|
sl@0
|
27 |
_LIT( KTestDatabase, "C:\\DBMS-TST\\T_DbmsStrComp.DB");
|
sl@0
|
28 |
|
sl@0
|
29 |
static RTest TheTest(_L("t_dbstrcmp"));
|
sl@0
|
30 |
static RFs TheFs;
|
sl@0
|
31 |
static RDbNamedDatabase TheDb;
|
sl@0
|
32 |
static RDbs TheDbSession;
|
sl@0
|
33 |
|
sl@0
|
34 |
//Test table defs
|
sl@0
|
35 |
_LIT(KTestTableName1, "TABLE1");//EDbColText16 key field
|
sl@0
|
36 |
_LIT(KTestTableName2, "TABLE2");//EDbColLongText16 key field
|
sl@0
|
37 |
|
sl@0
|
38 |
struct TColDef
|
sl@0
|
39 |
{
|
sl@0
|
40 |
const TText* iName;
|
sl@0
|
41 |
TDbColType iType;
|
sl@0
|
42 |
TInt iAttributes;
|
sl@0
|
43 |
};
|
sl@0
|
44 |
static TColDef const KColDefs1[]=
|
sl@0
|
45 |
{
|
sl@0
|
46 |
{_S("ID"), EDbColText16, 0},
|
sl@0
|
47 |
{_S("DATA"), EDbColUint32, 0},
|
sl@0
|
48 |
{0}
|
sl@0
|
49 |
};
|
sl@0
|
50 |
static TColDef const KColDefs2[]=
|
sl@0
|
51 |
{
|
sl@0
|
52 |
{_S("ID"), EDbColLongText16, 0},
|
sl@0
|
53 |
{_S("DATA"), EDbColUint32, 0},
|
sl@0
|
54 |
{0}
|
sl@0
|
55 |
};
|
sl@0
|
56 |
|
sl@0
|
57 |
//Test strings
|
sl@0
|
58 |
const TInt KTestStrLen = 3; //The length of test strings
|
sl@0
|
59 |
typedef TBuf16<KTestStrLen> TNameBuf;
|
sl@0
|
60 |
//Test strings array - using upper and lower case - which will force the DBMS server to make
|
sl@0
|
61 |
//different decisions depending on what is the current case: ordering or searching.
|
sl@0
|
62 |
const TNameBuf KTestStr[] =
|
sl@0
|
63 |
{
|
sl@0
|
64 |
_L16("aaa"),
|
sl@0
|
65 |
_L16("aAa"),
|
sl@0
|
66 |
_L16("bbB"),
|
sl@0
|
67 |
_L16("BbB")
|
sl@0
|
68 |
};
|
sl@0
|
69 |
const TInt KTestStrCnt = sizeof(KTestStr) / sizeof(KTestStr[0]);
|
sl@0
|
70 |
|
sl@0
|
71 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
72 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
73 |
//Destroy test environment - global functions
|
sl@0
|
74 |
|
sl@0
|
75 |
//Deletes "aFullName" file.
|
sl@0
|
76 |
static TInt DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
RFs fsSession;
|
sl@0
|
79 |
TInt err = fsSession.Connect();
|
sl@0
|
80 |
if(err == KErrNone)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TEntry entry;
|
sl@0
|
83 |
err = fsSession.Entry(aFullName, entry);
|
sl@0
|
84 |
if(err == KErrNone)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
87 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
88 |
if(err != KErrNone)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
91 |
}
|
sl@0
|
92 |
err = fsSession.Delete(aFullName);
|
sl@0
|
93 |
if(err != KErrNone)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
}
|
sl@0
|
98 |
fsSession.Close();
|
sl@0
|
99 |
}
|
sl@0
|
100 |
else
|
sl@0
|
101 |
{
|
sl@0
|
102 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
103 |
}
|
sl@0
|
104 |
return err;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
108 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
109 |
//Tests macros and functions.
|
sl@0
|
110 |
//If (!aValue) then the test will be panicked, the test data files will be deleted.
|
sl@0
|
111 |
static void Check(TInt aValue, TInt aLine)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
if(!aValue)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
::DeleteDataFile(KTestDatabase);
|
sl@0
|
116 |
TheTest(EFalse, aLine);
|
sl@0
|
117 |
}
|
sl@0
|
118 |
}
|
sl@0
|
119 |
//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
|
sl@0
|
120 |
static void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
if(aValue != aExpected)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
|
sl@0
|
125 |
::DeleteDataFile(KTestDatabase);
|
sl@0
|
126 |
TheTest(EFalse, aLine);
|
sl@0
|
127 |
}
|
sl@0
|
128 |
}
|
sl@0
|
129 |
//Use these to test conditions.
|
sl@0
|
130 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
131 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
132 |
|
sl@0
|
133 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
134 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
135 |
//Global functions
|
sl@0
|
136 |
|
sl@0
|
137 |
//Prepares the test directory.
|
sl@0
|
138 |
//TheFs.Connect() has to be called already.
|
sl@0
|
139 |
static void SetupTestDirectory()
|
sl@0
|
140 |
{
|
sl@0
|
141 |
TInt err = TheFs.MkDir(KTestDatabase);
|
sl@0
|
142 |
TEST(err == KErrNone || err == KErrAlreadyExists);
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
//Leaves with info message printed out
|
sl@0
|
146 |
static void LeaveL(TInt aError, TInt aLine)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
RDebug::Print(_L("*** Leave. Error: %d, Line: %d\r\n"), aError, aLine);
|
sl@0
|
149 |
User::Leave(aError);
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
//Leaves if aError < 0 with info message printed out
|
sl@0
|
153 |
static void LeaveIfErrorL(TInt aError, TInt aLine)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
if(aError < KErrNone)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
LeaveL(aError, aLine);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
//Use LEAVE() macro instead of User::Leave() and LEAVE_IF_ERROR() macro instead of
|
sl@0
|
162 |
//User::LeaveIfError(). They will print the line number, where the "leave" was called.
|
sl@0
|
163 |
#define LEAVE(aError) ::LeaveL(aError, __LINE__)
|
sl@0
|
164 |
#define LEAVE_IF_ERROR(aError) ::LeaveIfErrorL(aError, __LINE__)
|
sl@0
|
165 |
|
sl@0
|
166 |
//Creates the test DBMS session
|
sl@0
|
167 |
static void CreateTestDbSession()
|
sl@0
|
168 |
{
|
sl@0
|
169 |
RDebug::Print(_L("Create DBMS session\n"));
|
sl@0
|
170 |
TInt err = TheDbSession.Connect();
|
sl@0
|
171 |
TEST2(err, KErrNone);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
|
sl@0
|
175 |
//Creates the test database
|
sl@0
|
176 |
//TheDbSession instance has to be connected already.
|
sl@0
|
177 |
//TheFs.Connect() has to be called already.
|
sl@0
|
178 |
static void CreateTestDatabase(RDbs& aDbs, RDbNamedDatabase& aDb)
|
sl@0
|
179 |
{
|
sl@0
|
180 |
RDebug::Print(_L("Create test database\n"));
|
sl@0
|
181 |
TInt err = aDb.Replace(TheFs, KTestDatabase);
|
sl@0
|
182 |
TEST2(err, KErrNone);
|
sl@0
|
183 |
TheDb.Close();
|
sl@0
|
184 |
err = aDb.Open(aDbs, KTestDatabase);
|
sl@0
|
185 |
TEST2(err, KErrNone);
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
//Creates test table
|
sl@0
|
189 |
static void DoCreateTestTableL(RDbNamedDatabase& aDb, const TDesC& aTblName, const TColDef aColDefs[])
|
sl@0
|
190 |
{
|
sl@0
|
191 |
CDbColSet* colSet = CDbColSet::NewLC();
|
sl@0
|
192 |
for(const TColDef* colDef=aColDefs;colDef->iName;++colDef)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
TDbCol col(TPtrC(colDef->iName), colDef->iType);
|
sl@0
|
195 |
col.iAttributes = colDef->iAttributes;
|
sl@0
|
196 |
colSet->AddL(col);
|
sl@0
|
197 |
}
|
sl@0
|
198 |
TEST2(aDb.CreateTable(aTblName, *colSet), KErrNone);
|
sl@0
|
199 |
CleanupStack::PopAndDestroy(colSet);
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
//Creates test tables
|
sl@0
|
203 |
static void CreateTestTablesL(RDbNamedDatabase& aDb)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
RDebug::Print(_L("Create test tables\n"));
|
sl@0
|
206 |
::DoCreateTestTableL(aDb, KTestTableName1, KColDefs1);
|
sl@0
|
207 |
::DoCreateTestTableL(aDb, KTestTableName2, KColDefs2);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
//Gets the value of the string field, which type may be EDbColText16 or EDbColLongText16
|
sl@0
|
211 |
void GetStrFieldValueL(RDbRowSet& aTbl, const TDesC& aTblName, TDes& aStrFldVal)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
if(aTblName.CompareF(KTestTableName1) == 0)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
aStrFldVal = aTbl.ColDes16(1);
|
sl@0
|
216 |
}
|
sl@0
|
217 |
else
|
sl@0
|
218 |
{
|
sl@0
|
219 |
RDbColReadStream blob;
|
sl@0
|
220 |
blob.OpenLC(aTbl, 1);
|
sl@0
|
221 |
blob.ReadL(aStrFldVal, aTbl.ColLength(1));
|
sl@0
|
222 |
CleanupStack::PopAndDestroy();
|
sl@0
|
223 |
}
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
//Prints all table records
|
sl@0
|
227 |
static TInt PrintRecordsL(RDbRowSet& aTbl, const TDesC& aTblName)
|
sl@0
|
228 |
{
|
sl@0
|
229 |
RDebug::Print(_L("Table: %S\n"), &aTblName);
|
sl@0
|
230 |
aTbl.FirstL();
|
sl@0
|
231 |
TInt rec = 0;
|
sl@0
|
232 |
while(aTbl.AtRow())
|
sl@0
|
233 |
{
|
sl@0
|
234 |
aTbl.GetL();
|
sl@0
|
235 |
TNameBuf strFldVal;
|
sl@0
|
236 |
GetStrFieldValueL(aTbl, aTblName, strFldVal);
|
sl@0
|
237 |
TUint32 v = aTbl.ColUint32(2);
|
sl@0
|
238 |
RDebug::Print(_L(" Record %d, Str: %S, Val: %d\n"), ++rec, &strFldVal, v);
|
sl@0
|
239 |
aTbl.NextL();
|
sl@0
|
240 |
}
|
sl@0
|
241 |
return rec;
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
//Checks if the records order (based on a string key field comparison) matches the order of the
|
sl@0
|
245 |
//strings in aTestStrArray
|
sl@0
|
246 |
static void AssertRecordsOrderL(RDbRowSet& aTbl, const TDesC& aTblName, const RArray<TNameBuf>& aTestStrArray)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
aTbl.FirstL();
|
sl@0
|
249 |
TInt rec = 0;
|
sl@0
|
250 |
while(aTbl.AtRow())
|
sl@0
|
251 |
{
|
sl@0
|
252 |
aTbl.GetL();
|
sl@0
|
253 |
TNameBuf strFldVal;
|
sl@0
|
254 |
GetStrFieldValueL(aTbl, aTblName, strFldVal);
|
sl@0
|
255 |
TEST(aTestStrArray[rec] == strFldVal);
|
sl@0
|
256 |
++rec;
|
sl@0
|
257 |
aTbl.NextL();
|
sl@0
|
258 |
}
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
//Adds test data to the specified table. Make sure that the records are not in
|
sl@0
|
262 |
//order (assuming that the first field will be the key).
|
sl@0
|
263 |
static void AddTestDataL(RDbNamedDatabase& aDb, const TDesC& aTblName)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
RDbTable tbl;
|
sl@0
|
266 |
CleanupClosePushL(tbl);
|
sl@0
|
267 |
TEST2(tbl.Open(aDb, aTblName, RDbRowSet::EUpdatable), KErrNone);
|
sl@0
|
268 |
for(TInt i=0;i<KTestStrCnt;++i)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
tbl.InsertL();
|
sl@0
|
271 |
tbl.SetColL(1, KTestStr[KTestStrCnt - i - 1]);
|
sl@0
|
272 |
tbl.SetColL(2, i + 1);
|
sl@0
|
273 |
tbl.PutL();
|
sl@0
|
274 |
}
|
sl@0
|
275 |
TEST(tbl.CountL() == KTestStrCnt);
|
sl@0
|
276 |
(void)::PrintRecordsL(tbl, aTblName);
|
sl@0
|
277 |
CleanupStack::PopAndDestroy(&tbl);
|
sl@0
|
278 |
}
|
sl@0
|
279 |
|
sl@0
|
280 |
//Adds the test data to test tables
|
sl@0
|
281 |
static void AddTestDataL(RDbNamedDatabase& aDb)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
RDebug::Print(_L("Add data to test tables\n"));
|
sl@0
|
284 |
::AddTestDataL(aDb, KTestTableName1);
|
sl@0
|
285 |
::AddTestDataL(aDb, KTestTableName2);
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
//Init test environment
|
sl@0
|
289 |
static void InitEnvL()
|
sl@0
|
290 |
{
|
sl@0
|
291 |
::CreateTestDbSession();
|
sl@0
|
292 |
//Create test database and tables. Add some test data to them.
|
sl@0
|
293 |
::CreateTestDatabase(TheDbSession, TheDb);
|
sl@0
|
294 |
::CreateTestTablesL(TheDb);
|
sl@0
|
295 |
::AddTestDataL(TheDb);
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
//String comparison function, used in FillStrArraySorted() function.
|
sl@0
|
299 |
static TInt CompareC(const TNameBuf& aName1, const TNameBuf& aName2)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
return aName1.CompareC(aName2);
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
//Inserts all test string into an ordered array - aTestStrArray
|
sl@0
|
305 |
static void FillStrArraySortedL(RArray<TNameBuf>& aTestStrArray)
|
sl@0
|
306 |
{
|
sl@0
|
307 |
for(TInt i=0;i<KTestStrCnt;++i)
|
sl@0
|
308 |
{
|
sl@0
|
309 |
User::LeaveIfError(aTestStrArray.InsertInOrder(KTestStr[i], TLinearOrder<TNameBuf>(CompareC)));
|
sl@0
|
310 |
}
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
static void CreateIndexL(RDbNamedDatabase& aDb, const TDesC& aTblName, const TDesC& aColumnName)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
RDebug::Print(_L("Create index. Table: %S, column: %S\n"), &aTblName, &aColumnName);
|
sl@0
|
316 |
CDbKey* key = CDbKey::NewLC();
|
sl@0
|
317 |
key->AddL(aColumnName);
|
sl@0
|
318 |
key->MakeUnique();
|
sl@0
|
319 |
key->SetComparison(EDbCompareCollated);
|
sl@0
|
320 |
LEAVE_IF_ERROR(aDb.CreateIndex(aColumnName, aTblName, *key));
|
sl@0
|
321 |
CleanupStack::PopAndDestroy(key);
|
sl@0
|
322 |
}
|
sl@0
|
323 |
|
sl@0
|
324 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
325 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
326 |
//Test cases
|
sl@0
|
327 |
|
sl@0
|
328 |
//Test case 1. Check SELECT statement with ORDER BY clause when the key field is a string.
|
sl@0
|
329 |
static void OrderByTestL(RDbNamedDatabase& aDb, const TDesC& aTblName, const RArray<TNameBuf>& aTestStrArray)
|
sl@0
|
330 |
{
|
sl@0
|
331 |
RDbView view;
|
sl@0
|
332 |
CleanupClosePushL(view);
|
sl@0
|
333 |
|
sl@0
|
334 |
TBuf<128> sqlStmt;
|
sl@0
|
335 |
sqlStmt.Append(_L("SELECT ID, DATA FROM "));
|
sl@0
|
336 |
sqlStmt.Append(aTblName);
|
sl@0
|
337 |
sqlStmt.Append(_L(" ORDER BY ID"));
|
sl@0
|
338 |
User::LeaveIfError(view.Prepare(aDb, TDbQuery(sqlStmt, EDbCompareCollated), TDbWindow::EUnlimited));
|
sl@0
|
339 |
User::LeaveIfError(view.EvaluateAll());
|
sl@0
|
340 |
|
sl@0
|
341 |
(void)::PrintRecordsL(view, aTblName);
|
sl@0
|
342 |
AssertRecordsOrderL(view, aTblName, aTestStrArray);
|
sl@0
|
343 |
|
sl@0
|
344 |
CleanupStack::PopAndDestroy(&view);
|
sl@0
|
345 |
}
|
sl@0
|
346 |
|
sl@0
|
347 |
//Test case 2. Check SELECT statement with LIKE keyword when the key field is a string.
|
sl@0
|
348 |
static void LikeTestL(RDbNamedDatabase& aDb, const TDesC& aTblName)
|
sl@0
|
349 |
{
|
sl@0
|
350 |
RDbView view;
|
sl@0
|
351 |
CleanupClosePushL(view);
|
sl@0
|
352 |
|
sl@0
|
353 |
TBuf<128> sqlStmt;
|
sl@0
|
354 |
sqlStmt.Append(_L("SELECT ID, DATA FROM "));
|
sl@0
|
355 |
sqlStmt.Append(aTblName);
|
sl@0
|
356 |
sqlStmt.Append(_L(" WHERE ID LIKE 'B*'"));
|
sl@0
|
357 |
User::LeaveIfError(view.Prepare(aDb, TDbQuery(sqlStmt, EDbCompareCollated), TDbWindow::EUnlimited));
|
sl@0
|
358 |
User::LeaveIfError(view.EvaluateAll());
|
sl@0
|
359 |
|
sl@0
|
360 |
TInt cnt = ::PrintRecordsL(view, aTblName);
|
sl@0
|
361 |
TEST(cnt == 2);
|
sl@0
|
362 |
|
sl@0
|
363 |
CleanupStack::PopAndDestroy(&view);
|
sl@0
|
364 |
}
|
sl@0
|
365 |
|
sl@0
|
366 |
//Test case 3. Check SELECT statement with LIKE & ORDER BY keywords when the key field is a string.
|
sl@0
|
367 |
static void LikeOrderTestL(RDbNamedDatabase& aDb, const TDesC& aTblName, const RArray<TNameBuf>& aTestStrArray)
|
sl@0
|
368 |
{
|
sl@0
|
369 |
RDbView view;
|
sl@0
|
370 |
CleanupClosePushL(view);
|
sl@0
|
371 |
|
sl@0
|
372 |
TBuf<128> sqlStmt;
|
sl@0
|
373 |
sqlStmt.Append(_L("SELECT ID, DATA FROM "));
|
sl@0
|
374 |
sqlStmt.Append(aTblName);
|
sl@0
|
375 |
sqlStmt.Append(_L(" WHERE ID LIKE 'B*' ORDER BY ID"));
|
sl@0
|
376 |
User::LeaveIfError(view.Prepare(aDb, TDbQuery(sqlStmt, EDbCompareCollated), TDbWindow::EUnlimited));
|
sl@0
|
377 |
User::LeaveIfError(view.EvaluateAll());
|
sl@0
|
378 |
|
sl@0
|
379 |
TInt cnt = ::PrintRecordsL(view, aTblName);
|
sl@0
|
380 |
TEST(cnt == 2);
|
sl@0
|
381 |
AssertRecordsOrderL(view, aTblName, aTestStrArray);
|
sl@0
|
382 |
|
sl@0
|
383 |
CleanupStack::PopAndDestroy(&view);
|
sl@0
|
384 |
}
|
sl@0
|
385 |
|
sl@0
|
386 |
//Test case 4. Indexed table. The index is a string field.
|
sl@0
|
387 |
static void IndexTestL(RDbNamedDatabase& aDb, const TDesC& aTblName, const RArray<TNameBuf>& aTestStrArray)
|
sl@0
|
388 |
{
|
sl@0
|
389 |
_LIT(KIdxName, "ID");
|
sl@0
|
390 |
::CreateIndexL(aDb, aTblName, KIdxName);
|
sl@0
|
391 |
|
sl@0
|
392 |
RDbTable tbl;
|
sl@0
|
393 |
CleanupClosePushL(tbl);
|
sl@0
|
394 |
TEST2(tbl.Open(aDb, aTblName, RDbRowSet::EReadOnly), KErrNone);
|
sl@0
|
395 |
TEST2(tbl.SetIndex(KIdxName), KErrNone);
|
sl@0
|
396 |
|
sl@0
|
397 |
(void)::PrintRecordsL(tbl, aTblName);
|
sl@0
|
398 |
AssertRecordsOrderL(tbl, aTblName, aTestStrArray);
|
sl@0
|
399 |
|
sl@0
|
400 |
CleanupStack::PopAndDestroy(&tbl);
|
sl@0
|
401 |
}
|
sl@0
|
402 |
|
sl@0
|
403 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
404 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
405 |
//The main test function.
|
sl@0
|
406 |
//Call your new test functions from here
|
sl@0
|
407 |
static void RunTestsL()
|
sl@0
|
408 |
{
|
sl@0
|
409 |
TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-LEGACY-DBMSSTRCOMP-0001 Init test environment "));
|
sl@0
|
410 |
::InitEnvL();
|
sl@0
|
411 |
|
sl@0
|
412 |
RArray<TNameBuf> testStrArray;
|
sl@0
|
413 |
CleanupClosePushL(testStrArray);
|
sl@0
|
414 |
::FillStrArraySortedL(testStrArray);
|
sl@0
|
415 |
|
sl@0
|
416 |
TheTest.Next(_L("SELECT, ORDER BY, EDbColText16"));
|
sl@0
|
417 |
::OrderByTestL(TheDb, KTestTableName1, testStrArray);
|
sl@0
|
418 |
|
sl@0
|
419 |
TheTest.Next(_L("SELECT, ORDER BY, EDbColLongText16"));
|
sl@0
|
420 |
::OrderByTestL(TheDb, KTestTableName2, testStrArray);
|
sl@0
|
421 |
|
sl@0
|
422 |
TheTest.Next(_L("SELECT, LIKE, EDbColText16"));
|
sl@0
|
423 |
::LikeTestL(TheDb, KTestTableName1);
|
sl@0
|
424 |
|
sl@0
|
425 |
TheTest.Next(_L("SELECT, LIKE, EDbColLongText16"));
|
sl@0
|
426 |
::LikeTestL(TheDb, KTestTableName2);
|
sl@0
|
427 |
|
sl@0
|
428 |
RArray<TNameBuf> testStrArray2;
|
sl@0
|
429 |
CleanupClosePushL(testStrArray2);
|
sl@0
|
430 |
testStrArray2.AppendL(testStrArray[2]);//"bbB"
|
sl@0
|
431 |
testStrArray2.AppendL(testStrArray[3]);//"BbB"
|
sl@0
|
432 |
|
sl@0
|
433 |
TheTest.Next(_L("SELECT, LIKE, ORDER BY, EDbColText16"));
|
sl@0
|
434 |
::LikeOrderTestL(TheDb, KTestTableName1, testStrArray2);
|
sl@0
|
435 |
|
sl@0
|
436 |
TheTest.Next(_L("SELECT, LIKE, ORDER BY, EDbColLongText16"));
|
sl@0
|
437 |
::LikeOrderTestL(TheDb, KTestTableName2, testStrArray2);
|
sl@0
|
438 |
|
sl@0
|
439 |
TheTest.Next(_L("Index, EDbColText16"));
|
sl@0
|
440 |
::IndexTestL(TheDb, KTestTableName1, testStrArray);
|
sl@0
|
441 |
|
sl@0
|
442 |
// Not possible to create a key with EDbColLongText16
|
sl@0
|
443 |
// TheTest.Next(_L("Index, EDbColLongText16"));
|
sl@0
|
444 |
// ::IndexTestL(TheDb, KTestTableName2, testStrArray);
|
sl@0
|
445 |
|
sl@0
|
446 |
//Add tests here!
|
sl@0
|
447 |
|
sl@0
|
448 |
CleanupStack::PopAndDestroy(&testStrArray2);
|
sl@0
|
449 |
CleanupStack::PopAndDestroy(&testStrArray);
|
sl@0
|
450 |
}
|
sl@0
|
451 |
|
sl@0
|
452 |
TInt E32Main()
|
sl@0
|
453 |
{
|
sl@0
|
454 |
TheTest.Title();
|
sl@0
|
455 |
|
sl@0
|
456 |
__UHEAP_MARK;
|
sl@0
|
457 |
|
sl@0
|
458 |
CTrapCleanup* trapCleanup = CTrapCleanup::New();
|
sl@0
|
459 |
TEST(trapCleanup != NULL);
|
sl@0
|
460 |
|
sl@0
|
461 |
TInt err = TheFs.Connect();
|
sl@0
|
462 |
TEST2(err, KErrNone);
|
sl@0
|
463 |
::SetupTestDirectory();
|
sl@0
|
464 |
|
sl@0
|
465 |
::DeleteDataFile(KTestDatabase);
|
sl@0
|
466 |
|
sl@0
|
467 |
TRAP(err, ::RunTestsL());
|
sl@0
|
468 |
TheDb.Close();
|
sl@0
|
469 |
TheDbSession.Close();
|
sl@0
|
470 |
TheFs.Close();
|
sl@0
|
471 |
TEST2(err, KErrNone);
|
sl@0
|
472 |
|
sl@0
|
473 |
::DeleteDataFile(KTestDatabase);
|
sl@0
|
474 |
|
sl@0
|
475 |
TheTest.End();
|
sl@0
|
476 |
TheTest.Close();
|
sl@0
|
477 |
|
sl@0
|
478 |
delete trapCleanup;
|
sl@0
|
479 |
|
sl@0
|
480 |
__UHEAP_MARKEND;
|
sl@0
|
481 |
|
sl@0
|
482 |
return 0;
|
sl@0
|
483 |
}
|
sl@0
|
484 |
|
sl@0
|
485 |
|