1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_limit.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,353 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +// MSVC++ up to 5.0 has problems with expanding inline functions
1.20 +// This disables the mad warnings for the whole project
1.21 +#if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
1.22 +#pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
1.23 +#endif
1.24 +
1.25 +#include <d32dbms.h>
1.26 +#include <e32test.h>
1.27 +#include <s32file.h>
1.28 +
1.29 +#include "crccheck.h"
1.30 +
1.31 +#undef __UHEAP_MARK
1.32 +#define __UHEAP_MARK
1.33 +#undef __UHEAP_MARKEND
1.34 +#define __UHEAP_MARKEND
1.35 +
1.36 +LOCAL_D TDBMS_CRCChecks TheCrcChecker;
1.37 +
1.38 +#ifndef __linux__ //No CRC test on LINUX
1.39 +#ifdef __TOOLS2__
1.40 +const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_LIMIT.CRC");
1.41 +#else
1.42 +const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_LIMIT.CRC");
1.43 +#endif
1.44 +#endif
1.45 +
1.46 +
1.47 +LOCAL_D CTrapCleanup* TheTrapCleanup;
1.48 +LOCAL_D RFs TheFs;
1.49 +LOCAL_D RDbs TheDbs;
1.50 +LOCAL_D RDbNamedDatabase TheDatabase;
1.51 +LOCAL_D RDbTable TheTable;
1.52 +LOCAL_D RDbView TheView;
1.53 +
1.54 +const TInt KTestCleanupStack=0x20;
1.55 +
1.56 +#ifdef __TOOLS2__
1.57 +const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_LIMIT.DB");
1.58 +#else
1.59 +const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_LIMIT.DB");
1.60 +#endif
1.61 +
1.62 +const TPtrC KTableName(_S("TestTable"));
1.63 +
1.64 +const TPtrC KColFormat=_L("c%d");
1.65 +
1.66 +LOCAL_D RTest test(_L("T_LIMIT - testing table limits"));
1.67 +
1.68 +const TInt KRecordLimit=8200;
1.69 +const TInt KMinInlineLimit=16;
1.70 +const TInt KMaxInlineLimit=255;
1.71 +
1.72 +// expected maxima for record structure
1.73 +const TInt KMaxColInt64NN=1025;
1.74 +const TInt KMaxColText8=32;
1.75 +const TInt KMaxColText16=16;
1.76 +const TInt KMaxColLongText8=504;
1.77 +
1.78 +
1.79 +LOCAL_C TBool FitBlob(TInt aCount)
1.80 +//
1.81 +// Matches heuristics in DBMS
1.82 +//
1.83 + {
1.84 + TInt used=(aCount*(2+(KMinInlineLimit<<3))+7)>>3;
1.85 + return used<=KRecordLimit;
1.86 + }
1.87 +
1.88 +LOCAL_C TInt InlineLimit(TInt aCount)
1.89 +//
1.90 +// Matches heuristics in DBMS
1.91 +//
1.92 + {
1.93 + TInt used=(aCount*(2+(KMinInlineLimit<<3))+7)>>3;
1.94 + TInt space=(KRecordLimit-used);//>>1;
1.95 + TInt inl=space/aCount+KMinInlineLimit-1;
1.96 + return Min(inl,KMaxInlineLimit);
1.97 + }
1.98 +
1.99 +LOCAL_C void OpenDatabase()
1.100 +//
1.101 +// Open the database
1.102 +//
1.103 + {
1.104 + test (TheDatabase.Open(TheDbs,KTestDatabase)==KErrNone);
1.105 + }
1.106 +
1.107 +LOCAL_C void CloseDatabase()
1.108 + {
1.109 + TheDatabase.Close();
1.110 + TheCrcChecker.GenerateCrcL(KTestDatabase);
1.111 + }
1.112 +
1.113 +LOCAL_C void CreateDatabase()
1.114 +//
1.115 +// Create the database-in-a-store
1.116 +//
1.117 + {
1.118 + test (TheDatabase.Replace(TheFs,KTestDatabase)==KErrNone);
1.119 + CloseDatabase();
1.120 + OpenDatabase();
1.121 + }
1.122 +
1.123 +LOCAL_C void DestroyDatabase()
1.124 + {
1.125 + test (TheDatabase.Destroy()==KErrNone);
1.126 + }
1.127 +
1.128 +LOCAL_C CDbColSet* SetLC(TDbCol& aCol,TInt aCount)
1.129 + {
1.130 + CDbColSet* set=CDbColSet::NewLC();
1.131 + TDbColName name;
1.132 + while (--aCount>=0)
1.133 + {
1.134 + name.Format(KColFormat,aCount);
1.135 + aCol.iName=name;
1.136 + set->AddL(aCol);
1.137 + }
1.138 + return set;
1.139 + }
1.140 +
1.141 +LOCAL_C TBool TestL(TDbCol& aCol,TInt aCount)
1.142 + {
1.143 + test.Printf(_L("\rtesting %d "),aCount);
1.144 + CDbColSet* set=SetLC(aCol,aCount);
1.145 + TInt r;
1.146 + r=TheDatabase.CreateTable(KTableName,*set);
1.147 + if (r==KErrNone)
1.148 + {
1.149 + CDbColSet* comp=TheDatabase.ColSetL(KTableName);
1.150 + test (comp->Count()==aCount);
1.151 + delete comp;
1.152 + }
1.153 + CleanupStack::PopAndDestroy();
1.154 + if (r==KErrTooBig)
1.155 + return EFalse;
1.156 + test (r==KErrNone);
1.157 + test (TheDatabase.DropTable(KTableName)==KErrNone);
1.158 + return ETrue;
1.159 + }
1.160 +
1.161 +/**
1.162 +See how many columns of this sort can be used
1.163 +
1.164 +@SYMTestCaseID SYSLIB-DBMS-CT-0631
1.165 +@SYMTestCaseDesc Tests for maximum limits on a Table
1.166 +@SYMTestPriority Medium
1.167 +@SYMTestActions Tests for creating a table with maximum number of columns
1.168 +@SYMTestExpectedResults Test must not fail
1.169 +@SYMREQ REQ0000
1.170 +*/
1.171 +LOCAL_C TInt TestTypeL(TDbCol& aCol)
1.172 + {
1.173 + CreateDatabase();
1.174 + TInt ii=1;
1.175 + for (;;)
1.176 + {
1.177 + if (!TestL(aCol,ii))
1.178 + break;
1.179 + ii<<=1;
1.180 + }
1.181 + TInt lim=ii>>=1;
1.182 + test (lim>0);
1.183 + while ((ii>>=1)>0)
1.184 + { // ok<=max<ok+ii*2
1.185 + if (TestL(aCol,lim+ii))
1.186 + lim+=ii;
1.187 + }
1.188 + DestroyDatabase();
1.189 + test.Printf(_L("\r create %d \n"),lim);
1.190 + return lim;
1.191 + }
1.192 +
1.193 +LOCAL_C void StretchRecordL()
1.194 + {
1.195 + CreateDatabase();
1.196 + TDbCol col;
1.197 + col.iType=EDbColLongText8;
1.198 + col.iMaxLength=KDbUndefinedLength;
1.199 + col.iAttributes=0;
1.200 + for (TInt ii=4;FitBlob(ii);ii+=4)
1.201 + {
1.202 + test.Printf(_L("\rtesting %d "),ii);
1.203 + CDbColSet* set=SetLC(col,ii);
1.204 + if (ii==4)
1.205 + test (TheDatabase.CreateTable(KTableName,*set)==KErrNone);
1.206 + else
1.207 + test (TheDatabase.AlterTable(KTableName,*set)==KErrNone);
1.208 + CleanupStack::PopAndDestroy();
1.209 + test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
1.210 + if (ii==4)
1.211 + TheTable.InsertL();
1.212 + else
1.213 + {
1.214 + TheTable.FirstL();
1.215 + TheTable.UpdateL();
1.216 + }
1.217 + TBuf8<256> buf;
1.218 + buf.Fill('-',InlineLimit(ii)/*>>1*/);
1.219 + TPtrC8 ptr((const TUint8*)buf.Ptr(),buf.Size());
1.220 + TheTable.SetColL(ii-3,ptr);
1.221 + TheTable.SetColL(ii-2,ptr);
1.222 + TheTable.SetColL(ii-1,ptr);
1.223 + TheTable.SetColL(ii,ptr);
1.224 + TheTable.PutL();
1.225 + TheTable.Close();
1.226 +// if ((ii&0x1c)==0)
1.227 +// test (TheDatabase.Compact()==KErrNone);
1.228 + }
1.229 + test (TheDatabase.Compact()==KErrNone);
1.230 + test.Printf(_L("\n"));
1.231 + CloseDatabase();
1.232 + }
1.233 +
1.234 +LOCAL_C void doMain()
1.235 + {
1.236 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0631 TInt64 NOT NULL "));
1.237 + TDbCol col;
1.238 + col.iType=EDbColInt64;
1.239 + col.iMaxLength=KDbUndefinedLength;
1.240 + col.iAttributes=TDbCol::ENotNull;
1.241 + test (TestTypeL(col)==KMaxColInt64NN);
1.242 + test.Next(_L("Text8"));
1.243 + col.iType=EDbColText8;
1.244 + col.iAttributes=0;
1.245 + test (TestTypeL(col)==KMaxColText8);
1.246 + test.Next(_L("Text16"));
1.247 + col.iType=EDbColText16;
1.248 + test (TestTypeL(col)==KMaxColText16);
1.249 + test.Next(_L("LongText8"));
1.250 + col.iType=EDbColLongText8;
1.251 + test (TestTypeL(col)==KMaxColLongText8);
1.252 + test.Next(_L("Stretching the record"));
1.253 + StretchRecordL();
1.254 + }
1.255 +
1.256 +LOCAL_C void setupTestDirectory()
1.257 +//
1.258 +// Prepare the test directory.
1.259 +//
1.260 + {
1.261 + TInt r=TheFs.Connect();
1.262 + test(r==KErrNone);
1.263 +//
1.264 + r=TheFs.MkDir(KTestDatabase);
1.265 + test(r==KErrNone || r==KErrAlreadyExists);
1.266 + }
1.267 +
1.268 +LOCAL_C void setupCleanup()
1.269 +//
1.270 +// Initialise the cleanup stack.
1.271 +//
1.272 + {
1.273 + TheTrapCleanup=CTrapCleanup::New();
1.274 + test(TheTrapCleanup!=NULL);
1.275 + TRAPD(r,\
1.276 + {\
1.277 + for (TInt i=KTestCleanupStack;i>0;i--)\
1.278 + CleanupStack::PushL((TAny*)0);\
1.279 + CleanupStack::Pop(KTestCleanupStack);\
1.280 + });
1.281 + test(r==KErrNone);
1.282 + }
1.283 +
1.284 +LOCAL_C void DeleteDataFile(const TDesC& aFullName)
1.285 + {
1.286 + RFs fsSession;
1.287 + TInt err = fsSession.Connect();
1.288 + if(err == KErrNone)
1.289 + {
1.290 + TEntry entry;
1.291 + if(fsSession.Entry(aFullName, entry) == KErrNone)
1.292 + {
1.293 + RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
1.294 + err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
1.295 + if(err != KErrNone)
1.296 + {
1.297 + RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
1.298 + }
1.299 + err = fsSession.Delete(aFullName);
1.300 + if(err != KErrNone)
1.301 + {
1.302 + RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
1.303 + }
1.304 + }
1.305 + fsSession.Close();
1.306 + }
1.307 + else
1.308 + {
1.309 + RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
1.310 + }
1.311 + }
1.312 +
1.313 +GLDEF_C TInt E32Main()
1.314 + {
1.315 + test.Title();
1.316 + setupTestDirectory();
1.317 + setupCleanup();
1.318 +#ifndef __TOOLS2__
1.319 + test (TheDbs.Connect()==KErrNone);
1.320 +#endif
1.321 + __UHEAP_MARK;
1.322 +//
1.323 + TRAPD(r,doMain();)
1.324 + test(r==KErrNone);
1.325 +
1.326 + test.Printf(_L("Waiting for server exit\n"));
1.327 + const TUint KExitDelay=6*0x100000; // ~6 seconds
1.328 + User::After(KExitDelay);
1.329 +
1.330 + ::DeleteDataFile(KTestDatabase); //deletion of data files must be done before call to end - DEF047652
1.331 +#ifndef __linux__
1.332 + TInt err;
1.333 +#ifndef __TOOLS2__
1.334 + TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
1.335 + test(err==KErrNone);
1.336 + test(lc==KErrNone);
1.337 +#else
1.338 + TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
1.339 + TPtrC errmsg;
1.340 + TheCrcChecker.ErrorReportL(err, errmsg);
1.341 + RDebug::Print(errmsg);
1.342 + test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
1.343 +#endif
1.344 +#endif
1.345 + test.End();
1.346 +//
1.347 + __UHEAP_MARKEND;
1.348 + delete TheTrapCleanup;
1.349 +
1.350 +#ifndef __TOOLS2__
1.351 + TheDbs.Close();
1.352 +#endif
1.353 + TheFs.Close();
1.354 + test.Close();
1.355 + return 0;
1.356 + }