os/persistentdata/persistentstorage/dbms/tdbms/t_dbclient.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/tdbms/t_dbclient.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,324 @@
     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_dbclient"));
    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 TestCDbColSetL()
    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 +	test(r!=KErrNone);
    1.84 +	__UHEAP_CHECK(0);
    1.85 +#endif
    1.86 +	c=CDbColSet::NewLC();
    1.87 +	test(c!=NULL);
    1.88 +	CleanupStack::PopAndDestroy();
    1.89 +	__UHEAP_CHECK(0);
    1.90 +	c=CDbColSet::NewL();
    1.91 +	TDbCol col(KColName,EDbColText,20);
    1.92 +	c->AddL(col);
    1.93 +	delete c;
    1.94 +	__UHEAP_CHECK(0);
    1.95 +	TRAP(r,c=CDbColSet::NewLC();c->AddL(col);User::Leave(KLeaveError););
    1.96 +	test(r==KLeaveError);
    1.97 +	__UHEAP_CHECK(0);
    1.98 +//
    1.99 +	test.Next(_L("Add columns"));
   1.100 +	c=CDbColSet::NewLC();
   1.101 +	TInt ii;
   1.102 +	for (ii=1;ii<=KColCount;ii++)
   1.103 +		{
   1.104 +		VarName[7]=(TUint8)('A'-1+ii);
   1.105 +		test(c->Col(VarName)==NULL);
   1.106 +		TDbCol column(VarName,EDbColInt32);
   1.107 +		c->AddL(column);
   1.108 +		test(c->Count()==ii);
   1.109 +		test(c->ColNo(VarName)!=KDbNullColNo);
   1.110 +		test(c->Col(VarName)!=NULL);
   1.111 +		}
   1.112 +	test.Next(_L("Check columns: operator[] and ColNo()"));
   1.113 +	for (ii=1;ii<=KColCount;ii++)
   1.114 +		{
   1.115 +		const TDbCol& col=(*c)[ii];
   1.116 +		test(c->ColNo(col.iName)==ii);
   1.117 +		}
   1.118 +	test.Next(_L("Remove columns"));
   1.119 +	for (ii=1;ii<=KColCount;ii+=2)
   1.120 +		{
   1.121 +		VarName[7]=(TUint8)('A'-1+ii);
   1.122 +		c->Remove(VarName);
   1.123 +		}
   1.124 +	test(c->Count()==13);
   1.125 +	test.Next(_L("Clear"));
   1.126 +	c->Clear();
   1.127 +	test(c->Count()==0);
   1.128 +	CleanupStack::PopAndDestroy();
   1.129 +	__UHEAP_CHECK(0);
   1.130 +	test.End();
   1.131 +	}
   1.132 +
   1.133 +/**
   1.134 +@SYMTestCaseID          SYSLIB-DBMS-CT-0588
   1.135 +@SYMTestCaseDesc        Tests for TDbColSetIter class
   1.136 +@SYMTestPriority        Medium
   1.137 +@SYMTestActions        	Tests for iterate over the contents of a column set
   1.138 +@SYMTestExpectedResults Test must not fail
   1.139 +@SYMREQ                 REQ0000
   1.140 +*/
   1.141 +LOCAL_C void TestTDbColSetIterL()
   1.142 +	{
   1.143 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0588 Testing TDbColSetIter "));
   1.144 +	CDbColSet* c=CDbColSet::NewLC();
   1.145 +	TInt ii;
   1.146 +	for (ii=0;ii<KColCount;++ii)
   1.147 +		{
   1.148 +		VarName[7]=(TUint8)('A'-1+ii);
   1.149 +		c->AddL(TDbCol(VarName,EDbColInt32));
   1.150 +		}
   1.151 +	TDbColSetIter iter1(*c);
   1.152 +	TDbColSetIter iter2(iter1);
   1.153 +	ii=0;
   1.154 +	for (;;)
   1.155 +		{
   1.156 +		test(iter1.Col()==++ii);
   1.157 +		test(iter1.operator->()==&iter1.operator*());
   1.158 +		test(&*iter1++==&*iter2);
   1.159 +		if (!iter1)
   1.160 +			break;
   1.161 +		test(&*iter1==&*++iter2);
   1.162 +		}
   1.163 +	test(!++iter2);
   1.164 +	test(ii==KColCount);
   1.165 +	CleanupStack::PopAndDestroy();
   1.166 +	__UHEAP_CHECK(0);
   1.167 +	}
   1.168 +
   1.169 +/**
   1.170 +@SYMTestCaseID          SYSLIB-DBMS-CT-0589
   1.171 +@SYMTestCaseDesc        Tests for TDbCol,CDbColSet,TDbColSetIter classes
   1.172 +@SYMTestPriority        Medium
   1.173 +@SYMTestActions        	Executes the tests of TDbCol,CDbColSet,TDbColSetIter
   1.174 +@SYMTestExpectedResults Test must not fail
   1.175 +@SYMREQ                 REQ0000
   1.176 +*/
   1.177 +LOCAL_C void TestColSetL()
   1.178 +	{
   1.179 +	test.Next(_L("@SYMTestCaseID:SYSLIB-DBMS-CT-0589 "));
   1.180 +	TestTDbCol();
   1.181 +	test.Next(_L("Testing CDbColSet"));
   1.182 +	TestCDbColSetL();
   1.183 +	TestTDbColSetIterL();
   1.184 +	test.End();
   1.185 +	}
   1.186 +
   1.187 +/**
   1.188 +@SYMTestCaseID          SYSLIB-DBMS-CT-0590
   1.189 +@SYMTestCaseDesc        Tests for TDbKeyCol class
   1.190 +@SYMTestPriority        Medium
   1.191 +@SYMTestActions         Attempts to test for attributes of the key column together.
   1.192 +@SYMTestExpectedResults Test must not fail
   1.193 +@SYMREQ                 REQ0000
   1.194 +*/
   1.195 +LOCAL_C void TestTDbKeyCol()
   1.196 +	{
   1.197 +	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0590 Testing TDbKeyCol "));
   1.198 +	TDbKeyCol c1(KColName);
   1.199 +	test(c1.iName==KColName);
   1.200 +	test(c1.iOrder==TDbKeyCol::EAsc);
   1.201 +	TDbKeyCol c2(KColName,TDbKeyCol::EDesc);
   1.202 +	test(c2.iName==KColName);
   1.203 +	test(c2.iOrder==TDbKeyCol::EDesc);
   1.204 +	}
   1.205 +
   1.206 +/**
   1.207 +@SYMTestCaseID          SYSLIB-DBMS-CT-0591
   1.208 +@SYMTestCaseDesc        Tests the CDbKey class
   1.209 +@SYMTestPriority        Medium
   1.210 +@SYMTestActions         Tests for the new CDbKey creation using NewL and NewLC functions
   1.211 +@SYMTestExpectedResults Test must not fail
   1.212 +@SYMREQ                 REQ0000
   1.213 +*/
   1.214 +LOCAL_C void TestCDbKeyL()
   1.215 +	{
   1.216 +	TInt r;
   1.217 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0591 ctor and dtor "));
   1.218 +	CDbKey* k=CDbKey::NewL();		// assume it will succeed
   1.219 +	test(k!=NULL);
   1.220 +	delete k;
   1.221 +	__UHEAP_CHECK(0);
   1.222 +#if defined(_DEBUG)
   1.223 +	__UHEAP_FAILNEXT(1);
   1.224 +	TRAP(r,k=CDbKey::NewL());
   1.225 +	test(r!=KErrNone);
   1.226 +	__UHEAP_CHECK(0);
   1.227 +#endif
   1.228 +	k=CDbKey::NewLC();
   1.229 +	test(k!=NULL);
   1.230 +	CleanupStack::PopAndDestroy();
   1.231 +	__UHEAP_CHECK(0);
   1.232 +	k=CDbKey::NewL();
   1.233 +	k->AddL(VarName);
   1.234 +	delete k;
   1.235 +	__UHEAP_CHECK(0);
   1.236 +	TRAP(r,k=CDbKey::NewLC();k->AddL(KColName);User::Leave(KLeaveError););
   1.237 +	test(r==KLeaveError);
   1.238 +	__UHEAP_CHECK(0);
   1.239 +//
   1.240 +	test.Next(_L("Add key columns"));
   1.241 +	k=CDbKey::NewLC();
   1.242 +	TInt ii;
   1.243 +	for (ii=1;ii<=KColCount;++ii)
   1.244 +		{
   1.245 +		VarName[7]=(TUint8)('A'-1+ii);
   1.246 +		k->AddL(VarName);
   1.247 +		test(k->Count()==ii);
   1.248 +		test((*k)[ii-1].iName==VarName);
   1.249 +		}
   1.250 +	test.Next(_L("Remove key columns"));
   1.251 +	for (ii=1;ii<=KColCount;ii+=2)
   1.252 +		{
   1.253 +		VarName[7]=TUint8('A'-1+ii);
   1.254 +		k->Remove(VarName);
   1.255 +		}
   1.256 +	test(k->Count()==KColCount/2);
   1.257 +	test.Next(_L("Clear"));
   1.258 +	k->Clear();
   1.259 +	test(k->Count()==0);
   1.260 +	test.Next(_L("Unique flag"));
   1.261 +	test(!k->IsUnique());
   1.262 +	k->MakeUnique();
   1.263 +	test(k->IsUnique());
   1.264 +	k->MakeUnique();
   1.265 +	test(k->IsUnique());
   1.266 +	CleanupStack::PopAndDestroy();
   1.267 +	__UHEAP_CHECK(0);
   1.268 +	test.End();
   1.269 +	}
   1.270 +
   1.271 +/**
   1.272 +@SYMTestCaseID          SYSLIB-DBMS-CT-0592
   1.273 +@SYMTestCaseDesc        Tests the TDbKeyCol,CDbKey classes
   1.274 +@SYMTestPriority        Medium
   1.275 +@SYMTestActions         Executes the TDbKeyCol,CDbKey tests
   1.276 +@SYMTestExpectedResults Test must not fail
   1.277 +@SYMREQ                 REQ0000
   1.278 +*/
   1.279 +LOCAL_C void TestKeyL()
   1.280 +	{
   1.281 +	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0592 "));
   1.282 +	TestTDbKeyCol();
   1.283 +	test.Next(_L("Testing CDbKey"));
   1.284 +	TestCDbKeyL();
   1.285 +	test.End();
   1.286 +	}
   1.287 +
   1.288 +
   1.289 +LOCAL_C void setupCleanup()
   1.290 +//
   1.291 +// Initialise the cleanup stack.
   1.292 +//
   1.293 +    {
   1.294 +	TheTrapCleanup=CTrapCleanup::New();
   1.295 +	test(TheTrapCleanup!=NULL);
   1.296 +	TRAPD(r,\
   1.297 +		{\
   1.298 +		for (TInt i=KTestCleanupStack;i>0;i--)\
   1.299 +			CleanupStack::PushL((TAny*)0);\
   1.300 +		CleanupStack::Pop(KTestCleanupStack);\
   1.301 +		});
   1.302 +	test(r==KErrNone);
   1.303 +	}
   1.304 +
   1.305 +GLDEF_C TInt E32Main()
   1.306 +//
   1.307 +// Test Client-side objects
   1.308 +//
   1.309 +    {
   1.310 +	test.Title();
   1.311 +	setupCleanup();
   1.312 +	__UHEAP_MARK;
   1.313 +//
   1.314 +	test.Start(_L("Test the Column Set"));
   1.315 +	TRAPD(r,TestColSetL();)
   1.316 +	test(r==KErrNone);
   1.317 +	__UHEAP_CHECK(0);
   1.318 +	test.Next(_L("Test the Key"));
   1.319 +	TRAP(r,TestKeyL();)
   1.320 +	test(r==KErrNone);
   1.321 +	test.End();
   1.322 +//
   1.323 +	__UHEAP_MARKEND;
   1.324 +	delete TheTrapCleanup;
   1.325 +	test.Close();
   1.326 +	return 0;
   1.327 +    }