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
31 #undef __UHEAP_MARKEND
32 #define __UHEAP_MARKEND
34 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
36 #ifndef __linux__ //No CRC test on LINUX
38 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_COMP.CRC");
40 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_COMP.CRC");
44 LOCAL_D RTest test(_L("T_COMP"));
45 LOCAL_D CTrapCleanup* TheTrapCleanup;
48 const TInt KTestCleanupStack=0x20;
51 const TPtrC KTestDir=_L(".\\dbms-tst\\");
53 const TPtrC KTestDir=_L("C:\\dbms-tst\\");
56 //T_BENCH.DB file is created by T_BENCH test and is used by the current test (T_COMP).
57 //T_COMP test will delete T_BENCH.DB at the end as it is no more needed.
58 //If you want to rerun T_COMP test again, you have to ensure that T_BENCH.DB file exists -
59 //run T_BENCH test again.
60 _LIT(KTestFile,"T_BENCH.DB");
62 _LIT(KRomTestFile,"Z:\\TEST\\T_COMP.DAT");
63 _LIT(KCompressedFile,"T_COMP.DB1");
64 _LIT(KDecompressedFile,"T_COMP.DB2");
66 const TStreamId KHelpId=2;
69 // Compress the database
71 LOCAL_C void CompressL(const TDesC& aSource,const TDesC& aTarget,TBool aCompress)
74 CFileMan* man=CFileMan::NewL(TheFs);
75 TInt r=man->Copy(aSource,aTarget);
77 User::LeaveIfError(r);
81 r = f1.Open(TheFs, aSource, EFileStreamText|EFileShareReadersOnly);
84 r=f2.Replace(TheFs, aTarget, EFileWrite);
94 TInt s=Min(rem,copyBuf.MaxSize());
95 r=f1.Read(pos,copyBuf,s);
97 test(copyBuf.Length()==s);
98 r=f2.Write(pos,copyBuf,s);
107 User::LeaveIfError(TheFs.SetAtt(aTarget,0,KEntryAttReadOnly));
109 CFileStore* store=CFileStore::OpenLC(TheFs,aTarget,EFileRead|EFileWrite);
110 TUint t=User::TickCount();
112 RDbStoreDatabase::CompressL(*store,store->Root());
114 RDbStoreDatabase::DecompressL(*store,store->Root());
115 t=User::TickCount()-t;
116 test.Printf(_L("%d ticks\r\n"),t);
119 CleanupStack::PopAndDestroy(); // store
121 TRAPD(lc, err = TheCrcChecker.GenerateCrcL(aTarget));
122 test(err == KErrNone);
123 test(lc == KErrNone);
126 LOCAL_C void CheckTableL(RDbDatabase& aDatabase,RDbDatabase& aCopy,const TDesC& aTable)
128 test.Printf(_L("Processing table %S\n"),&aTable);
130 test (table.Open(aDatabase,aTable,table.EReadOnly)==KErrNone);
132 test (copy.Open(aCopy,aTable,table.EReadOnly)==KErrNone);
133 TInt columns=table.ColCount();
134 while (table.NextL())
139 for (TInt ii=1;ii<=columns;++ii)
141 if (TDbCol::IsLong(table.ColType(ii)))
143 TInt len=table.ColSize(ii);
144 test (len==copy.ColSize(ii));
145 RDbColReadStream strm1;
146 strm1.OpenLC(table,ii);
147 RDbColReadStream strm2;
148 strm2.OpenLC(copy,ii);
153 TInt block=Min(512,len);
154 strm1.ReadL(buf1,block);
155 strm2.ReadL(buf2,block);
159 CleanupStack::PopAndDestroy(2);
163 test (table.ColDes8(ii)==copy.ColDes8(ii));
171 LOCAL_C void CheckL(const TDesC& aSource,const TDesC& aTarget)
173 RDbNamedDatabase comp;
174 RDbNamedDatabase copy;
175 test (comp.Open(TheFs,aSource,TPtrC(),comp.EReadOnly)==KErrNone);
176 test (copy.Open(TheFs,aTarget,TPtrC(),copy.EReadOnly)==KErrNone);
177 CDbTableNames* tables=comp.TableNamesL();
178 for (TInt ii=0;ii<tables->Count();++ii)
179 CheckTableL(comp,copy,(*tables)[ii]);
186 @SYMTestCaseID SYSLIB-DBMS-CT-0593
187 @SYMTestCaseDesc Database compression tests.
188 @SYMTestPriority Medium
189 @SYMTestActions Tests for RDbStoreDatabase::CompressL(),RDbStoreDatabase::DecompressL() functions
190 @SYMTestExpectedResults Test must not fail
193 LOCAL_C void Test(const TDesC& aSource,const TDesC& aTarget,TBool aCompress)
195 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0593 Converting database "));
196 TRAPD(r,CompressL(aSource,aTarget,aCompress));
198 test.Next(_L("Checking database"));
199 TRAP(r,CheckL(aSource,aTarget));
205 // Prepare the test directory.
207 LOCAL_C void setupTestDirectory()
209 TInt r=TheFs.Connect();
212 r=TheFs.MkDir(KTestDir);
213 test(r==KErrNone || r==KErrAlreadyExists);
214 r=TheFs.SetSessionPath(KTestDir);
216 // On TOOLS2 - RFs::SetSessionPath() will affect all RFs Sessions,
217 // the two RFs need same session path anyway
219 r=TheCrcChecker.SetSessionPath(KTestDir);
225 // Initialise the cleanup stack.
227 LOCAL_C void setupCleanup()
229 TheTrapCleanup=CTrapCleanup::New();
230 test(TheTrapCleanup!=NULL);
233 for (TInt i=KTestCleanupStack;i>0;i--)\
234 CleanupStack::PushL((TAny*)0);\
235 CleanupStack::Pop(KTestCleanupStack);\
240 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
243 TInt err = fsSession.Connect();
247 if(fsSession.Entry(aFullName, entry) == KErrNone)
249 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
250 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
253 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
255 err = fsSession.Delete(aFullName);
258 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
265 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
270 // Test streaming conversions.
272 GLDEF_C TInt E32Main()
276 setupTestDirectory();
279 test.Start(_L("Compressing..."));
280 // Don't use the rom test file.
283 TInt err = TheFs.Att(KRomTestFile,dummy);
285 Test(KRomTestFile,KCompressedFile,ETrue);
287 Test(KTestFile,KCompressedFile,ETrue);
289 Test(KTestFile,KCompressedFile,ETrue);
290 test.Next(_L("Decompressing..."));
291 Test(KCompressedFile,KDecompressedFile,EFalse);
296 _LIT(KTestDbName,"C:\\dbms-tst\\T_BENCH.DB");
297 ::DeleteDataFile(KTestDbName);
298 _LIT(KTestDbName1,"C:\\dbms-tst\\T_COMP.DB1");
299 ::DeleteDataFile(KTestDbName1);
300 _LIT(KTestDbName2,"C:\\dbms-tst\\T_COMP.DB2");
301 ::DeleteDataFile(KTestDbName2);
303 _LIT(KTestDbName,"T_BENCH.DB");
304 ::DeleteDataFile(KTestDbName);
305 _LIT(KTestDbName1,"T_COMP.DB1");
306 ::DeleteDataFile(KTestDbName1);
307 _LIT(KTestDbName2,"T_COMP.DB2");
308 ::DeleteDataFile(KTestDbName2);
312 #ifdef CRC_COMP // Exclude Crc checking for this test. It's out of scope.
315 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
319 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
321 TheCrcChecker.ErrorReportL(err, errmsg);
322 RDebug::Print(errmsg);
323 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
328 delete TheTrapCleanup;
329 test.End(); //call to end must be after deletion of files - DEF047652