1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/store/TSTRM/t_storswizzle.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,261 @@
1.4 +// Copyright (c) 2010 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 "S32STD.H"
1.20 +#include "S32MEM.H"
1.21 +#include <e32test.h>
1.22 +
1.23 +RTest TheTest(_L("t_storswizzle"));
1.24 +
1.25 +///////////////////////////////////////////////////////////////////////////////////////
1.26 +///////////////////////////////////////////////////////////////////////////////////////
1.27 +//Test macros and functions
1.28 +void Check(TInt aValue, TInt aLine)
1.29 + {
1.30 + if(!aValue)
1.31 + {
1.32 + RDebug::Print(_L("*** Boolean expression evaluated to false.\r\n"));
1.33 + TheTest(EFalse, aLine);
1.34 + }
1.35 + }
1.36 +void Check(TInt aValue, TInt aExpected, TInt aLine)
1.37 + {
1.38 + if(aValue != aExpected)
1.39 + {
1.40 + RDebug::Print(_L("*** Expected error: %d, got: %d.\r\n"), aExpected, aValue);
1.41 + TheTest(EFalse, aLine);
1.42 + }
1.43 + }
1.44 +#define TEST(arg) ::Check((arg), __LINE__)
1.45 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.46 +
1.47 +///////////////////////////////////////////////////////////////////////////////////////
1.48 +
1.49 +class TRectangle
1.50 + {
1.51 +public:
1.52 + TRectangle();
1.53 + TRectangle(TInt aWidth, TInt aHeight);
1.54 +
1.55 + void ExternalizeL(RWriteStream& aStream) const;
1.56 + void InternalizeL(RReadStream& aStream);
1.57 +
1.58 +public:
1.59 + TInt iWidth;
1.60 + TInt iHeight;
1.61 + };
1.62 +
1.63 +TBool operator==(const TRectangle& aLeft, const TRectangle& aRight)
1.64 + {
1.65 + return aLeft.iWidth == aRight.iWidth && aLeft.iHeight == aRight.iHeight;
1.66 + }
1.67 +
1.68 +TRectangle::TRectangle() :
1.69 + iWidth(-1),
1.70 + iHeight(-1)
1.71 + {
1.72 + }
1.73 +
1.74 +TRectangle::TRectangle(TInt aWidth, TInt aHeight) :
1.75 + iWidth(aWidth),
1.76 + iHeight(aHeight)
1.77 + {
1.78 + }
1.79 +
1.80 +void TRectangle::ExternalizeL(RWriteStream& aStream) const
1.81 + {
1.82 + aStream << (TInt32)iWidth;
1.83 + aStream << (TInt32)iHeight;
1.84 + }
1.85 +
1.86 +void TRectangle::InternalizeL(RReadStream& aStream)
1.87 + {
1.88 + TInt32 a;
1.89 + aStream >> a;
1.90 + iWidth = a;
1.91 + aStream >> a;
1.92 + iHeight = a;
1.93 + }
1.94 +
1.95 +///////////////////////////////////////////////////////////////////////////////////////
1.96 +
1.97 +/**
1.98 +@SYMTestCaseID PDS-STORE-CT-4060
1.99 +@SYMTestCaseDesc TSwizzleC<T> tests.
1.100 +@SYMTestActions TSwizzleC<T> functionality test.
1.101 +@SYMTestPriority High
1.102 +@SYMTestExpectedResults Test must not fail
1.103 +*/
1.104 +void TestSwizzleCL()
1.105 + {
1.106 + CBufStore* bufStore = CBufStore::NewLC(100);
1.107 +
1.108 + const TInt KWidth = 10;
1.109 + const TInt KHeight = 20;
1.110 + TRectangle r1(KWidth, KHeight);
1.111 + RStoreWriteStream wstrm1;
1.112 + TStreamId strmId1 = wstrm1.CreateLC(*bufStore);
1.113 + TSwizzleC<TRectangle> swizzle1(&r1);
1.114 + TEST((const void*)swizzle1 == (const void*)&r1);
1.115 + wstrm1 << *swizzle1;
1.116 + wstrm1.CommitL();
1.117 + CleanupStack::PopAndDestroy(&wstrm1);
1.118 +
1.119 + TRectangle r2;
1.120 + RStoreReadStream rstrm1;
1.121 + rstrm1.OpenLC(*bufStore, strmId1);
1.122 + rstrm1 >> r2;
1.123 + CleanupStack::PopAndDestroy(&rstrm1);
1.124 +
1.125 + TEST(r1 == r2);
1.126 +
1.127 + CleanupStack::PopAndDestroy(bufStore);
1.128 +
1.129 + TSwizzleC<TRectangle> swizzle2(swizzle1);
1.130 + TEST(swizzle1->iWidth == swizzle2->iWidth);
1.131 + TEST(swizzle1->iHeight == swizzle2->iHeight);
1.132 + TEST(swizzle1.AsPtr()->iHeight == swizzle2.AsPtr()->iHeight);
1.133 +
1.134 +
1.135 + TSwizzleC<TRectangle> swizzle3;
1.136 + swizzle3 = &r2;
1.137 + TEST(swizzle1->iWidth == swizzle3->iWidth);
1.138 + TEST(swizzle1->iHeight == swizzle3->iHeight);
1.139 + TEST(swizzle1.AsPtr()->iHeight == swizzle3.AsPtr()->iHeight);
1.140 + }
1.141 +
1.142 +/**
1.143 +@SYMTestCaseID PDS-STORE-CT-4061
1.144 +@SYMTestCaseDesc TSwizzleC<TAny> tests.
1.145 +@SYMTestActions TSwizzleC<TAny> functionality test.
1.146 +@SYMTestPriority High
1.147 +@SYMTestExpectedResults Test must not fail
1.148 +*/
1.149 +void TestSwizzleCAny()
1.150 + {
1.151 + const TInt KWidth = 10;
1.152 + const TInt KHeight = 20;
1.153 + TRectangle r1(KWidth, KHeight);
1.154 +
1.155 + TSwizzleC<TAny> swizzle1(&r1);
1.156 + TSwizzleC<TAny> swizzle2(&r1);
1.157 + TSwizzleC<TAny> swizzle3;
1.158 + swizzle3 = &r1;
1.159 + TEST((const void*)swizzle3 == (const void*)&r1);
1.160 +
1.161 + TSwizzleCBase b1 = swizzle1;
1.162 + TSwizzleCBase b2 = swizzle2;
1.163 + TBool rc = b1 == b2;
1.164 + TEST(rc);
1.165 + rc = b1 != b2;
1.166 + TEST(!rc);
1.167 +
1.168 + TSwizzleC<TAny> swizzle4(b1);
1.169 + TEST(swizzle4.AsPtr() == swizzle1.AsPtr());
1.170 +
1.171 + const void* p1 = swizzle1.AsPtr();
1.172 + const void* p2 = swizzle2.AsPtr();
1.173 + const void* p3 = swizzle3.AsPtr();
1.174 +
1.175 + TEST(((const TRectangle*)p1)->iWidth == ((const TRectangle*)p2)->iWidth);
1.176 + TEST(((const TRectangle*)p1)->iHeight == ((const TRectangle*)p2)->iHeight);
1.177 + TEST(((const TRectangle*)p3)->iWidth == ((const TRectangle*)p2)->iWidth);
1.178 + TEST(((const TRectangle*)p3)->iHeight == ((const TRectangle*)p2)->iHeight);
1.179 + }
1.180 +
1.181 +/**
1.182 +@SYMTestCaseID PDS-STORE-CT-4062
1.183 +@SYMTestCaseDesc TSwizzle<TAny> tests.
1.184 +@SYMTestActions TSwizzle<TAny> functionality test.
1.185 +@SYMTestPriority High
1.186 +@SYMTestExpectedResults Test must not fail
1.187 +*/
1.188 +void TestSwizzleAny()
1.189 + {
1.190 + const TInt KWidth = 10;
1.191 + const TInt KHeight = 20;
1.192 + TRectangle r1(KWidth, KHeight);
1.193 +
1.194 + TSwizzle<TAny> swizzle1(&r1);
1.195 + TSwizzle<TAny> swizzle2(&r1);
1.196 + TSwizzle<TAny> swizzle3;
1.197 + swizzle3 = &r1;
1.198 + TEST((void*)swizzle3 == (void*)&r1);
1.199 +
1.200 + TSwizzleBase b1 = swizzle1;
1.201 + TSwizzleBase b2 = swizzle2;
1.202 + TBool rc = b1 == b2;
1.203 + TEST(rc);
1.204 + rc = b1 != b2;
1.205 + TEST(!rc);
1.206 +
1.207 + TSwizzle<TAny> swizzle4(b1);
1.208 + TEST(swizzle4.AsPtr() == swizzle1.AsPtr());
1.209 +
1.210 + void* p1 = swizzle1.AsPtr();
1.211 + void* p2 = swizzle2.AsPtr();
1.212 + void* p3 = swizzle3.AsPtr();
1.213 +
1.214 + TEST(((TRectangle*)p1)->iWidth == ((TRectangle*)p2)->iWidth);
1.215 + TEST(((TRectangle*)p1)->iHeight == ((TRectangle*)p2)->iHeight);
1.216 + TEST(((TRectangle*)p3)->iWidth == ((TRectangle*)p2)->iWidth);
1.217 + TEST(((TRectangle*)p3)->iHeight == ((TRectangle*)p2)->iHeight);
1.218 +
1.219 + ((TRectangle*)p3)->iWidth = 5;
1.220 + ((TRectangle*)p3)->iHeight = 3;
1.221 +
1.222 + TEST2(r1.iWidth, 5);
1.223 + TEST2(r1.iHeight, 3);
1.224 +
1.225 + TSwizzle<TRectangle> swizzle5;
1.226 + swizzle5 = &r1;
1.227 + TEST2(swizzle5->iWidth, 5);
1.228 + TEST2(swizzle5->iHeight, 3);
1.229 + }
1.230 +
1.231 +void DoTestsL()
1.232 + {
1.233 + TheTest.Start(_L("@SYMTestCaseID:PDS-STORE-CT-4060: TSwizzleC<T> test"));
1.234 + TestSwizzleCL();
1.235 +
1.236 + TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4061: TSwizzleC<TAny> test"));
1.237 + TestSwizzleCAny();
1.238 +
1.239 + TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4062: TSwizzle<TAny> test"));
1.240 + TestSwizzleAny();
1.241 + }
1.242 +
1.243 +TInt E32Main()
1.244 + {
1.245 + TheTest.Title();
1.246 +
1.247 + CTrapCleanup* tc = CTrapCleanup::New();
1.248 + TheTest(tc != NULL);
1.249 +
1.250 + __UHEAP_MARK;
1.251 +
1.252 + TRAPD(err, DoTestsL());
1.253 + TEST2(err, KErrNone);
1.254 +
1.255 + __UHEAP_MARKEND;
1.256 +
1.257 + TheTest.End();
1.258 + TheTest.Close();
1.259 +
1.260 + delete tc;
1.261 +
1.262 + User::Heap().Check();
1.263 + return KErrNone;
1.264 + }