0
|
1 |
// Copyright (c) 1997-2009 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 the License "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 |
// e32test\math\t_realx.cpp
|
|
15 |
// T_REALX.CPP - Test routines for TRealX
|
|
16 |
// Overview:
|
|
17 |
// Test the functionality of a class that encapsulates 64 bit extended precision
|
|
18 |
// real values.
|
|
19 |
// API Information:
|
|
20 |
// TRealX
|
|
21 |
// Details:
|
|
22 |
// - Test the constructor and assignment operator with signed, unsigned, 64 bit
|
|
23 |
// integer, float and double values.
|
|
24 |
// - Check the conversion of TRealX value to signed, unsigned, 64 bit integer,
|
|
25 |
// float and double values is as expected.
|
|
26 |
// - Set TRealX variable with some special values and check it is as expected.
|
|
27 |
// - Test addition, multiplication, division of TRealX values is as expected.
|
|
28 |
// - Test Unary operators, comparison of two TRealX values are as expected.
|
|
29 |
// Platforms/Drives/Compatibility:
|
|
30 |
// All
|
|
31 |
// Assumptions/Requirement/Pre-requisites:
|
|
32 |
// Failures and causes:
|
|
33 |
// Base Port information:
|
|
34 |
//
|
|
35 |
//
|
|
36 |
|
|
37 |
#include <e32std.h>
|
|
38 |
#include <e32std_private.h>
|
|
39 |
#include <e32test.h>
|
|
40 |
#include <e32math.h>
|
|
41 |
#include "t_realxd.h"
|
|
42 |
|
|
43 |
LOCAL_D RTest test(_L("T_TREALX"));
|
|
44 |
|
|
45 |
// Conversion functions TInt64 <-> TReal64
|
|
46 |
LOCAL_C void TReal64ToTInt64(TInt64 *aDest, const TReal64 *aSrc)
|
|
47 |
{
|
|
48 |
TInt *pD=(TInt*)aDest;
|
|
49 |
const TInt *pS=(TInt*)aSrc;
|
|
50 |
#ifdef __DOUBLE_WORDS_SWAPPED__
|
|
51 |
pD[1]=pS[0]; // word containing sign,exp
|
|
52 |
pD[0]=pS[1];
|
|
53 |
#else
|
|
54 |
pD[1]=pS[1]; // word containing sign,exp
|
|
55 |
pD[0]=pS[0];
|
|
56 |
#endif
|
|
57 |
}
|
|
58 |
|
|
59 |
LOCAL_C void TInt64ToTReal64(TReal64 *aDest, const TInt64 *aSrc)
|
|
60 |
{
|
|
61 |
TInt *pD=(TInt*)aDest;
|
|
62 |
const TInt *pS=(TInt*)aSrc;
|
|
63 |
#ifdef __DOUBLE_WORDS_SWAPPED__
|
|
64 |
pD[0]=pS[1]; // word containing sign,exp
|
|
65 |
pD[1]=pS[0];
|
|
66 |
#else
|
|
67 |
pD[1]=pS[1]; // word containing sign,exp
|
|
68 |
pD[0]=pS[0];
|
|
69 |
#endif
|
|
70 |
}
|
|
71 |
|
|
72 |
// Test functions
|
|
73 |
SRealX::SRealX(TUint a, TUint b, TUint c)
|
|
74 |
{
|
|
75 |
iExpFlagSign=a;
|
|
76 |
iMantHigh=b;
|
|
77 |
iMantLow=c;
|
|
78 |
}
|
|
79 |
|
|
80 |
SRealX::SRealX(const TRealX& aRealX)
|
|
81 |
{
|
|
82 |
const TUint *pR = (const TUint *)&aRealX;
|
|
83 |
iExpFlagSign=pR[2];
|
|
84 |
iMantHigh=pR[1];
|
|
85 |
iMantLow=pR[0];
|
|
86 |
}
|
|
87 |
|
|
88 |
SRealX& SRealX::operator=(const TRealX& aRealX)
|
|
89 |
{
|
|
90 |
const TUint *pR = (const TUint *)&aRealX;
|
|
91 |
iExpFlagSign=pR[2];
|
|
92 |
iMantHigh=pR[1];
|
|
93 |
iMantLow=pR[0];
|
|
94 |
return *this;
|
|
95 |
}
|
|
96 |
|
|
97 |
SRealX::operator TRealX() const
|
|
98 |
{
|
|
99 |
TRealX r;
|
|
100 |
TUint *pR=(TUint *)&r;
|
|
101 |
pR[2]=iExpFlagSign;
|
|
102 |
pR[1]=iMantHigh;
|
|
103 |
pR[0]=iMantLow;
|
|
104 |
return r;
|
|
105 |
}
|
|
106 |
|
|
107 |
TBool SRealX::operator==(const SRealX& aSRealX) const
|
|
108 |
{
|
|
109 |
TUint e1=iExpFlagSign >> 16;
|
|
110 |
TUint e2=aSRealX.iExpFlagSign >> 16;
|
|
111 |
TUint s1=iExpFlagSign & 0x00000001;
|
|
112 |
TUint s2=aSRealX.iExpFlagSign & 0x00000001;
|
|
113 |
TUint f1=iExpFlagSign & 0x00000300;
|
|
114 |
TUint f2=aSRealX.iExpFlagSign & 0x00000300;
|
|
115 |
return( e1==e2 && s1==s2 && (e1==0 || (f1==f2 && iMantHigh==aSRealX.iMantHigh && iMantLow==aSRealX.iMantLow)) );
|
|
116 |
}
|
|
117 |
|
|
118 |
SConvertFrom32BitTest::SConvertFrom32BitTest(TInt op, const SRealX& res, TInt r)
|
|
119 |
{
|
|
120 |
iOperand=op;
|
|
121 |
iResult=res;
|
|
122 |
iReturnCode=r;
|
|
123 |
}
|
|
124 |
|
|
125 |
void SConvertFrom32BitTest::Test(TConversionFrom32Bits aConversion) const
|
|
126 |
{
|
|
127 |
TInt r=iReturnCode;
|
|
128 |
SRealX sr;
|
|
129 |
switch(aConversion)
|
|
130 |
{
|
|
131 |
case EConstructInt:
|
|
132 |
{
|
|
133 |
TRealX x(iOperand);
|
|
134 |
sr=(SRealX)x;
|
|
135 |
break;
|
|
136 |
}
|
|
137 |
case EAssignInt:
|
|
138 |
{
|
|
139 |
TRealX x;
|
|
140 |
x=iOperand;
|
|
141 |
sr=(SRealX)x;
|
|
142 |
break;
|
|
143 |
}
|
|
144 |
case ESetInt:
|
|
145 |
{
|
|
146 |
TRealX x;
|
|
147 |
r=x.Set(iOperand);
|
|
148 |
sr=(SRealX)x;
|
|
149 |
break;
|
|
150 |
}
|
|
151 |
case EConstructUint:
|
|
152 |
{
|
|
153 |
TUint uint=(TUint)iOperand;
|
|
154 |
TRealX x(uint);
|
|
155 |
sr=(SRealX)x;
|
|
156 |
break;
|
|
157 |
}
|
|
158 |
case EAssignUint:
|
|
159 |
{
|
|
160 |
TUint uint=(TUint)iOperand;
|
|
161 |
TRealX x;
|
|
162 |
x=uint;
|
|
163 |
sr=(SRealX)x;
|
|
164 |
break;
|
|
165 |
}
|
|
166 |
case ESetUint:
|
|
167 |
{
|
|
168 |
TUint uint=(TUint)iOperand;
|
|
169 |
TRealX x;
|
|
170 |
r=x.Set(uint);
|
|
171 |
sr=(SRealX)x;
|
|
172 |
break;
|
|
173 |
}
|
|
174 |
case EConstructFloat:
|
|
175 |
{
|
|
176 |
TReal32 f;
|
|
177 |
TInt *pF=(TInt*)&f;
|
|
178 |
*pF=iOperand;
|
|
179 |
TRealX x(f);
|
|
180 |
sr=(SRealX)x;
|
|
181 |
break;
|
|
182 |
}
|
|
183 |
case EAssignFloat:
|
|
184 |
{
|
|
185 |
TReal32 f;
|
|
186 |
TInt *pF=(TInt*)&f;
|
|
187 |
*pF=iOperand;
|
|
188 |
TRealX x;
|
|
189 |
x=f;
|
|
190 |
sr=(SRealX)x;
|
|
191 |
break;
|
|
192 |
}
|
|
193 |
case ESetFloat:
|
|
194 |
{
|
|
195 |
TReal32 f;
|
|
196 |
TInt *pF=(TInt*)&f;
|
|
197 |
*pF=iOperand;
|
|
198 |
TRealX x;
|
|
199 |
r=x.Set(f);
|
|
200 |
sr=(SRealX)x;
|
|
201 |
break;
|
|
202 |
}
|
|
203 |
}
|
|
204 |
if (sr==iResult && r==iReturnCode)
|
|
205 |
return;
|
|
206 |
test.Printf(_L("Conversion %d from 32 bit operand test failed\noperand = %08X\n"),
|
|
207 |
(TInt)aConversion, iOperand );
|
|
208 |
test.Printf(_L("Result %08X %08X %08X\nReturn code %d\n"),
|
|
209 |
sr.iExpFlagSign, sr.iMantHigh, sr.iMantLow, r );
|
|
210 |
test.Printf(_L("Correct result %08X %08X %08X\nCorrect return code %d\n"),
|
|
211 |
iResult.iExpFlagSign, iResult.iMantHigh, iResult.iMantLow, iReturnCode );
|
|
212 |
//test.Getch();
|
|
213 |
test(0);
|
|
214 |
}
|
|
215 |
|
|
216 |
SConvertFrom64BitTest::SConvertFrom64BitTest(TInt64 op, const SRealX& res, TInt r)
|
|
217 |
{
|
|
218 |
iOperand=op;
|
|
219 |
iResult=res;
|
|
220 |
iReturnCode=r;
|
|
221 |
}
|
|
222 |
|
|
223 |
void SConvertFrom64BitTest::Test(TConversionFrom64Bits aConversion) const
|
|
224 |
{
|
|
225 |
TInt r=iReturnCode;
|
|
226 |
SRealX sr;
|
|
227 |
switch(aConversion)
|
|
228 |
{
|
|
229 |
case EConstructInt64:
|
|
230 |
{
|
|
231 |
TRealX x(iOperand);
|
|
232 |
sr=(SRealX)x;
|
|
233 |
break;
|
|
234 |
}
|
|
235 |
case EAssignInt64:
|
|
236 |
{
|
|
237 |
TRealX x;
|
|
238 |
x=iOperand;
|
|
239 |
sr=(SRealX)x;
|
|
240 |
break;
|
|
241 |
}
|
|
242 |
case ESetInt64:
|
|
243 |
{
|
|
244 |
TRealX x;
|
|
245 |
r=x.Set(iOperand);
|
|
246 |
sr=(SRealX)x;
|
|
247 |
break;
|
|
248 |
}
|
|
249 |
/* case EConstructUint:
|
|
250 |
{
|
|
251 |
TUint uint=(TUint)iOperand;
|
|
252 |
TRealX x(uint);
|
|
253 |
sr=(SRealX)x;
|
|
254 |
break;
|
|
255 |
}
|
|
256 |
case EAssignUint:
|
|
257 |
{
|
|
258 |
TUint uint=(TUint)iOperand;
|
|
259 |
TRealX x;
|
|
260 |
x=uint;
|
|
261 |
sr=(SRealX)x;
|
|
262 |
break;
|
|
263 |
}
|
|
264 |
case ESetUint:
|
|
265 |
{
|
|
266 |
TUint uint=(TUint)iOperand;
|
|
267 |
TRealX x;
|
|
268 |
r=x.Set(uint);
|
|
269 |
sr=(SRealX)x;
|
|
270 |
break;
|
|
271 |
}*/
|
|
272 |
case EConstructDouble:
|
|
273 |
{
|
|
274 |
TReal64 d;
|
|
275 |
TInt64ToTReal64(&d, &iOperand);
|
|
276 |
TRealX x(d);
|
|
277 |
sr=(SRealX)x;
|
|
278 |
break;
|
|
279 |
}
|
|
280 |
case EAssignDouble:
|
|
281 |
{
|
|
282 |
TReal64 d;
|
|
283 |
TInt64ToTReal64(&d, &iOperand);
|
|
284 |
TRealX x;
|
|
285 |
x=d;
|
|
286 |
sr=(SRealX)x;
|
|
287 |
break;
|
|
288 |
}
|
|
289 |
case ESetDouble:
|
|
290 |
{
|
|
291 |
TReal64 d;
|
|
292 |
TInt64ToTReal64(&d, &iOperand);
|
|
293 |
TRealX x;
|
|
294 |
r=x.Set(d);
|
|
295 |
sr=(SRealX)x;
|
|
296 |
break;
|
|
297 |
}
|
|
298 |
}
|
|
299 |
if (sr==iResult && r==iReturnCode)
|
|
300 |
return;
|
|
301 |
test.Printf(_L("Conversion %d from 64 bit operand test failed\noperand = %08X %08X\n"),
|
|
302 |
(TInt)aConversion, I64HIGH(iOperand), I64LOW(iOperand) );
|
|
303 |
test.Printf(_L("Result %08X %08X %08X\nReturn code %d\n"),
|
|
304 |
sr.iExpFlagSign, sr.iMantHigh, sr.iMantLow, r );
|
|
305 |
test.Printf(_L("Correct result %08X %08X %08X\nCorrect return code %d\n"),
|
|
306 |
iResult.iExpFlagSign, iResult.iMantHigh, iResult.iMantLow, iReturnCode );
|
|
307 |
//test.Getch();
|
|
308 |
test(0);
|
|
309 |
}
|
|
310 |
|
|
311 |
SConvertTo32BitTest::SConvertTo32BitTest(const SRealX& op, TInt res, TInt r)
|
|
312 |
{
|
|
313 |
iOperand=op;
|
|
314 |
iResult=res;
|
|
315 |
iReturnCode=r;
|
|
316 |
}
|
|
317 |
|
|
318 |
void SConvertTo32BitTest::Test(TConversionTo32Bits aConversion) const
|
|
319 |
{
|
|
320 |
TInt r=iReturnCode;
|
|
321 |
TRealX op=(TRealX)iOperand;
|
|
322 |
TInt result=0;
|
|
323 |
switch(aConversion)
|
|
324 |
{
|
|
325 |
case EOperatorInt:
|
|
326 |
result=(TInt)op;
|
|
327 |
break;
|
|
328 |
case EOperatorUint:
|
|
329 |
{
|
|
330 |
TUint uint;
|
|
331 |
uint=(TUint)op;
|
|
332 |
result=(TInt)uint;
|
|
333 |
break;
|
|
334 |
}
|
|
335 |
case EOperatorTReal32:
|
|
336 |
{
|
|
337 |
TReal32 x;
|
|
338 |
x=(TReal32)op;
|
|
339 |
result=*((TInt*)&x);
|
|
340 |
break;
|
|
341 |
}
|
|
342 |
case EGetTReal32:
|
|
343 |
{
|
|
344 |
TReal32 x;
|
|
345 |
r=op.GetTReal(x);
|
|
346 |
result=*((TInt*)&x);
|
|
347 |
break;
|
|
348 |
}
|
|
349 |
}
|
|
350 |
if (result==iResult && r==iReturnCode)
|
|
351 |
return;
|
|
352 |
test.Printf(_L("Conversion %d to 32 bit operand test failed\noperand = %08X %08X %08X\n"),
|
|
353 |
(TInt)aConversion, iOperand.iExpFlagSign, iOperand.iMantHigh, iOperand.iMantLow );
|
|
354 |
test.Printf(_L("Result %08X\nReturn code %d\n"),
|
|
355 |
result, r );
|
|
356 |
test.Printf(_L("Correct result %08X\nCorrect return code %d\n"),
|
|
357 |
iResult, iReturnCode );
|
|
358 |
//test.Getch();
|
|
359 |
test(0);
|
|
360 |
}
|
|
361 |
|
|
362 |
SConvertTo64BitTest::SConvertTo64BitTest(const SRealX& op, TInt64 res, TInt r)
|
|
363 |
{
|
|
364 |
iOperand=op;
|
|
365 |
iResult=res;
|
|
366 |
iReturnCode=r;
|
|
367 |
}
|
|
368 |
|
|
369 |
void SConvertTo64BitTest::Test(TConversionTo64Bits aConversion) const
|
|
370 |
{
|
|
371 |
TInt r=iReturnCode;
|
|
372 |
TRealX op=(TRealX)iOperand;
|
|
373 |
TInt64 result=0;
|
|
374 |
switch(aConversion)
|
|
375 |
{
|
|
376 |
case EOperatorInt64:
|
|
377 |
result=op.operator TInt64(); // odd conversion syntax required for VC5 compilation
|
|
378 |
break;
|
|
379 |
case EOperatorTReal64:
|
|
380 |
{
|
|
381 |
TReal64 d;
|
|
382 |
d=(TReal64)op;
|
|
383 |
TReal64ToTInt64(&result, &d);
|
|
384 |
break;
|
|
385 |
}
|
|
386 |
case EGetTReal64:
|
|
387 |
{
|
|
388 |
TReal64 d;
|
|
389 |
r=op.GetTReal(d);
|
|
390 |
TReal64ToTInt64(&result, &d);
|
|
391 |
break;
|
|
392 |
}
|
|
393 |
}
|
|
394 |
if (result==iResult && r==iReturnCode)
|
|
395 |
return;
|
|
396 |
test.Printf(_L("Conversion %d to 64 bit operand test failed\noperand = %08X %08X %08X\n"),
|
|
397 |
(TInt)aConversion, iOperand.iExpFlagSign, iOperand.iMantHigh, iOperand.iMantLow );
|
|
398 |
test.Printf(_L("Result %08X %08X\nReturn code %d\n"),
|
|
399 |
I64HIGH(result), I64LOW(result), r );
|
|
400 |
test.Printf(_L("Correct result %08X %08X\nCorrect return code %d\n"),
|
|
401 |
I64HIGH(iResult), I64LOW(iResult), iReturnCode );
|
|
402 |
//test.Getch();
|
|
403 |
test(0);
|
|
404 |
}
|
|
405 |
|
|
406 |
SCompareTest::SCompareTest(const SRealX& o1, const SRealX& o2, TInt r)
|
|
407 |
{
|
|
408 |
iOperand1=o1;
|
|
409 |
iOperand2=o2;
|
|
410 |
iReturnCode=r;
|
|
411 |
}
|
|
412 |
|
|
413 |
void SCompareTest::Test() const
|
|
414 |
{
|
|
415 |
TRealX op1=(TRealX)iOperand1;
|
|
416 |
TRealX op2=(TRealX)iOperand2;
|
|
417 |
TRealX::TRealXOrder r=op1.Compare(op2);
|
|
418 |
TBool lt=op1<op2;
|
|
419 |
TBool le=op1<=op2;
|
|
420 |
TBool gt=op1>op2;
|
|
421 |
TBool ge=op1>=op2;
|
|
422 |
TBool eq=op1==op2;
|
|
423 |
TBool ne=op1!=op2;
|
|
424 |
if ((TInt)r==iReturnCode)
|
|
425 |
{
|
|
426 |
switch(r)
|
|
427 |
{
|
|
428 |
case TRealX::ELessThan:
|
|
429 |
if (lt && le && !gt && !ge && !eq && ne)
|
|
430 |
return;
|
|
431 |
break;
|
|
432 |
|
|
433 |
case TRealX::EEqual:
|
|
434 |
if (!lt && le && !gt && ge && eq && !ne)
|
|
435 |
return;
|
|
436 |
break;
|
|
437 |
case TRealX::EGreaterThan:
|
|
438 |
if (!lt && !le && gt && ge && !eq && ne)
|
|
439 |
return;
|
|
440 |
break;
|
|
441 |
|
|
442 |
case TRealX::EUnordered:
|
|
443 |
if (!lt && !le && !gt && !ge && !eq && ne)
|
|
444 |
return;
|
|
445 |
break;
|
|
446 |
}
|
|
447 |
}
|
|
448 |
test.Printf(_L("Compare test failed\nop1 = %08X %08X %08X\nop2 = %08X %08X %08X\n"),
|
|
449 |
iOperand1.iExpFlagSign, iOperand1.iMantHigh, iOperand1.iMantLow,
|
|
450 |
iOperand2.iExpFlagSign, iOperand2.iMantHigh, iOperand2.iMantLow );
|
|
451 |
test.Printf(_L("Return code %d\nlt=%d, le=%d, gt=%d, ge=%d, eq=%d, ne=%d\n"),
|
|
452 |
r, lt, le, gt, ge, eq, ne );
|
|
453 |
//test.Getch();
|
|
454 |
test(0);
|
|
455 |
}
|
|
456 |
|
|
457 |
SOneOpTest::SOneOpTest(const SRealX& op, const SRealX& res, TInt r)
|
|
458 |
{
|
|
459 |
iOperand=op;
|
|
460 |
iResult=res;
|
|
461 |
iReturnCode=r;
|
|
462 |
}
|
|
463 |
|
|
464 |
TInt SOneOpTest::DoTest(TUnaryOperation anOperation, TRealX *aResult) const
|
|
465 |
{
|
|
466 |
TInt r=KErrNone;
|
|
467 |
TRealX op;
|
|
468 |
*aResult=(TRealX)iOperand;
|
|
469 |
|
|
470 |
switch(anOperation)
|
|
471 |
{
|
|
472 |
case EUnaryPlus:
|
|
473 |
*aResult=+(*aResult);
|
|
474 |
break;
|
|
475 |
case EUnaryMinus:
|
|
476 |
*aResult=-(*aResult);
|
|
477 |
break;
|
|
478 |
case EPreInc:
|
|
479 |
++*aResult;
|
|
480 |
break;
|
|
481 |
case EPreDec:
|
|
482 |
--*aResult;
|
|
483 |
break;
|
|
484 |
case EPostInc:
|
|
485 |
op=(*aResult)++;
|
|
486 |
if (!(SRealX(op)==iOperand))
|
|
487 |
r=KErrGeneral;
|
|
488 |
break;
|
|
489 |
case EPostDec:
|
|
490 |
op=(*aResult)--;
|
|
491 |
if (!(SRealX(op)==iOperand))
|
|
492 |
r=KErrGeneral;
|
|
493 |
break;
|
|
494 |
}
|
|
495 |
return r;
|
|
496 |
}
|
|
497 |
|
|
498 |
TInt OneOpTestThreadFunction(TAny *anInfo)
|
|
499 |
{
|
|
500 |
SOneOpTestThreadInfo *pI=(SOneOpTestThreadInfo *)anInfo;
|
|
501 |
TInt r=pI->iTest->DoTest(pI->iOperation,pI->iResult);
|
|
502 |
return r;
|
|
503 |
}
|
|
504 |
|
|
505 |
void SOneOpTest::Test(TUnaryOperation anOperation) const
|
|
506 |
{
|
|
507 |
SOneOpTestThreadInfo info;
|
|
508 |
TRealX result;
|
|
509 |
info.iTest=this;
|
|
510 |
info.iOperation=anOperation;
|
|
511 |
info.iResult=&result;
|
|
512 |
RThread t;
|
|
513 |
TInt r=t.Create(_L("TestThread"),OneOpTestThreadFunction,0x1000,0x1000,0x100000,&info);
|
|
514 |
test(r==KErrNone);
|
|
515 |
t.SetPriority(EPriorityMore); // so we will not run again until thread terminates
|
|
516 |
TRequestStatus s;
|
|
517 |
t.Logon(s);
|
|
518 |
t.Resume();
|
|
519 |
User::WaitForRequest(s);
|
|
520 |
TExitType exittype=t.ExitType();
|
|
521 |
r=s.Int();
|
|
522 |
CLOSE_AND_WAIT(t);
|
|
523 |
SRealX sr(result);
|
|
524 |
if (sr==iResult && r==iReturnCode)
|
|
525 |
{
|
|
526 |
if (anOperation>EUnaryMinus)
|
|
527 |
{
|
|
528 |
if (r==KErrNone && exittype==EExitKill)
|
|
529 |
return;
|
|
530 |
if (r!=KErrNone && exittype==EExitPanic)
|
|
531 |
return;
|
|
532 |
}
|
|
533 |
else
|
|
534 |
{
|
|
535 |
if (exittype==EExitKill)
|
|
536 |
return;
|
|
537 |
}
|
|
538 |
}
|
|
539 |
|
|
540 |
test.Printf(_L("Unary operation %d test failed\nop = %08X %08X %08X\n"),
|
|
541 |
(TInt)anOperation,
|
|
542 |
iOperand.iExpFlagSign, iOperand.iMantHigh, iOperand.iMantLow );
|
|
543 |
test.Printf(_L("Result %08X %08X %08X\nReturn code %d Exit type %d\n"),
|
|
544 |
sr.iExpFlagSign, sr.iMantHigh, sr.iMantLow, r, (TInt)exittype );
|
|
545 |
test.Printf(_L("Correct result %08X %08X %08X\nCorrect return code %d\n"),
|
|
546 |
iResult.iExpFlagSign, iResult.iMantHigh, iResult.iMantLow, iReturnCode );
|
|
547 |
//test.Getch();
|
|
548 |
test(0);
|
|
549 |
}
|
|
550 |
|
|
551 |
STwoOpTest::STwoOpTest(const SRealX& o1, const SRealX& o2, const SRealX& res, TInt r)
|
|
552 |
{
|
|
553 |
iOperand1=o1;
|
|
554 |
iOperand2=o2;
|
|
555 |
iResult=res;
|
|
556 |
iReturnCode=r;
|
|
557 |
}
|
|
558 |
|
|
559 |
TInt STwoOpTest::DoTest(TBinaryOperation anOperation, TRealX *aResult, TBool aSwap) const
|
|
560 |
{
|
|
561 |
TInt r=KErrNone;
|
|
562 |
TRealX op1, op2;
|
|
563 |
if (aSwap)
|
|
564 |
{
|
|
565 |
op2=(TRealX)iOperand1;
|
|
566 |
op1=(TRealX)iOperand2;
|
|
567 |
*aResult=(TRealX)iOperand2;
|
|
568 |
}
|
|
569 |
else
|
|
570 |
{
|
|
571 |
op1=(TRealX)iOperand1;
|
|
572 |
op2=(TRealX)iOperand2;
|
|
573 |
*aResult=(TRealX)iOperand1;
|
|
574 |
}
|
|
575 |
|
|
576 |
switch(anOperation)
|
|
577 |
{
|
|
578 |
case EAddEq:
|
|
579 |
r=aResult->AddEq(op2);
|
|
580 |
break;
|
|
581 |
case ESubEq:
|
|
582 |
r=aResult->SubEq(op2);
|
|
583 |
break;
|
|
584 |
case EMultEq:
|
|
585 |
r=aResult->MultEq(op2);
|
|
586 |
break;
|
|
587 |
case EDivEq:
|
|
588 |
r=aResult->DivEq(op2);
|
|
589 |
break;
|
|
590 |
case EAdd:
|
|
591 |
r=op1.Add(*aResult,op2);
|
|
592 |
break;
|
|
593 |
case ESub:
|
|
594 |
r=op1.Sub(*aResult,op2);
|
|
595 |
break;
|
|
596 |
case EMult:
|
|
597 |
r=op1.Mult(*aResult,op2);
|
|
598 |
break;
|
|
599 |
case EDiv:
|
|
600 |
r=op1.Div(*aResult,op2);
|
|
601 |
break;
|
|
602 |
case EPlusEq:
|
|
603 |
*aResult+=op2;
|
|
604 |
break;
|
|
605 |
case EMinusEq:
|
|
606 |
*aResult-=op2;
|
|
607 |
break;
|
|
608 |
case EStarEq:
|
|
609 |
*aResult*=op2;
|
|
610 |
break;
|
|
611 |
case ESlashEq:
|
|
612 |
*aResult/=op2;
|
|
613 |
break;
|
|
614 |
case EPlus:
|
|
615 |
*aResult=op1+op2;
|
|
616 |
break;
|
|
617 |
case EMinus:
|
|
618 |
*aResult=op1-op2;
|
|
619 |
break;
|
|
620 |
case EStar:
|
|
621 |
*aResult=op1*op2;
|
|
622 |
break;
|
|
623 |
case ESlash:
|
|
624 |
*aResult=op1/op2;
|
|
625 |
break;
|
|
626 |
}
|
|
627 |
return r;
|
|
628 |
}
|
|
629 |
|
|
630 |
TInt TwoOpTestThreadFunction(TAny *anInfo)
|
|
631 |
{
|
|
632 |
STwoOpTestThreadInfo *pI=(STwoOpTestThreadInfo *)anInfo;
|
|
633 |
TInt r=pI->iTest->DoTest(pI->iOperation,pI->iResult,pI->iSwap);
|
|
634 |
return r;
|
|
635 |
}
|
|
636 |
|
|
637 |
void STwoOpTest::Test(TBinaryOperation anOperation, TBool aSwap) const
|
|
638 |
{
|
|
639 |
STwoOpTestThreadInfo info;
|
|
640 |
TRealX result;
|
|
641 |
info.iTest=this;
|
|
642 |
info.iOperation=anOperation;
|
|
643 |
info.iResult=&result;
|
|
644 |
info.iSwap=aSwap;
|
|
645 |
RThread t;
|
|
646 |
TInt r=t.Create(_L("TestThread"),TwoOpTestThreadFunction,0x1000,0x1000,0x100000,&info);
|
|
647 |
test(r==KErrNone);
|
|
648 |
t.SetPriority(EPriorityMore); // so we will not run again until thread terminates
|
|
649 |
TRequestStatus s;
|
|
650 |
t.Logon(s);
|
|
651 |
t.Resume();
|
|
652 |
User::WaitForRequest(s);
|
|
653 |
TExitType exittype=t.ExitType();
|
|
654 |
r=s.Int();
|
|
655 |
CLOSE_AND_WAIT(t);
|
|
656 |
SRealX sr(result);
|
|
657 |
if (anOperation>=EPlus && exittype==EExitPanic)
|
|
658 |
{
|
|
659 |
// if +,-,*,/ operation paniced, result will be lost
|
|
660 |
sr=iResult;
|
|
661 |
}
|
|
662 |
if (sr==iResult && r==iReturnCode)
|
|
663 |
{
|
|
664 |
if (anOperation>=EPlusEq)
|
|
665 |
{
|
|
666 |
if (r==KErrNone && exittype==EExitKill)
|
|
667 |
return;
|
|
668 |
if (r!=KErrNone && exittype==EExitPanic)
|
|
669 |
return;
|
|
670 |
}
|
|
671 |
else
|
|
672 |
{
|
|
673 |
if (exittype==EExitKill)
|
|
674 |
return;
|
|
675 |
}
|
|
676 |
}
|
|
677 |
|
|
678 |
test.Printf(_L("Binary operation %d test failed\nop1 = %08X %08X %08X\nop2 = %08X %08X %08X\n"),
|
|
679 |
(TInt)anOperation,
|
|
680 |
iOperand1.iExpFlagSign, iOperand1.iMantHigh, iOperand1.iMantLow,
|
|
681 |
iOperand2.iExpFlagSign, iOperand2.iMantHigh, iOperand2.iMantLow );
|
|
682 |
test.Printf(_L("Result %08X %08X %08X\nReturn code %d Exit type %d\n"),
|
|
683 |
sr.iExpFlagSign, sr.iMantHigh, sr.iMantLow, r, (TInt)exittype );
|
|
684 |
test.Printf(_L("Correct result %08X %08X %08X\nCorrect return code %d\n"),
|
|
685 |
iResult.iExpFlagSign, iResult.iMantHigh, iResult.iMantLow, iReturnCode );
|
|
686 |
//test.Getch();
|
|
687 |
test(0);
|
|
688 |
}
|
|
689 |
|
|
690 |
SSpecialValueTest::SSpecialValueTest(const SRealX& op, TInt aResults)
|
|
691 |
{
|
|
692 |
iOperand=op;
|
|
693 |
iIsZero=aResults & 8;
|
|
694 |
iIsNaN=aResults & 4;
|
|
695 |
iIsInfinite=aResults & 2;
|
|
696 |
iIsFinite=aResults & 1;
|
|
697 |
}
|
|
698 |
|
|
699 |
LOCAL_C TBool same(TBool a, TBool b)
|
|
700 |
{
|
|
701 |
return( (a && b) || (!a && !b) );
|
|
702 |
}
|
|
703 |
|
|
704 |
void SSpecialValueTest::Test() const
|
|
705 |
{
|
|
706 |
TRealX x=(TRealX)iOperand;
|
|
707 |
TBool isZero=x.IsZero();
|
|
708 |
TBool isNaN=x.IsNaN();
|
|
709 |
TBool isInfinite=x.IsInfinite();
|
|
710 |
TBool isFinite=x.IsFinite();
|
|
711 |
if ( same(isZero,iIsZero) && same(isNaN,iIsNaN) && same(isInfinite,iIsInfinite) && same(isFinite,iIsFinite) )
|
|
712 |
return;
|
|
713 |
test.Printf(_L("Special value test failed\nOperand %08X %08X %08X\n"),
|
|
714 |
iOperand.iExpFlagSign, iOperand.iMantHigh, iOperand.iMantLow );
|
|
715 |
test.Printf(_L("Results IsZero=%d, IsNaN=%d, IsInfinite=%d, IsFinite=%d "),
|
|
716 |
isZero, isNaN, isInfinite, isFinite );
|
|
717 |
test.Printf(_L("Correct results IsZero=%d, IsNaN=%d, IsInfinite=%d, IsFinite=%d "),
|
|
718 |
iIsZero, iIsNaN, iIsInfinite, iIsFinite );
|
|
719 |
//test.Getch();
|
|
720 |
test(0);
|
|
721 |
}
|
|
722 |
|
|
723 |
LOCAL_C void TestAssignConstruct()
|
|
724 |
{
|
|
725 |
TInt i;
|
|
726 |
|
|
727 |
// test default constructor
|
|
728 |
TRealX z;
|
|
729 |
SRealX sz(z);
|
|
730 |
test(sz.iExpFlagSign==0);
|
|
731 |
test(sz.iMantHigh==0);
|
|
732 |
test(sz.iMantLow==0);
|
|
733 |
|
|
734 |
for (i=0; i<NumConvertFromIntTests; i++)
|
|
735 |
{
|
|
736 |
const SConvertFrom32BitTest *pT=&(ConvertFromIntTests[i]);
|
|
737 |
pT->Test(EConstructInt);
|
|
738 |
pT->Test(EAssignInt);
|
|
739 |
pT->Test(ESetInt);
|
|
740 |
}
|
|
741 |
for (i=0; i<NumConvertFromUintTests; i++)
|
|
742 |
{
|
|
743 |
const SConvertFrom32BitTest *pT=&(ConvertFromUintTests[i]);
|
|
744 |
pT->Test(EConstructUint);
|
|
745 |
pT->Test(EAssignUint);
|
|
746 |
pT->Test(ESetUint);
|
|
747 |
}
|
|
748 |
for (i=0; i<NumConvertFromInt64Tests; i++)
|
|
749 |
{
|
|
750 |
const SConvertFrom64BitTest *pT=&(ConvertFromInt64Tests[i]);
|
|
751 |
pT->Test(EConstructInt64);
|
|
752 |
pT->Test(EAssignInt64);
|
|
753 |
pT->Test(ESetInt64);
|
|
754 |
}
|
|
755 |
for (i=0; i<NumConvertFromFloatTests; i++)
|
|
756 |
{
|
|
757 |
const SConvertFrom32BitTest *pT=&(ConvertFromFloatTests[i]);
|
|
758 |
pT->Test(EConstructFloat);
|
|
759 |
pT->Test(EAssignFloat);
|
|
760 |
pT->Test(ESetFloat);
|
|
761 |
}
|
|
762 |
for (i=0; i<NumConvertFromDoubleTests; i++)
|
|
763 |
{
|
|
764 |
const SConvertFrom64BitTest *pT=&(ConvertFromDoubleTests[i]);
|
|
765 |
pT->Test(EConstructDouble);
|
|
766 |
pT->Test(EAssignDouble);
|
|
767 |
pT->Test(ESetDouble);
|
|
768 |
}
|
|
769 |
}
|
|
770 |
|
|
771 |
LOCAL_C void TestConversions()
|
|
772 |
{
|
|
773 |
TInt i;
|
|
774 |
for (i=0; i<NumConvertToIntTests; i++)
|
|
775 |
{
|
|
776 |
const SConvertTo32BitTest *pT=&(ConvertToIntTests[i]);
|
|
777 |
pT->Test(EOperatorInt);
|
|
778 |
}
|
|
779 |
for (i=0; i<NumConvertToUintTests; i++)
|
|
780 |
{
|
|
781 |
const SConvertTo32BitTest *pT=&(ConvertToUintTests[i]);
|
|
782 |
pT->Test(EOperatorUint);
|
|
783 |
}
|
|
784 |
for (i=0; i<NumConvertToInt64Tests; i++)
|
|
785 |
{
|
|
786 |
const SConvertTo64BitTest *pT=&(ConvertToInt64Tests[i]);
|
|
787 |
pT->Test(EOperatorInt64);
|
|
788 |
}
|
|
789 |
for (i=0; i<NumConvertToFloatTests; i++)
|
|
790 |
{
|
|
791 |
const SConvertTo32BitTest *pT=&(ConvertToFloatTests[i]);
|
|
792 |
pT->Test(EOperatorTReal32);
|
|
793 |
pT->Test(EGetTReal32);
|
|
794 |
}
|
|
795 |
for (i=0; i<NumConvertToDoubleTests; i++)
|
|
796 |
{
|
|
797 |
const SConvertTo64BitTest *pT=&(ConvertToDoubleTests[i]);
|
|
798 |
pT->Test(EOperatorTReal64);
|
|
799 |
pT->Test(EGetTReal64);
|
|
800 |
}
|
|
801 |
}
|
|
802 |
|
|
803 |
LOCAL_C void TestSpecials()
|
|
804 |
{
|
|
805 |
TRealX x;
|
|
806 |
SRealX sx;
|
|
807 |
x.SetInfinite(EFalse);
|
|
808 |
sx=x;
|
|
809 |
test(sx.iExpFlagSign==0xFFFF0000);
|
|
810 |
test(sx.iMantHigh==0x80000000);
|
|
811 |
test(sx.iMantLow==0);
|
|
812 |
x.SetZero();
|
|
813 |
sx=x;
|
|
814 |
test(sx.iExpFlagSign==0x00000000);
|
|
815 |
x.SetInfinite(ETrue);
|
|
816 |
sx=x;
|
|
817 |
test(sx.iExpFlagSign==0xFFFF0001);
|
|
818 |
test(sx.iMantHigh==0x80000000);
|
|
819 |
test(sx.iMantLow==0);
|
|
820 |
x.SetNaN();
|
|
821 |
sx=x;
|
|
822 |
test(sx.iExpFlagSign==0xFFFF0001);
|
|
823 |
test(sx.iMantHigh==0xC0000000);
|
|
824 |
test(sx.iMantLow==0);
|
|
825 |
x.SetZero(ETrue);
|
|
826 |
sx=x;
|
|
827 |
test(sx.iExpFlagSign==0x00000001);
|
|
828 |
|
|
829 |
TInt i;
|
|
830 |
for(i=0; i<NumSpecialValueTests; i++)
|
|
831 |
{
|
|
832 |
const SSpecialValueTest *pT=&(SpecialValueTests[i]);
|
|
833 |
pT->Test();
|
|
834 |
}
|
|
835 |
}
|
|
836 |
|
|
837 |
LOCAL_C void TestUnaryOperators()
|
|
838 |
{
|
|
839 |
TInt i;
|
|
840 |
for (i=0; i<NumUnaryPlusTests; i++)
|
|
841 |
{
|
|
842 |
const SOneOpTest *pT=&(UnaryPlusTests[i]);
|
|
843 |
pT->Test(EUnaryPlus);
|
|
844 |
}
|
|
845 |
for (i=0; i<NumUnaryMinusTests; i++)
|
|
846 |
{
|
|
847 |
const SOneOpTest *pT=&(UnaryMinusTests[i]);
|
|
848 |
pT->Test(EUnaryMinus);
|
|
849 |
}
|
|
850 |
for (i=0; i<NumIncTests; i++)
|
|
851 |
{
|
|
852 |
const SOneOpTest *pT=&(IncTests[i]);
|
|
853 |
pT->Test(EPreInc);
|
|
854 |
pT->Test(EPostInc);
|
|
855 |
}
|
|
856 |
for (i=0; i<NumDecTests; i++)
|
|
857 |
{
|
|
858 |
const SOneOpTest *pT=&(DecTests[i]);
|
|
859 |
pT->Test(EPreDec);
|
|
860 |
pT->Test(EPostDec);
|
|
861 |
}
|
|
862 |
}
|
|
863 |
|
|
864 |
LOCAL_C void TestAddition()
|
|
865 |
{
|
|
866 |
TInt i;
|
|
867 |
for (i=0; i<NumAdditionTests; i++)
|
|
868 |
{
|
|
869 |
const STwoOpTest *pT=&(AdditionTests[i]);
|
|
870 |
pT->Test(EAddEq,EFalse);
|
|
871 |
pT->Test(EAddEq,ETrue);
|
|
872 |
pT->Test(EAdd,EFalse);
|
|
873 |
pT->Test(EAdd,ETrue);
|
|
874 |
pT->Test(EPlusEq,EFalse);
|
|
875 |
pT->Test(EPlusEq,ETrue);
|
|
876 |
pT->Test(EPlus,EFalse);
|
|
877 |
pT->Test(EPlus,ETrue);
|
|
878 |
}
|
|
879 |
for (i=0; i<NumBinaryOpNaNTests; i++)
|
|
880 |
{
|
|
881 |
const STwoOpTest *pT=&(BinaryOpNaNTests[i]);
|
|
882 |
pT->Test(EAddEq,EFalse);
|
|
883 |
pT->Test(EAddEq,ETrue);
|
|
884 |
pT->Test(EAdd,EFalse);
|
|
885 |
pT->Test(EAdd,ETrue);
|
|
886 |
pT->Test(EPlusEq,EFalse);
|
|
887 |
pT->Test(EPlusEq,ETrue);
|
|
888 |
pT->Test(EPlus,EFalse);
|
|
889 |
pT->Test(EPlus,ETrue);
|
|
890 |
}
|
|
891 |
}
|
|
892 |
|
|
893 |
LOCAL_C void TestMultiplication()
|
|
894 |
{
|
|
895 |
TInt i;
|
|
896 |
for (i=0; i<NumMultiplicationTests; i++)
|
|
897 |
{
|
|
898 |
const STwoOpTest *pT=&(MultiplicationTests[i]);
|
|
899 |
pT->Test(EMultEq,EFalse);
|
|
900 |
pT->Test(EMultEq,ETrue);
|
|
901 |
pT->Test(EMult,EFalse);
|
|
902 |
pT->Test(EMult,ETrue);
|
|
903 |
pT->Test(EStarEq,EFalse);
|
|
904 |
pT->Test(EStarEq,ETrue);
|
|
905 |
pT->Test(EStar,EFalse);
|
|
906 |
pT->Test(EStar,ETrue);
|
|
907 |
}
|
|
908 |
for (i=0; i<NumBinaryOpNaNTests; i++)
|
|
909 |
{
|
|
910 |
const STwoOpTest *pT=&(BinaryOpNaNTests[i]);
|
|
911 |
pT->Test(EMultEq,EFalse);
|
|
912 |
pT->Test(EMultEq,ETrue);
|
|
913 |
pT->Test(EMult,EFalse);
|
|
914 |
pT->Test(EMult,ETrue);
|
|
915 |
pT->Test(EStarEq,EFalse);
|
|
916 |
pT->Test(EStarEq,ETrue);
|
|
917 |
pT->Test(EStar,EFalse);
|
|
918 |
pT->Test(EStar,ETrue);
|
|
919 |
}
|
|
920 |
}
|
|
921 |
|
|
922 |
LOCAL_C void TestDivision()
|
|
923 |
{
|
|
924 |
TInt i;
|
|
925 |
for (i=0; i<NumDivisionTests; i++)
|
|
926 |
{
|
|
927 |
const STwoOpTest *pT=&(DivisionTests[i]);
|
|
928 |
pT->Test(EDivEq,EFalse);
|
|
929 |
pT->Test(EDiv,EFalse);
|
|
930 |
pT->Test(ESlashEq,EFalse);
|
|
931 |
pT->Test(ESlash,EFalse);
|
|
932 |
}
|
|
933 |
for (i=0; i<NumBinaryOpNaNTests; i++)
|
|
934 |
{
|
|
935 |
const STwoOpTest *pT=&(BinaryOpNaNTests[i]);
|
|
936 |
pT->Test(EDivEq,EFalse);
|
|
937 |
pT->Test(EDiv,EFalse);
|
|
938 |
pT->Test(ESlashEq,EFalse);
|
|
939 |
pT->Test(ESlash,EFalse);
|
|
940 |
}
|
|
941 |
}
|
|
942 |
|
|
943 |
LOCAL_C void TestComparison()
|
|
944 |
{
|
|
945 |
TInt i;
|
|
946 |
for (i=0; i<NumComparisonTests; i++)
|
|
947 |
{
|
|
948 |
const SCompareTest *pT=&(ComparisonTests[i]);
|
|
949 |
pT->Test();
|
|
950 |
}
|
|
951 |
}
|
|
952 |
|
|
953 |
|
|
954 |
GLDEF_C TInt E32Main()
|
|
955 |
//
|
|
956 |
// Test TRealX
|
|
957 |
//
|
|
958 |
{
|
|
959 |
|
|
960 |
User::SetJustInTime(EFalse);
|
|
961 |
test.Title();
|
|
962 |
test.Start(_L("Assignment Operator and Constructors"));
|
|
963 |
TestAssignConstruct();
|
|
964 |
test.Next(_L("Conversions"));
|
|
965 |
TestConversions();
|
|
966 |
test.Next(_L("Setting and Checking Specials"));
|
|
967 |
TestSpecials();
|
|
968 |
test.Next(_L("Addition"));
|
|
969 |
TestAddition();
|
|
970 |
test.Next(_L("Multiplication"));
|
|
971 |
TestMultiplication();
|
|
972 |
test.Next(_L("Division"));
|
|
973 |
TestDivision();
|
|
974 |
test.Next(_L("Unary Operators"));
|
|
975 |
TestUnaryOperators();
|
|
976 |
test.Next(_L("Comparisons"));
|
|
977 |
TestComparison();
|
|
978 |
|
|
979 |
test.End();
|
|
980 |
return(KErrNone);
|
|
981 |
}
|