24 //Test macros and functions |
24 //Test macros and functions |
25 void Check(TInt aValue, TInt aLine) |
25 void Check(TInt aValue, TInt aLine) |
26 { |
26 { |
27 if(!aValue) |
27 if(!aValue) |
28 { |
28 { |
29 RDebug::Print(_L("*** Boolean expression evaluated to false.\r\n")); |
29 TheTest.Printf(_L("*** Expression evaluated to false.\r\n")); |
30 TheTest(EFalse, aLine); |
30 TheTest(EFalse, aLine); |
31 } |
31 } |
32 } |
32 } |
33 void Check(TInt aValue, TInt aExpected, TInt aLine) |
33 void Check(TInt aValue, TInt aExpected, TInt aLine) |
34 { |
34 { |
35 if(aValue != aExpected) |
35 if(aValue != aExpected) |
36 { |
36 { |
37 RDebug::Print(_L("*** Expected error: %d, got: %d.\r\n"), aExpected, aValue); |
37 TheTest.Printf(_L("*** Expected error: %d, got: %d.\r\n"), aExpected, aValue); |
38 TheTest(EFalse, aLine); |
38 TheTest(EFalse, aLine); |
39 } |
39 } |
40 } |
40 } |
41 #define TEST(arg) ::Check((arg), __LINE__) |
41 #define TEST(arg) ::Check((arg), __LINE__) |
42 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
42 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
103 CBufStore* bufStore = CBufStore::NewLC(100); |
143 CBufStore* bufStore = CBufStore::NewLC(100); |
104 |
144 |
105 const TInt KWidth = 10; |
145 const TInt KWidth = 10; |
106 const TInt KHeight = 20; |
146 const TInt KHeight = 20; |
107 TRectangle r1(KWidth, KHeight); |
147 TRectangle r1(KWidth, KHeight); |
|
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 |
108 RStoreWriteStream wstrm1; |
162 RStoreWriteStream wstrm1; |
109 TStreamId strmId1 = wstrm1.CreateLC(*bufStore); |
163 TStreamId strmId1 = wstrm1.CreateLC(*bufStore); |
110 TSwizzleC<TRectangle> swizzle1(&r1); |
164 TSwizzleC<TRectangle> swizzle1(&r1); |
111 TEST((const void*)swizzle1 == (const void*)&r1); |
165 TEST((const void*)swizzle1 == (const void*)&r1); |
112 wstrm1 << *swizzle1; |
166 wstrm1 << *swizzle1; |
113 wstrm1.CommitL(); |
167 wstrm1.CommitL(); |
114 CleanupStack::PopAndDestroy(&wstrm1); |
168 CleanupStack::PopAndDestroy(&wstrm1); |
115 |
169 |
116 TRectangle r2; |
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); |
|
189 |
|
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; |
117 RStoreReadStream rstrm1; |
202 RStoreReadStream rstrm1; |
118 rstrm1.OpenLC(*bufStore, strmId1); |
203 rstrm1.OpenLC(*bufStore, strmId1); |
119 rstrm1 >> r2; |
204 rstrm1 >> r1in; |
120 CleanupStack::PopAndDestroy(&rstrm1); |
205 CleanupStack::PopAndDestroy(&rstrm1); |
121 |
206 TEST(r1 == r1in); |
122 TEST(r1 == r2); |
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); |
123 |
239 |
124 CleanupStack::PopAndDestroy(bufStore); |
240 CleanupStack::PopAndDestroy(bufStore); |
125 |
241 |
126 TSwizzleC<TRectangle> swizzle2(swizzle1); |
242 //TSwizzleC copy constructor test |
127 TEST(swizzle1->iWidth == swizzle2->iWidth); |
243 TSwizzleC<TRectangle> swizzle1copy(swizzle1); |
128 TEST(swizzle1->iHeight == swizzle2->iHeight); |
244 TEST(swizzle1->iWidth == swizzle1copy->iWidth); |
129 TEST(swizzle1.AsPtr()->iHeight == swizzle2.AsPtr()->iHeight); |
245 TEST(swizzle1->iHeight == swizzle1copy->iHeight); |
130 |
246 TEST(swizzle1.AsPtr()->iHeight == swizzle1copy.AsPtr()->iHeight); |
131 |
247 |
132 TSwizzleC<TRectangle> swizzle3; |
248 //TSwizzleC assignment operator test |
133 swizzle3 = &r2; |
249 TSwizzleC<TRectangle> swizzle1assign; |
134 TEST(swizzle1->iWidth == swizzle3->iWidth); |
250 swizzle1assign = &r1in; |
135 TEST(swizzle1->iHeight == swizzle3->iHeight); |
251 TEST(swizzle1->iWidth == swizzle1assign->iWidth); |
136 TEST(swizzle1.AsPtr()->iHeight == swizzle3.AsPtr()->iHeight); |
252 TEST(swizzle1->iHeight == swizzle1assign->iHeight); |
|
253 TEST(swizzle1.AsPtr()->iHeight == swizzle1assign.AsPtr()->iHeight); |
137 } |
254 } |
138 |
255 |
139 /** |
256 /** |
140 @SYMTestCaseID PDS-STORE-CT-4061 |
257 @SYMTestCaseID PDS-STORE-CT-4061 |
141 @SYMTestCaseDesc TSwizzleC<TAny> tests. |
258 @SYMTestCaseDesc TSwizzleC<TAny> tests. |