os/persistentdata/persistentstorage/dbms/pcdbms/tdbms/src/t_client.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32std.h>
    17 #include <d32dbms.h>
    18 #include <e32test.h>
    19 
    20 LOCAL_D CTrapCleanup* TheTrapCleanup;
    21 
    22 LOCAL_D RTest test(_L("T_CLIENT"));
    23 
    24 LOCAL_D const TPtrC KColName(_S("A_column_name"));
    25 LOCAL_D TDbColName VarName(_S("Column_A"));
    26 
    27 const TInt KTestCleanupStack=0x20;
    28 const TInt KLeaveError=-4000;
    29 const TInt KColCount=26;
    30 
    31 /**
    32 @SYMTestCaseID          SYSLIB-DBMS-CT-0586
    33 @SYMTestCaseDesc        Tests for TDbCol class
    34 @SYMTestPriority        Medium
    35 @SYMTestActions        	Tests for column name and type after creating them. 
    36 @SYMTestExpectedResults Test must not fail
    37 @SYMREQ                 REQ0000
    38 */
    39 LOCAL_C void TestTDbCol()
    40 	{
    41 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0586 Testing TDbCol "));
    42 	TDbCol c1(KColName,EDbColText8);
    43 	test(c1.iName==KColName);
    44 	test(c1.iType==EDbColText8);
    45 	test(c1.iMaxLength==KDbDefaultTextColLength);
    46 	test(c1.iAttributes==0);
    47 	TDbCol c2(KColName,EDbColText8,1234);
    48 	test(c2.iName==KColName);
    49 	test(c2.iType==EDbColText8);
    50 	test(c2.iMaxLength==1234);
    51 	test(c2.iAttributes==0);
    52 	TDbCol c3(KColName,EDbColBit);
    53 	test(c3.iName==KColName);
    54 	test(c3.iType==EDbColBit);
    55 	test(c3.iMaxLength==KDbUndefinedLength);
    56 	test(c3.iAttributes==0);
    57 	}
    58 
    59 /**
    60 @SYMTestCaseID          SYSLIB-DBMS-CT-0587
    61 @SYMTestCaseDesc        CDbColSet class test
    62 @SYMTestPriority        Medium
    63 @SYMTestActions        	Tests for creation of a CDbColSet column set object
    64                         Tests for adding and removing columns to the column set
    65 @SYMTestExpectedResults Test must not fail
    66 @SYMREQ                 REQ0000
    67 */
    68 LOCAL_C void TestCDbColSet()
    69 	{
    70 	TInt r;
    71 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0587 ctor and dtor "));
    72 	CDbColSet* c=CDbColSet::NewL();		// assume it will succeed
    73 	test(c!=NULL);
    74 	test (c->Count()==0);
    75 	delete c;
    76 	__UHEAP_CHECK(0);
    77 #if defined(_DEBUG)
    78 	__UHEAP_FAILNEXT(1);
    79 	TRAP(r,c=CDbColSet::NewL());
    80 
    81 	test(r!=KErrNone);
    82 
    83 	__UHEAP_CHECK(0);
    84 #endif
    85 	c=CDbColSet::NewLC();
    86 	test(c!=NULL);
    87 	CleanupStack::PopAndDestroy();
    88 	__UHEAP_CHECK(0);
    89 	c=CDbColSet::NewL();
    90 	TDbCol col(KColName,EDbColText,20);
    91 	c->AddL(col);
    92 	delete c;
    93 	__UHEAP_CHECK(0);
    94 	TRAP(r,c=CDbColSet::NewLC();c->AddL(col);User::Leave(KLeaveError););
    95 	test(r==KLeaveError);
    96 	__UHEAP_CHECK(0);
    97 //
    98 	test.Next(_L("Add columns"));
    99 	c=CDbColSet::NewLC();
   100 	TInt ii;
   101 	for (ii=1;ii<=KColCount;ii++)
   102 		{
   103 		VarName[7]=(TUint8)('A'-1+ii);
   104 		test(c->Col(VarName)==NULL);
   105 		TDbCol column(VarName,EDbColInt32);
   106 		c->AddL(column);
   107 		test(c->Count()==ii);
   108 		test(c->ColNo(VarName)!=KDbNullColNo);
   109 		test(c->Col(VarName)!=NULL);
   110 		}
   111 	test.Next(_L("Check columns: operator[] and ColNo()"));
   112 	for (ii=1;ii<=KColCount;ii++)
   113 		{
   114 		const TDbCol& col=(*c)[ii];
   115 		test(c->ColNo(col.iName)==ii);
   116 		}
   117 	test.Next(_L("Remove columns"));
   118 	for (ii=1;ii<=KColCount;ii+=2)
   119 		{
   120 		VarName[7]=(TUint8)('A'-1+ii);
   121 		c->Remove(VarName);
   122 		}
   123 	test(c->Count()==13);
   124 	test.Next(_L("Clear"));
   125 	c->Clear();
   126 	test(c->Count()==0);
   127 	CleanupStack::PopAndDestroy();
   128 	__UHEAP_CHECK(0);
   129 	test.End();
   130 	}
   131 
   132 /**
   133 @SYMTestCaseID          SYSLIB-DBMS-CT-0588
   134 @SYMTestCaseDesc        Tests for TDbColSetIter class
   135 @SYMTestPriority        Medium
   136 @SYMTestActions        	Tests for iterate over the contents of a column set
   137 @SYMTestExpectedResults Test must not fail
   138 @SYMREQ                 REQ0000
   139 */
   140 LOCAL_C void TestTDbColSetIter()
   141 	{
   142 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0588 Testing TDbColSetIter "));
   143 	CDbColSet* c=CDbColSet::NewLC();
   144 	TInt ii;
   145 	for (ii=0;ii<KColCount;++ii)
   146 		{
   147 		VarName[7]=(TUint8)('A'-1+ii);
   148 		c->AddL(TDbCol(VarName,EDbColInt32));
   149 		}
   150 	TDbColSetIter iter1(*c);
   151 	TDbColSetIter iter2(iter1);
   152 	ii=0;
   153 	for (;;)
   154 		{
   155 		test(iter1.Col()==++ii);
   156 		test(iter1.operator->()==&iter1.operator*());
   157 		test(&*iter1++==&*iter2);
   158 		if (!iter1)
   159 			break;
   160 		test(&*iter1==&*++iter2);
   161 		}
   162 	test(!++iter2);
   163 	test(ii==KColCount);
   164 	CleanupStack::PopAndDestroy();
   165 	__UHEAP_CHECK(0);
   166 	}
   167 
   168 /**
   169 @SYMTestCaseID          SYSLIB-DBMS-CT-0589
   170 @SYMTestCaseDesc        Tests for TDbCol,CDbColSet,TDbColSetIter classes 
   171 @SYMTestPriority        Medium
   172 @SYMTestActions        	Executes the tests of TDbCol,CDbColSet,TDbColSetIter
   173 @SYMTestExpectedResults Test must not fail
   174 @SYMREQ                 REQ0000
   175 */
   176 LOCAL_C void TestColSet()
   177 	{
   178 	test.Next(_L("@SYMTestCaseID:SYSLIB-DBMS-CT-0589 "));
   179 	TestTDbCol();
   180 	test.Next(_L("Testing CDbColSet"));
   181 	TestCDbColSet();
   182 	test.Next(_L("Testing TDbColSetIter"));
   183 	TestTDbColSetIter();
   184 	test.End();
   185 	}
   186 
   187 /**
   188 @SYMTestCaseID          SYSLIB-DBMS-CT-0590
   189 @SYMTestCaseDesc        Tests for TDbKeyCol class
   190 @SYMTestPriority        Medium
   191 @SYMTestActions         Attempts to test for attributes of the key column together.
   192 @SYMTestExpectedResults Test must not fail
   193 @SYMREQ                 REQ0000
   194 */
   195 LOCAL_C void TestTDbKeyCol()
   196 	{
   197 	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0590 Testing TDbKeyCol "));
   198 	TDbKeyCol c1(KColName);
   199 	test(c1.iName==KColName);
   200 	test(c1.iOrder==TDbKeyCol::EAsc);
   201 	TDbKeyCol c2(KColName,TDbKeyCol::EDesc);
   202 	test(c2.iName==KColName);
   203 	test(c2.iOrder==TDbKeyCol::EDesc);
   204 	}
   205 
   206 /**
   207 @SYMTestCaseID          SYSLIB-DBMS-CT-0591
   208 @SYMTestCaseDesc        Tests the CDbKey class 
   209 @SYMTestPriority        Medium
   210 @SYMTestActions         Tests for the new CDbKey creation using NewL and NewLC functions
   211 @SYMTestExpectedResults Test must not fail
   212 @SYMREQ                 REQ0000
   213 */
   214 LOCAL_C void TestCDbKey()
   215 	{
   216 	TInt r;
   217 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0591 ctor and dtor "));
   218 	CDbKey* k=CDbKey::NewL();		// assume it will succeed
   219 	test(k!=NULL);
   220 	delete k;
   221 	__UHEAP_CHECK(0);
   222 #if defined(_DEBUG)
   223 	__UHEAP_FAILNEXT(1);
   224 	TRAP(r,k=CDbKey::NewL());
   225 
   226 	test(r!=KErrNone);
   227 
   228 	__UHEAP_CHECK(0);
   229 #endif
   230 	k=CDbKey::NewLC();
   231 	test(k!=NULL);
   232 	CleanupStack::PopAndDestroy();
   233 	__UHEAP_CHECK(0);
   234 	k=CDbKey::NewL();
   235 	k->AddL(VarName);
   236 	delete k;
   237 	__UHEAP_CHECK(0);
   238 	TRAP(r,k=CDbKey::NewLC();k->AddL(KColName);User::Leave(KLeaveError););
   239 	test(r==KLeaveError);
   240 	__UHEAP_CHECK(0);
   241 //
   242 	test.Next(_L("Add key columns"));
   243 	k=CDbKey::NewLC();
   244 	TInt ii;
   245 	for (ii=1;ii<=KColCount;++ii)
   246 		{
   247 		VarName[7]=(TUint8)('A'-1+ii);
   248 		k->AddL(VarName);
   249 		test(k->Count()==ii);
   250 		test((*k)[ii-1].iName==VarName);
   251 		}
   252 	test.Next(_L("Remove key columns"));
   253 	for (ii=1;ii<=KColCount;ii+=2)
   254 		{
   255 		VarName[7]=TUint8('A'-1+ii);
   256 		k->Remove(VarName);
   257 		}
   258 	test(k->Count()==KColCount/2);
   259 	test.Next(_L("Clear"));
   260 	k->Clear();
   261 	test(k->Count()==0);
   262 	test.Next(_L("Unique flag"));
   263 	test(!k->IsUnique());
   264 	k->MakeUnique();
   265 	test(k->IsUnique());
   266 	k->MakeUnique();
   267 	test(k->IsUnique());
   268 	CleanupStack::PopAndDestroy();
   269 	__UHEAP_CHECK(0);
   270 	test.End();
   271 	}
   272 
   273 /**
   274 @SYMTestCaseID          SYSLIB-DBMS-CT-0592
   275 @SYMTestCaseDesc        Tests the TDbKeyCol,CDbKey classes
   276 @SYMTestPriority        Medium
   277 @SYMTestActions         Executes the TDbKeyCol,CDbKey tests 
   278 @SYMTestExpectedResults Test must not fail
   279 @SYMREQ                 REQ0000
   280 */
   281 LOCAL_C void TestKey()
   282 	{
   283 	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0592 "));
   284 	TestTDbKeyCol();
   285 	test.Next(_L("Testing CDbKey"));
   286 	TestCDbKey();
   287 	test.End();
   288 	}
   289 
   290 
   291 LOCAL_C void setupCleanup()
   292 //
   293 // Initialise the cleanup stack.
   294 //
   295     {
   296 	TheTrapCleanup=CTrapCleanup::New();
   297 	test(TheTrapCleanup!=NULL);
   298 	TRAPD(r,\
   299 		{\
   300 		for (TInt i=KTestCleanupStack;i>0;i--)\
   301 			CleanupStack::PushL((TAny*)0);\
   302 		CleanupStack::Pop(KTestCleanupStack);\
   303 		});
   304 	test(r==KErrNone);
   305 	}
   306 
   307 
   308 GLDEF_C TInt E32Main()
   309     {
   310 	test.Title();
   311 	setupCleanup();
   312 	__UHEAP_MARK;
   313 //
   314 	test.Start(_L("Test the Column Set"));
   315 	TRAPD(r,TestColSet();)
   316 	test(r==KErrNone);
   317 	__UHEAP_CHECK(0);
   318 	test.Next(_L("Test the Key"));
   319 	TRAP(r,TestKey();)
   320 	test(r==KErrNone);
   321 	test.End();
   322 //
   323 	__UHEAP_MARKEND;
   324 	delete TheTrapCleanup;
   325 	test.Close();
   326 	return 0;
   327     }