51
|
1 |
// Copyright (c) 2010 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 "S32STD.H"
|
|
17 |
#include "S32MEM.H"
|
|
18 |
#include <e32test.h>
|
|
19 |
|
|
20 |
RTest TheTest(_L("t_storswizzle"));
|
|
21 |
|
|
22 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
23 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
24 |
//Test macros and functions
|
|
25 |
void Check(TInt aValue, TInt aLine)
|
|
26 |
{
|
|
27 |
if(!aValue)
|
|
28 |
{
|
55
|
29 |
TheTest.Printf(_L("*** Expression evaluated to false.\r\n"));
|
51
|
30 |
TheTest(EFalse, aLine);
|
|
31 |
}
|
|
32 |
}
|
|
33 |
void Check(TInt aValue, TInt aExpected, TInt aLine)
|
|
34 |
{
|
|
35 |
if(aValue != aExpected)
|
|
36 |
{
|
55
|
37 |
TheTest.Printf(_L("*** Expected error: %d, got: %d.\r\n"), aExpected, aValue);
|
51
|
38 |
TheTest(EFalse, aLine);
|
|
39 |
}
|
|
40 |
}
|
|
41 |
#define TEST(arg) ::Check((arg), __LINE__)
|
|
42 |
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
|
|
43 |
|
|
44 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
45 |
|
|
46 |
class TRectangle
|
|
47 |
{
|
|
48 |
public:
|
|
49 |
TRectangle();
|
|
50 |
TRectangle(TInt aWidth, TInt aHeight);
|
|
51 |
|
|
52 |
void ExternalizeL(RWriteStream& aStream) const;
|
|
53 |
void InternalizeL(RReadStream& aStream);
|
|
54 |
|
|
55 |
public:
|
|
56 |
TInt iWidth;
|
|
57 |
TInt iHeight;
|
|
58 |
};
|
|
59 |
|
|
60 |
TBool operator==(const TRectangle& aLeft, const TRectangle& aRight)
|
|
61 |
{
|
|
62 |
return aLeft.iWidth == aRight.iWidth && aLeft.iHeight == aRight.iHeight;
|
|
63 |
}
|
|
64 |
|
|
65 |
TRectangle::TRectangle() :
|
|
66 |
iWidth(-1),
|
|
67 |
iHeight(-1)
|
|
68 |
{
|
|
69 |
}
|
|
70 |
|
|
71 |
TRectangle::TRectangle(TInt aWidth, TInt aHeight) :
|
|
72 |
iWidth(aWidth),
|
|
73 |
iHeight(aHeight)
|
|
74 |
{
|
|
75 |
}
|
|
76 |
|
|
77 |
void TRectangle::ExternalizeL(RWriteStream& aStream) const
|
|
78 |
{
|
|
79 |
aStream << (TInt32)iWidth;
|
|
80 |
aStream << (TInt32)iHeight;
|
|
81 |
}
|
|
82 |
|
|
83 |
void TRectangle::InternalizeL(RReadStream& aStream)
|
|
84 |
{
|
|
85 |
TInt32 a;
|
|
86 |
aStream >> a;
|
|
87 |
iWidth = a;
|
|
88 |
aStream >> a;
|
|
89 |
iHeight = a;
|
|
90 |
}
|
|
91 |
|
55
|
92 |
class TRectangleExternalizer : public MExternalizer<TRectangle>
|
|
93 |
{
|
|
94 |
public:
|
|
95 |
virtual void ExternalizeL(const TRectangle& aObject, RWriteStream& aStream) const;
|
|
96 |
};
|
|
97 |
|
|
98 |
void TRectangleExternalizer::ExternalizeL(const TRectangle& aObject, RWriteStream& aStream) const
|
|
99 |
{
|
|
100 |
aStream << aObject;
|
|
101 |
}
|
|
102 |
|
|
103 |
class TRectangleInternalizer : public MInternalizer<TRectangle>
|
|
104 |
{
|
|
105 |
public:
|
|
106 |
virtual void InternalizeL(TRectangle& aObject, RReadStream& aStream) const;
|
|
107 |
};
|
|
108 |
|
|
109 |
void TRectangleInternalizer::InternalizeL(TRectangle& aObject, RReadStream& aStream) const
|
|
110 |
{
|
|
111 |
aStream >> aObject;
|
|
112 |
}
|
|
113 |
|
|
114 |
void RectangleExternalizeL(const TAny* aPtr, RWriteStream& aStream)
|
|
115 |
{
|
|
116 |
TRectangle* rcPtr = (TRectangle*)aPtr;
|
|
117 |
rcPtr->ExternalizeL(aStream);
|
|
118 |
}
|
|
119 |
|
|
120 |
class TStreamRefExternalizer : public MExternalizer<TStreamRef>
|
|
121 |
{
|
|
122 |
public:
|
|
123 |
virtual void ExternalizeL(const TStreamRef& aObject, RWriteStream& aStream) const;
|
|
124 |
};
|
|
125 |
|
|
126 |
void TStreamRefExternalizer::ExternalizeL(const TStreamRef& aObject, RWriteStream& aStream) const
|
|
127 |
{
|
|
128 |
TExternalizeFunction func = aObject.Function();
|
|
129 |
(*func)(aObject.Ptr(), aStream);
|
|
130 |
}
|
|
131 |
|
51
|
132 |
///////////////////////////////////////////////////////////////////////////////////////
|
|
133 |
|
|
134 |
/**
|
|
135 |
@SYMTestCaseID PDS-STORE-CT-4060
|
|
136 |
@SYMTestCaseDesc TSwizzleC<T> tests.
|
|
137 |
@SYMTestActions TSwizzleC<T> functionality test.
|
|
138 |
@SYMTestPriority High
|
|
139 |
@SYMTestExpectedResults Test must not fail
|
|
140 |
*/
|
|
141 |
void TestSwizzleCL()
|
|
142 |
{
|
|
143 |
CBufStore* bufStore = CBufStore::NewLC(100);
|
|
144 |
|
|
145 |
const TInt KWidth = 10;
|
|
146 |
const TInt KHeight = 20;
|
|
147 |
TRectangle r1(KWidth, KHeight);
|
55
|
148 |
|
|
149 |
const TInt KWidth2 = 6;
|
|
150 |
const TInt KHeight2 = 17;
|
|
151 |
TRectangle r2(KWidth2, KHeight2);
|
|
152 |
|
|
153 |
const TInt KWidth3 = 19;
|
|
154 |
const TInt KHeight3 = 5;
|
|
155 |
TRectangle r3(KWidth3, KHeight3);
|
|
156 |
|
|
157 |
const TInt KWidth4 = 22;
|
|
158 |
const TInt KHeight4 = 19;
|
|
159 |
TRectangle r4(KWidth4, KHeight4);
|
|
160 |
|
|
161 |
//Externalize r1 using RStoreWriteStream directly
|
51
|
162 |
RStoreWriteStream wstrm1;
|
|
163 |
TStreamId strmId1 = wstrm1.CreateLC(*bufStore);
|
|
164 |
TSwizzleC<TRectangle> swizzle1(&r1);
|
|
165 |
TEST((const void*)swizzle1 == (const void*)&r1);
|
|
166 |
wstrm1 << *swizzle1;
|
|
167 |
wstrm1.CommitL();
|
|
168 |
CleanupStack::PopAndDestroy(&wstrm1);
|
55
|
169 |
|
|
170 |
//Externalize r2 using TRectangleExternalizer
|
|
171 |
RStoreWriteStream wstrm2;
|
|
172 |
TStreamId strmId2 = wstrm2.CreateLC(*bufStore);
|
|
173 |
TSwizzleC<TRectangle> swizzle2(&r2);
|
|
174 |
TEST((const void*)swizzle2 == (const void*)&r2);
|
|
175 |
TRectangleExternalizer rcExternalizer2;
|
|
176 |
rcExternalizer2(*swizzle2, wstrm2);
|
|
177 |
wstrm2.CommitL();
|
|
178 |
CleanupStack::PopAndDestroy(&wstrm2);
|
|
179 |
|
|
180 |
//Externalize r3 using TExternalizer<TRectangle>
|
|
181 |
RStoreWriteStream wstrm3;
|
|
182 |
TStreamId strmId3 = wstrm3.CreateLC(*bufStore);
|
|
183 |
TSwizzleC<TRectangle> swizzle3(&r3);
|
|
184 |
TEST((const void*)swizzle3 == (const void*)&r3);
|
|
185 |
TExternalizer<TRectangle> rcExternalizer3;
|
|
186 |
rcExternalizer3(*swizzle3, wstrm3);
|
|
187 |
wstrm3.CommitL();
|
|
188 |
CleanupStack::PopAndDestroy(&wstrm3);
|
51
|
189 |
|
55
|
190 |
//Externalize r4 using TSwizzleC::ExternalizeL()
|
|
191 |
TStreamRefExternalizer rcExternalizer4;
|
|
192 |
RStoreWriteStream wstrm4(rcExternalizer4);
|
|
193 |
TStreamId strmId4 = wstrm4.CreateLC(*bufStore);
|
|
194 |
TSwizzleC<TRectangle> swizzle4(&r4);
|
|
195 |
TEST((const void*)swizzle4 == (const void*)&r4);
|
|
196 |
swizzle4.ExternalizeL(wstrm4);
|
|
197 |
wstrm4.CommitL();
|
|
198 |
CleanupStack::PopAndDestroy(&wstrm4);
|
|
199 |
|
|
200 |
//Internalize r1 using RStoreReadStream directly
|
|
201 |
TRectangle r1in;
|
51
|
202 |
RStoreReadStream rstrm1;
|
|
203 |
rstrm1.OpenLC(*bufStore, strmId1);
|
55
|
204 |
rstrm1 >> r1in;
|
51
|
205 |
CleanupStack::PopAndDestroy(&rstrm1);
|
55
|
206 |
TEST(r1 == r1in);
|
|
207 |
|
|
208 |
//Internalize r2 using TRectangleInternalizer
|
|
209 |
TRectangle r2in;
|
|
210 |
TSwizzle<TRectangle> swizzle2in(&r2in);
|
|
211 |
RStoreReadStream rstrm2;
|
|
212 |
rstrm2.OpenLC(*bufStore, strmId2);
|
|
213 |
TRectangleInternalizer rcInternalizer2;
|
|
214 |
rcInternalizer2(*swizzle2in, rstrm2);
|
|
215 |
CleanupStack::PopAndDestroy(&rstrm2);
|
|
216 |
TEST(r2 == r2in);
|
|
217 |
TEST(*swizzle2 == *swizzle2in);
|
|
218 |
|
|
219 |
//Internalize r3 using TInternalizer<TRectangle>
|
|
220 |
TRectangle r3in;
|
|
221 |
TSwizzle<TRectangle> swizzle3in(&r3in);
|
|
222 |
RStoreReadStream rstrm3;
|
|
223 |
rstrm3.OpenLC(*bufStore, strmId3);
|
|
224 |
TInternalizer<TRectangle> rcInternalizer3;
|
|
225 |
rcInternalizer3(*swizzle3in, rstrm3);
|
|
226 |
CleanupStack::PopAndDestroy(&rstrm3);
|
|
227 |
TEST(r3 == r3in);
|
|
228 |
TEST(*swizzle3 == *swizzle3in);
|
|
229 |
|
|
230 |
//Internalize r4
|
|
231 |
TSwizzle<TRectangle> swizzle4in(strmId4);
|
|
232 |
TEST(swizzle4in.IsId());
|
|
233 |
RStoreReadStream rstrm4;
|
|
234 |
rstrm4.OpenLC(*bufStore, swizzle4in.AsId());
|
|
235 |
TRectangle r4in;
|
|
236 |
rstrm4 >> r4in;
|
|
237 |
CleanupStack::PopAndDestroy(&rstrm4);
|
|
238 |
TEST(r4 == r4in);
|
51
|
239 |
|
|
240 |
CleanupStack::PopAndDestroy(bufStore);
|
55
|
241 |
|
|
242 |
//TSwizzleC copy constructor test
|
|
243 |
TSwizzleC<TRectangle> swizzle1copy(swizzle1);
|
|
244 |
TEST(swizzle1->iWidth == swizzle1copy->iWidth);
|
|
245 |
TEST(swizzle1->iHeight == swizzle1copy->iHeight);
|
|
246 |
TEST(swizzle1.AsPtr()->iHeight == swizzle1copy.AsPtr()->iHeight);
|
51
|
247 |
|
55
|
248 |
//TSwizzleC assignment operator test
|
|
249 |
TSwizzleC<TRectangle> swizzle1assign;
|
|
250 |
swizzle1assign = &r1in;
|
|
251 |
TEST(swizzle1->iWidth == swizzle1assign->iWidth);
|
|
252 |
TEST(swizzle1->iHeight == swizzle1assign->iHeight);
|
|
253 |
TEST(swizzle1.AsPtr()->iHeight == swizzle1assign.AsPtr()->iHeight);
|
51
|
254 |
}
|
|
255 |
|
|
256 |
/**
|
|
257 |
@SYMTestCaseID PDS-STORE-CT-4061
|
|
258 |
@SYMTestCaseDesc TSwizzleC<TAny> tests.
|
|
259 |
@SYMTestActions TSwizzleC<TAny> functionality test.
|
|
260 |
@SYMTestPriority High
|
|
261 |
@SYMTestExpectedResults Test must not fail
|
|
262 |
*/
|
|
263 |
void TestSwizzleCAny()
|
|
264 |
{
|
|
265 |
const TInt KWidth = 10;
|
|
266 |
const TInt KHeight = 20;
|
|
267 |
TRectangle r1(KWidth, KHeight);
|
|
268 |
|
|
269 |
TSwizzleC<TAny> swizzle1(&r1);
|
|
270 |
TSwizzleC<TAny> swizzle2(&r1);
|
|
271 |
TSwizzleC<TAny> swizzle3;
|
|
272 |
swizzle3 = &r1;
|
|
273 |
TEST((const void*)swizzle3 == (const void*)&r1);
|
|
274 |
|
|
275 |
TSwizzleCBase b1 = swizzle1;
|
|
276 |
TSwizzleCBase b2 = swizzle2;
|
|
277 |
TBool rc = b1 == b2;
|
|
278 |
TEST(rc);
|
|
279 |
rc = b1 != b2;
|
|
280 |
TEST(!rc);
|
|
281 |
|
|
282 |
TSwizzleC<TAny> swizzle4(b1);
|
|
283 |
TEST(swizzle4.AsPtr() == swizzle1.AsPtr());
|
|
284 |
|
|
285 |
const void* p1 = swizzle1.AsPtr();
|
|
286 |
const void* p2 = swizzle2.AsPtr();
|
|
287 |
const void* p3 = swizzle3.AsPtr();
|
|
288 |
|
|
289 |
TEST(((const TRectangle*)p1)->iWidth == ((const TRectangle*)p2)->iWidth);
|
|
290 |
TEST(((const TRectangle*)p1)->iHeight == ((const TRectangle*)p2)->iHeight);
|
|
291 |
TEST(((const TRectangle*)p3)->iWidth == ((const TRectangle*)p2)->iWidth);
|
|
292 |
TEST(((const TRectangle*)p3)->iHeight == ((const TRectangle*)p2)->iHeight);
|
|
293 |
}
|
|
294 |
|
|
295 |
/**
|
|
296 |
@SYMTestCaseID PDS-STORE-CT-4062
|
|
297 |
@SYMTestCaseDesc TSwizzle<TAny> tests.
|
|
298 |
@SYMTestActions TSwizzle<TAny> functionality test.
|
|
299 |
@SYMTestPriority High
|
|
300 |
@SYMTestExpectedResults Test must not fail
|
|
301 |
*/
|
|
302 |
void TestSwizzleAny()
|
|
303 |
{
|
|
304 |
const TInt KWidth = 10;
|
|
305 |
const TInt KHeight = 20;
|
|
306 |
TRectangle r1(KWidth, KHeight);
|
|
307 |
|
|
308 |
TSwizzle<TAny> swizzle1(&r1);
|
|
309 |
TSwizzle<TAny> swizzle2(&r1);
|
|
310 |
TSwizzle<TAny> swizzle3;
|
|
311 |
swizzle3 = &r1;
|
|
312 |
TEST((void*)swizzle3 == (void*)&r1);
|
|
313 |
|
|
314 |
TSwizzleBase b1 = swizzle1;
|
|
315 |
TSwizzleBase b2 = swizzle2;
|
|
316 |
TBool rc = b1 == b2;
|
|
317 |
TEST(rc);
|
|
318 |
rc = b1 != b2;
|
|
319 |
TEST(!rc);
|
|
320 |
|
|
321 |
TSwizzle<TAny> swizzle4(b1);
|
|
322 |
TEST(swizzle4.AsPtr() == swizzle1.AsPtr());
|
|
323 |
|
|
324 |
void* p1 = swizzle1.AsPtr();
|
|
325 |
void* p2 = swizzle2.AsPtr();
|
|
326 |
void* p3 = swizzle3.AsPtr();
|
|
327 |
|
|
328 |
TEST(((TRectangle*)p1)->iWidth == ((TRectangle*)p2)->iWidth);
|
|
329 |
TEST(((TRectangle*)p1)->iHeight == ((TRectangle*)p2)->iHeight);
|
|
330 |
TEST(((TRectangle*)p3)->iWidth == ((TRectangle*)p2)->iWidth);
|
|
331 |
TEST(((TRectangle*)p3)->iHeight == ((TRectangle*)p2)->iHeight);
|
|
332 |
|
|
333 |
((TRectangle*)p3)->iWidth = 5;
|
|
334 |
((TRectangle*)p3)->iHeight = 3;
|
|
335 |
|
|
336 |
TEST2(r1.iWidth, 5);
|
|
337 |
TEST2(r1.iHeight, 3);
|
|
338 |
|
|
339 |
TSwizzle<TRectangle> swizzle5;
|
|
340 |
swizzle5 = &r1;
|
|
341 |
TEST2(swizzle5->iWidth, 5);
|
|
342 |
TEST2(swizzle5->iHeight, 3);
|
|
343 |
}
|
|
344 |
|
|
345 |
void DoTestsL()
|
|
346 |
{
|
|
347 |
TheTest.Start(_L("@SYMTestCaseID:PDS-STORE-CT-4060: TSwizzleC<T> test"));
|
|
348 |
TestSwizzleCL();
|
|
349 |
|
|
350 |
TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4061: TSwizzleC<TAny> test"));
|
|
351 |
TestSwizzleCAny();
|
|
352 |
|
|
353 |
TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4062: TSwizzle<TAny> test"));
|
|
354 |
TestSwizzleAny();
|
|
355 |
}
|
|
356 |
|
|
357 |
TInt E32Main()
|
|
358 |
{
|
|
359 |
TheTest.Title();
|
|
360 |
|
|
361 |
CTrapCleanup* tc = CTrapCleanup::New();
|
|
362 |
TheTest(tc != NULL);
|
|
363 |
|
|
364 |
__UHEAP_MARK;
|
|
365 |
|
|
366 |
TRAPD(err, DoTestsL());
|
|
367 |
TEST2(err, KErrNone);
|
|
368 |
|
|
369 |
__UHEAP_MARKEND;
|
|
370 |
|
|
371 |
TheTest.End();
|
|
372 |
TheTest.Close();
|
|
373 |
|
|
374 |
delete tc;
|
|
375 |
|
|
376 |
User::Heap().Check();
|
|
377 |
return KErrNone;
|
|
378 |
}
|