sl@0
|
1 |
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
//
|
sl@0
|
16 |
#include "S32STD.H"
|
sl@0
|
17 |
#include "S32MEM.H"
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
RTest TheTest(_L("t_storswizzle"));
|
sl@0
|
21 |
|
sl@0
|
22 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
23 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
24 |
//Test macros and functions
|
sl@0
|
25 |
void Check(TInt aValue, TInt aLine)
|
sl@0
|
26 |
{
|
sl@0
|
27 |
if(!aValue)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
RDebug::Print(_L("*** Boolean expression evaluated to false.\r\n"));
|
sl@0
|
30 |
TheTest(EFalse, aLine);
|
sl@0
|
31 |
}
|
sl@0
|
32 |
}
|
sl@0
|
33 |
void Check(TInt aValue, TInt aExpected, TInt aLine)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
if(aValue != aExpected)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
RDebug::Print(_L("*** Expected error: %d, got: %d.\r\n"), aExpected, aValue);
|
sl@0
|
38 |
TheTest(EFalse, aLine);
|
sl@0
|
39 |
}
|
sl@0
|
40 |
}
|
sl@0
|
41 |
#define TEST(arg) ::Check((arg), __LINE__)
|
sl@0
|
42 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
sl@0
|
43 |
|
sl@0
|
44 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
45 |
|
sl@0
|
46 |
class TRectangle
|
sl@0
|
47 |
{
|
sl@0
|
48 |
public:
|
sl@0
|
49 |
TRectangle();
|
sl@0
|
50 |
TRectangle(TInt aWidth, TInt aHeight);
|
sl@0
|
51 |
|
sl@0
|
52 |
void ExternalizeL(RWriteStream& aStream) const;
|
sl@0
|
53 |
void InternalizeL(RReadStream& aStream);
|
sl@0
|
54 |
|
sl@0
|
55 |
public:
|
sl@0
|
56 |
TInt iWidth;
|
sl@0
|
57 |
TInt iHeight;
|
sl@0
|
58 |
};
|
sl@0
|
59 |
|
sl@0
|
60 |
TBool operator==(const TRectangle& aLeft, const TRectangle& aRight)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
return aLeft.iWidth == aRight.iWidth && aLeft.iHeight == aRight.iHeight;
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
TRectangle::TRectangle() :
|
sl@0
|
66 |
iWidth(-1),
|
sl@0
|
67 |
iHeight(-1)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
TRectangle::TRectangle(TInt aWidth, TInt aHeight) :
|
sl@0
|
72 |
iWidth(aWidth),
|
sl@0
|
73 |
iHeight(aHeight)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
void TRectangle::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
78 |
{
|
sl@0
|
79 |
aStream << (TInt32)iWidth;
|
sl@0
|
80 |
aStream << (TInt32)iHeight;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
void TRectangle::InternalizeL(RReadStream& aStream)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
TInt32 a;
|
sl@0
|
86 |
aStream >> a;
|
sl@0
|
87 |
iWidth = a;
|
sl@0
|
88 |
aStream >> a;
|
sl@0
|
89 |
iHeight = a;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
///////////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
93 |
|
sl@0
|
94 |
/**
|
sl@0
|
95 |
@SYMTestCaseID PDS-STORE-CT-4060
|
sl@0
|
96 |
@SYMTestCaseDesc TSwizzleC<T> tests.
|
sl@0
|
97 |
@SYMTestActions TSwizzleC<T> functionality test.
|
sl@0
|
98 |
@SYMTestPriority High
|
sl@0
|
99 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
100 |
*/
|
sl@0
|
101 |
void TestSwizzleCL()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
CBufStore* bufStore = CBufStore::NewLC(100);
|
sl@0
|
104 |
|
sl@0
|
105 |
const TInt KWidth = 10;
|
sl@0
|
106 |
const TInt KHeight = 20;
|
sl@0
|
107 |
TRectangle r1(KWidth, KHeight);
|
sl@0
|
108 |
RStoreWriteStream wstrm1;
|
sl@0
|
109 |
TStreamId strmId1 = wstrm1.CreateLC(*bufStore);
|
sl@0
|
110 |
TSwizzleC<TRectangle> swizzle1(&r1);
|
sl@0
|
111 |
TEST((const void*)swizzle1 == (const void*)&r1);
|
sl@0
|
112 |
wstrm1 << *swizzle1;
|
sl@0
|
113 |
wstrm1.CommitL();
|
sl@0
|
114 |
CleanupStack::PopAndDestroy(&wstrm1);
|
sl@0
|
115 |
|
sl@0
|
116 |
TRectangle r2;
|
sl@0
|
117 |
RStoreReadStream rstrm1;
|
sl@0
|
118 |
rstrm1.OpenLC(*bufStore, strmId1);
|
sl@0
|
119 |
rstrm1 >> r2;
|
sl@0
|
120 |
CleanupStack::PopAndDestroy(&rstrm1);
|
sl@0
|
121 |
|
sl@0
|
122 |
TEST(r1 == r2);
|
sl@0
|
123 |
|
sl@0
|
124 |
CleanupStack::PopAndDestroy(bufStore);
|
sl@0
|
125 |
|
sl@0
|
126 |
TSwizzleC<TRectangle> swizzle2(swizzle1);
|
sl@0
|
127 |
TEST(swizzle1->iWidth == swizzle2->iWidth);
|
sl@0
|
128 |
TEST(swizzle1->iHeight == swizzle2->iHeight);
|
sl@0
|
129 |
TEST(swizzle1.AsPtr()->iHeight == swizzle2.AsPtr()->iHeight);
|
sl@0
|
130 |
|
sl@0
|
131 |
|
sl@0
|
132 |
TSwizzleC<TRectangle> swizzle3;
|
sl@0
|
133 |
swizzle3 = &r2;
|
sl@0
|
134 |
TEST(swizzle1->iWidth == swizzle3->iWidth);
|
sl@0
|
135 |
TEST(swizzle1->iHeight == swizzle3->iHeight);
|
sl@0
|
136 |
TEST(swizzle1.AsPtr()->iHeight == swizzle3.AsPtr()->iHeight);
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
/**
|
sl@0
|
140 |
@SYMTestCaseID PDS-STORE-CT-4061
|
sl@0
|
141 |
@SYMTestCaseDesc TSwizzleC<TAny> tests.
|
sl@0
|
142 |
@SYMTestActions TSwizzleC<TAny> functionality test.
|
sl@0
|
143 |
@SYMTestPriority High
|
sl@0
|
144 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
145 |
*/
|
sl@0
|
146 |
void TestSwizzleCAny()
|
sl@0
|
147 |
{
|
sl@0
|
148 |
const TInt KWidth = 10;
|
sl@0
|
149 |
const TInt KHeight = 20;
|
sl@0
|
150 |
TRectangle r1(KWidth, KHeight);
|
sl@0
|
151 |
|
sl@0
|
152 |
TSwizzleC<TAny> swizzle1(&r1);
|
sl@0
|
153 |
TSwizzleC<TAny> swizzle2(&r1);
|
sl@0
|
154 |
TSwizzleC<TAny> swizzle3;
|
sl@0
|
155 |
swizzle3 = &r1;
|
sl@0
|
156 |
TEST((const void*)swizzle3 == (const void*)&r1);
|
sl@0
|
157 |
|
sl@0
|
158 |
TSwizzleCBase b1 = swizzle1;
|
sl@0
|
159 |
TSwizzleCBase b2 = swizzle2;
|
sl@0
|
160 |
TBool rc = b1 == b2;
|
sl@0
|
161 |
TEST(rc);
|
sl@0
|
162 |
rc = b1 != b2;
|
sl@0
|
163 |
TEST(!rc);
|
sl@0
|
164 |
|
sl@0
|
165 |
TSwizzleC<TAny> swizzle4(b1);
|
sl@0
|
166 |
TEST(swizzle4.AsPtr() == swizzle1.AsPtr());
|
sl@0
|
167 |
|
sl@0
|
168 |
const void* p1 = swizzle1.AsPtr();
|
sl@0
|
169 |
const void* p2 = swizzle2.AsPtr();
|
sl@0
|
170 |
const void* p3 = swizzle3.AsPtr();
|
sl@0
|
171 |
|
sl@0
|
172 |
TEST(((const TRectangle*)p1)->iWidth == ((const TRectangle*)p2)->iWidth);
|
sl@0
|
173 |
TEST(((const TRectangle*)p1)->iHeight == ((const TRectangle*)p2)->iHeight);
|
sl@0
|
174 |
TEST(((const TRectangle*)p3)->iWidth == ((const TRectangle*)p2)->iWidth);
|
sl@0
|
175 |
TEST(((const TRectangle*)p3)->iHeight == ((const TRectangle*)p2)->iHeight);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
/**
|
sl@0
|
179 |
@SYMTestCaseID PDS-STORE-CT-4062
|
sl@0
|
180 |
@SYMTestCaseDesc TSwizzle<TAny> tests.
|
sl@0
|
181 |
@SYMTestActions TSwizzle<TAny> functionality test.
|
sl@0
|
182 |
@SYMTestPriority High
|
sl@0
|
183 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
184 |
*/
|
sl@0
|
185 |
void TestSwizzleAny()
|
sl@0
|
186 |
{
|
sl@0
|
187 |
const TInt KWidth = 10;
|
sl@0
|
188 |
const TInt KHeight = 20;
|
sl@0
|
189 |
TRectangle r1(KWidth, KHeight);
|
sl@0
|
190 |
|
sl@0
|
191 |
TSwizzle<TAny> swizzle1(&r1);
|
sl@0
|
192 |
TSwizzle<TAny> swizzle2(&r1);
|
sl@0
|
193 |
TSwizzle<TAny> swizzle3;
|
sl@0
|
194 |
swizzle3 = &r1;
|
sl@0
|
195 |
TEST((void*)swizzle3 == (void*)&r1);
|
sl@0
|
196 |
|
sl@0
|
197 |
TSwizzleBase b1 = swizzle1;
|
sl@0
|
198 |
TSwizzleBase b2 = swizzle2;
|
sl@0
|
199 |
TBool rc = b1 == b2;
|
sl@0
|
200 |
TEST(rc);
|
sl@0
|
201 |
rc = b1 != b2;
|
sl@0
|
202 |
TEST(!rc);
|
sl@0
|
203 |
|
sl@0
|
204 |
TSwizzle<TAny> swizzle4(b1);
|
sl@0
|
205 |
TEST(swizzle4.AsPtr() == swizzle1.AsPtr());
|
sl@0
|
206 |
|
sl@0
|
207 |
void* p1 = swizzle1.AsPtr();
|
sl@0
|
208 |
void* p2 = swizzle2.AsPtr();
|
sl@0
|
209 |
void* p3 = swizzle3.AsPtr();
|
sl@0
|
210 |
|
sl@0
|
211 |
TEST(((TRectangle*)p1)->iWidth == ((TRectangle*)p2)->iWidth);
|
sl@0
|
212 |
TEST(((TRectangle*)p1)->iHeight == ((TRectangle*)p2)->iHeight);
|
sl@0
|
213 |
TEST(((TRectangle*)p3)->iWidth == ((TRectangle*)p2)->iWidth);
|
sl@0
|
214 |
TEST(((TRectangle*)p3)->iHeight == ((TRectangle*)p2)->iHeight);
|
sl@0
|
215 |
|
sl@0
|
216 |
((TRectangle*)p3)->iWidth = 5;
|
sl@0
|
217 |
((TRectangle*)p3)->iHeight = 3;
|
sl@0
|
218 |
|
sl@0
|
219 |
TEST2(r1.iWidth, 5);
|
sl@0
|
220 |
TEST2(r1.iHeight, 3);
|
sl@0
|
221 |
|
sl@0
|
222 |
TSwizzle<TRectangle> swizzle5;
|
sl@0
|
223 |
swizzle5 = &r1;
|
sl@0
|
224 |
TEST2(swizzle5->iWidth, 5);
|
sl@0
|
225 |
TEST2(swizzle5->iHeight, 3);
|
sl@0
|
226 |
}
|
sl@0
|
227 |
|
sl@0
|
228 |
void DoTestsL()
|
sl@0
|
229 |
{
|
sl@0
|
230 |
TheTest.Start(_L("@SYMTestCaseID:PDS-STORE-CT-4060: TSwizzleC<T> test"));
|
sl@0
|
231 |
TestSwizzleCL();
|
sl@0
|
232 |
|
sl@0
|
233 |
TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4061: TSwizzleC<TAny> test"));
|
sl@0
|
234 |
TestSwizzleCAny();
|
sl@0
|
235 |
|
sl@0
|
236 |
TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4062: TSwizzle<TAny> test"));
|
sl@0
|
237 |
TestSwizzleAny();
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
TInt E32Main()
|
sl@0
|
241 |
{
|
sl@0
|
242 |
TheTest.Title();
|
sl@0
|
243 |
|
sl@0
|
244 |
CTrapCleanup* tc = CTrapCleanup::New();
|
sl@0
|
245 |
TheTest(tc != NULL);
|
sl@0
|
246 |
|
sl@0
|
247 |
__UHEAP_MARK;
|
sl@0
|
248 |
|
sl@0
|
249 |
TRAPD(err, DoTestsL());
|
sl@0
|
250 |
TEST2(err, KErrNone);
|
sl@0
|
251 |
|
sl@0
|
252 |
__UHEAP_MARKEND;
|
sl@0
|
253 |
|
sl@0
|
254 |
TheTest.End();
|
sl@0
|
255 |
TheTest.Close();
|
sl@0
|
256 |
|
sl@0
|
257 |
delete tc;
|
sl@0
|
258 |
|
sl@0
|
259 |
User::Heap().Check();
|
sl@0
|
260 |
return KErrNone;
|
sl@0
|
261 |
}
|