sl@0
|
1 |
// Copyright (c) 1995-2009 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 the License "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 |
// e32test\math\t_i64_2.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test 64-bit integer functionality.
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// TInt64, TUInt64.
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Construct TInt64 and TUInt64 and verify the results.
|
sl@0
|
21 |
// - Test the unary and shift operators and check results are as expected.
|
sl@0
|
22 |
// - Test the + - * / and % operators, verify results are as expected.
|
sl@0
|
23 |
// - Test the + - * / and % operators with random numbers, verify results
|
sl@0
|
24 |
// are as expected.
|
sl@0
|
25 |
// - Test the conversion of TInt64 to/from TReal. Verify that the results
|
sl@0
|
26 |
// are as expected.
|
sl@0
|
27 |
// - Test the conversion of TInt64 to/from text. Verify that the results
|
sl@0
|
28 |
// are as expected.
|
sl@0
|
29 |
// Platforms/Drives/Compatibility:
|
sl@0
|
30 |
// All.
|
sl@0
|
31 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
32 |
// Failures and causes:
|
sl@0
|
33 |
// Base Port information:
|
sl@0
|
34 |
//
|
sl@0
|
35 |
//
|
sl@0
|
36 |
|
sl@0
|
37 |
#include <e32test.h>
|
sl@0
|
38 |
#include <e32math.h>
|
sl@0
|
39 |
#include "largeint.h"
|
sl@0
|
40 |
#include "../misc/prbs.h"
|
sl@0
|
41 |
|
sl@0
|
42 |
typedef TLargeInt<2> I64;
|
sl@0
|
43 |
typedef TLargeInt<4> I128;
|
sl@0
|
44 |
|
sl@0
|
45 |
RTest test(_L("T_I64_2"));
|
sl@0
|
46 |
TUint Seed[2];
|
sl@0
|
47 |
|
sl@0
|
48 |
TUint64 Random64()
|
sl@0
|
49 |
{
|
sl@0
|
50 |
TUint h = Random(Seed);
|
sl@0
|
51 |
TUint l = Random(Seed);
|
sl@0
|
52 |
return MAKE_TUINT64(h,l);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
#define BOOL(x) ((x)?1:0)
|
sl@0
|
56 |
|
sl@0
|
57 |
#define FOREACH(p, table, esize) \
|
sl@0
|
58 |
for(p=table; p<(const TUint32*)((const TUint8*)table+sizeof(table)); p+=esize/sizeof(TUint32))
|
sl@0
|
59 |
|
sl@0
|
60 |
const TUint32 Table1[] =
|
sl@0
|
61 |
{
|
sl@0
|
62 |
0x00000000, 0x00000000,
|
sl@0
|
63 |
0x00000001, 0x00000000,
|
sl@0
|
64 |
0x0000cc01, 0x00000000,
|
sl@0
|
65 |
0x00db2701, 0x00000000,
|
sl@0
|
66 |
0xcc9ffcd1, 0x00000000,
|
sl@0
|
67 |
0x00000000, 0xffffffff,
|
sl@0
|
68 |
0xeeeeeeee, 0xffffffff,
|
sl@0
|
69 |
0x04030201, 0x00000055,
|
sl@0
|
70 |
0x04030201, 0x00006655,
|
sl@0
|
71 |
0x04030201, 0x00776655,
|
sl@0
|
72 |
0x04030201, 0x33776655,
|
sl@0
|
73 |
0xf9de6484, 0xb504f333
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
void Test1()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
test.Next(_L("Unary operators and shifts"));
|
sl@0
|
79 |
|
sl@0
|
80 |
const TUint32* p;
|
sl@0
|
81 |
FOREACH(p,Table1,8)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
I64 a(p);
|
sl@0
|
84 |
TInt64 b = MAKE_TINT64(p[1], p[0]);
|
sl@0
|
85 |
I64 c(b);
|
sl@0
|
86 |
test(a==c);
|
sl@0
|
87 |
TUint64 d = MAKE_TUINT64(p[1], p[0]);
|
sl@0
|
88 |
I64 e(d);
|
sl@0
|
89 |
test(a==e);
|
sl@0
|
90 |
I64 c2(~b);
|
sl@0
|
91 |
I64 c3(-b);
|
sl@0
|
92 |
a.Not();
|
sl@0
|
93 |
test(c2==a);
|
sl@0
|
94 |
a.Not();
|
sl@0
|
95 |
test(c==a);
|
sl@0
|
96 |
a.Neg();
|
sl@0
|
97 |
test(c3==a);
|
sl@0
|
98 |
a.Neg();
|
sl@0
|
99 |
test(c==a);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
FOREACH(p,Table1,8)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
I64 a(p);
|
sl@0
|
104 |
TInt64 s = MAKE_TINT64(p[1], p[0]);
|
sl@0
|
105 |
TUint64 u = MAKE_TUINT64(p[1], p[0]);
|
sl@0
|
106 |
TInt n;
|
sl@0
|
107 |
for (n=0; n<64; ++n)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
I64 b(a), c(a), d(a);
|
sl@0
|
110 |
b.Lsl(n), c.Lsr(n), d.Asr(n);
|
sl@0
|
111 |
TInt64 s2 = s<<n;
|
sl@0
|
112 |
TInt64 s3 = s>>n;
|
sl@0
|
113 |
TUint64 u2 = u<<n;
|
sl@0
|
114 |
TUint64 u3 = u>>n;
|
sl@0
|
115 |
// test.Printf(_L("s2=%lx\ns3=%lx\n,u2=%lx\n,u3=%lx\n"),s2,s3,u2,u3);
|
sl@0
|
116 |
test(b == I64(s2));
|
sl@0
|
117 |
test(b == I64(u2));
|
sl@0
|
118 |
test(c == I64(u3));
|
sl@0
|
119 |
test(d == I64(s3));
|
sl@0
|
120 |
}
|
sl@0
|
121 |
}
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
const TUint32 Table2[] =
|
sl@0
|
125 |
{
|
sl@0
|
126 |
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
sl@0
|
127 |
0x00000001, 0x00000000, 0x00000000, 0x00000000,
|
sl@0
|
128 |
0x05f5e100, 0x00000000, 0x000000cb, 0x00000000,
|
sl@0
|
129 |
0xffffff9c, 0xffffffff, 0x00129cbb, 0x00000000,
|
sl@0
|
130 |
0xffffcd03, 0xffffffff, 0xffff9123, 0xffffffff,
|
sl@0
|
131 |
0xf9de6484, 0xb504f333, 0xf9de6484, 0xb504f333,
|
sl@0
|
132 |
0xf9de6484, 0xb504f333, 0x2168c235, 0xc90fdaa2,
|
sl@0
|
133 |
0xf9de6484, 0xb504f333, 0x000000cb, 0x00000000,
|
sl@0
|
134 |
0xf9de6484, 0xb504f333, 0x800000cb, 0x00000000,
|
sl@0
|
135 |
0xf9de6484, 0xb504f333, 0x000000cb, 0x00000001,
|
sl@0
|
136 |
0xf9de6484, 0xb504f333, 0xfffffed9, 0xffffffff,
|
sl@0
|
137 |
0xf9de6484, 0xb504f333, 0x197383db, 0xffffffff,
|
sl@0
|
138 |
0xf9de6484, 0xb504f333, 0x197383db, 0xffffffec,
|
sl@0
|
139 |
0x38aa3b29, 0x5c17f0bc, 0x000019c7, 0x00000000,
|
sl@0
|
140 |
0x38aa3b29, 0x5c17f0bc, 0x800019c7, 0x00000000,
|
sl@0
|
141 |
0x38aa3b29, 0x5c17f0bc, 0x000019c7, 0x00000003,
|
sl@0
|
142 |
0x38aa3b29, 0x5c17f0bc, 0x197383db, 0xffffffff,
|
sl@0
|
143 |
0x38aa3b29, 0x5c17f0bc, 0x197383db, 0xffffffec,
|
sl@0
|
144 |
0x00123456, 0x00000000, 0x8cb9fc1b, 0x00000000,
|
sl@0
|
145 |
0x00000123, 0x00000000, 0x8cb9fc1b, 0x0000cc9f,
|
sl@0
|
146 |
0xfffffe33, 0xffffffff, 0x8cb9fc1b, 0x0000cc9f
|
sl@0
|
147 |
};
|
sl@0
|
148 |
|
sl@0
|
149 |
void Test2(const TUint32* p)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
I64 a(p), b(p+2);
|
sl@0
|
152 |
TInt64 x = MAKE_TINT64(p[1], p[0]);
|
sl@0
|
153 |
TInt64 y = MAKE_TINT64(p[3], p[2]);
|
sl@0
|
154 |
TUint64 u = MAKE_TUINT64(p[1], p[0]);
|
sl@0
|
155 |
TUint64 v = MAKE_TUINT64(p[3], p[2]);
|
sl@0
|
156 |
{
|
sl@0
|
157 |
I64 c(a); c.Add(b); test(c==I64(x+y)); test(c==I64(u+v));
|
sl@0
|
158 |
test(c==I64(y+x)); test(c==I64(v+u));
|
sl@0
|
159 |
}
|
sl@0
|
160 |
{
|
sl@0
|
161 |
I64 c(a); c.Sub(b); test(c==I64(x-y)); test(c==I64(u-v));
|
sl@0
|
162 |
I64 d(b); d.Sub(a); test(d==I64(y-x)); test(d==I64(v-u));
|
sl@0
|
163 |
}
|
sl@0
|
164 |
{
|
sl@0
|
165 |
I64 c(a); c.Mul(b); test(c==I64(x*y)); test(c==I64(u*v));
|
sl@0
|
166 |
test(c==I64(y*x)); test(c==I64(v*u));
|
sl@0
|
167 |
}
|
sl@0
|
168 |
{
|
sl@0
|
169 |
I128 c = a.LongMultS(b);
|
sl@0
|
170 |
TUint32 t[4];
|
sl@0
|
171 |
Math::Mul64(x, y, *(TInt64*)(t+2), *(TUint64*)t);
|
sl@0
|
172 |
test(c==I128(t));
|
sl@0
|
173 |
Math::Mul64(y, x, *(TInt64*)(t+2), *(TUint64*)t);
|
sl@0
|
174 |
test(c==I128(t));
|
sl@0
|
175 |
}
|
sl@0
|
176 |
{
|
sl@0
|
177 |
I128 c = a.LongMultU(b);
|
sl@0
|
178 |
TUint32 t[4];
|
sl@0
|
179 |
Math::UMul64(u, v, *(TUint64*)(t+2), *(TUint64*)t);
|
sl@0
|
180 |
test(c==I128(t));
|
sl@0
|
181 |
Math::UMul64(v, u, *(TUint64*)(t+2), *(TUint64*)t);
|
sl@0
|
182 |
test(c==I128(t));
|
sl@0
|
183 |
}
|
sl@0
|
184 |
if (y!=0)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
I64 r; I64 q(a); q.DivS(b,r);
|
sl@0
|
187 |
test(q==I64(x/y));
|
sl@0
|
188 |
test(r==I64(x%y));
|
sl@0
|
189 |
TInt64 r2;
|
sl@0
|
190 |
TInt64 q2 = Math::DivMod64(x, y, r2);
|
sl@0
|
191 |
test(q==I64(q2));
|
sl@0
|
192 |
test(r==I64(r2));
|
sl@0
|
193 |
}
|
sl@0
|
194 |
if (x!=0)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
I64 r; I64 q(b); q.DivS(a,r);
|
sl@0
|
197 |
test(q==I64(y/x));
|
sl@0
|
198 |
test(r==I64(y%x));
|
sl@0
|
199 |
TInt64 r2;
|
sl@0
|
200 |
TInt64 q2 = Math::DivMod64(y, x, r2);
|
sl@0
|
201 |
test(q==I64(q2));
|
sl@0
|
202 |
test(r==I64(r2));
|
sl@0
|
203 |
}
|
sl@0
|
204 |
if (v!=0)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
I64 r; I64 q(a); q.DivU(b,r);
|
sl@0
|
207 |
test(q==I64(u/v));
|
sl@0
|
208 |
test(r==I64(u%v));
|
sl@0
|
209 |
TUint64 r2;
|
sl@0
|
210 |
TUint64 q2 = Math::UDivMod64(u, v, r2);
|
sl@0
|
211 |
test(q==I64(q2));
|
sl@0
|
212 |
test(r==I64(r2));
|
sl@0
|
213 |
}
|
sl@0
|
214 |
if (u!=0)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
I64 r; I64 q(b); q.DivU(a,r);
|
sl@0
|
217 |
test(q==I64(v/u));
|
sl@0
|
218 |
test(r==I64(v%u));
|
sl@0
|
219 |
TUint64 r2;
|
sl@0
|
220 |
TUint64 q2 = Math::UDivMod64(v, u, r2);
|
sl@0
|
221 |
test(q==I64(q2));
|
sl@0
|
222 |
test(r==I64(r2));
|
sl@0
|
223 |
}
|
sl@0
|
224 |
{
|
sl@0
|
225 |
TInt cmpu = a.CompareU(b);
|
sl@0
|
226 |
TInt cmps = a.CompareS(b);
|
sl@0
|
227 |
TInt equ = BOOL(u==v);
|
sl@0
|
228 |
TInt neu = BOOL(u!=v);
|
sl@0
|
229 |
TInt hi = BOOL(u>v);
|
sl@0
|
230 |
TInt hs = BOOL(u>=v);
|
sl@0
|
231 |
TInt lo = BOOL(u<v);
|
sl@0
|
232 |
TInt ls = BOOL(u<=v);
|
sl@0
|
233 |
|
sl@0
|
234 |
TInt eqs = BOOL(x==y);
|
sl@0
|
235 |
TInt nes = BOOL(x!=y);
|
sl@0
|
236 |
TInt gt = BOOL(x>y);
|
sl@0
|
237 |
TInt ge = BOOL(x>=y);
|
sl@0
|
238 |
TInt lt = BOOL(x<y);
|
sl@0
|
239 |
TInt le = BOOL(x<=y);
|
sl@0
|
240 |
|
sl@0
|
241 |
test(equ==eqs);
|
sl@0
|
242 |
test(neu==nes);
|
sl@0
|
243 |
test(equ!=neu);
|
sl@0
|
244 |
if (cmpu>0)
|
sl@0
|
245 |
test(!equ && hi && hs && !lo && !ls);
|
sl@0
|
246 |
else if (cmpu<0)
|
sl@0
|
247 |
test(!equ && !hi && !hs && lo && ls);
|
sl@0
|
248 |
else
|
sl@0
|
249 |
test(equ && !hi && hs && !lo && ls);
|
sl@0
|
250 |
if (cmps>0)
|
sl@0
|
251 |
test(!eqs && gt && ge && !lt && !le);
|
sl@0
|
252 |
else if (cmps<0)
|
sl@0
|
253 |
test(!eqs && !gt && !ge && lt && le);
|
sl@0
|
254 |
else
|
sl@0
|
255 |
test(eqs && !gt && ge && !lt && le);
|
sl@0
|
256 |
}
|
sl@0
|
257 |
}
|
sl@0
|
258 |
|
sl@0
|
259 |
void Test2()
|
sl@0
|
260 |
{
|
sl@0
|
261 |
test.Next(_L("Test + - * / % (1)"));
|
sl@0
|
262 |
const TUint32* p;
|
sl@0
|
263 |
FOREACH(p,Table2,16)
|
sl@0
|
264 |
{
|
sl@0
|
265 |
Test2(p);
|
sl@0
|
266 |
}
|
sl@0
|
267 |
}
|
sl@0
|
268 |
|
sl@0
|
269 |
void Test3()
|
sl@0
|
270 |
{
|
sl@0
|
271 |
test.Next(_L("Test + - * / % (2)"));
|
sl@0
|
272 |
TInt i;
|
sl@0
|
273 |
for (i=0; i<100; ++i)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
TUint32 p[4];
|
sl@0
|
276 |
p[0] = Random(Seed);
|
sl@0
|
277 |
p[1] = Random(Seed);
|
sl@0
|
278 |
p[2] = Random(Seed);
|
sl@0
|
279 |
p[3] = Random(Seed);
|
sl@0
|
280 |
Test2(p);
|
sl@0
|
281 |
}
|
sl@0
|
282 |
}
|
sl@0
|
283 |
|
sl@0
|
284 |
void Test4()
|
sl@0
|
285 |
{
|
sl@0
|
286 |
test.Next(_L("Test conversion to/from TReal"));
|
sl@0
|
287 |
TReal x;
|
sl@0
|
288 |
TReal limit=1048576.0*1048576.0*8192.0;
|
sl@0
|
289 |
TInt64 t22 = (TInt64)limit;
|
sl@0
|
290 |
test(t22 == TInt64(1)<<53);
|
sl@0
|
291 |
TInt64 t23 = (TInt64)(limit-1.0);
|
sl@0
|
292 |
test(t23 == (TInt64(1)<<53)-1);
|
sl@0
|
293 |
|
sl@0
|
294 |
|
sl@0
|
295 |
TInt i;
|
sl@0
|
296 |
TInt64 l;
|
sl@0
|
297 |
for (i=-99; i<100; i++)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
x=1;
|
sl@0
|
300 |
l=1;
|
sl@0
|
301 |
TReal a(i);
|
sl@0
|
302 |
TInt64 b(i);
|
sl@0
|
303 |
while (Abs(x)<limit)
|
sl@0
|
304 |
{
|
sl@0
|
305 |
TInt64 ll = (TInt64)x;
|
sl@0
|
306 |
// test.Printf(_L("r64 %g -> i64 %lx (%lx)\n"), x, ll, l);
|
sl@0
|
307 |
test(ll==l);
|
sl@0
|
308 |
ll=0;
|
sl@0
|
309 |
ll = (TInt64)x;
|
sl@0
|
310 |
test(ll==l);
|
sl@0
|
311 |
x*=a;
|
sl@0
|
312 |
l*=b;
|
sl@0
|
313 |
if (i==1 || i==0 || (i==-1 && l==TInt64(1)))
|
sl@0
|
314 |
break;
|
sl@0
|
315 |
}
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
TReal i64limit = 1024.0*limit;
|
sl@0
|
319 |
l=MAKE_TINT64(0x7fffffff,0xfffffc00);
|
sl@0
|
320 |
x=(TReal)l;
|
sl@0
|
321 |
test(x==i64limit-1024.0);
|
sl@0
|
322 |
l=MAKE_TINT64(0x80000000,0x00000000);
|
sl@0
|
323 |
x=(TReal)l;
|
sl@0
|
324 |
test(x==-i64limit);
|
sl@0
|
325 |
l=MAKE_TINT64(0x80000000,0x00000400);
|
sl@0
|
326 |
x=(TReal)l;
|
sl@0
|
327 |
test(x==1024.0-i64limit);
|
sl@0
|
328 |
l=MAKE_TINT64(0x00000001,0x00000000);
|
sl@0
|
329 |
x=(TReal)l;
|
sl@0
|
330 |
test(x==65536.0*65536.0);
|
sl@0
|
331 |
l=MAKE_TINT64(0xffffffff,0x00000000);
|
sl@0
|
332 |
x=(TReal)l;
|
sl@0
|
333 |
test(x==-65536.0*65536.0);
|
sl@0
|
334 |
|
sl@0
|
335 |
for (i=-99; i<100; i++)
|
sl@0
|
336 |
{
|
sl@0
|
337 |
x=1;
|
sl@0
|
338 |
l=1;
|
sl@0
|
339 |
TReal a(i);
|
sl@0
|
340 |
TInt64 b(i);
|
sl@0
|
341 |
while (Abs(x)<limit)
|
sl@0
|
342 |
{
|
sl@0
|
343 |
TReal y = (TReal)l;
|
sl@0
|
344 |
test(y==x);
|
sl@0
|
345 |
x*=a;
|
sl@0
|
346 |
l*=b;
|
sl@0
|
347 |
if (i==1 || i==0 || (i==-1 && l==TInt64(1)))
|
sl@0
|
348 |
break;
|
sl@0
|
349 |
}
|
sl@0
|
350 |
}
|
sl@0
|
351 |
|
sl@0
|
352 |
}
|
sl@0
|
353 |
|
sl@0
|
354 |
_LIT8(KTestHex8,"0 1 8 a 1b 2c7 10000000 100000000 1901cbfdc b504f333f9de6484 ffffffffffffffff");
|
sl@0
|
355 |
_LIT16(KTestHex16,"0 1 8 a 1b 2c7 10000000 100000000 1901cbfdc b504f333f9de6484 ffffffffffffffff");
|
sl@0
|
356 |
|
sl@0
|
357 |
const TUint32 TestHexTable[] =
|
sl@0
|
358 |
{
|
sl@0
|
359 |
0x00000000, 0x00000000,
|
sl@0
|
360 |
0x00000001, 0x00000000,
|
sl@0
|
361 |
0x00000008, 0x00000000,
|
sl@0
|
362 |
0x0000000a, 0x00000000,
|
sl@0
|
363 |
0x0000001b, 0x00000000,
|
sl@0
|
364 |
0x000002c7, 0x00000000,
|
sl@0
|
365 |
0x10000000, 0x00000000,
|
sl@0
|
366 |
0x00000000, 0x00000001,
|
sl@0
|
367 |
0x901cbfdc, 0x00000001,
|
sl@0
|
368 |
0xf9de6484, 0xb504f333,
|
sl@0
|
369 |
0xffffffff, 0xffffffff
|
sl@0
|
370 |
};
|
sl@0
|
371 |
|
sl@0
|
372 |
_LIT8(KTestDec8,"0 1 8 100 6561 536870912 2147483648 4294967295 4294967296 549755813888 1000000000000000 9223372036854775807 \
|
sl@0
|
373 |
-9223372036854775808 -9223372036854775807 -9000000000000000000 -1099511627776 -4294967296 -1000 -1");
|
sl@0
|
374 |
_LIT16(KTestDec16,"0 1 8 100 6561 536870912 2147483648 4294967295 4294967296 549755813888 1000000000000000 9223372036854775807 \
|
sl@0
|
375 |
-9223372036854775808 -9223372036854775807 -9000000000000000000 -1099511627776 -4294967296 -1000 -1");
|
sl@0
|
376 |
|
sl@0
|
377 |
const TUint32 TestDecTable[] =
|
sl@0
|
378 |
{
|
sl@0
|
379 |
0x00000000, 0x00000000,
|
sl@0
|
380 |
0x00000001, 0x00000000,
|
sl@0
|
381 |
0x00000008, 0x00000000,
|
sl@0
|
382 |
0x00000064, 0x00000000,
|
sl@0
|
383 |
0x000019a1, 0x00000000,
|
sl@0
|
384 |
0x20000000, 0x00000000,
|
sl@0
|
385 |
0x80000000, 0x00000000,
|
sl@0
|
386 |
0xffffffff, 0x00000000,
|
sl@0
|
387 |
0x00000000, 0x00000001,
|
sl@0
|
388 |
0x00000000, 0x00000080,
|
sl@0
|
389 |
0xa4c68000, 0x00038d7e,
|
sl@0
|
390 |
0xffffffff, 0x7fffffff,
|
sl@0
|
391 |
0x00000000, 0x80000000,
|
sl@0
|
392 |
0x00000001, 0x80000000,
|
sl@0
|
393 |
0x1d7c0000, 0x831993af,
|
sl@0
|
394 |
0x00000000, 0xffffff00,
|
sl@0
|
395 |
0x00000000, 0xffffffff,
|
sl@0
|
396 |
0xfffffc18, 0xffffffff,
|
sl@0
|
397 |
0xffffffff, 0xffffffff
|
sl@0
|
398 |
};
|
sl@0
|
399 |
|
sl@0
|
400 |
void Test5()
|
sl@0
|
401 |
{
|
sl@0
|
402 |
test.Next(_L("Test conversion to/from text"));
|
sl@0
|
403 |
TLex8 lex8;
|
sl@0
|
404 |
lex8.Assign(KTestHex8());
|
sl@0
|
405 |
TInt64 u;
|
sl@0
|
406 |
const TUint32* p = TestHexTable;
|
sl@0
|
407 |
for (; !lex8.Eos(); lex8.SkipSpace(), p+=2)
|
sl@0
|
408 |
{
|
sl@0
|
409 |
lex8.Mark();
|
sl@0
|
410 |
test(lex8.Val(u,EHex)==KErrNone);
|
sl@0
|
411 |
test(u == MAKE_TINT64(p[1], p[0]));
|
sl@0
|
412 |
TPtrC8 text = lex8.MarkedToken();
|
sl@0
|
413 |
TBuf8<64> b;
|
sl@0
|
414 |
b.Num(u,EHex);
|
sl@0
|
415 |
test(b==text);
|
sl@0
|
416 |
b.NumUC(u,EHex);
|
sl@0
|
417 |
TBuf8<64> uc = text;
|
sl@0
|
418 |
uc.UpperCase();
|
sl@0
|
419 |
test(b==uc);
|
sl@0
|
420 |
}
|
sl@0
|
421 |
lex8.Assign(KTestDec8());
|
sl@0
|
422 |
TInt64 s;
|
sl@0
|
423 |
p = TestDecTable;
|
sl@0
|
424 |
for (; !lex8.Eos(); lex8.SkipSpace(), p+=2)
|
sl@0
|
425 |
{
|
sl@0
|
426 |
lex8.Mark();
|
sl@0
|
427 |
test(lex8.Val(s)==KErrNone);
|
sl@0
|
428 |
test(s == MAKE_TINT64(p[1], p[0]));
|
sl@0
|
429 |
TPtrC8 text = lex8.MarkedToken();
|
sl@0
|
430 |
TBuf8<64> b;
|
sl@0
|
431 |
b.Num(s);
|
sl@0
|
432 |
test(b==text);
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
TLex16 lex16;
|
sl@0
|
436 |
lex16.Assign(KTestHex16());
|
sl@0
|
437 |
p = TestHexTable;
|
sl@0
|
438 |
for (; !lex16.Eos(); lex16.SkipSpace(), p+=2)
|
sl@0
|
439 |
{
|
sl@0
|
440 |
lex16.Mark();
|
sl@0
|
441 |
test(lex16.Val(u,EHex)==KErrNone);
|
sl@0
|
442 |
test(u == MAKE_TINT64(p[1], p[0]));
|
sl@0
|
443 |
TPtrC16 text = lex16.MarkedToken();
|
sl@0
|
444 |
TBuf16<64> b;
|
sl@0
|
445 |
b.Num(u,EHex);
|
sl@0
|
446 |
test(b==text);
|
sl@0
|
447 |
b.NumUC(u,EHex);
|
sl@0
|
448 |
TBuf16<64> uc = text;
|
sl@0
|
449 |
uc.UpperCase();
|
sl@0
|
450 |
test(b==uc);
|
sl@0
|
451 |
}
|
sl@0
|
452 |
lex16.Assign(KTestDec16());
|
sl@0
|
453 |
p = TestDecTable;
|
sl@0
|
454 |
for (; !lex16.Eos(); lex16.SkipSpace(), p+=2)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
lex16.Mark();
|
sl@0
|
457 |
test(lex16.Val(s)==KErrNone);
|
sl@0
|
458 |
test(s == MAKE_TINT64(p[1], p[0]));
|
sl@0
|
459 |
TPtrC16 text = lex16.MarkedToken();
|
sl@0
|
460 |
TBuf16<64> b;
|
sl@0
|
461 |
b.Num(s);
|
sl@0
|
462 |
test(b==text);
|
sl@0
|
463 |
}
|
sl@0
|
464 |
}
|
sl@0
|
465 |
|
sl@0
|
466 |
GLDEF_C TInt E32Main()
|
sl@0
|
467 |
{
|
sl@0
|
468 |
|
sl@0
|
469 |
Seed[0] = 0xb8aa3b29;
|
sl@0
|
470 |
Seed[1] = 0;
|
sl@0
|
471 |
|
sl@0
|
472 |
test.Title();
|
sl@0
|
473 |
test.Start(_L("Testing 64 bit integers"));
|
sl@0
|
474 |
|
sl@0
|
475 |
Test1();
|
sl@0
|
476 |
Test2();
|
sl@0
|
477 |
Test3();
|
sl@0
|
478 |
Test4();
|
sl@0
|
479 |
Test5();
|
sl@0
|
480 |
|
sl@0
|
481 |
test.End();
|
sl@0
|
482 |
return(KErrNone);
|
sl@0
|
483 |
}
|
sl@0
|
484 |
|