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 <e32std.h>
|
sl@0
|
17 |
#include <d32dbms.h>
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
21 |
|
sl@0
|
22 |
LOCAL_D RTest test(_L("t_dbclient"));
|
sl@0
|
23 |
|
sl@0
|
24 |
LOCAL_D const TPtrC KColName(_S("A_column_name"));
|
sl@0
|
25 |
LOCAL_D TDbColName VarName(_S("Column_A"));
|
sl@0
|
26 |
|
sl@0
|
27 |
const TInt KTestCleanupStack=0x20;
|
sl@0
|
28 |
const TInt KLeaveError=-4000;
|
sl@0
|
29 |
const TInt KColCount=26;
|
sl@0
|
30 |
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
@SYMTestCaseID SYSLIB-DBMS-CT-0586
|
sl@0
|
33 |
@SYMTestCaseDesc Tests for TDbCol class
|
sl@0
|
34 |
@SYMTestPriority Medium
|
sl@0
|
35 |
@SYMTestActions Tests for column name and type after creating them.
|
sl@0
|
36 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
37 |
@SYMREQ REQ0000
|
sl@0
|
38 |
*/
|
sl@0
|
39 |
LOCAL_C void TestTDbCol()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0586 Testing TDbCol "));
|
sl@0
|
42 |
TDbCol c1(KColName,EDbColText8);
|
sl@0
|
43 |
test(c1.iName==KColName);
|
sl@0
|
44 |
test(c1.iType==EDbColText8);
|
sl@0
|
45 |
test(c1.iMaxLength==KDbDefaultTextColLength);
|
sl@0
|
46 |
test(c1.iAttributes==0);
|
sl@0
|
47 |
TDbCol c2(KColName,EDbColText8,1234);
|
sl@0
|
48 |
test(c2.iName==KColName);
|
sl@0
|
49 |
test(c2.iType==EDbColText8);
|
sl@0
|
50 |
test(c2.iMaxLength==1234);
|
sl@0
|
51 |
test(c2.iAttributes==0);
|
sl@0
|
52 |
TDbCol c3(KColName,EDbColBit);
|
sl@0
|
53 |
test(c3.iName==KColName);
|
sl@0
|
54 |
test(c3.iType==EDbColBit);
|
sl@0
|
55 |
test(c3.iMaxLength==KDbUndefinedLength);
|
sl@0
|
56 |
test(c3.iAttributes==0);
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
/**
|
sl@0
|
60 |
@SYMTestCaseID SYSLIB-DBMS-CT-0587
|
sl@0
|
61 |
@SYMTestCaseDesc CDbColSet class test
|
sl@0
|
62 |
@SYMTestPriority Medium
|
sl@0
|
63 |
@SYMTestActions Tests for creation of a CDbColSet column set object
|
sl@0
|
64 |
Tests for adding and removing columns to the column set
|
sl@0
|
65 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
66 |
@SYMREQ REQ0000
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
LOCAL_C void TestCDbColSetL()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
TInt r;
|
sl@0
|
71 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0587 ctor and dtor "));
|
sl@0
|
72 |
CDbColSet* c=CDbColSet::NewL(); // assume it will succeed
|
sl@0
|
73 |
test(c!=NULL);
|
sl@0
|
74 |
test (c->Count()==0);
|
sl@0
|
75 |
delete c;
|
sl@0
|
76 |
__UHEAP_CHECK(0);
|
sl@0
|
77 |
#if defined(_DEBUG)
|
sl@0
|
78 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
79 |
TRAP(r,c=CDbColSet::NewL());
|
sl@0
|
80 |
test(r!=KErrNone);
|
sl@0
|
81 |
__UHEAP_CHECK(0);
|
sl@0
|
82 |
#endif
|
sl@0
|
83 |
c=CDbColSet::NewLC();
|
sl@0
|
84 |
test(c!=NULL);
|
sl@0
|
85 |
CleanupStack::PopAndDestroy();
|
sl@0
|
86 |
__UHEAP_CHECK(0);
|
sl@0
|
87 |
c=CDbColSet::NewL();
|
sl@0
|
88 |
TDbCol col(KColName,EDbColText,20);
|
sl@0
|
89 |
c->AddL(col);
|
sl@0
|
90 |
delete c;
|
sl@0
|
91 |
__UHEAP_CHECK(0);
|
sl@0
|
92 |
TRAP(r,c=CDbColSet::NewLC();c->AddL(col);User::Leave(KLeaveError););
|
sl@0
|
93 |
test(r==KLeaveError);
|
sl@0
|
94 |
__UHEAP_CHECK(0);
|
sl@0
|
95 |
//
|
sl@0
|
96 |
test.Next(_L("Add columns"));
|
sl@0
|
97 |
c=CDbColSet::NewLC();
|
sl@0
|
98 |
TInt ii;
|
sl@0
|
99 |
for (ii=1;ii<=KColCount;ii++)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
VarName[7]=(TUint8)('A'-1+ii);
|
sl@0
|
102 |
test(c->Col(VarName)==NULL);
|
sl@0
|
103 |
TDbCol column(VarName,EDbColInt32);
|
sl@0
|
104 |
c->AddL(column);
|
sl@0
|
105 |
test(c->Count()==ii);
|
sl@0
|
106 |
test(c->ColNo(VarName)!=KDbNullColNo);
|
sl@0
|
107 |
test(c->Col(VarName)!=NULL);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
test.Next(_L("Check columns: operator[] and ColNo()"));
|
sl@0
|
110 |
for (ii=1;ii<=KColCount;ii++)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
const TDbCol& col=(*c)[ii];
|
sl@0
|
113 |
test(c->ColNo(col.iName)==ii);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
test.Next(_L("Remove columns"));
|
sl@0
|
116 |
for (ii=1;ii<=KColCount;ii+=2)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
VarName[7]=(TUint8)('A'-1+ii);
|
sl@0
|
119 |
c->Remove(VarName);
|
sl@0
|
120 |
}
|
sl@0
|
121 |
test(c->Count()==13);
|
sl@0
|
122 |
test.Next(_L("Clear"));
|
sl@0
|
123 |
c->Clear();
|
sl@0
|
124 |
test(c->Count()==0);
|
sl@0
|
125 |
CleanupStack::PopAndDestroy();
|
sl@0
|
126 |
__UHEAP_CHECK(0);
|
sl@0
|
127 |
test.End();
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
/**
|
sl@0
|
131 |
@SYMTestCaseID SYSLIB-DBMS-CT-0588
|
sl@0
|
132 |
@SYMTestCaseDesc Tests for TDbColSetIter class
|
sl@0
|
133 |
@SYMTestPriority Medium
|
sl@0
|
134 |
@SYMTestActions Tests for iterate over the contents of a column set
|
sl@0
|
135 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
136 |
@SYMREQ REQ0000
|
sl@0
|
137 |
*/
|
sl@0
|
138 |
LOCAL_C void TestTDbColSetIterL()
|
sl@0
|
139 |
{
|
sl@0
|
140 |
test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0588 Testing TDbColSetIter "));
|
sl@0
|
141 |
CDbColSet* c=CDbColSet::NewLC();
|
sl@0
|
142 |
TInt ii;
|
sl@0
|
143 |
for (ii=0;ii<KColCount;++ii)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
VarName[7]=(TUint8)('A'-1+ii);
|
sl@0
|
146 |
c->AddL(TDbCol(VarName,EDbColInt32));
|
sl@0
|
147 |
}
|
sl@0
|
148 |
TDbColSetIter iter1(*c);
|
sl@0
|
149 |
TDbColSetIter iter2(iter1);
|
sl@0
|
150 |
ii=0;
|
sl@0
|
151 |
for (;;)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
test(iter1.Col()==++ii);
|
sl@0
|
154 |
test(iter1.operator->()==&iter1.operator*());
|
sl@0
|
155 |
test(&*iter1++==&*iter2);
|
sl@0
|
156 |
if (!iter1)
|
sl@0
|
157 |
break;
|
sl@0
|
158 |
test(&*iter1==&*++iter2);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
test(!++iter2);
|
sl@0
|
161 |
test(ii==KColCount);
|
sl@0
|
162 |
CleanupStack::PopAndDestroy();
|
sl@0
|
163 |
__UHEAP_CHECK(0);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
/**
|
sl@0
|
167 |
@SYMTestCaseID SYSLIB-DBMS-CT-0589
|
sl@0
|
168 |
@SYMTestCaseDesc Tests for TDbCol,CDbColSet,TDbColSetIter classes
|
sl@0
|
169 |
@SYMTestPriority Medium
|
sl@0
|
170 |
@SYMTestActions Executes the tests of TDbCol,CDbColSet,TDbColSetIter
|
sl@0
|
171 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
172 |
@SYMREQ REQ0000
|
sl@0
|
173 |
*/
|
sl@0
|
174 |
LOCAL_C void TestColSetL()
|
sl@0
|
175 |
{
|
sl@0
|
176 |
test.Next(_L("@SYMTestCaseID:SYSLIB-DBMS-CT-0589 "));
|
sl@0
|
177 |
TestTDbCol();
|
sl@0
|
178 |
test.Next(_L("Testing CDbColSet"));
|
sl@0
|
179 |
TestCDbColSetL();
|
sl@0
|
180 |
TestTDbColSetIterL();
|
sl@0
|
181 |
test.End();
|
sl@0
|
182 |
}
|
sl@0
|
183 |
|
sl@0
|
184 |
/**
|
sl@0
|
185 |
@SYMTestCaseID SYSLIB-DBMS-CT-0590
|
sl@0
|
186 |
@SYMTestCaseDesc Tests for TDbKeyCol class
|
sl@0
|
187 |
@SYMTestPriority Medium
|
sl@0
|
188 |
@SYMTestActions Attempts to test for attributes of the key column together.
|
sl@0
|
189 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
190 |
@SYMREQ REQ0000
|
sl@0
|
191 |
*/
|
sl@0
|
192 |
LOCAL_C void TestTDbKeyCol()
|
sl@0
|
193 |
{
|
sl@0
|
194 |
test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0590 Testing TDbKeyCol "));
|
sl@0
|
195 |
TDbKeyCol c1(KColName);
|
sl@0
|
196 |
test(c1.iName==KColName);
|
sl@0
|
197 |
test(c1.iOrder==TDbKeyCol::EAsc);
|
sl@0
|
198 |
TDbKeyCol c2(KColName,TDbKeyCol::EDesc);
|
sl@0
|
199 |
test(c2.iName==KColName);
|
sl@0
|
200 |
test(c2.iOrder==TDbKeyCol::EDesc);
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
/**
|
sl@0
|
204 |
@SYMTestCaseID SYSLIB-DBMS-CT-0591
|
sl@0
|
205 |
@SYMTestCaseDesc Tests the CDbKey class
|
sl@0
|
206 |
@SYMTestPriority Medium
|
sl@0
|
207 |
@SYMTestActions Tests for the new CDbKey creation using NewL and NewLC functions
|
sl@0
|
208 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
209 |
@SYMREQ REQ0000
|
sl@0
|
210 |
*/
|
sl@0
|
211 |
LOCAL_C void TestCDbKeyL()
|
sl@0
|
212 |
{
|
sl@0
|
213 |
TInt r;
|
sl@0
|
214 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0591 ctor and dtor "));
|
sl@0
|
215 |
CDbKey* k=CDbKey::NewL(); // assume it will succeed
|
sl@0
|
216 |
test(k!=NULL);
|
sl@0
|
217 |
delete k;
|
sl@0
|
218 |
__UHEAP_CHECK(0);
|
sl@0
|
219 |
#if defined(_DEBUG)
|
sl@0
|
220 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
221 |
TRAP(r,k=CDbKey::NewL());
|
sl@0
|
222 |
test(r!=KErrNone);
|
sl@0
|
223 |
__UHEAP_CHECK(0);
|
sl@0
|
224 |
#endif
|
sl@0
|
225 |
k=CDbKey::NewLC();
|
sl@0
|
226 |
test(k!=NULL);
|
sl@0
|
227 |
CleanupStack::PopAndDestroy();
|
sl@0
|
228 |
__UHEAP_CHECK(0);
|
sl@0
|
229 |
k=CDbKey::NewL();
|
sl@0
|
230 |
k->AddL(VarName);
|
sl@0
|
231 |
delete k;
|
sl@0
|
232 |
__UHEAP_CHECK(0);
|
sl@0
|
233 |
TRAP(r,k=CDbKey::NewLC();k->AddL(KColName);User::Leave(KLeaveError););
|
sl@0
|
234 |
test(r==KLeaveError);
|
sl@0
|
235 |
__UHEAP_CHECK(0);
|
sl@0
|
236 |
//
|
sl@0
|
237 |
test.Next(_L("Add key columns"));
|
sl@0
|
238 |
k=CDbKey::NewLC();
|
sl@0
|
239 |
TInt ii;
|
sl@0
|
240 |
for (ii=1;ii<=KColCount;++ii)
|
sl@0
|
241 |
{
|
sl@0
|
242 |
VarName[7]=(TUint8)('A'-1+ii);
|
sl@0
|
243 |
k->AddL(VarName);
|
sl@0
|
244 |
test(k->Count()==ii);
|
sl@0
|
245 |
test((*k)[ii-1].iName==VarName);
|
sl@0
|
246 |
}
|
sl@0
|
247 |
test.Next(_L("Remove key columns"));
|
sl@0
|
248 |
for (ii=1;ii<=KColCount;ii+=2)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
VarName[7]=TUint8('A'-1+ii);
|
sl@0
|
251 |
k->Remove(VarName);
|
sl@0
|
252 |
}
|
sl@0
|
253 |
test(k->Count()==KColCount/2);
|
sl@0
|
254 |
test.Next(_L("Clear"));
|
sl@0
|
255 |
k->Clear();
|
sl@0
|
256 |
test(k->Count()==0);
|
sl@0
|
257 |
test.Next(_L("Unique flag"));
|
sl@0
|
258 |
test(!k->IsUnique());
|
sl@0
|
259 |
k->MakeUnique();
|
sl@0
|
260 |
test(k->IsUnique());
|
sl@0
|
261 |
k->MakeUnique();
|
sl@0
|
262 |
test(k->IsUnique());
|
sl@0
|
263 |
CleanupStack::PopAndDestroy();
|
sl@0
|
264 |
__UHEAP_CHECK(0);
|
sl@0
|
265 |
test.End();
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
/**
|
sl@0
|
269 |
@SYMTestCaseID SYSLIB-DBMS-CT-0592
|
sl@0
|
270 |
@SYMTestCaseDesc Tests the TDbKeyCol,CDbKey classes
|
sl@0
|
271 |
@SYMTestPriority Medium
|
sl@0
|
272 |
@SYMTestActions Executes the TDbKeyCol,CDbKey tests
|
sl@0
|
273 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
274 |
@SYMREQ REQ0000
|
sl@0
|
275 |
*/
|
sl@0
|
276 |
LOCAL_C void TestKeyL()
|
sl@0
|
277 |
{
|
sl@0
|
278 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0592 "));
|
sl@0
|
279 |
TestTDbKeyCol();
|
sl@0
|
280 |
test.Next(_L("Testing CDbKey"));
|
sl@0
|
281 |
TestCDbKeyL();
|
sl@0
|
282 |
test.End();
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
|
sl@0
|
286 |
LOCAL_C void setupCleanup()
|
sl@0
|
287 |
//
|
sl@0
|
288 |
// Initialise the cleanup stack.
|
sl@0
|
289 |
//
|
sl@0
|
290 |
{
|
sl@0
|
291 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
292 |
test(TheTrapCleanup!=NULL);
|
sl@0
|
293 |
TRAPD(r,\
|
sl@0
|
294 |
{\
|
sl@0
|
295 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
296 |
CleanupStack::PushL((TAny*)0);\
|
sl@0
|
297 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
298 |
});
|
sl@0
|
299 |
test(r==KErrNone);
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
GLDEF_C TInt E32Main()
|
sl@0
|
303 |
//
|
sl@0
|
304 |
// Test Client-side objects
|
sl@0
|
305 |
//
|
sl@0
|
306 |
{
|
sl@0
|
307 |
test.Title();
|
sl@0
|
308 |
setupCleanup();
|
sl@0
|
309 |
__UHEAP_MARK;
|
sl@0
|
310 |
//
|
sl@0
|
311 |
test.Start(_L("Test the Column Set"));
|
sl@0
|
312 |
TRAPD(r,TestColSetL();)
|
sl@0
|
313 |
test(r==KErrNone);
|
sl@0
|
314 |
__UHEAP_CHECK(0);
|
sl@0
|
315 |
test.Next(_L("Test the Key"));
|
sl@0
|
316 |
TRAP(r,TestKeyL();)
|
sl@0
|
317 |
test(r==KErrNone);
|
sl@0
|
318 |
test.End();
|
sl@0
|
319 |
//
|
sl@0
|
320 |
__UHEAP_MARKEND;
|
sl@0
|
321 |
delete TheTrapCleanup;
|
sl@0
|
322 |
test.Close();
|
sl@0
|
323 |
return 0;
|
sl@0
|
324 |
}
|