sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <d32dbms.h>
|
sl@0
|
17 |
#include <e32math.h>
|
sl@0
|
18 |
#include <s32file.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include "t_dbfail.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
_LIT(KTestTitle,"t_dbfail: DBMS Failure mode test");
|
sl@0
|
23 |
GLDEF_D RTest test(KTestTitle);
|
sl@0
|
24 |
GLDEF_D RDbs TheDbs;
|
sl@0
|
25 |
GLDEF_D RDbNamedDatabase TheDatabase;
|
sl@0
|
26 |
GLDEF_D TClientHeap KClientHeap;
|
sl@0
|
27 |
GLDEF_D TServerHeap KServerHeap;
|
sl@0
|
28 |
|
sl@0
|
29 |
|
sl@0
|
30 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
31 |
LOCAL_D RFs TheFs;
|
sl@0
|
32 |
LOCAL_D RDbView TheView;
|
sl@0
|
33 |
LOCAL_D RDbTable TheTable;
|
sl@0
|
34 |
LOCAL_D RDbRowSet::TAccess Access;
|
sl@0
|
35 |
LOCAL_D CDbColSet* TheColSet;
|
sl@0
|
36 |
LOCAL_D CDbKey* TheKey;
|
sl@0
|
37 |
LOCAL_D const TDesC* TheSql;
|
sl@0
|
38 |
LOCAL_D TBuf<64> TheFormat;
|
sl@0
|
39 |
|
sl@0
|
40 |
const TInt KTestCleanupStack=0x20;
|
sl@0
|
41 |
_LIT(KTestDatabase,"C:\\DBMS-TST\\t_fail.db");
|
sl@0
|
42 |
_LIT(TableName,"Table1");
|
sl@0
|
43 |
_LIT(TableName2,"Table_two");
|
sl@0
|
44 |
_LIT(TableNameX,"Bad Table Name");
|
sl@0
|
45 |
_LIT(IndexName,"Index1");
|
sl@0
|
46 |
_LIT(IndexName2,"Index2");
|
sl@0
|
47 |
_LIT(Column1,"column_one");
|
sl@0
|
48 |
_LIT(Column1Fold,"COLUMN_ONE");
|
sl@0
|
49 |
_LIT(Column2,"column_2");
|
sl@0
|
50 |
_LIT(Column2X,"column_2%");
|
sl@0
|
51 |
_LIT(SimpleSql,"select * from Table1");
|
sl@0
|
52 |
_LIT(UpdateSql,"update Table1 SET column_2='hello'");
|
sl@0
|
53 |
|
sl@0
|
54 |
//const TPtrC ComplexSql(_S("select * from Table1 where column_one<0 and not column_one is null or column_2 not like '*fred*' and column_2>'m' order by column_one desc"));
|
sl@0
|
55 |
const TPtrC ComplexSql[]=
|
sl@0
|
56 |
{
|
sl@0
|
57 |
_S("select * from Table1 where column_one<0 and column_one is null"),
|
sl@0
|
58 |
_S("select * from Table1 where column_one<0 and (column_one is null and column_2 like '')"),
|
sl@0
|
59 |
_S("select * from Table1 where (column_one<0 and column_one is null) and column_2 like ''"),
|
sl@0
|
60 |
_S("select * from Table1 where (column_one<0 and column_one is null) and (column_2 like '' and column_one>0)"),
|
sl@0
|
61 |
_S("select * from Table1 where (column_one<0 and column_one is null) and (column_2 like '' and column_one>0 and column_one is null)"),
|
sl@0
|
62 |
_S("select * from Table1 where (column_one<0 and column_one is null and column_one = 10) and (column_2 like '' and column_one>0 and column_one is null)"),
|
sl@0
|
63 |
_S("select * from Table1 where column_one<0 and column_one is null and column_one = 10 and column_2 like '' and column_one>0 and column_one is null")
|
sl@0
|
64 |
};
|
sl@0
|
65 |
|
sl@0
|
66 |
struct SSqlErrors
|
sl@0
|
67 |
{
|
sl@0
|
68 |
const TText* iSql;
|
sl@0
|
69 |
TInt iError;
|
sl@0
|
70 |
};
|
sl@0
|
71 |
|
sl@0
|
72 |
LOCAL_D SSqlErrors const BadSql[]=
|
sl@0
|
73 |
{
|
sl@0
|
74 |
{_S("sponge"),KErrArgument},
|
sl@0
|
75 |
{_S("select * from widget"),KErrNotFound},
|
sl@0
|
76 |
{_S("select * from Table1 where x = 0"),KErrNotFound},
|
sl@0
|
77 |
{_S("select * from Table1 where x 0 like"),KErrArgument},
|
sl@0
|
78 |
{_S("select * from Table1 where column_2>'a' and column_one<'z'"),KErrGeneral},
|
sl@0
|
79 |
{_S("select from Table1"),KErrArgument},
|
sl@0
|
80 |
{_S("select x, from Table1"),KErrArgument},
|
sl@0
|
81 |
{_S("select x from Table1"),KErrNotFound},
|
sl@0
|
82 |
{_S("select column_2 column_one from Table1"),KErrArgument},
|
sl@0
|
83 |
{_S("select * from Table1 order by x"),KErrNotFound},
|
sl@0
|
84 |
{_S("select * from Table1 order column_one"),KErrArgument},
|
sl@0
|
85 |
{_S("select * from Table1 order by column_one down"),KErrArgument}
|
sl@0
|
86 |
};
|
sl@0
|
87 |
|
sl@0
|
88 |
GLDEF_C void Connect()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
TInt r=TheDbs.Connect();
|
sl@0
|
91 |
test (r==KErrNone);
|
sl@0
|
92 |
TheDbs.ResourceMark();
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
GLDEF_C void Disconnect()
|
sl@0
|
96 |
{
|
sl@0
|
97 |
TheDbs.ResourceCheck();
|
sl@0
|
98 |
TheDbs.Close();
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
|
sl@0
|
102 |
//SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version
|
sl@0
|
103 |
LOCAL_C void DbCreateL()
|
sl@0
|
104 |
{
|
sl@0
|
105 |
User::LeaveIfError(TheDatabase.Replace(TheFs,KTestDatabase,TheFormat));
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
//SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version
|
sl@0
|
109 |
LOCAL_C void DbOpenL()
|
sl@0
|
110 |
{
|
sl@0
|
111 |
User::LeaveIfError(TheDatabase.Open(TheFs,KTestDatabase,TheFormat));
|
sl@0
|
112 |
CleanupClosePushL(TheDatabase);
|
sl@0
|
113 |
delete TheDatabase.TableNamesL(); // force a schema load
|
sl@0
|
114 |
CleanupStack::Pop();
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
//SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version
|
sl@0
|
118 |
LOCAL_C void DbShareL()
|
sl@0
|
119 |
{
|
sl@0
|
120 |
User::LeaveIfError(TheDatabase.Open(TheDbs,KTestDatabase,TheFormat));
|
sl@0
|
121 |
CleanupClosePushL(TheDatabase);
|
sl@0
|
122 |
delete TheDatabase.TableNamesL(); // force a schema load
|
sl@0
|
123 |
CleanupStack::Pop();
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
|
sl@0
|
127 |
/**
|
sl@0
|
128 |
@SYMTestCaseID SYSLIB-DBMS-CT-0612
|
sl@0
|
129 |
@SYMTestCaseDesc Database validity test
|
sl@0
|
130 |
@SYMTestPriority Medium
|
sl@0
|
131 |
@SYMTestActions Tests for opening and closing of database
|
sl@0
|
132 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
133 |
@SYMREQ REQ0000
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
LOCAL_C void TestOpenL()
|
sl@0
|
136 |
{
|
sl@0
|
137 |
_LIT(KFileNotFound,"not a database");
|
sl@0
|
138 |
TInt r=TheDatabase.Open(TheFs,KFileNotFound);
|
sl@0
|
139 |
test (r==KErrNotFound || r==KErrPathNotFound);
|
sl@0
|
140 |
//
|
sl@0
|
141 |
_LIT(KPathNotFound,"C:\\not a path\\database.db");
|
sl@0
|
142 |
r=TheDatabase.Open(TheFs,KPathNotFound);
|
sl@0
|
143 |
test (r==KErrPathNotFound);
|
sl@0
|
144 |
//
|
sl@0
|
145 |
_LIT(KNotFormat,"not.a.dbx");
|
sl@0
|
146 |
r=TheDatabase.Open(TheFs,KFileNotFound,KNotFormat);
|
sl@0
|
147 |
test (r==KErrNotFound || r==KErrPathNotFound);
|
sl@0
|
148 |
//
|
sl@0
|
149 |
DbCreateL();
|
sl@0
|
150 |
TheDatabase.Close();
|
sl@0
|
151 |
r=TheDatabase.Open(TheFs,KTestDatabase,TUid::Uid(0x01234567).Name());
|
sl@0
|
152 |
test (r==KErrNone); // New code has no loadable drivers, it is irrelevant to expect error here
|
sl@0
|
153 |
TheDatabase.Close(); // We have added it here because previous statement does not return error anymore
|
sl@0
|
154 |
//
|
sl@0
|
155 |
RFile f;
|
sl@0
|
156 |
r=f.Replace(TheFs,KTestDatabase,EFileWrite);
|
sl@0
|
157 |
test (r==KErrNone);
|
sl@0
|
158 |
TCheckedUid type(KDirectFileStoreLayoutUid);
|
sl@0
|
159 |
r=f.Write(type.Des());
|
sl@0
|
160 |
test (r==KErrNone);
|
sl@0
|
161 |
f.Close();
|
sl@0
|
162 |
r=TheDatabase.Open(TheFs,KTestDatabase);
|
sl@0
|
163 |
test (r==KErrNotSupported);
|
sl@0
|
164 |
//
|
sl@0
|
165 |
_LIT(KDefaultFormat,"epoc");
|
sl@0
|
166 |
r=TheDatabase.Open(TheFs,KTestDatabase,KDefaultFormat);
|
sl@0
|
167 |
test (r==KErrNotSupported); // We expect not supported db here
|
sl@0
|
168 |
}
|
sl@0
|
169 |
|
sl@0
|
170 |
class TClient : public TContext
|
sl@0
|
171 |
{
|
sl@0
|
172 |
public:
|
sl@0
|
173 |
TClient() {}
|
sl@0
|
174 |
private:
|
sl@0
|
175 |
void OpenDbL() const
|
sl@0
|
176 |
{DbOpenL();}
|
sl@0
|
177 |
};
|
sl@0
|
178 |
class TServer : public TContext
|
sl@0
|
179 |
{
|
sl@0
|
180 |
public:
|
sl@0
|
181 |
TServer() {}
|
sl@0
|
182 |
private:
|
sl@0
|
183 |
void OpenDbL() const
|
sl@0
|
184 |
{DbShareL();}
|
sl@0
|
185 |
};
|
sl@0
|
186 |
|
sl@0
|
187 |
const TClient KClient;
|
sl@0
|
188 |
const TServer KServer;
|
sl@0
|
189 |
|
sl@0
|
190 |
void TFail::Test(const THeapFail& aHeap,const TContext* aContext)
|
sl@0
|
191 |
{
|
sl@0
|
192 |
TInt ii;
|
sl@0
|
193 |
TInt errCode;
|
sl@0
|
194 |
for (ii=1;;++ii)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
if (aContext)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TRAP(errCode, aContext->OpenDbL());
|
sl@0
|
199 |
if(errCode != KErrNone)
|
sl@0
|
200 |
return;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
aHeap.Fail(ii);
|
sl@0
|
203 |
aHeap.Mark();
|
sl@0
|
204 |
TRAPD(r,RunL());
|
sl@0
|
205 |
aHeap.Reset();
|
sl@0
|
206 |
if (r==KErrNone)
|
sl@0
|
207 |
break;
|
sl@0
|
208 |
test(r==KErrNoMemory);
|
sl@0
|
209 |
if (aContext)
|
sl@0
|
210 |
TheDatabase.Close();
|
sl@0
|
211 |
aHeap.Check();
|
sl@0
|
212 |
}
|
sl@0
|
213 |
End();
|
sl@0
|
214 |
if (aContext)
|
sl@0
|
215 |
TheDatabase.Close();
|
sl@0
|
216 |
aHeap.Check();
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
class TFailCreateDatabase : public TFail
|
sl@0
|
220 |
{
|
sl@0
|
221 |
void RunL()
|
sl@0
|
222 |
{DbCreateL();}
|
sl@0
|
223 |
void End()
|
sl@0
|
224 |
{TheDatabase.Close();}
|
sl@0
|
225 |
};
|
sl@0
|
226 |
|
sl@0
|
227 |
class TFailOpenDatabase : public TFail
|
sl@0
|
228 |
{
|
sl@0
|
229 |
void RunL()
|
sl@0
|
230 |
{DbOpenL();}
|
sl@0
|
231 |
void End()
|
sl@0
|
232 |
{TheDatabase.Close();}
|
sl@0
|
233 |
};
|
sl@0
|
234 |
|
sl@0
|
235 |
class TFailShareDatabase : public TFail
|
sl@0
|
236 |
{
|
sl@0
|
237 |
void RunL()
|
sl@0
|
238 |
{DbShareL();}
|
sl@0
|
239 |
void End()
|
sl@0
|
240 |
{TheDatabase.Close();}
|
sl@0
|
241 |
};
|
sl@0
|
242 |
|
sl@0
|
243 |
/**
|
sl@0
|
244 |
@SYMTestCaseID SYSLIB-DBMS-CT-0613
|
sl@0
|
245 |
@SYMTestCaseDesc Tests for allocation failures on creating a database
|
sl@0
|
246 |
@SYMTestPriority Medium
|
sl@0
|
247 |
@SYMTestActions Tests for allocation failure for differently sourced databases
|
sl@0
|
248 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
249 |
@SYMREQ REQ0000
|
sl@0
|
250 |
*/
|
sl@0
|
251 |
LOCAL_C void OriginsL()
|
sl@0
|
252 |
{
|
sl@0
|
253 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0613 Allocation failures on Creating a database "));
|
sl@0
|
254 |
TFailCreateDatabase t1;
|
sl@0
|
255 |
t1.Test(KClientHeap);
|
sl@0
|
256 |
//
|
sl@0
|
257 |
test.Next(_L("Fail to create existing database"));
|
sl@0
|
258 |
TUint att;
|
sl@0
|
259 |
TInt r=TheFs.Att(KTestDatabase,att);
|
sl@0
|
260 |
test (r==KErrNone);
|
sl@0
|
261 |
r=TheDatabase.Create(TheFs,KTestDatabase,TheFormat);
|
sl@0
|
262 |
test (r==KErrAlreadyExists);
|
sl@0
|
263 |
r=TheFs.Att(KTestDatabase,att);
|
sl@0
|
264 |
test (r==KErrNone);
|
sl@0
|
265 |
//
|
sl@0
|
266 |
test.Next(_L("Allocation failures on Open"));
|
sl@0
|
267 |
TFailOpenDatabase t2;
|
sl@0
|
268 |
t2.Test(KClientHeap);
|
sl@0
|
269 |
//
|
sl@0
|
270 |
test.Next(_L("Allocation failures on 1st Share"));
|
sl@0
|
271 |
Connect();
|
sl@0
|
272 |
TFailShareDatabase t3;
|
sl@0
|
273 |
t3.Test(KClientHeap);
|
sl@0
|
274 |
t3.Test(KServerHeap);
|
sl@0
|
275 |
//
|
sl@0
|
276 |
test.Next(_L("Allocation failures on 2nd Share"));
|
sl@0
|
277 |
DbShareL();
|
sl@0
|
278 |
RDbNamedDatabase temp=TheDatabase;TheDatabase=RDbNamedDatabase();
|
sl@0
|
279 |
t3.Test(KClientHeap);
|
sl@0
|
280 |
t3.Test(KServerHeap);
|
sl@0
|
281 |
temp.Close();
|
sl@0
|
282 |
Disconnect();
|
sl@0
|
283 |
test.End();
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
|
sl@0
|
287 |
class TFailCreateTable : public TFail
|
sl@0
|
288 |
{
|
sl@0
|
289 |
void RunL()
|
sl@0
|
290 |
{User::LeaveIfError(TheDatabase.CreateTable(TableName,*TheColSet));}
|
sl@0
|
291 |
};
|
sl@0
|
292 |
|
sl@0
|
293 |
class TFailAlterTable : public TFail
|
sl@0
|
294 |
{
|
sl@0
|
295 |
void RunL()
|
sl@0
|
296 |
{User::LeaveIfError(TheDatabase.AlterTable(TableName,*TheColSet));}
|
sl@0
|
297 |
};
|
sl@0
|
298 |
|
sl@0
|
299 |
class TFailDropTable : public TFail
|
sl@0
|
300 |
{
|
sl@0
|
301 |
void RunL()
|
sl@0
|
302 |
{User::LeaveIfError(TheDatabase.DropTable(TableName));}
|
sl@0
|
303 |
};
|
sl@0
|
304 |
|
sl@0
|
305 |
class TFailCreateIndex : public TFail
|
sl@0
|
306 |
{
|
sl@0
|
307 |
void RunL()
|
sl@0
|
308 |
{User::LeaveIfError(TheDatabase.CreateIndex(IndexName,TableName,*TheKey));}
|
sl@0
|
309 |
};
|
sl@0
|
310 |
|
sl@0
|
311 |
class TFailDropIndex : public TFail
|
sl@0
|
312 |
{
|
sl@0
|
313 |
void RunL()
|
sl@0
|
314 |
{User::LeaveIfError(TheDatabase.DropIndex(IndexName,TableName));}
|
sl@0
|
315 |
};
|
sl@0
|
316 |
|
sl@0
|
317 |
class TFailGetObject : public TFail
|
sl@0
|
318 |
{
|
sl@0
|
319 |
protected:
|
sl@0
|
320 |
void End()
|
sl@0
|
321 |
{delete iObject;}
|
sl@0
|
322 |
protected:
|
sl@0
|
323 |
CBase* iObject;
|
sl@0
|
324 |
};
|
sl@0
|
325 |
|
sl@0
|
326 |
class TFailDatabaseTables : public TFailGetObject
|
sl@0
|
327 |
{
|
sl@0
|
328 |
void RunL()
|
sl@0
|
329 |
{iObject=TheDatabase.TableNamesL();}
|
sl@0
|
330 |
};
|
sl@0
|
331 |
|
sl@0
|
332 |
class TFailDatabaseColSet : public TFailGetObject
|
sl@0
|
333 |
{
|
sl@0
|
334 |
void RunL()
|
sl@0
|
335 |
{iObject=TheDatabase.ColSetL(TableName);}
|
sl@0
|
336 |
};
|
sl@0
|
337 |
|
sl@0
|
338 |
class TFailDatabaseIndexes : public TFailGetObject
|
sl@0
|
339 |
{
|
sl@0
|
340 |
void RunL()
|
sl@0
|
341 |
{iObject=TheDatabase.IndexNamesL(TableName);}
|
sl@0
|
342 |
};
|
sl@0
|
343 |
|
sl@0
|
344 |
class TFailDatabaseKeys : public TFailGetObject
|
sl@0
|
345 |
{
|
sl@0
|
346 |
void RunL()
|
sl@0
|
347 |
{iObject=TheDatabase.KeyL(IndexName,TableName);}
|
sl@0
|
348 |
};
|
sl@0
|
349 |
|
sl@0
|
350 |
const TInt KRowCount=60;
|
sl@0
|
351 |
|
sl@0
|
352 |
LOCAL_C void WriteTableL()
|
sl@0
|
353 |
{
|
sl@0
|
354 |
DbOpenL();
|
sl@0
|
355 |
TInt r=TheTable.Open(TheDatabase,TableName);
|
sl@0
|
356 |
test (r==KErrNone);
|
sl@0
|
357 |
TheDatabase.Begin();
|
sl@0
|
358 |
for (TInt ii=0;ii<KRowCount;++ii)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
TheTable.InsertL();
|
sl@0
|
361 |
TheTable.SetColL(1,TUint((ii*17)%KRowCount));
|
sl@0
|
362 |
TheTable.PutL();
|
sl@0
|
363 |
}
|
sl@0
|
364 |
r=TheDatabase.Commit();
|
sl@0
|
365 |
test (r==KErrNone);
|
sl@0
|
366 |
TheTable.Close();
|
sl@0
|
367 |
TheDatabase.Close();
|
sl@0
|
368 |
}
|
sl@0
|
369 |
|
sl@0
|
370 |
LOCAL_C void DatabaseL()
|
sl@0
|
371 |
{
|
sl@0
|
372 |
test.Start(_L("Adding and dropping tables"));
|
sl@0
|
373 |
DbCreateL();
|
sl@0
|
374 |
// ensure the database locking list has been allocated
|
sl@0
|
375 |
TheDatabase.Begin();
|
sl@0
|
376 |
TheDatabase.Commit();
|
sl@0
|
377 |
//
|
sl@0
|
378 |
CDbColSet *col=CDbColSet::NewLC();
|
sl@0
|
379 |
//
|
sl@0
|
380 |
test.Next(_L("Empty Column Set"));
|
sl@0
|
381 |
__UHEAP_MARK;
|
sl@0
|
382 |
test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
|
sl@0
|
383 |
__UHEAP_MARKEND;
|
sl@0
|
384 |
//
|
sl@0
|
385 |
test.Next(_L("Invalid table name"));
|
sl@0
|
386 |
col->AddL(TDbCol(Column1,EDbColInt32));
|
sl@0
|
387 |
__UHEAP_MARK;
|
sl@0
|
388 |
test(TheDatabase.CreateTable(TableNameX,*col)!=KErrNone);
|
sl@0
|
389 |
__UHEAP_MARKEND;
|
sl@0
|
390 |
//
|
sl@0
|
391 |
test.Next(_L("Invalid column name"));
|
sl@0
|
392 |
col->AddL(TDbCol(Column2X,EDbColBit));
|
sl@0
|
393 |
__UHEAP_MARK;
|
sl@0
|
394 |
test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
|
sl@0
|
395 |
__UHEAP_MARKEND;
|
sl@0
|
396 |
//
|
sl@0
|
397 |
test.Next(_L("Duplicate column name"));
|
sl@0
|
398 |
col->Remove(Column2X);
|
sl@0
|
399 |
col->AddL(TDbCol(Column1Fold,EDbColBit));
|
sl@0
|
400 |
__UHEAP_MARK;
|
sl@0
|
401 |
test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
|
sl@0
|
402 |
__UHEAP_MARKEND;
|
sl@0
|
403 |
//
|
sl@0
|
404 |
test.Next(_L("Invalid column type"));
|
sl@0
|
405 |
col->Remove(Column1);
|
sl@0
|
406 |
col->AddL(TDbCol(Column2,TDbColType(-1)));
|
sl@0
|
407 |
__UHEAP_MARK;
|
sl@0
|
408 |
test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
|
sl@0
|
409 |
__UHEAP_MARKEND;
|
sl@0
|
410 |
//
|
sl@0
|
411 |
test.Next(_L("Invalid maximum length"));
|
sl@0
|
412 |
col->Remove(Column2);
|
sl@0
|
413 |
col->AddL(TDbCol(Column2,EDbColInt32,0));
|
sl@0
|
414 |
__UHEAP_MARK;
|
sl@0
|
415 |
test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
|
sl@0
|
416 |
__UHEAP_MARKEND;
|
sl@0
|
417 |
//
|
sl@0
|
418 |
test.Next(_L("Invalid attributes"));
|
sl@0
|
419 |
col->Remove(Column2);
|
sl@0
|
420 |
TDbCol cc(Column2,EDbColInt32);
|
sl@0
|
421 |
cc.iAttributes=13;
|
sl@0
|
422 |
col->AddL(cc);
|
sl@0
|
423 |
__UHEAP_MARK;
|
sl@0
|
424 |
test(TheDatabase.CreateTable(TableName,*col)!=KErrNone);
|
sl@0
|
425 |
__UHEAP_MARKEND;
|
sl@0
|
426 |
//
|
sl@0
|
427 |
test.Next(_L("Adding/dropping a table name twice"));
|
sl@0
|
428 |
col->Remove(Column2);
|
sl@0
|
429 |
col->AddL(TDbCol(Column2,EDbColText8));
|
sl@0
|
430 |
__UHEAP_MARK;
|
sl@0
|
431 |
test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
|
sl@0
|
432 |
test(TheDatabase.CreateTable(TableName,*col)==KErrAlreadyExists);
|
sl@0
|
433 |
test(TheDatabase.DropTable(TableNameX)!=KErrNone);
|
sl@0
|
434 |
test(TheDatabase.DropTable(TableName)==KErrNone);
|
sl@0
|
435 |
test(TheDatabase.DropTable(TableName)==KErrNotFound);
|
sl@0
|
436 |
__UHEAP_MARKEND;
|
sl@0
|
437 |
//
|
sl@0
|
438 |
test.Next(_L("Adding and dropping indexes"));
|
sl@0
|
439 |
test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
|
sl@0
|
440 |
TheDatabase.Close();
|
sl@0
|
441 |
CDbKey *key=CDbKey::NewLC();
|
sl@0
|
442 |
__UHEAP_MARK;
|
sl@0
|
443 |
DbOpenL();
|
sl@0
|
444 |
test(TheDatabase.CreateIndex(IndexName,TableName,*key)!=KErrNone);
|
sl@0
|
445 |
TheDatabase.Close();
|
sl@0
|
446 |
__UHEAP_MARKEND;
|
sl@0
|
447 |
key->AddL(Column2X());
|
sl@0
|
448 |
__UHEAP_MARK;
|
sl@0
|
449 |
DbOpenL();
|
sl@0
|
450 |
test(TheDatabase.CreateIndex(IndexName,TableName,*key)!=KErrNone);
|
sl@0
|
451 |
TheDatabase.Close();
|
sl@0
|
452 |
__UHEAP_MARKEND;
|
sl@0
|
453 |
key->Clear();
|
sl@0
|
454 |
key->AddL(Column1());
|
sl@0
|
455 |
__UHEAP_MARK;
|
sl@0
|
456 |
DbOpenL();
|
sl@0
|
457 |
test(TheDatabase.CreateIndex(TableNameX,TableName,*key)!=KErrNone);
|
sl@0
|
458 |
TheDatabase.Close();
|
sl@0
|
459 |
__UHEAP_CHECK(0);
|
sl@0
|
460 |
DbOpenL();
|
sl@0
|
461 |
test(TheDatabase.CreateIndex(IndexName,TableNameX,*key)!=KErrNone);
|
sl@0
|
462 |
TheDatabase.Close();
|
sl@0
|
463 |
__UHEAP_MARKEND;
|
sl@0
|
464 |
__UHEAP_MARK;
|
sl@0
|
465 |
DbOpenL();
|
sl@0
|
466 |
test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrNone);
|
sl@0
|
467 |
test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrAlreadyExists);
|
sl@0
|
468 |
test(TheDatabase.DropIndex(TableNameX,TableName)!=KErrNone);
|
sl@0
|
469 |
test(TheDatabase.DropIndex(IndexName,TableNameX)!=KErrNone);
|
sl@0
|
470 |
test(TheDatabase.DropIndex(IndexName,TableName)==KErrNone);
|
sl@0
|
471 |
test(TheDatabase.DropIndex(IndexName,TableName)==KErrNotFound);
|
sl@0
|
472 |
test(TheDatabase.DropTable(TableName)==KErrNone);
|
sl@0
|
473 |
test(TheDatabase.DropIndex(IndexName,TableName)==KErrNotFound);
|
sl@0
|
474 |
TheDatabase.Close();
|
sl@0
|
475 |
__UHEAP_MARKEND;
|
sl@0
|
476 |
//
|
sl@0
|
477 |
test.Next(_L("Allocation failure during DDL"));
|
sl@0
|
478 |
TFailCreateTable fct;
|
sl@0
|
479 |
TFailAlterTable fat;
|
sl@0
|
480 |
TFailDropTable fdt;
|
sl@0
|
481 |
TFailCreateIndex fci;
|
sl@0
|
482 |
TFailDropIndex fdi;
|
sl@0
|
483 |
TheColSet=CDbColSet::NewL();
|
sl@0
|
484 |
TheColSet->AddL(TDbCol(Column1,EDbColUint16));
|
sl@0
|
485 |
TheKey=CDbKey::NewL();
|
sl@0
|
486 |
TheKey->AddL(Column1());
|
sl@0
|
487 |
fct.Test(KClientHeap,KClient);
|
sl@0
|
488 |
WriteTableL();
|
sl@0
|
489 |
TheColSet->AddL(TDbCol(Column2,EDbColText));
|
sl@0
|
490 |
fat.Test(KClientHeap,KClient);
|
sl@0
|
491 |
fci.Test(KClientHeap,KClient);
|
sl@0
|
492 |
fdi.Test(KClientHeap,KClient);
|
sl@0
|
493 |
fdt.Test(KClientHeap,KClient);
|
sl@0
|
494 |
//
|
sl@0
|
495 |
test.Next(_L("Allocation failure during server DDL"));
|
sl@0
|
496 |
Connect();
|
sl@0
|
497 |
TheColSet->Remove(Column2);
|
sl@0
|
498 |
fct.Test(KClientHeap,KServer);
|
sl@0
|
499 |
WriteTableL();
|
sl@0
|
500 |
TheColSet->AddL(TDbCol(Column2,EDbColText));
|
sl@0
|
501 |
fat.Test(KClientHeap,KServer);
|
sl@0
|
502 |
fci.Test(KClientHeap,KServer);
|
sl@0
|
503 |
fdi.Test(KClientHeap,KServer);
|
sl@0
|
504 |
fdt.Test(KClientHeap,KServer);
|
sl@0
|
505 |
//
|
sl@0
|
506 |
TheColSet->Remove(Column2);
|
sl@0
|
507 |
fct.Test(KServerHeap,KServer);
|
sl@0
|
508 |
WriteTableL();
|
sl@0
|
509 |
TheColSet->AddL(TDbCol(Column2,EDbColText));
|
sl@0
|
510 |
fat.Test(KServerHeap,KServer);
|
sl@0
|
511 |
fci.Test(KServerHeap,KServer);
|
sl@0
|
512 |
fdi.Test(KServerHeap,KServer);
|
sl@0
|
513 |
fdt.Test(KServerHeap,KServer);
|
sl@0
|
514 |
Disconnect();
|
sl@0
|
515 |
//
|
sl@0
|
516 |
delete TheColSet;
|
sl@0
|
517 |
delete TheKey;
|
sl@0
|
518 |
|
sl@0
|
519 |
//
|
sl@0
|
520 |
test.Next(_L("Allocation failure on schema enquiry"));
|
sl@0
|
521 |
DbCreateL();
|
sl@0
|
522 |
test(TheDatabase.CreateTable(TableName,*col)==KErrNone);
|
sl@0
|
523 |
test(TheDatabase.CreateIndex(IndexName,TableName,*key)==KErrNone);
|
sl@0
|
524 |
CleanupStack::PopAndDestroy(2); // columns set and key
|
sl@0
|
525 |
TheDatabase.Close();
|
sl@0
|
526 |
TFailDatabaseTables t4;
|
sl@0
|
527 |
TFailDatabaseColSet t5;
|
sl@0
|
528 |
TFailDatabaseIndexes t6;
|
sl@0
|
529 |
TFailDatabaseKeys t7;
|
sl@0
|
530 |
t4.Test(KClientHeap,KClient);
|
sl@0
|
531 |
t5.Test(KClientHeap,KClient);
|
sl@0
|
532 |
t6.Test(KClientHeap,KClient);
|
sl@0
|
533 |
t7.Test(KClientHeap,KClient);
|
sl@0
|
534 |
//
|
sl@0
|
535 |
test.Next(_L("Allocation failure on server schema enquiry"));
|
sl@0
|
536 |
Connect();
|
sl@0
|
537 |
t4.Test(KClientHeap,KServer);
|
sl@0
|
538 |
t4.Test(KServerHeap,KServer);
|
sl@0
|
539 |
t5.Test(KClientHeap,KServer);
|
sl@0
|
540 |
t5.Test(KServerHeap,KServer);
|
sl@0
|
541 |
t6.Test(KClientHeap,KServer);
|
sl@0
|
542 |
t6.Test(KServerHeap,KServer);
|
sl@0
|
543 |
t7.Test(KClientHeap,KServer);
|
sl@0
|
544 |
t7.Test(KServerHeap,KServer);
|
sl@0
|
545 |
Disconnect();
|
sl@0
|
546 |
test.End();
|
sl@0
|
547 |
}
|
sl@0
|
548 |
|
sl@0
|
549 |
class TFailOpenTable : public TFail
|
sl@0
|
550 |
{
|
sl@0
|
551 |
void RunL()
|
sl@0
|
552 |
{User::LeaveIfError(TheTable.Open(TheDatabase,TableName,Access));}
|
sl@0
|
553 |
void End()
|
sl@0
|
554 |
{TheTable.Close();}
|
sl@0
|
555 |
};
|
sl@0
|
556 |
|
sl@0
|
557 |
/**
|
sl@0
|
558 |
@SYMTestCaseID SYSLIB-DBMS-CT-0614
|
sl@0
|
559 |
@SYMTestCaseDesc Tests for allocation failure on opening and closing of database
|
sl@0
|
560 |
@SYMTestPriority Medium
|
sl@0
|
561 |
@SYMTestActions Tests for opening and closing of database
|
sl@0
|
562 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
563 |
@SYMREQ REQ0000
|
sl@0
|
564 |
*/
|
sl@0
|
565 |
LOCAL_C void TestTableL(const THeapFail& aHeap,const TContext& aContext)
|
sl@0
|
566 |
{
|
sl@0
|
567 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0614 Allocation failure on Open "));
|
sl@0
|
568 |
TFailOpenTable fot;
|
sl@0
|
569 |
Access=RDbRowSet::EUpdatable;
|
sl@0
|
570 |
fot.Test(aHeap,aContext);
|
sl@0
|
571 |
Access=RDbRowSet::EReadOnly;
|
sl@0
|
572 |
fot.Test(aHeap,aContext);
|
sl@0
|
573 |
Access=RDbRowSet::EInsertOnly;
|
sl@0
|
574 |
fot.Test(aHeap,aContext);
|
sl@0
|
575 |
//
|
sl@0
|
576 |
test.Next(_L("Open invalid table"));
|
sl@0
|
577 |
aContext.OpenDbL();
|
sl@0
|
578 |
__UHEAP_MARK;
|
sl@0
|
579 |
TInt r=TheTable.Open(TheDatabase,TableNameX);
|
sl@0
|
580 |
test (r!=KErrNone);
|
sl@0
|
581 |
__UHEAP_MARKEND;
|
sl@0
|
582 |
//
|
sl@0
|
583 |
test.Next(_L("Set invalid index"));
|
sl@0
|
584 |
r=TheTable.Open(TheDatabase,TableName);
|
sl@0
|
585 |
test (r==KErrNone);
|
sl@0
|
586 |
__UHEAP_MARK;
|
sl@0
|
587 |
r=TheTable.SetIndex(IndexName2);
|
sl@0
|
588 |
test (r!=KErrNone);
|
sl@0
|
589 |
__UHEAP_MARKEND;
|
sl@0
|
590 |
//
|
sl@0
|
591 |
test.Next(_L("Allocation failure on 2nd Open"));
|
sl@0
|
592 |
RDbTable table(TheTable);
|
sl@0
|
593 |
Access=RDbRowSet::EUpdatable;
|
sl@0
|
594 |
fot.Test(aHeap);
|
sl@0
|
595 |
Access=RDbRowSet::EReadOnly;
|
sl@0
|
596 |
fot.Test(aHeap);
|
sl@0
|
597 |
Access=RDbRowSet::EInsertOnly;
|
sl@0
|
598 |
fot.Test(aHeap);
|
sl@0
|
599 |
table.Close();
|
sl@0
|
600 |
TheDatabase.Close();
|
sl@0
|
601 |
test.End();
|
sl@0
|
602 |
}
|
sl@0
|
603 |
|
sl@0
|
604 |
LOCAL_C void TestTableDDL(const TContext& aContext)
|
sl@0
|
605 |
{
|
sl@0
|
606 |
test.Start(_L("DDL while open"));
|
sl@0
|
607 |
aContext.OpenDbL();
|
sl@0
|
608 |
TInt r=TheTable.Open(TheDatabase,TableName);
|
sl@0
|
609 |
test (r==KErrNone);
|
sl@0
|
610 |
CDbColSet* set=CDbColSet::NewLC();
|
sl@0
|
611 |
set->AddL(TDbCol(Column1,EDbColText));
|
sl@0
|
612 |
r=TheDatabase.CreateTable(TableName2,*set);
|
sl@0
|
613 |
test (r==KErrNone);
|
sl@0
|
614 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
615 |
test (r==KErrNone);
|
sl@0
|
616 |
TheTable.Close();
|
sl@0
|
617 |
r=TheTable.Open(TheDatabase,TableName2);
|
sl@0
|
618 |
test (r==KErrNone);
|
sl@0
|
619 |
//
|
sl@0
|
620 |
set->AddL(TDbCol(Column2,EDbColUint32));
|
sl@0
|
621 |
r=TheDatabase.AlterTable(TableName2,*set);
|
sl@0
|
622 |
test (r==KErrNone);
|
sl@0
|
623 |
CleanupStack::PopAndDestroy(); // set
|
sl@0
|
624 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
625 |
test (r==KErrDisconnected);
|
sl@0
|
626 |
TheTable.Reset();
|
sl@0
|
627 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
628 |
test (r==KErrDisconnected);
|
sl@0
|
629 |
TheTable.Close();
|
sl@0
|
630 |
r=TheTable.Open(TheDatabase,TableName2);
|
sl@0
|
631 |
test (r==KErrNone);
|
sl@0
|
632 |
//
|
sl@0
|
633 |
CDbKey* key=CDbKey::NewLC();
|
sl@0
|
634 |
key->AddL(Column2());
|
sl@0
|
635 |
r=TheDatabase.CreateIndex(IndexName2,TableName,*key);
|
sl@0
|
636 |
test (r==KErrNone);
|
sl@0
|
637 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
638 |
test (r==KErrNone);
|
sl@0
|
639 |
r=TheDatabase.DropIndex(IndexName2,TableName);
|
sl@0
|
640 |
test (r==KErrNone);
|
sl@0
|
641 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
642 |
test (r==KErrNone);
|
sl@0
|
643 |
//
|
sl@0
|
644 |
r=TheDatabase.CreateIndex(IndexName,TableName2,*key);
|
sl@0
|
645 |
test (r==KErrNone);
|
sl@0
|
646 |
CleanupStack::PopAndDestroy(); // key
|
sl@0
|
647 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
648 |
test (r==KErrDisconnected);
|
sl@0
|
649 |
TheTable.Close();
|
sl@0
|
650 |
r=TheTable.Open(TheDatabase,TableName2);
|
sl@0
|
651 |
test (r==KErrNone);
|
sl@0
|
652 |
//
|
sl@0
|
653 |
r=TheDatabase.DropIndex(IndexName,TableName2);
|
sl@0
|
654 |
test (r==KErrNone);
|
sl@0
|
655 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
656 |
test (r==KErrDisconnected);
|
sl@0
|
657 |
TheTable.Close();
|
sl@0
|
658 |
r=TheTable.Open(TheDatabase,TableName2);
|
sl@0
|
659 |
test (r==KErrNone);
|
sl@0
|
660 |
//
|
sl@0
|
661 |
r=TheDatabase.DropTable(TableName2);
|
sl@0
|
662 |
test (r==KErrNone);
|
sl@0
|
663 |
TRAP(r,TheTable.CountL(TheTable.EQuick));
|
sl@0
|
664 |
test (r==KErrDisconnected);
|
sl@0
|
665 |
TheTable.Close();
|
sl@0
|
666 |
TheDatabase.Close();
|
sl@0
|
667 |
test.End();
|
sl@0
|
668 |
}
|
sl@0
|
669 |
|
sl@0
|
670 |
LOCAL_C void TableL()
|
sl@0
|
671 |
{
|
sl@0
|
672 |
test.Start(_L("Testing Client-side"));
|
sl@0
|
673 |
TestTableL(KClientHeap,KClient);
|
sl@0
|
674 |
TestTableDDL(KClient);
|
sl@0
|
675 |
test.Next(_L("Testing Client-Server"));
|
sl@0
|
676 |
Connect();
|
sl@0
|
677 |
TestTableL(KClientHeap,KServer);
|
sl@0
|
678 |
TestTableL(KServerHeap,KServer);
|
sl@0
|
679 |
TestTableDDL(KServer);
|
sl@0
|
680 |
Disconnect();
|
sl@0
|
681 |
test.End();
|
sl@0
|
682 |
}
|
sl@0
|
683 |
|
sl@0
|
684 |
class TFailExecuteSQL : public TFail
|
sl@0
|
685 |
{
|
sl@0
|
686 |
void RunL()
|
sl@0
|
687 |
{User::LeaveIfError(TheDatabase.Execute(*TheSql));}
|
sl@0
|
688 |
void End()
|
sl@0
|
689 |
{}
|
sl@0
|
690 |
};
|
sl@0
|
691 |
|
sl@0
|
692 |
class TFailPrepareView : public TFail
|
sl@0
|
693 |
{
|
sl@0
|
694 |
void RunL()
|
sl@0
|
695 |
{User::LeaveIfError(TheView.Prepare(TheDatabase,*TheSql,Access));}
|
sl@0
|
696 |
void End()
|
sl@0
|
697 |
{TheView.Close();}
|
sl@0
|
698 |
};
|
sl@0
|
699 |
|
sl@0
|
700 |
/**
|
sl@0
|
701 |
@SYMTestCaseID SYSLIB-DBMS-CT-0615
|
sl@0
|
702 |
@SYMTestCaseDesc Tests for allocation failure on prepare
|
sl@0
|
703 |
@SYMTestPriority Medium
|
sl@0
|
704 |
@SYMTestActions Tests for error on updating a row set data
|
sl@0
|
705 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
706 |
@SYMREQ REQ0000
|
sl@0
|
707 |
*/
|
sl@0
|
708 |
LOCAL_C void TestView(const THeapFail& aHeap,const TContext& aContext)
|
sl@0
|
709 |
{
|
sl@0
|
710 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0615 Allocation failure on Prepare "));
|
sl@0
|
711 |
TFailPrepareView fpv;
|
sl@0
|
712 |
TheSql=&SimpleSql;
|
sl@0
|
713 |
Access=RDbRowSet::EUpdatable;
|
sl@0
|
714 |
fpv.Test(aHeap,aContext);
|
sl@0
|
715 |
Access=RDbRowSet::EReadOnly;
|
sl@0
|
716 |
fpv.Test(aHeap,aContext);
|
sl@0
|
717 |
Access=RDbRowSet::EInsertOnly;
|
sl@0
|
718 |
fpv.Test(aHeap,aContext);
|
sl@0
|
719 |
//
|
sl@0
|
720 |
test.Next(_L("Allocation failure on Prepare (complex SQL)"));
|
sl@0
|
721 |
for (TUint ii=0;ii<sizeof(ComplexSql)/sizeof(ComplexSql[0]);++ii)
|
sl@0
|
722 |
{
|
sl@0
|
723 |
TheSql=&ComplexSql[ii];
|
sl@0
|
724 |
Access=RDbRowSet::EUpdatable;
|
sl@0
|
725 |
fpv.Test(aHeap,aContext);
|
sl@0
|
726 |
}
|
sl@0
|
727 |
test.End();
|
sl@0
|
728 |
}
|
sl@0
|
729 |
|
sl@0
|
730 |
/**
|
sl@0
|
731 |
@SYMTestCaseID SYSLIB-DBMS-CT-0616
|
sl@0
|
732 |
@SYMTestCaseDesc Bad SQL query test
|
sl@0
|
733 |
@SYMTestPriority Medium
|
sl@0
|
734 |
@SYMTestActions Test for bad query
|
sl@0
|
735 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
736 |
@SYMREQ REQ0000
|
sl@0
|
737 |
*/
|
sl@0
|
738 |
LOCAL_C void TestSQLL(const TContext& aContext)
|
sl@0
|
739 |
{
|
sl@0
|
740 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0616 Bad SQL "));
|
sl@0
|
741 |
aContext.OpenDbL();
|
sl@0
|
742 |
for (TUint ii=0;ii<sizeof(BadSql)/sizeof(BadSql[0]);++ii)
|
sl@0
|
743 |
test(TheView.Prepare(TheDatabase,TPtrC(BadSql[ii].iSql))==BadSql[ii].iError);
|
sl@0
|
744 |
TheDatabase.Close();
|
sl@0
|
745 |
test.End();
|
sl@0
|
746 |
}
|
sl@0
|
747 |
|
sl@0
|
748 |
/**
|
sl@0
|
749 |
@SYMTestCaseID SYSLIB-DBMS-CT-0617
|
sl@0
|
750 |
@SYMTestCaseDesc Tests for updation of an SQL statement
|
sl@0
|
751 |
@SYMTestPriority Medium
|
sl@0
|
752 |
@SYMTestActions Tests for update SQL statement
|
sl@0
|
753 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
754 |
@SYMREQ REQ0000
|
sl@0
|
755 |
*/
|
sl@0
|
756 |
LOCAL_C void TestUpdateSQL(const THeapFail& aHeap,const TContext& aContext)
|
sl@0
|
757 |
{
|
sl@0
|
758 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0617 Test for UPDATE SQL statement "));
|
sl@0
|
759 |
TFailExecuteSQL fsql;
|
sl@0
|
760 |
TheSql=&UpdateSql;
|
sl@0
|
761 |
fsql.Test(aHeap,aContext);
|
sl@0
|
762 |
test.End();
|
sl@0
|
763 |
}
|
sl@0
|
764 |
|
sl@0
|
765 |
LOCAL_C void ViewL()
|
sl@0
|
766 |
{
|
sl@0
|
767 |
test.Start(_L("Client side"));
|
sl@0
|
768 |
TestView(KClientHeap,KClient);
|
sl@0
|
769 |
TestSQLL(KClient);
|
sl@0
|
770 |
test.Next(_L("Client-Server"));
|
sl@0
|
771 |
Connect();
|
sl@0
|
772 |
TestView(KClientHeap,KServer);
|
sl@0
|
773 |
TestView(KServerHeap,KServer);
|
sl@0
|
774 |
TestSQLL(KServer);
|
sl@0
|
775 |
TestUpdateSQL(KClientHeap,KClient);
|
sl@0
|
776 |
TestUpdateSQL(KServerHeap,KClient);
|
sl@0
|
777 |
Disconnect();
|
sl@0
|
778 |
test.End();
|
sl@0
|
779 |
}
|
sl@0
|
780 |
|
sl@0
|
781 |
//TFailIncrementalUpdate implements the base class' virtual methods - RunL() and End().
|
sl@0
|
782 |
//TFailIncrementalUpdate::RunL() is called by the base class' Test() method, which simulates
|
sl@0
|
783 |
//OOM failures and checks the behaviour of the "incremental update" statement used by RunL().
|
sl@0
|
784 |
class TFailIncrementalUpdate : public TFail
|
sl@0
|
785 |
{
|
sl@0
|
786 |
virtual void RunL()
|
sl@0
|
787 |
{
|
sl@0
|
788 |
RDbUpdate dbUpdate;
|
sl@0
|
789 |
CleanupClosePushL(dbUpdate);
|
sl@0
|
790 |
User::LeaveIfError(dbUpdate.Execute(TheDatabase, _L("UPDATE A SET Name = 'ModifiedNameString' WHERE Id2 > 10")));
|
sl@0
|
791 |
TInt step = 0;
|
sl@0
|
792 |
for(TInt err=1;err>0;++step)
|
sl@0
|
793 |
{
|
sl@0
|
794 |
err = dbUpdate.Next();
|
sl@0
|
795 |
User::LeaveIfError(err);
|
sl@0
|
796 |
}
|
sl@0
|
797 |
test(step > 1);//just to be sure that the test executes dbUpdate.Next() more than once
|
sl@0
|
798 |
CleanupStack::PopAndDestroy(&dbUpdate);
|
sl@0
|
799 |
}
|
sl@0
|
800 |
virtual void End()
|
sl@0
|
801 |
{
|
sl@0
|
802 |
TheDatabase.Close();
|
sl@0
|
803 |
}
|
sl@0
|
804 |
};
|
sl@0
|
805 |
|
sl@0
|
806 |
/**
|
sl@0
|
807 |
@SYMTestCaseID SYSLIB-DBMS-UT-3414
|
sl@0
|
808 |
@SYMTestCaseDesc "Incremental update" operations - OOM test.
|
sl@0
|
809 |
@SYMTestPriority High
|
sl@0
|
810 |
@SYMTestActions Create a test database with one table and insert some records there (> 100).
|
sl@0
|
811 |
Run an "incremental update" operation in OOM loop.
|
sl@0
|
812 |
@SYMTestExpectedResults The test should not fail or panic.
|
sl@0
|
813 |
@SYMDEF INC101720
|
sl@0
|
814 |
*/
|
sl@0
|
815 |
LOCAL_C void IncrementalUpdateTest(const THeapFail& aHeap)
|
sl@0
|
816 |
{
|
sl@0
|
817 |
//Create a test shared database with a table
|
sl@0
|
818 |
TheDatabase.Close();
|
sl@0
|
819 |
TheDbs.Close();
|
sl@0
|
820 |
TInt err = TheDbs.Connect();
|
sl@0
|
821 |
test(err == KErrNone);
|
sl@0
|
822 |
err = TheDatabase.Replace(TheFs, KTestDatabase);
|
sl@0
|
823 |
test(err == KErrNone);
|
sl@0
|
824 |
TheDatabase.Close();
|
sl@0
|
825 |
err = TheDatabase.Open(TheDbs, KTestDatabase);
|
sl@0
|
826 |
test(err == KErrNone);
|
sl@0
|
827 |
//Create a test table and fill the table with enough test records (> 100)
|
sl@0
|
828 |
err = TheDatabase.Execute(_L("CREATE TABLE A(Id COUNTER, Id2 INTEGER, Name LONG VARCHAR)"));
|
sl@0
|
829 |
test(err == KErrNone);
|
sl@0
|
830 |
const TInt KTestRecCount = 110;
|
sl@0
|
831 |
err = TheDatabase.Begin();
|
sl@0
|
832 |
test(err == KErrNone);
|
sl@0
|
833 |
for(TInt i=0;i<KTestRecCount;++i)
|
sl@0
|
834 |
{
|
sl@0
|
835 |
_LIT(KSqlFmtStr, "INSERT INTO A(Id2, Name) VALUES(%d, 'TestNameString')");
|
sl@0
|
836 |
TBuf<100> sql;
|
sl@0
|
837 |
TUint32 id = Math::Random() % KTestRecCount;
|
sl@0
|
838 |
sql.Format(KSqlFmtStr, id + 1);
|
sl@0
|
839 |
err = TheDatabase.Execute(sql);
|
sl@0
|
840 |
test(err == 1);
|
sl@0
|
841 |
}
|
sl@0
|
842 |
err = TheDatabase.Commit();
|
sl@0
|
843 |
test(err == KErrNone);
|
sl@0
|
844 |
//The OOM test
|
sl@0
|
845 |
TFailIncrementalUpdate testObj;
|
sl@0
|
846 |
testObj.Test(aHeap);
|
sl@0
|
847 |
//Cleanup
|
sl@0
|
848 |
TheDatabase.Close();
|
sl@0
|
849 |
TheDbs.Close();
|
sl@0
|
850 |
}
|
sl@0
|
851 |
|
sl@0
|
852 |
//
|
sl@0
|
853 |
// Testing the DBMS for failure modes
|
sl@0
|
854 |
//
|
sl@0
|
855 |
LOCAL_C void doMainL()
|
sl@0
|
856 |
{
|
sl@0
|
857 |
test.Start(_L("Class RDbNamedDatabase"));
|
sl@0
|
858 |
__UHEAP_MARK;
|
sl@0
|
859 |
OriginsL();
|
sl@0
|
860 |
__UHEAP_CHECK(0);
|
sl@0
|
861 |
__UHEAP_MARK;
|
sl@0
|
862 |
Origins2();
|
sl@0
|
863 |
__UHEAP_CHECK(0);
|
sl@0
|
864 |
test.Next(_L("Class RDbDatabase"));
|
sl@0
|
865 |
DatabaseL();
|
sl@0
|
866 |
__UHEAP_CHECK(0);
|
sl@0
|
867 |
test.Next(_L("Class RDbTable"));
|
sl@0
|
868 |
TableL();
|
sl@0
|
869 |
__UHEAP_CHECK(0);
|
sl@0
|
870 |
test.Next(_L("Class RDbView"));
|
sl@0
|
871 |
ViewL();
|
sl@0
|
872 |
__UHEAP_MARKEND;
|
sl@0
|
873 |
test.End();
|
sl@0
|
874 |
}
|
sl@0
|
875 |
|
sl@0
|
876 |
//
|
sl@0
|
877 |
// Prepare the test directory.
|
sl@0
|
878 |
//
|
sl@0
|
879 |
LOCAL_C void setupTestDirectory()
|
sl@0
|
880 |
{
|
sl@0
|
881 |
TInt r=TheFs.Connect();
|
sl@0
|
882 |
test(r==KErrNone);
|
sl@0
|
883 |
//
|
sl@0
|
884 |
r=TheFs.MkDir(KTestDatabase);
|
sl@0
|
885 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
886 |
}
|
sl@0
|
887 |
|
sl@0
|
888 |
//
|
sl@0
|
889 |
// Initialise the cleanup stack.
|
sl@0
|
890 |
//
|
sl@0
|
891 |
LOCAL_C void setupCleanup()
|
sl@0
|
892 |
{
|
sl@0
|
893 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
894 |
test(TheTrapCleanup!=NULL);
|
sl@0
|
895 |
TRAPD(r,\
|
sl@0
|
896 |
{\
|
sl@0
|
897 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
898 |
CleanupStack::PushL((TAny*)0);\
|
sl@0
|
899 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
900 |
});
|
sl@0
|
901 |
test(r==KErrNone);
|
sl@0
|
902 |
}
|
sl@0
|
903 |
|
sl@0
|
904 |
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
905 |
{
|
sl@0
|
906 |
RFs fsSession;
|
sl@0
|
907 |
TInt err = fsSession.Connect();
|
sl@0
|
908 |
if(err == KErrNone)
|
sl@0
|
909 |
{
|
sl@0
|
910 |
TEntry entry;
|
sl@0
|
911 |
if(fsSession.Entry(aFullName, entry) == KErrNone)
|
sl@0
|
912 |
{
|
sl@0
|
913 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
914 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
915 |
if(err != KErrNone)
|
sl@0
|
916 |
{
|
sl@0
|
917 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
918 |
}
|
sl@0
|
919 |
err = fsSession.Delete(aFullName);
|
sl@0
|
920 |
if(err != KErrNone)
|
sl@0
|
921 |
{
|
sl@0
|
922 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
923 |
}
|
sl@0
|
924 |
}
|
sl@0
|
925 |
fsSession.Close();
|
sl@0
|
926 |
}
|
sl@0
|
927 |
else
|
sl@0
|
928 |
{
|
sl@0
|
929 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
930 |
}
|
sl@0
|
931 |
}
|
sl@0
|
932 |
|
sl@0
|
933 |
GLDEF_C TInt E32Main()
|
sl@0
|
934 |
{
|
sl@0
|
935 |
test.Title();
|
sl@0
|
936 |
setupTestDirectory();
|
sl@0
|
937 |
setupCleanup();
|
sl@0
|
938 |
__UHEAP_MARK;
|
sl@0
|
939 |
//
|
sl@0
|
940 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0612 Locating a database "));
|
sl@0
|
941 |
TRAPD(r,TestOpenL());
|
sl@0
|
942 |
test(r==KErrNone);
|
sl@0
|
943 |
PrepareDbFmtString();
|
sl@0
|
944 |
TRAP(r,TestOpen2());
|
sl@0
|
945 |
test(r==KErrNone);
|
sl@0
|
946 |
test.Next(_L("Standard database"));
|
sl@0
|
947 |
TRAP(r,doMainL());
|
sl@0
|
948 |
test(r==KErrNone);
|
sl@0
|
949 |
test.Next(_L("Secure database"));
|
sl@0
|
950 |
TRAP(r,doMainL());
|
sl@0
|
951 |
test(r==KErrNone);
|
sl@0
|
952 |
test.Next(_L("ISAM database"));
|
sl@0
|
953 |
TheFormat=_S("epoc[12345678]");
|
sl@0
|
954 |
TRAP(r,OriginsL());
|
sl@0
|
955 |
test(r==KErrNone);
|
sl@0
|
956 |
TRAP(r,Origins2());
|
sl@0
|
957 |
test(r==KErrNone);
|
sl@0
|
958 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3414 \"Incremental update\" - client test "));
|
sl@0
|
959 |
IncrementalUpdateTest(KClientHeap);
|
sl@0
|
960 |
test.End();
|
sl@0
|
961 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3414 \"Incremental update\" - client-server test "));
|
sl@0
|
962 |
IncrementalUpdateTest(KServerHeap);
|
sl@0
|
963 |
test.End();
|
sl@0
|
964 |
|
sl@0
|
965 |
::DeleteDataFile(KTestDatabase); // clean up data file used by this test - must be done before call to End() - DEF047652
|
sl@0
|
966 |
test.End();
|
sl@0
|
967 |
//
|
sl@0
|
968 |
__UHEAP_MARKEND;
|
sl@0
|
969 |
|
sl@0
|
970 |
delete TheTrapCleanup;
|
sl@0
|
971 |
TheFs.Close();
|
sl@0
|
972 |
test.Close();
|
sl@0
|
973 |
return 0;
|
sl@0
|
974 |
}
|