|
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 { |
|
29 RDebug::Print(_L("*** Boolean expression evaluated to false.\r\n")); |
|
30 TheTest(EFalse, aLine); |
|
31 } |
|
32 } |
|
33 void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
34 { |
|
35 if(aValue != aExpected) |
|
36 { |
|
37 RDebug::Print(_L("*** Expected error: %d, got: %d.\r\n"), aExpected, aValue); |
|
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 |
|
92 /////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
94 /** |
|
95 @SYMTestCaseID PDS-STORE-CT-4060 |
|
96 @SYMTestCaseDesc TSwizzleC<T> tests. |
|
97 @SYMTestActions TSwizzleC<T> functionality test. |
|
98 @SYMTestPriority High |
|
99 @SYMTestExpectedResults Test must not fail |
|
100 */ |
|
101 void TestSwizzleCL() |
|
102 { |
|
103 CBufStore* bufStore = CBufStore::NewLC(100); |
|
104 |
|
105 const TInt KWidth = 10; |
|
106 const TInt KHeight = 20; |
|
107 TRectangle r1(KWidth, KHeight); |
|
108 RStoreWriteStream wstrm1; |
|
109 TStreamId strmId1 = wstrm1.CreateLC(*bufStore); |
|
110 TSwizzleC<TRectangle> swizzle1(&r1); |
|
111 TEST((const void*)swizzle1 == (const void*)&r1); |
|
112 wstrm1 << *swizzle1; |
|
113 wstrm1.CommitL(); |
|
114 CleanupStack::PopAndDestroy(&wstrm1); |
|
115 |
|
116 TRectangle r2; |
|
117 RStoreReadStream rstrm1; |
|
118 rstrm1.OpenLC(*bufStore, strmId1); |
|
119 rstrm1 >> r2; |
|
120 CleanupStack::PopAndDestroy(&rstrm1); |
|
121 |
|
122 TEST(r1 == r2); |
|
123 |
|
124 CleanupStack::PopAndDestroy(bufStore); |
|
125 |
|
126 TSwizzleC<TRectangle> swizzle2(swizzle1); |
|
127 TEST(swizzle1->iWidth == swizzle2->iWidth); |
|
128 TEST(swizzle1->iHeight == swizzle2->iHeight); |
|
129 TEST(swizzle1.AsPtr()->iHeight == swizzle2.AsPtr()->iHeight); |
|
130 |
|
131 |
|
132 TSwizzleC<TRectangle> swizzle3; |
|
133 swizzle3 = &r2; |
|
134 TEST(swizzle1->iWidth == swizzle3->iWidth); |
|
135 TEST(swizzle1->iHeight == swizzle3->iHeight); |
|
136 TEST(swizzle1.AsPtr()->iHeight == swizzle3.AsPtr()->iHeight); |
|
137 } |
|
138 |
|
139 /** |
|
140 @SYMTestCaseID PDS-STORE-CT-4061 |
|
141 @SYMTestCaseDesc TSwizzleC<TAny> tests. |
|
142 @SYMTestActions TSwizzleC<TAny> functionality test. |
|
143 @SYMTestPriority High |
|
144 @SYMTestExpectedResults Test must not fail |
|
145 */ |
|
146 void TestSwizzleCAny() |
|
147 { |
|
148 const TInt KWidth = 10; |
|
149 const TInt KHeight = 20; |
|
150 TRectangle r1(KWidth, KHeight); |
|
151 |
|
152 TSwizzleC<TAny> swizzle1(&r1); |
|
153 TSwizzleC<TAny> swizzle2(&r1); |
|
154 TSwizzleC<TAny> swizzle3; |
|
155 swizzle3 = &r1; |
|
156 TEST((const void*)swizzle3 == (const void*)&r1); |
|
157 |
|
158 TSwizzleCBase b1 = swizzle1; |
|
159 TSwizzleCBase b2 = swizzle2; |
|
160 TBool rc = b1 == b2; |
|
161 TEST(rc); |
|
162 rc = b1 != b2; |
|
163 TEST(!rc); |
|
164 |
|
165 TSwizzleC<TAny> swizzle4(b1); |
|
166 TEST(swizzle4.AsPtr() == swizzle1.AsPtr()); |
|
167 |
|
168 const void* p1 = swizzle1.AsPtr(); |
|
169 const void* p2 = swizzle2.AsPtr(); |
|
170 const void* p3 = swizzle3.AsPtr(); |
|
171 |
|
172 TEST(((const TRectangle*)p1)->iWidth == ((const TRectangle*)p2)->iWidth); |
|
173 TEST(((const TRectangle*)p1)->iHeight == ((const TRectangle*)p2)->iHeight); |
|
174 TEST(((const TRectangle*)p3)->iWidth == ((const TRectangle*)p2)->iWidth); |
|
175 TEST(((const TRectangle*)p3)->iHeight == ((const TRectangle*)p2)->iHeight); |
|
176 } |
|
177 |
|
178 /** |
|
179 @SYMTestCaseID PDS-STORE-CT-4062 |
|
180 @SYMTestCaseDesc TSwizzle<TAny> tests. |
|
181 @SYMTestActions TSwizzle<TAny> functionality test. |
|
182 @SYMTestPriority High |
|
183 @SYMTestExpectedResults Test must not fail |
|
184 */ |
|
185 void TestSwizzleAny() |
|
186 { |
|
187 const TInt KWidth = 10; |
|
188 const TInt KHeight = 20; |
|
189 TRectangle r1(KWidth, KHeight); |
|
190 |
|
191 TSwizzle<TAny> swizzle1(&r1); |
|
192 TSwizzle<TAny> swizzle2(&r1); |
|
193 TSwizzle<TAny> swizzle3; |
|
194 swizzle3 = &r1; |
|
195 TEST((void*)swizzle3 == (void*)&r1); |
|
196 |
|
197 TSwizzleBase b1 = swizzle1; |
|
198 TSwizzleBase b2 = swizzle2; |
|
199 TBool rc = b1 == b2; |
|
200 TEST(rc); |
|
201 rc = b1 != b2; |
|
202 TEST(!rc); |
|
203 |
|
204 TSwizzle<TAny> swizzle4(b1); |
|
205 TEST(swizzle4.AsPtr() == swizzle1.AsPtr()); |
|
206 |
|
207 void* p1 = swizzle1.AsPtr(); |
|
208 void* p2 = swizzle2.AsPtr(); |
|
209 void* p3 = swizzle3.AsPtr(); |
|
210 |
|
211 TEST(((TRectangle*)p1)->iWidth == ((TRectangle*)p2)->iWidth); |
|
212 TEST(((TRectangle*)p1)->iHeight == ((TRectangle*)p2)->iHeight); |
|
213 TEST(((TRectangle*)p3)->iWidth == ((TRectangle*)p2)->iWidth); |
|
214 TEST(((TRectangle*)p3)->iHeight == ((TRectangle*)p2)->iHeight); |
|
215 |
|
216 ((TRectangle*)p3)->iWidth = 5; |
|
217 ((TRectangle*)p3)->iHeight = 3; |
|
218 |
|
219 TEST2(r1.iWidth, 5); |
|
220 TEST2(r1.iHeight, 3); |
|
221 |
|
222 TSwizzle<TRectangle> swizzle5; |
|
223 swizzle5 = &r1; |
|
224 TEST2(swizzle5->iWidth, 5); |
|
225 TEST2(swizzle5->iHeight, 3); |
|
226 } |
|
227 |
|
228 void DoTestsL() |
|
229 { |
|
230 TheTest.Start(_L("@SYMTestCaseID:PDS-STORE-CT-4060: TSwizzleC<T> test")); |
|
231 TestSwizzleCL(); |
|
232 |
|
233 TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4061: TSwizzleC<TAny> test")); |
|
234 TestSwizzleCAny(); |
|
235 |
|
236 TheTest.Next(_L("@SYMTestCaseID:PDS-STORE-CT-4062: TSwizzle<TAny> test")); |
|
237 TestSwizzleAny(); |
|
238 } |
|
239 |
|
240 TInt E32Main() |
|
241 { |
|
242 TheTest.Title(); |
|
243 |
|
244 CTrapCleanup* tc = CTrapCleanup::New(); |
|
245 TheTest(tc != NULL); |
|
246 |
|
247 __UHEAP_MARK; |
|
248 |
|
249 TRAPD(err, DoTestsL()); |
|
250 TEST2(err, KErrNone); |
|
251 |
|
252 __UHEAP_MARKEND; |
|
253 |
|
254 TheTest.End(); |
|
255 TheTest.Close(); |
|
256 |
|
257 delete tc; |
|
258 |
|
259 User::Heap().Check(); |
|
260 return KErrNone; |
|
261 } |