sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: LOCAL_D CTrapCleanup* TheTrapCleanup; sl@0: sl@0: LOCAL_D RTest test(_L("t_dbclient")); sl@0: sl@0: LOCAL_D const TPtrC KColName(_S("A_column_name")); sl@0: LOCAL_D TDbColName VarName(_S("Column_A")); sl@0: sl@0: const TInt KTestCleanupStack=0x20; sl@0: const TInt KLeaveError=-4000; sl@0: const TInt KColCount=26; sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0586 sl@0: @SYMTestCaseDesc Tests for TDbCol class sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for column name and type after creating them. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestTDbCol() sl@0: { sl@0: test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0586 Testing TDbCol ")); sl@0: TDbCol c1(KColName,EDbColText8); sl@0: test(c1.iName==KColName); sl@0: test(c1.iType==EDbColText8); sl@0: test(c1.iMaxLength==KDbDefaultTextColLength); sl@0: test(c1.iAttributes==0); sl@0: TDbCol c2(KColName,EDbColText8,1234); sl@0: test(c2.iName==KColName); sl@0: test(c2.iType==EDbColText8); sl@0: test(c2.iMaxLength==1234); sl@0: test(c2.iAttributes==0); sl@0: TDbCol c3(KColName,EDbColBit); sl@0: test(c3.iName==KColName); sl@0: test(c3.iType==EDbColBit); sl@0: test(c3.iMaxLength==KDbUndefinedLength); sl@0: test(c3.iAttributes==0); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0587 sl@0: @SYMTestCaseDesc CDbColSet class test sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for creation of a CDbColSet column set object sl@0: Tests for adding and removing columns to the column set sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestCDbColSetL() sl@0: { sl@0: TInt r; sl@0: test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0587 ctor and dtor ")); sl@0: CDbColSet* c=CDbColSet::NewL(); // assume it will succeed sl@0: test(c!=NULL); sl@0: test (c->Count()==0); sl@0: delete c; sl@0: __UHEAP_CHECK(0); sl@0: #if defined(_DEBUG) sl@0: __UHEAP_FAILNEXT(1); sl@0: TRAP(r,c=CDbColSet::NewL()); sl@0: test(r!=KErrNone); sl@0: __UHEAP_CHECK(0); sl@0: #endif sl@0: c=CDbColSet::NewLC(); sl@0: test(c!=NULL); sl@0: CleanupStack::PopAndDestroy(); sl@0: __UHEAP_CHECK(0); sl@0: c=CDbColSet::NewL(); sl@0: TDbCol col(KColName,EDbColText,20); sl@0: c->AddL(col); sl@0: delete c; sl@0: __UHEAP_CHECK(0); sl@0: TRAP(r,c=CDbColSet::NewLC();c->AddL(col);User::Leave(KLeaveError);); sl@0: test(r==KLeaveError); sl@0: __UHEAP_CHECK(0); sl@0: // sl@0: test.Next(_L("Add columns")); sl@0: c=CDbColSet::NewLC(); sl@0: TInt ii; sl@0: for (ii=1;ii<=KColCount;ii++) sl@0: { sl@0: VarName[7]=(TUint8)('A'-1+ii); sl@0: test(c->Col(VarName)==NULL); sl@0: TDbCol column(VarName,EDbColInt32); sl@0: c->AddL(column); sl@0: test(c->Count()==ii); sl@0: test(c->ColNo(VarName)!=KDbNullColNo); sl@0: test(c->Col(VarName)!=NULL); sl@0: } sl@0: test.Next(_L("Check columns: operator[] and ColNo()")); sl@0: for (ii=1;ii<=KColCount;ii++) sl@0: { sl@0: const TDbCol& col=(*c)[ii]; sl@0: test(c->ColNo(col.iName)==ii); sl@0: } sl@0: test.Next(_L("Remove columns")); sl@0: for (ii=1;ii<=KColCount;ii+=2) sl@0: { sl@0: VarName[7]=(TUint8)('A'-1+ii); sl@0: c->Remove(VarName); sl@0: } sl@0: test(c->Count()==13); sl@0: test.Next(_L("Clear")); sl@0: c->Clear(); sl@0: test(c->Count()==0); sl@0: CleanupStack::PopAndDestroy(); sl@0: __UHEAP_CHECK(0); sl@0: test.End(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0588 sl@0: @SYMTestCaseDesc Tests for TDbColSetIter class sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for iterate over the contents of a column set sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestTDbColSetIterL() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0588 Testing TDbColSetIter ")); sl@0: CDbColSet* c=CDbColSet::NewLC(); sl@0: TInt ii; sl@0: for (ii=0;iiAddL(TDbCol(VarName,EDbColInt32)); sl@0: } sl@0: TDbColSetIter iter1(*c); sl@0: TDbColSetIter iter2(iter1); sl@0: ii=0; sl@0: for (;;) sl@0: { sl@0: test(iter1.Col()==++ii); sl@0: test(iter1.operator->()==&iter1.operator*()); sl@0: test(&*iter1++==&*iter2); sl@0: if (!iter1) sl@0: break; sl@0: test(&*iter1==&*++iter2); sl@0: } sl@0: test(!++iter2); sl@0: test(ii==KColCount); sl@0: CleanupStack::PopAndDestroy(); sl@0: __UHEAP_CHECK(0); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0589 sl@0: @SYMTestCaseDesc Tests for TDbCol,CDbColSet,TDbColSetIter classes sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Executes the tests of TDbCol,CDbColSet,TDbColSetIter sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestColSetL() sl@0: { sl@0: test.Next(_L("@SYMTestCaseID:SYSLIB-DBMS-CT-0589 ")); sl@0: TestTDbCol(); sl@0: test.Next(_L("Testing CDbColSet")); sl@0: TestCDbColSetL(); sl@0: TestTDbColSetIterL(); sl@0: test.End(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0590 sl@0: @SYMTestCaseDesc Tests for TDbKeyCol class sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Attempts to test for attributes of the key column together. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestTDbKeyCol() sl@0: { sl@0: test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0590 Testing TDbKeyCol ")); sl@0: TDbKeyCol c1(KColName); sl@0: test(c1.iName==KColName); sl@0: test(c1.iOrder==TDbKeyCol::EAsc); sl@0: TDbKeyCol c2(KColName,TDbKeyCol::EDesc); sl@0: test(c2.iName==KColName); sl@0: test(c2.iOrder==TDbKeyCol::EDesc); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0591 sl@0: @SYMTestCaseDesc Tests the CDbKey class sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Tests for the new CDbKey creation using NewL and NewLC functions sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestCDbKeyL() sl@0: { sl@0: TInt r; sl@0: test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0591 ctor and dtor ")); sl@0: CDbKey* k=CDbKey::NewL(); // assume it will succeed sl@0: test(k!=NULL); sl@0: delete k; sl@0: __UHEAP_CHECK(0); sl@0: #if defined(_DEBUG) sl@0: __UHEAP_FAILNEXT(1); sl@0: TRAP(r,k=CDbKey::NewL()); sl@0: test(r!=KErrNone); sl@0: __UHEAP_CHECK(0); sl@0: #endif sl@0: k=CDbKey::NewLC(); sl@0: test(k!=NULL); sl@0: CleanupStack::PopAndDestroy(); sl@0: __UHEAP_CHECK(0); sl@0: k=CDbKey::NewL(); sl@0: k->AddL(VarName); sl@0: delete k; sl@0: __UHEAP_CHECK(0); sl@0: TRAP(r,k=CDbKey::NewLC();k->AddL(KColName);User::Leave(KLeaveError);); sl@0: test(r==KLeaveError); sl@0: __UHEAP_CHECK(0); sl@0: // sl@0: test.Next(_L("Add key columns")); sl@0: k=CDbKey::NewLC(); sl@0: TInt ii; sl@0: for (ii=1;ii<=KColCount;++ii) sl@0: { sl@0: VarName[7]=(TUint8)('A'-1+ii); sl@0: k->AddL(VarName); sl@0: test(k->Count()==ii); sl@0: test((*k)[ii-1].iName==VarName); sl@0: } sl@0: test.Next(_L("Remove key columns")); sl@0: for (ii=1;ii<=KColCount;ii+=2) sl@0: { sl@0: VarName[7]=TUint8('A'-1+ii); sl@0: k->Remove(VarName); sl@0: } sl@0: test(k->Count()==KColCount/2); sl@0: test.Next(_L("Clear")); sl@0: k->Clear(); sl@0: test(k->Count()==0); sl@0: test.Next(_L("Unique flag")); sl@0: test(!k->IsUnique()); sl@0: k->MakeUnique(); sl@0: test(k->IsUnique()); sl@0: k->MakeUnique(); sl@0: test(k->IsUnique()); sl@0: CleanupStack::PopAndDestroy(); sl@0: __UHEAP_CHECK(0); sl@0: test.End(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-DBMS-CT-0592 sl@0: @SYMTestCaseDesc Tests the TDbKeyCol,CDbKey classes sl@0: @SYMTestPriority Medium sl@0: @SYMTestActions Executes the TDbKeyCol,CDbKey tests sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestKeyL() sl@0: { sl@0: test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0592 ")); sl@0: TestTDbKeyCol(); sl@0: test.Next(_L("Testing CDbKey")); sl@0: TestCDbKeyL(); sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void setupCleanup() sl@0: // sl@0: // Initialise the cleanup stack. sl@0: // sl@0: { sl@0: TheTrapCleanup=CTrapCleanup::New(); sl@0: test(TheTrapCleanup!=NULL); sl@0: TRAPD(r,\ sl@0: {\ sl@0: for (TInt i=KTestCleanupStack;i>0;i--)\ sl@0: CleanupStack::PushL((TAny*)0);\ sl@0: CleanupStack::Pop(KTestCleanupStack);\ sl@0: }); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: // sl@0: // Test Client-side objects sl@0: // sl@0: { sl@0: test.Title(); sl@0: setupCleanup(); sl@0: __UHEAP_MARK; sl@0: // sl@0: test.Start(_L("Test the Column Set")); sl@0: TRAPD(r,TestColSetL();) sl@0: test(r==KErrNone); sl@0: __UHEAP_CHECK(0); sl@0: test.Next(_L("Test the Key")); sl@0: TRAP(r,TestKeyL();) sl@0: test(r==KErrNone); sl@0: test.End(); sl@0: // sl@0: __UHEAP_MARKEND; sl@0: delete TheTrapCleanup; sl@0: test.Close(); sl@0: return 0; sl@0: }