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 |
// MSVC++ up to 5.0 has problems with expanding inline functions
|
sl@0
|
17 |
// This disables the mad warnings for the whole project
|
sl@0
|
18 |
#if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
|
sl@0
|
19 |
#pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
|
sl@0
|
20 |
#endif
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <d32dbms.h>
|
sl@0
|
23 |
#include <e32test.h>
|
sl@0
|
24 |
#include <s32file.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
LOCAL_D CTrapCleanup* TheTrapCleanup;
|
sl@0
|
27 |
LOCAL_D RFs TheFs;
|
sl@0
|
28 |
LOCAL_D RDbs TheDbs;
|
sl@0
|
29 |
LOCAL_D RDbNamedDatabase TheDatabase;
|
sl@0
|
30 |
LOCAL_D RDbTable TheTable;
|
sl@0
|
31 |
LOCAL_D RDbView TheView;
|
sl@0
|
32 |
|
sl@0
|
33 |
const TInt KTestCleanupStack=0x20;
|
sl@0
|
34 |
const TPtrC KTestDatabase=_L("C:\\DBMS-TST\\T_LIMIT.DB");
|
sl@0
|
35 |
const TPtrC KTableName(_S("TestTable"));
|
sl@0
|
36 |
|
sl@0
|
37 |
const TPtrC KColFormat=_L("c%d");
|
sl@0
|
38 |
|
sl@0
|
39 |
LOCAL_D RTest test(_L("t_dblimit - testing table limits"));
|
sl@0
|
40 |
|
sl@0
|
41 |
const TInt KRecordLimit=8200;
|
sl@0
|
42 |
const TInt KMinInlineLimit=16;
|
sl@0
|
43 |
const TInt KMaxInlineLimit=255;
|
sl@0
|
44 |
|
sl@0
|
45 |
// expected maxima for record structure
|
sl@0
|
46 |
const TInt KMaxColInt64NN=1025;
|
sl@0
|
47 |
const TInt KMaxColText8=32;
|
sl@0
|
48 |
const TInt KMaxColText16=16;
|
sl@0
|
49 |
const TInt KMaxColLongText8=504;
|
sl@0
|
50 |
|
sl@0
|
51 |
|
sl@0
|
52 |
LOCAL_C TBool FitBlob(TInt aCount)
|
sl@0
|
53 |
//
|
sl@0
|
54 |
// Matches heuristics in DBMS
|
sl@0
|
55 |
//
|
sl@0
|
56 |
{
|
sl@0
|
57 |
TInt used=(aCount*(2+(KMinInlineLimit<<3))+7)>>3;
|
sl@0
|
58 |
return used<=KRecordLimit;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
LOCAL_C TInt InlineLimit(TInt aCount)
|
sl@0
|
62 |
//
|
sl@0
|
63 |
// Matches heuristics in DBMS
|
sl@0
|
64 |
//
|
sl@0
|
65 |
{
|
sl@0
|
66 |
TInt used=(aCount*(2+(KMinInlineLimit<<3))+7)>>3;
|
sl@0
|
67 |
TInt space=(KRecordLimit-used);//>>1;
|
sl@0
|
68 |
TInt inl=space/aCount+KMinInlineLimit-1;
|
sl@0
|
69 |
return Min(inl,KMaxInlineLimit);
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
LOCAL_C void OpenDatabase()
|
sl@0
|
73 |
//
|
sl@0
|
74 |
// Open the database
|
sl@0
|
75 |
//
|
sl@0
|
76 |
{
|
sl@0
|
77 |
test (TheDatabase.Open(TheDbs,KTestDatabase)==KErrNone);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
LOCAL_C void CloseDatabase()
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TheDatabase.Close();
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
LOCAL_C void CreateDatabase()
|
sl@0
|
86 |
//
|
sl@0
|
87 |
// Create the database-in-a-store
|
sl@0
|
88 |
//
|
sl@0
|
89 |
{
|
sl@0
|
90 |
test (TheDatabase.Replace(TheFs,KTestDatabase)==KErrNone);
|
sl@0
|
91 |
CloseDatabase();
|
sl@0
|
92 |
OpenDatabase();
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
LOCAL_C void DestroyDatabase()
|
sl@0
|
96 |
{
|
sl@0
|
97 |
test (TheDatabase.Destroy()==KErrNone);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
LOCAL_C CDbColSet* SetLC(TDbCol& aCol,TInt aCount)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
CDbColSet* set=CDbColSet::NewLC();
|
sl@0
|
103 |
TDbColName name;
|
sl@0
|
104 |
while (--aCount>=0)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
name.Format(KColFormat,aCount);
|
sl@0
|
107 |
aCol.iName=name;
|
sl@0
|
108 |
set->AddL(aCol);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
return set;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
LOCAL_C TBool TestL(TDbCol& aCol,TInt aCount)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
test.Printf(_L("\rtesting %d "),aCount);
|
sl@0
|
116 |
CDbColSet* set=SetLC(aCol,aCount);
|
sl@0
|
117 |
TInt r;
|
sl@0
|
118 |
r=TheDatabase.CreateTable(KTableName,*set);
|
sl@0
|
119 |
if (r==KErrNone)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
CDbColSet* comp=TheDatabase.ColSetL(KTableName);
|
sl@0
|
122 |
test (comp->Count()==aCount);
|
sl@0
|
123 |
delete comp;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
CleanupStack::PopAndDestroy();
|
sl@0
|
126 |
if (r==KErrTooBig)
|
sl@0
|
127 |
return EFalse;
|
sl@0
|
128 |
test (r==KErrNone);
|
sl@0
|
129 |
test (TheDatabase.DropTable(KTableName)==KErrNone);
|
sl@0
|
130 |
return ETrue;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
/**
|
sl@0
|
134 |
See how many columns of this sort can be used
|
sl@0
|
135 |
|
sl@0
|
136 |
@SYMTestCaseID SYSLIB-DBMS-CT-0631
|
sl@0
|
137 |
@SYMTestCaseDesc Tests for maximum limits on a Table
|
sl@0
|
138 |
@SYMTestPriority Medium
|
sl@0
|
139 |
@SYMTestActions Tests for creating a table with maximum number of columns
|
sl@0
|
140 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
141 |
@SYMREQ REQ0000
|
sl@0
|
142 |
*/
|
sl@0
|
143 |
LOCAL_C TInt TestTypeL(TDbCol& aCol)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
CreateDatabase();
|
sl@0
|
146 |
TInt ii=1;
|
sl@0
|
147 |
for (;;)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
if (!TestL(aCol,ii))
|
sl@0
|
150 |
break;
|
sl@0
|
151 |
ii<<=1;
|
sl@0
|
152 |
}
|
sl@0
|
153 |
TInt lim=ii>>=1;
|
sl@0
|
154 |
test (lim>0);
|
sl@0
|
155 |
while ((ii>>=1)>0)
|
sl@0
|
156 |
{ // ok<=max<ok+ii*2
|
sl@0
|
157 |
if (TestL(aCol,lim+ii))
|
sl@0
|
158 |
lim+=ii;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
DestroyDatabase();
|
sl@0
|
161 |
test.Printf(_L("\r create %d \n"),lim);
|
sl@0
|
162 |
return lim;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
LOCAL_C void StretchRecordL()
|
sl@0
|
166 |
{
|
sl@0
|
167 |
CreateDatabase();
|
sl@0
|
168 |
TDbCol col;
|
sl@0
|
169 |
col.iType=EDbColLongText8;
|
sl@0
|
170 |
col.iMaxLength=KDbUndefinedLength;
|
sl@0
|
171 |
col.iAttributes=0;
|
sl@0
|
172 |
for (TInt ii=4;FitBlob(ii);ii+=4)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
test.Printf(_L("\rtesting %d "),ii);
|
sl@0
|
175 |
CDbColSet* set=SetLC(col,ii);
|
sl@0
|
176 |
if (ii==4)
|
sl@0
|
177 |
test (TheDatabase.CreateTable(KTableName,*set)==KErrNone);
|
sl@0
|
178 |
else
|
sl@0
|
179 |
test (TheDatabase.AlterTable(KTableName,*set)==KErrNone);
|
sl@0
|
180 |
CleanupStack::PopAndDestroy();
|
sl@0
|
181 |
test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
|
sl@0
|
182 |
if (ii==4)
|
sl@0
|
183 |
TheTable.InsertL();
|
sl@0
|
184 |
else
|
sl@0
|
185 |
{
|
sl@0
|
186 |
TheTable.FirstL();
|
sl@0
|
187 |
TheTable.UpdateL();
|
sl@0
|
188 |
}
|
sl@0
|
189 |
TBuf8<256> buf;
|
sl@0
|
190 |
buf.Fill('-',InlineLimit(ii)/*>>1*/);
|
sl@0
|
191 |
TPtrC8 ptr((const TUint8*)buf.Ptr(),buf.Size());
|
sl@0
|
192 |
TheTable.SetColL(ii-3,ptr);
|
sl@0
|
193 |
TheTable.SetColL(ii-2,ptr);
|
sl@0
|
194 |
TheTable.SetColL(ii-1,ptr);
|
sl@0
|
195 |
TheTable.SetColL(ii,ptr);
|
sl@0
|
196 |
TheTable.PutL();
|
sl@0
|
197 |
TheTable.Close();
|
sl@0
|
198 |
// if ((ii&0x1c)==0)
|
sl@0
|
199 |
// test (TheDatabase.Compact()==KErrNone);
|
sl@0
|
200 |
}
|
sl@0
|
201 |
test (TheDatabase.Compact()==KErrNone);
|
sl@0
|
202 |
test.Printf(_L("\n"));
|
sl@0
|
203 |
CloseDatabase();
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
LOCAL_C void doMainL()
|
sl@0
|
207 |
{
|
sl@0
|
208 |
test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0631 TInt64 NOT NULL "));
|
sl@0
|
209 |
TDbCol col;
|
sl@0
|
210 |
col.iType=EDbColInt64;
|
sl@0
|
211 |
col.iMaxLength=KDbUndefinedLength;
|
sl@0
|
212 |
col.iAttributes=TDbCol::ENotNull;
|
sl@0
|
213 |
test (TestTypeL(col)==KMaxColInt64NN);
|
sl@0
|
214 |
test.Next(_L("Text8"));
|
sl@0
|
215 |
col.iType=EDbColText8;
|
sl@0
|
216 |
col.iAttributes=0;
|
sl@0
|
217 |
test (TestTypeL(col)==KMaxColText8);
|
sl@0
|
218 |
test.Next(_L("Text16"));
|
sl@0
|
219 |
col.iType=EDbColText16;
|
sl@0
|
220 |
test (TestTypeL(col)==KMaxColText16);
|
sl@0
|
221 |
test.Next(_L("LongText8"));
|
sl@0
|
222 |
col.iType=EDbColLongText8;
|
sl@0
|
223 |
test (TestTypeL(col)==KMaxColLongText8);
|
sl@0
|
224 |
test.Next(_L("Stretching the record"));
|
sl@0
|
225 |
StretchRecordL();
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
LOCAL_C void setupTestDirectory()
|
sl@0
|
229 |
//
|
sl@0
|
230 |
// Prepare the test directory.
|
sl@0
|
231 |
//
|
sl@0
|
232 |
{
|
sl@0
|
233 |
TInt r=TheFs.Connect();
|
sl@0
|
234 |
test(r==KErrNone);
|
sl@0
|
235 |
//
|
sl@0
|
236 |
r=TheFs.MkDir(KTestDatabase);
|
sl@0
|
237 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
LOCAL_C void setupCleanup()
|
sl@0
|
241 |
//
|
sl@0
|
242 |
// Initialise the cleanup stack.
|
sl@0
|
243 |
//
|
sl@0
|
244 |
{
|
sl@0
|
245 |
TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
246 |
test(TheTrapCleanup!=NULL);
|
sl@0
|
247 |
TRAPD(r,\
|
sl@0
|
248 |
{\
|
sl@0
|
249 |
for (TInt i=KTestCleanupStack;i>0;i--)\
|
sl@0
|
250 |
CleanupStack::PushL((TAny*)0);\
|
sl@0
|
251 |
CleanupStack::Pop(KTestCleanupStack);\
|
sl@0
|
252 |
});
|
sl@0
|
253 |
test(r==KErrNone);
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
RFs fsSession;
|
sl@0
|
259 |
TInt err = fsSession.Connect();
|
sl@0
|
260 |
if(err == KErrNone)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
TEntry entry;
|
sl@0
|
263 |
if(fsSession.Entry(aFullName, entry) == KErrNone)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
|
sl@0
|
266 |
err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
|
sl@0
|
267 |
if(err != KErrNone)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
|
sl@0
|
270 |
}
|
sl@0
|
271 |
err = fsSession.Delete(aFullName);
|
sl@0
|
272 |
if(err != KErrNone)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
|
sl@0
|
275 |
}
|
sl@0
|
276 |
}
|
sl@0
|
277 |
fsSession.Close();
|
sl@0
|
278 |
}
|
sl@0
|
279 |
else
|
sl@0
|
280 |
{
|
sl@0
|
281 |
RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
|
sl@0
|
282 |
}
|
sl@0
|
283 |
}
|
sl@0
|
284 |
|
sl@0
|
285 |
GLDEF_C TInt E32Main()
|
sl@0
|
286 |
//
|
sl@0
|
287 |
// Test streaming conversions.
|
sl@0
|
288 |
//
|
sl@0
|
289 |
{
|
sl@0
|
290 |
test.Title();
|
sl@0
|
291 |
setupTestDirectory();
|
sl@0
|
292 |
setupCleanup();
|
sl@0
|
293 |
test (TheDbs.Connect()==KErrNone);
|
sl@0
|
294 |
__UHEAP_MARK;
|
sl@0
|
295 |
//
|
sl@0
|
296 |
TRAPD(r,doMainL();)
|
sl@0
|
297 |
test(r==KErrNone);
|
sl@0
|
298 |
|
sl@0
|
299 |
::DeleteDataFile(KTestDatabase); //deletion of data files must be done before call to end - DEF047652
|
sl@0
|
300 |
test.End();
|
sl@0
|
301 |
//
|
sl@0
|
302 |
__UHEAP_MARKEND;
|
sl@0
|
303 |
delete TheTrapCleanup;
|
sl@0
|
304 |
|
sl@0
|
305 |
|
sl@0
|
306 |
|
sl@0
|
307 |
TheDbs.Close();
|
sl@0
|
308 |
TheFs.Close();
|
sl@0
|
309 |
test.Close();
|
sl@0
|
310 |
return 0;
|
sl@0
|
311 |
}
|