1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_client.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,327 @@
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 +#include <e32std.h>
1.20 +#include <d32dbms.h>
1.21 +#include <e32test.h>
1.22 +
1.23 +LOCAL_D CTrapCleanup* TheTrapCleanup;
1.24 +
1.25 +LOCAL_D RTest test(_L("T_CLIENT"));
1.26 +
1.27 +LOCAL_D const TPtrC KColName(_S("A_column_name"));
1.28 +LOCAL_D TDbColName VarName(_S("Column_A"));
1.29 +
1.30 +const TInt KTestCleanupStack=0x20;
1.31 +const TInt KLeaveError=-4000;
1.32 +const TInt KColCount=26;
1.33 +
1.34 +/**
1.35 +@SYMTestCaseID SYSLIB-DBMS-CT-0586
1.36 +@SYMTestCaseDesc Tests for TDbCol class
1.37 +@SYMTestPriority Medium
1.38 +@SYMTestActions Tests for column name and type after creating them.
1.39 +@SYMTestExpectedResults Test must not fail
1.40 +@SYMREQ REQ0000
1.41 +*/
1.42 +LOCAL_C void TestTDbCol()
1.43 + {
1.44 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0586 Testing TDbCol "));
1.45 + TDbCol c1(KColName,EDbColText8);
1.46 + test(c1.iName==KColName);
1.47 + test(c1.iType==EDbColText8);
1.48 + test(c1.iMaxLength==KDbDefaultTextColLength);
1.49 + test(c1.iAttributes==0);
1.50 + TDbCol c2(KColName,EDbColText8,1234);
1.51 + test(c2.iName==KColName);
1.52 + test(c2.iType==EDbColText8);
1.53 + test(c2.iMaxLength==1234);
1.54 + test(c2.iAttributes==0);
1.55 + TDbCol c3(KColName,EDbColBit);
1.56 + test(c3.iName==KColName);
1.57 + test(c3.iType==EDbColBit);
1.58 + test(c3.iMaxLength==KDbUndefinedLength);
1.59 + test(c3.iAttributes==0);
1.60 + }
1.61 +
1.62 +/**
1.63 +@SYMTestCaseID SYSLIB-DBMS-CT-0587
1.64 +@SYMTestCaseDesc CDbColSet class test
1.65 +@SYMTestPriority Medium
1.66 +@SYMTestActions Tests for creation of a CDbColSet column set object
1.67 + Tests for adding and removing columns to the column set
1.68 +@SYMTestExpectedResults Test must not fail
1.69 +@SYMREQ REQ0000
1.70 +*/
1.71 +LOCAL_C void TestCDbColSet()
1.72 + {
1.73 + TInt r;
1.74 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0587 ctor and dtor "));
1.75 + CDbColSet* c=CDbColSet::NewL(); // assume it will succeed
1.76 + test(c!=NULL);
1.77 + test (c->Count()==0);
1.78 + delete c;
1.79 + __UHEAP_CHECK(0);
1.80 +#if defined(_DEBUG)
1.81 + __UHEAP_FAILNEXT(1);
1.82 + TRAP(r,c=CDbColSet::NewL());
1.83 +
1.84 + test(r!=KErrNone);
1.85 +
1.86 + __UHEAP_CHECK(0);
1.87 +#endif
1.88 + c=CDbColSet::NewLC();
1.89 + test(c!=NULL);
1.90 + CleanupStack::PopAndDestroy();
1.91 + __UHEAP_CHECK(0);
1.92 + c=CDbColSet::NewL();
1.93 + TDbCol col(KColName,EDbColText,20);
1.94 + c->AddL(col);
1.95 + delete c;
1.96 + __UHEAP_CHECK(0);
1.97 + TRAP(r,c=CDbColSet::NewLC();c->AddL(col);User::Leave(KLeaveError););
1.98 + test(r==KLeaveError);
1.99 + __UHEAP_CHECK(0);
1.100 +//
1.101 + test.Next(_L("Add columns"));
1.102 + c=CDbColSet::NewLC();
1.103 + TInt ii;
1.104 + for (ii=1;ii<=KColCount;ii++)
1.105 + {
1.106 + VarName[7]=(TUint8)('A'-1+ii);
1.107 + test(c->Col(VarName)==NULL);
1.108 + TDbCol column(VarName,EDbColInt32);
1.109 + c->AddL(column);
1.110 + test(c->Count()==ii);
1.111 + test(c->ColNo(VarName)!=KDbNullColNo);
1.112 + test(c->Col(VarName)!=NULL);
1.113 + }
1.114 + test.Next(_L("Check columns: operator[] and ColNo()"));
1.115 + for (ii=1;ii<=KColCount;ii++)
1.116 + {
1.117 + const TDbCol& col=(*c)[ii];
1.118 + test(c->ColNo(col.iName)==ii);
1.119 + }
1.120 + test.Next(_L("Remove columns"));
1.121 + for (ii=1;ii<=KColCount;ii+=2)
1.122 + {
1.123 + VarName[7]=(TUint8)('A'-1+ii);
1.124 + c->Remove(VarName);
1.125 + }
1.126 + test(c->Count()==13);
1.127 + test.Next(_L("Clear"));
1.128 + c->Clear();
1.129 + test(c->Count()==0);
1.130 + CleanupStack::PopAndDestroy();
1.131 + __UHEAP_CHECK(0);
1.132 + test.End();
1.133 + }
1.134 +
1.135 +/**
1.136 +@SYMTestCaseID SYSLIB-DBMS-CT-0588
1.137 +@SYMTestCaseDesc Tests for TDbColSetIter class
1.138 +@SYMTestPriority Medium
1.139 +@SYMTestActions Tests for iterate over the contents of a column set
1.140 +@SYMTestExpectedResults Test must not fail
1.141 +@SYMREQ REQ0000
1.142 +*/
1.143 +LOCAL_C void TestTDbColSetIter()
1.144 + {
1.145 + test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0588 Testing TDbColSetIter "));
1.146 + CDbColSet* c=CDbColSet::NewLC();
1.147 + TInt ii;
1.148 + for (ii=0;ii<KColCount;++ii)
1.149 + {
1.150 + VarName[7]=(TUint8)('A'-1+ii);
1.151 + c->AddL(TDbCol(VarName,EDbColInt32));
1.152 + }
1.153 + TDbColSetIter iter1(*c);
1.154 + TDbColSetIter iter2(iter1);
1.155 + ii=0;
1.156 + for (;;)
1.157 + {
1.158 + test(iter1.Col()==++ii);
1.159 + test(iter1.operator->()==&iter1.operator*());
1.160 + test(&*iter1++==&*iter2);
1.161 + if (!iter1)
1.162 + break;
1.163 + test(&*iter1==&*++iter2);
1.164 + }
1.165 + test(!++iter2);
1.166 + test(ii==KColCount);
1.167 + CleanupStack::PopAndDestroy();
1.168 + __UHEAP_CHECK(0);
1.169 + }
1.170 +
1.171 +/**
1.172 +@SYMTestCaseID SYSLIB-DBMS-CT-0589
1.173 +@SYMTestCaseDesc Tests for TDbCol,CDbColSet,TDbColSetIter classes
1.174 +@SYMTestPriority Medium
1.175 +@SYMTestActions Executes the tests of TDbCol,CDbColSet,TDbColSetIter
1.176 +@SYMTestExpectedResults Test must not fail
1.177 +@SYMREQ REQ0000
1.178 +*/
1.179 +LOCAL_C void TestColSet()
1.180 + {
1.181 + test.Next(_L("@SYMTestCaseID:SYSLIB-DBMS-CT-0589 "));
1.182 + TestTDbCol();
1.183 + test.Next(_L("Testing CDbColSet"));
1.184 + TestCDbColSet();
1.185 + test.Next(_L("Testing TDbColSetIter"));
1.186 + TestTDbColSetIter();
1.187 + test.End();
1.188 + }
1.189 +
1.190 +/**
1.191 +@SYMTestCaseID SYSLIB-DBMS-CT-0590
1.192 +@SYMTestCaseDesc Tests for TDbKeyCol class
1.193 +@SYMTestPriority Medium
1.194 +@SYMTestActions Attempts to test for attributes of the key column together.
1.195 +@SYMTestExpectedResults Test must not fail
1.196 +@SYMREQ REQ0000
1.197 +*/
1.198 +LOCAL_C void TestTDbKeyCol()
1.199 + {
1.200 + test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0590 Testing TDbKeyCol "));
1.201 + TDbKeyCol c1(KColName);
1.202 + test(c1.iName==KColName);
1.203 + test(c1.iOrder==TDbKeyCol::EAsc);
1.204 + TDbKeyCol c2(KColName,TDbKeyCol::EDesc);
1.205 + test(c2.iName==KColName);
1.206 + test(c2.iOrder==TDbKeyCol::EDesc);
1.207 + }
1.208 +
1.209 +/**
1.210 +@SYMTestCaseID SYSLIB-DBMS-CT-0591
1.211 +@SYMTestCaseDesc Tests the CDbKey class
1.212 +@SYMTestPriority Medium
1.213 +@SYMTestActions Tests for the new CDbKey creation using NewL and NewLC functions
1.214 +@SYMTestExpectedResults Test must not fail
1.215 +@SYMREQ REQ0000
1.216 +*/
1.217 +LOCAL_C void TestCDbKey()
1.218 + {
1.219 + TInt r;
1.220 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0591 ctor and dtor "));
1.221 + CDbKey* k=CDbKey::NewL(); // assume it will succeed
1.222 + test(k!=NULL);
1.223 + delete k;
1.224 + __UHEAP_CHECK(0);
1.225 +#if defined(_DEBUG)
1.226 + __UHEAP_FAILNEXT(1);
1.227 + TRAP(r,k=CDbKey::NewL());
1.228 +
1.229 + test(r!=KErrNone);
1.230 +
1.231 + __UHEAP_CHECK(0);
1.232 +#endif
1.233 + k=CDbKey::NewLC();
1.234 + test(k!=NULL);
1.235 + CleanupStack::PopAndDestroy();
1.236 + __UHEAP_CHECK(0);
1.237 + k=CDbKey::NewL();
1.238 + k->AddL(VarName);
1.239 + delete k;
1.240 + __UHEAP_CHECK(0);
1.241 + TRAP(r,k=CDbKey::NewLC();k->AddL(KColName);User::Leave(KLeaveError););
1.242 + test(r==KLeaveError);
1.243 + __UHEAP_CHECK(0);
1.244 +//
1.245 + test.Next(_L("Add key columns"));
1.246 + k=CDbKey::NewLC();
1.247 + TInt ii;
1.248 + for (ii=1;ii<=KColCount;++ii)
1.249 + {
1.250 + VarName[7]=(TUint8)('A'-1+ii);
1.251 + k->AddL(VarName);
1.252 + test(k->Count()==ii);
1.253 + test((*k)[ii-1].iName==VarName);
1.254 + }
1.255 + test.Next(_L("Remove key columns"));
1.256 + for (ii=1;ii<=KColCount;ii+=2)
1.257 + {
1.258 + VarName[7]=TUint8('A'-1+ii);
1.259 + k->Remove(VarName);
1.260 + }
1.261 + test(k->Count()==KColCount/2);
1.262 + test.Next(_L("Clear"));
1.263 + k->Clear();
1.264 + test(k->Count()==0);
1.265 + test.Next(_L("Unique flag"));
1.266 + test(!k->IsUnique());
1.267 + k->MakeUnique();
1.268 + test(k->IsUnique());
1.269 + k->MakeUnique();
1.270 + test(k->IsUnique());
1.271 + CleanupStack::PopAndDestroy();
1.272 + __UHEAP_CHECK(0);
1.273 + test.End();
1.274 + }
1.275 +
1.276 +/**
1.277 +@SYMTestCaseID SYSLIB-DBMS-CT-0592
1.278 +@SYMTestCaseDesc Tests the TDbKeyCol,CDbKey classes
1.279 +@SYMTestPriority Medium
1.280 +@SYMTestActions Executes the TDbKeyCol,CDbKey tests
1.281 +@SYMTestExpectedResults Test must not fail
1.282 +@SYMREQ REQ0000
1.283 +*/
1.284 +LOCAL_C void TestKey()
1.285 + {
1.286 + test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0592 "));
1.287 + TestTDbKeyCol();
1.288 + test.Next(_L("Testing CDbKey"));
1.289 + TestCDbKey();
1.290 + test.End();
1.291 + }
1.292 +
1.293 +
1.294 +LOCAL_C void setupCleanup()
1.295 +//
1.296 +// Initialise the cleanup stack.
1.297 +//
1.298 + {
1.299 + TheTrapCleanup=CTrapCleanup::New();
1.300 + test(TheTrapCleanup!=NULL);
1.301 + TRAPD(r,\
1.302 + {\
1.303 + for (TInt i=KTestCleanupStack;i>0;i--)\
1.304 + CleanupStack::PushL((TAny*)0);\
1.305 + CleanupStack::Pop(KTestCleanupStack);\
1.306 + });
1.307 + test(r==KErrNone);
1.308 + }
1.309 +
1.310 +
1.311 +GLDEF_C TInt E32Main()
1.312 + {
1.313 + test.Title();
1.314 + setupCleanup();
1.315 + __UHEAP_MARK;
1.316 +//
1.317 + test.Start(_L("Test the Column Set"));
1.318 + TRAPD(r,TestColSet();)
1.319 + test(r==KErrNone);
1.320 + __UHEAP_CHECK(0);
1.321 + test.Next(_L("Test the Key"));
1.322 + TRAP(r,TestKey();)
1.323 + test(r==KErrNone);
1.324 + test.End();
1.325 +//
1.326 + __UHEAP_MARKEND;
1.327 + delete TheTrapCleanup;
1.328 + test.Close();
1.329 + return 0;
1.330 + }