Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 // MSVC++ up to 5.0 has problems with expanding inline functions
17 // This disables the mad warnings for the whole project
18 #if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
19 #pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
30 #undef __UHEAP_MARKEND
31 #define __UHEAP_MARKEND
33 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
35 #ifndef __linux__ //No CRC test on LINUX
37 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_LIMIT.CRC");
39 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_LIMIT.CRC");
44 LOCAL_D CTrapCleanup* TheTrapCleanup;
47 LOCAL_D RDbNamedDatabase TheDatabase;
48 LOCAL_D RDbTable TheTable;
49 LOCAL_D RDbView TheView;
51 const TInt KTestCleanupStack=0x20;
54 const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_LIMIT.DB");
56 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_LIMIT.DB");
59 const TPtrC KTableName(_S("TestTable"));
61 const TPtrC KColFormat=_L("c%d");
63 LOCAL_D RTest test(_L("T_LIMIT - testing table limits"));
65 const TInt KRecordLimit=8200;
66 const TInt KMinInlineLimit=16;
67 const TInt KMaxInlineLimit=255;
69 // expected maxima for record structure
70 const TInt KMaxColInt64NN=1025;
71 const TInt KMaxColText8=32;
72 const TInt KMaxColText16=16;
73 const TInt KMaxColLongText8=504;
76 LOCAL_C TBool FitBlob(TInt aCount)
78 // Matches heuristics in DBMS
81 TInt used=(aCount*(2+(KMinInlineLimit<<3))+7)>>3;
82 return used<=KRecordLimit;
85 LOCAL_C TInt InlineLimit(TInt aCount)
87 // Matches heuristics in DBMS
90 TInt used=(aCount*(2+(KMinInlineLimit<<3))+7)>>3;
91 TInt space=(KRecordLimit-used);//>>1;
92 TInt inl=space/aCount+KMinInlineLimit-1;
93 return Min(inl,KMaxInlineLimit);
96 LOCAL_C void OpenDatabase()
101 test (TheDatabase.Open(TheDbs,KTestDatabase)==KErrNone);
104 LOCAL_C void CloseDatabase()
107 TheCrcChecker.GenerateCrcL(KTestDatabase);
110 LOCAL_C void CreateDatabase()
112 // Create the database-in-a-store
115 test (TheDatabase.Replace(TheFs,KTestDatabase)==KErrNone);
120 LOCAL_C void DestroyDatabase()
122 test (TheDatabase.Destroy()==KErrNone);
125 LOCAL_C CDbColSet* SetLC(TDbCol& aCol,TInt aCount)
127 CDbColSet* set=CDbColSet::NewLC();
131 name.Format(KColFormat,aCount);
138 LOCAL_C TBool TestL(TDbCol& aCol,TInt aCount)
140 test.Printf(_L("\rtesting %d "),aCount);
141 CDbColSet* set=SetLC(aCol,aCount);
143 r=TheDatabase.CreateTable(KTableName,*set);
146 CDbColSet* comp=TheDatabase.ColSetL(KTableName);
147 test (comp->Count()==aCount);
150 CleanupStack::PopAndDestroy();
154 test (TheDatabase.DropTable(KTableName)==KErrNone);
159 See how many columns of this sort can be used
161 @SYMTestCaseID SYSLIB-DBMS-CT-0631
162 @SYMTestCaseDesc Tests for maximum limits on a Table
163 @SYMTestPriority Medium
164 @SYMTestActions Tests for creating a table with maximum number of columns
165 @SYMTestExpectedResults Test must not fail
168 LOCAL_C TInt TestTypeL(TDbCol& aCol)
182 if (TestL(aCol,lim+ii))
186 test.Printf(_L("\r create %d \n"),lim);
190 LOCAL_C void StretchRecordL()
194 col.iType=EDbColLongText8;
195 col.iMaxLength=KDbUndefinedLength;
197 for (TInt ii=4;FitBlob(ii);ii+=4)
199 test.Printf(_L("\rtesting %d "),ii);
200 CDbColSet* set=SetLC(col,ii);
202 test (TheDatabase.CreateTable(KTableName,*set)==KErrNone);
204 test (TheDatabase.AlterTable(KTableName,*set)==KErrNone);
205 CleanupStack::PopAndDestroy();
206 test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
215 buf.Fill('-',InlineLimit(ii)/*>>1*/);
216 TPtrC8 ptr((const TUint8*)buf.Ptr(),buf.Size());
217 TheTable.SetColL(ii-3,ptr);
218 TheTable.SetColL(ii-2,ptr);
219 TheTable.SetColL(ii-1,ptr);
220 TheTable.SetColL(ii,ptr);
224 // test (TheDatabase.Compact()==KErrNone);
226 test (TheDatabase.Compact()==KErrNone);
227 test.Printf(_L("\n"));
231 LOCAL_C void doMain()
233 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0631 TInt64 NOT NULL "));
235 col.iType=EDbColInt64;
236 col.iMaxLength=KDbUndefinedLength;
237 col.iAttributes=TDbCol::ENotNull;
238 test (TestTypeL(col)==KMaxColInt64NN);
239 test.Next(_L("Text8"));
240 col.iType=EDbColText8;
242 test (TestTypeL(col)==KMaxColText8);
243 test.Next(_L("Text16"));
244 col.iType=EDbColText16;
245 test (TestTypeL(col)==KMaxColText16);
246 test.Next(_L("LongText8"));
247 col.iType=EDbColLongText8;
248 test (TestTypeL(col)==KMaxColLongText8);
249 test.Next(_L("Stretching the record"));
253 LOCAL_C void setupTestDirectory()
255 // Prepare the test directory.
258 TInt r=TheFs.Connect();
261 r=TheFs.MkDir(KTestDatabase);
262 test(r==KErrNone || r==KErrAlreadyExists);
265 LOCAL_C void setupCleanup()
267 // Initialise the cleanup stack.
270 TheTrapCleanup=CTrapCleanup::New();
271 test(TheTrapCleanup!=NULL);
274 for (TInt i=KTestCleanupStack;i>0;i--)\
275 CleanupStack::PushL((TAny*)0);\
276 CleanupStack::Pop(KTestCleanupStack);\
281 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
284 TInt err = fsSession.Connect();
288 if(fsSession.Entry(aFullName, entry) == KErrNone)
290 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
291 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
294 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
296 err = fsSession.Delete(aFullName);
299 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
306 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
310 GLDEF_C TInt E32Main()
313 setupTestDirectory();
316 test (TheDbs.Connect()==KErrNone);
323 test.Printf(_L("Waiting for server exit\n"));
324 const TUint KExitDelay=6*0x100000; // ~6 seconds
325 User::After(KExitDelay);
327 ::DeleteDataFile(KTestDatabase); //deletion of data files must be done before call to end - DEF047652
331 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
335 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
337 TheCrcChecker.ErrorReportL(err, errmsg);
338 RDebug::Print(errmsg);
339 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
345 delete TheTrapCleanup;