VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/lltest.c@ 46155

Last change on this file since 46155 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.6 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/*
39** testll.c -- test suite for 64bit integer (longlong) operations
40**
41** Summary: testll [-d] | [-h]
42**
43** Where:
44** -d set debug mode on; displays individual test failures
45** -v verbose mode; displays progress in test, plus -d
46** -h gives usage message.
47**
48** Description:
49** lltest.c tests the functions defined in NSPR 2.0's prlong.h.
50**
51** Successive tests begin to depend on other LL functions working
52** correctly. So, ... Do not change the order of the tests as run
53** from main().
54**
55** Caveats:
56** Do not even begin to think that this is an exhaustive test!
57**
58** These tests try a little of everything, but not all boundary
59** conditions and limits are tested.
60** You want better coverage? ... Add it.
61**
62** ---
63** Author: Lawrence Hardiman <larryh@netscape.com>.
64** ---
65** Revision History:
66** 01-Oct-1997. Original implementation.
67**
68*/
69
70#include "nspr.h"
71#include "plgetopt.h"
72
73/* --- Local Definitions --- */
74#define ReportProgress(m) if (verboseMode) PR_fprintf(output, (m));
75
76
77/* --- Global variables --- */
78static PRIntn failedAlready = 0;
79static PRFileDesc* output = NULL;
80static PRBool debugMode = PR_FALSE;
81static PRBool verboseMode = PR_FALSE;
82
83/*
84** Constants used in tests.
85*/
86const PRInt64 bigZero = LL_INIT( 0, 0 );
87const PRInt64 bigOne = LL_INIT( 0, 1 );
88const PRInt64 bigTwo = LL_INIT( 0, 2 );
89const PRInt64 bigSixTeen = LL_INIT( 0, 16 );
90const PRInt64 bigThirtyTwo = LL_INIT( 0, 32 );
91const PRInt64 bigMinusOne = LL_INIT( 0xffffffff, 0xffffffff );
92const PRInt64 bigMinusTwo = LL_INIT( 0xffffffff, 0xfffffffe );
93const PRInt64 bigNumber = LL_INIT( 0x7fffffff, 0xffffffff );
94const PRInt64 bigMinusNumber = LL_INIT( 0x80000000, 0x00000001 );
95const PRInt64 bigMaxInt32 = LL_INIT( 0x00000000, 0x7fffffff );
96const PRInt64 big2To31 = LL_INIT( 0x00000000, 0x80000000 );
97const PRUint64 bigZeroFox = LL_INIT( 0x00000000, 0xffffffff );
98const PRUint64 bigFoxFox = LL_INIT( 0xffffffff, 0xffffffff );
99const PRUint64 bigFoxZero = LL_INIT( 0xffffffff, 0x00000000 );
100const PRUint64 bigEightZero = LL_INIT( 0x80000000, 0x00000000 );
101const PRUint64 big64K = LL_INIT( 0x00000000, 0x00010000 );
102const PRInt64 bigInt0 = LL_INIT( 0x01a00000, 0x00001000 );
103const PRInt64 bigInt1 = LL_INIT( 0x01a00000, 0x00001100 );
104const PRInt64 bigInt2 = LL_INIT( 0x01a00000, 0x00000100 );
105const PRInt64 bigInt3 = LL_INIT( 0x01a00001, 0x00001000 );
106const PRInt64 bigInt4 = LL_INIT( 0x01a00001, 0x00001100 );
107const PRInt64 bigInt5 = LL_INIT( 0x01a00001, 0x00000100 );
108const PRInt64 bigInt6 = LL_INIT( 0xb1a00000, 0x00001000 );
109const PRInt64 bigInt7 = LL_INIT( 0xb1a00000, 0x00001100 );
110const PRInt64 bigInt8 = LL_INIT( 0xb1a00000, 0x00000100 );
111const PRInt64 bigInt9 = LL_INIT( 0xb1a00001, 0x00001000 );
112const PRInt64 bigInt10 = LL_INIT( 0xb1a00001, 0x00001100 );
113const PRInt64 bigInt11 = LL_INIT( 0xb1a00001, 0x00000100 );
114const PRInt32 one = 1l;
115const PRInt32 minusOne = -1l;
116const PRInt32 sixteen = 16l;
117const PRInt32 thirtyTwo = 32l;
118const PRInt32 sixtyThree = 63l;
119
120/*
121** SetFailed() -- Report individual test failure
122**
123*/
124static void
125SetFailed( char *what, char *how )
126{
127 failedAlready = 1;
128 if ( debugMode )
129 PR_fprintf(output, "%s: failed: %s\n", what, how );
130 return;
131}
132
133static void
134ResultFailed( char *what, char *how, PRInt64 expected, PRInt64 got)
135{
136 if ( debugMode)
137 {
138 SetFailed( what, how );
139 PR_fprintf(output, "Expected: 0x%llx Got: 0x%llx\n", expected, got );
140 }
141 return;
142}
143
144
145/*
146** TestAssignment() -- Test the assignment
147*/
148static void TestAssignment( void )
149{
150 PRInt64 zero = LL_Zero();
151 PRInt64 min = LL_MinInt();
152 PRInt64 max = LL_MaxInt();
153 if (!LL_EQ(zero, bigZero))
154 SetFailed("LL_EQ(zero, bigZero)", "!=");
155 if (!LL_CMP(max, >, min))
156 SetFailed("LL_CMP(max, >, min)", "!>");
157}
158
159/*
160** TestComparisons() -- Test the longlong comparison operations
161*/
162static void
163TestComparisons( void )
164{
165 ReportProgress("Testing Comparisons Operations\n");
166
167 /* test for zero */
168 if ( !LL_IS_ZERO( bigZero ))
169 SetFailed( "LL_IS_ZERO", "Zero is not zero" );
170
171 if ( LL_IS_ZERO( bigOne ))
172 SetFailed( "LL_IS_ZERO", "One tests as zero" );
173
174 if ( LL_IS_ZERO( bigMinusOne ))
175 SetFailed( "LL_IS_ZERO", "Minus One tests as zero" );
176
177 /* test equal */
178 if ( !LL_EQ( bigZero, bigZero ))
179 SetFailed( "LL_EQ", "zero EQ zero");
180
181 if ( !LL_EQ( bigOne, bigOne ))
182 SetFailed( "LL_EQ", "one EQ one" );
183
184 if ( !LL_EQ( bigNumber, bigNumber ))
185 SetFailed( "LL_EQ", "bigNumber EQ bigNumber" );
186
187 if ( !LL_EQ( bigMinusOne, bigMinusOne ))
188 SetFailed( "LL_EQ", "minus one EQ minus one");
189
190 if ( LL_EQ( bigZero, bigOne ))
191 SetFailed( "LL_EQ", "zero EQ one");
192
193 if ( LL_EQ( bigOne, bigZero ))
194 SetFailed( "LL_EQ", "one EQ zero" );
195
196 if ( LL_EQ( bigMinusOne, bigOne ))
197 SetFailed( "LL_EQ", "minus one EQ one");
198
199 if ( LL_EQ( bigNumber, bigOne ))
200 SetFailed( "LL_EQ", "bigNumber EQ one");
201
202 /* test not equal */
203 if ( LL_NE( bigZero, bigZero ))
204 SetFailed( "LL_NE", "0 NE 0");
205
206 if ( LL_NE( bigOne, bigOne ))
207 SetFailed( "LL_NE", "1 NE 1");
208
209 if ( LL_NE( bigMinusOne, bigMinusOne ))
210 SetFailed( "LL_NE", "-1 NE -1");
211
212 if ( LL_NE( bigNumber, bigNumber ))
213 SetFailed( "LL_NE", "n NE n");
214
215 if ( LL_NE( bigMinusNumber, bigMinusNumber ))
216 SetFailed( "LL_NE", "-n NE -n");
217
218 if ( !LL_NE( bigZero, bigOne))
219 SetFailed( "LL_NE", "0 NE 1");
220
221 if ( !LL_NE( bigOne, bigMinusNumber))
222 SetFailed( "LL_NE", "1 NE -n");
223
224 /* Greater than or equal to zero */
225 if ( !LL_GE_ZERO( bigZero ))
226 SetFailed( "LL_GE_ZERO", "0");
227
228 if ( !LL_GE_ZERO( bigOne ))
229 SetFailed( "LL_GE_ZERO", "1");
230
231 if ( !LL_GE_ZERO( bigNumber ))
232 SetFailed( "LL_GE_ZERO", "n");
233
234 if ( LL_GE_ZERO( bigMinusOne ))
235 SetFailed( "LL_GE_ZERO", "-1");
236
237 if ( LL_GE_ZERO( bigMinusNumber ))
238 SetFailed( "LL_GE_ZERO", "-n");
239
240 /* Algebraic Compare two values */
241 if ( !LL_CMP( bigZero, ==, bigZero ))
242 SetFailed( "LL_CMP", "0 == 0");
243
244 if ( LL_CMP( bigZero, >, bigZero ))
245 SetFailed( "LL_CMP", "0 > 0");
246
247 if ( LL_CMP( bigZero, <, bigZero ))
248 SetFailed( "LL_CMP", "0 < 0");
249
250 if ( LL_CMP( bigNumber, <, bigOne ))
251 SetFailed( "LL_CMP", "n < 1");
252
253 if ( !LL_CMP( bigNumber, >, bigOne ))
254 SetFailed( "LL_CMP", "n <= 1");
255
256 if ( LL_CMP( bigOne, >, bigNumber ))
257 SetFailed( "LL_CMP", "1 > n");
258
259 if ( LL_CMP( bigMinusNumber, >, bigNumber ))
260 SetFailed( "LL_CMP", "-n > n");
261
262 if ( LL_CMP( bigNumber, !=, bigNumber))
263 SetFailed( "LL_CMP", "n != n");
264
265 if ( !LL_CMP( bigMinusOne, >, bigMinusTwo ))
266 SetFailed( "LL_CMP", "-1 <= -2");
267
268 if ( !LL_CMP( bigMaxInt32, <, big2To31 ))
269 SetFailed( "LL_CMP", "Max 32-bit signed int >= 2^31");
270
271 /* Two positive numbers */
272 if ( !LL_CMP( bigInt0, <=, bigInt0 ))
273 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
274
275 if ( !LL_CMP( bigInt0, <=, bigInt1 ))
276 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
277
278 if ( LL_CMP( bigInt0, <=, bigInt2 ))
279 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
280
281 if ( !LL_CMP( bigInt0, <=, bigInt3 ))
282 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
283
284 if ( !LL_CMP( bigInt0, <=, bigInt4 ))
285 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
286
287 if ( !LL_CMP( bigInt0, <=, bigInt5 ))
288 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
289
290 /* Two negative numbers */
291 if ( !LL_CMP( bigInt6, <=, bigInt6 ))
292 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
293
294 if ( !LL_CMP( bigInt6, <=, bigInt7 ))
295 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
296
297 if ( LL_CMP( bigInt6, <=, bigInt8 ))
298 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
299
300 if ( !LL_CMP( bigInt6, <=, bigInt9 ))
301 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
302
303 if ( !LL_CMP( bigInt6, <=, bigInt10 ))
304 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
305
306 if ( !LL_CMP( bigInt6, <=, bigInt11 ))
307 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
308
309 /* One positive, one negative */
310 if ( LL_CMP( bigInt0, <=, bigInt6 ))
311 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
312
313 if ( LL_CMP( bigInt0, <=, bigInt7 ))
314 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
315
316 if ( LL_CMP( bigInt0, <=, bigInt8 ))
317 SetFailed( "LL_CMP", "LL_CMP(<=) failed");
318
319 /* Bitwise Compare two numbers */
320 if ( !LL_UCMP( bigZero, ==, bigZero ))
321 SetFailed( "LL_UCMP", "0 == 0");
322
323 if ( LL_UCMP( bigZero, >, bigZero ))
324 SetFailed( "LL_UCMP", "0 > 0");
325
326 if ( LL_UCMP( bigZero, <, bigZero ))
327 SetFailed( "LL_UCMP", "0 < 0");
328
329 if ( LL_UCMP( bigNumber, <, bigOne ))
330 SetFailed( "LL_UCMP", "n < 1");
331
332 if ( !LL_UCMP( bigNumber, >, bigOne ))
333 SetFailed( "LL_UCMP", "n < 1");
334
335 if ( LL_UCMP( bigOne, >, bigNumber ))
336 SetFailed( "LL_UCMP", "1 > n");
337
338 if ( LL_UCMP( bigMinusNumber, <, bigNumber ))
339 SetFailed( "LL_UCMP", "-n < n");
340
341 /* Two positive numbers */
342 if ( !LL_UCMP( bigInt0, <=, bigInt0 ))
343 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
344
345 if ( !LL_UCMP( bigInt0, <=, bigInt1 ))
346 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
347
348 if ( LL_UCMP( bigInt0, <=, bigInt2 ))
349 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
350
351 if ( !LL_UCMP( bigInt0, <=, bigInt3 ))
352 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
353
354 if ( !LL_UCMP( bigInt0, <=, bigInt4 ))
355 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
356
357 if ( !LL_UCMP( bigInt0, <=, bigInt5 ))
358 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
359
360 /* Two negative numbers */
361 if ( !LL_UCMP( bigInt6, <=, bigInt6 ))
362 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
363
364 if ( !LL_UCMP( bigInt6, <=, bigInt7 ))
365 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
366
367 if ( LL_UCMP( bigInt6, <=, bigInt8 ))
368 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
369
370 if ( !LL_UCMP( bigInt6, <=, bigInt9 ))
371 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
372
373 if ( !LL_UCMP( bigInt6, <=, bigInt10 ))
374 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
375
376 if ( !LL_UCMP( bigInt6, <=, bigInt11 ))
377 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
378
379 /* One positive, one negative */
380 if ( !LL_UCMP( bigInt0, <=, bigInt6 ))
381 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
382
383 if ( !LL_UCMP( bigInt0, <=, bigInt7 ))
384 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
385
386 if ( !LL_UCMP( bigInt0, <=, bigInt8 ))
387 SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
388
389 return;
390}
391
392/*
393** TestLogicalOperations() -- Tests for AND, OR, ...
394**
395*/
396static void
397TestLogicalOperations( void )
398{
399 PRUint64 result, result2;
400
401 ReportProgress("Testing Logical Operations\n");
402
403 /* Test AND */
404 LL_AND( result, bigZero, bigZero );
405 if ( !LL_IS_ZERO( result ))
406 ResultFailed( "LL_AND", "0 & 0", bigZero, result );
407
408 LL_AND( result, bigOne, bigOne );
409 if ( LL_IS_ZERO( result ))
410 ResultFailed( "LL_AND", "1 & 1", bigOne, result );
411
412 LL_AND( result, bigZero, bigOne );
413 if ( !LL_IS_ZERO( result ))
414 ResultFailed( "LL_AND", "1 & 1", bigZero, result );
415
416 LL_AND( result, bigMinusOne, bigMinusOne );
417 if ( !LL_UCMP( result, ==, bigMinusOne ))
418 ResultFailed( "LL_AND", "-1 & -1", bigMinusOne, result );
419
420 /* test OR */
421 LL_OR( result, bigZero, bigZero );
422 if ( !LL_IS_ZERO( result ))
423 ResultFailed( "LL_OR", "0 | 1", bigZero, result);
424
425 LL_OR( result, bigZero, bigOne );
426 if ( LL_IS_ZERO( result ))
427 ResultFailed( "LL_OR", "0 | 1", bigOne, result );
428
429 LL_OR( result, bigZero, bigMinusNumber );
430 if ( !LL_UCMP( result, ==, bigMinusNumber ))
431 ResultFailed( "LL_OR", "0 | -n", bigMinusNumber, result);
432
433 LL_OR( result, bigMinusNumber, bigZero );
434 if ( !LL_UCMP( result, ==, bigMinusNumber ))
435 ResultFailed( "LL_OR", "-n | 0", bigMinusNumber, result );
436
437 /* test XOR */
438 LL_XOR( result, bigZero, bigZero );
439 if ( LL_UCMP( result, !=, bigZero ))
440 ResultFailed( "LL_XOR", "0 ^ 0", bigZero, result);
441
442 LL_XOR( result, bigOne, bigZero );
443 if ( LL_UCMP( result, !=, bigOne ))
444 ResultFailed( "LL_XOR", "1 ^ 0", bigZero, result );
445
446 LL_XOR( result, bigMinusNumber, bigZero );
447 if ( LL_UCMP( result, !=, bigMinusNumber ))
448 ResultFailed( "LL_XOR", "-n ^ 0", bigMinusNumber, result );
449
450 LL_XOR( result, bigMinusNumber, bigMinusNumber );
451 if ( LL_UCMP( result, !=, bigZero ))
452 ResultFailed( "LL_XOR", "-n ^ -n", bigMinusNumber, result);
453
454 /* test OR2. */
455 result = bigZero;
456 LL_OR2( result, bigOne );
457 if ( LL_UCMP( result, !=, bigOne ))
458 ResultFailed( "LL_OR2", "(r=0) |= 1", bigOne, result);
459
460 result = bigOne;
461 LL_OR2( result, bigNumber );
462 if ( LL_UCMP( result, !=, bigNumber ))
463 ResultFailed( "LL_OR2", "(r=1) |= n", bigNumber, result);
464
465 result = bigMinusNumber;
466 LL_OR2( result, bigMinusNumber );
467 if ( LL_UCMP( result, !=, bigMinusNumber ))
468 ResultFailed( "LL_OR2", "(r=-n) |= -n", bigMinusNumber, result);
469
470 /* test NOT */
471 LL_NOT( result, bigMinusNumber);
472 LL_NOT( result2, result);
473 if ( LL_UCMP( result2, !=, bigMinusNumber ))
474 ResultFailed( "LL_NOT", "r != ~(~-n)", bigMinusNumber, result);
475
476 /* test Negation */
477 LL_NEG( result, bigMinusNumber );
478 LL_NEG( result2, result );
479 if ( LL_CMP( result2, !=, bigMinusNumber ))
480 ResultFailed( "LL_NEG", "r != -(-(-n))", bigMinusNumber, result);
481
482 return;
483}
484
485
486
487/*
488** TestConversion() -- Test Conversion Operations
489**
490*/
491static void
492TestConversion( void )
493{
494 PRInt64 result;
495 PRInt64 resultU;
496 PRInt32 result32;
497 PRUint32 resultU32;
498 float resultF;
499 PRFloat64 resultD;
500
501 ReportProgress("Testing Conversion Operations\n");
502
503 /* LL_L2I -- Convert to signed 32bit */
504 LL_L2I(result32, bigOne );
505 if ( result32 != one )
506 SetFailed( "LL_L2I", "r != 1");
507
508 LL_L2I(result32, bigMinusOne );
509 if ( result32 != minusOne )
510 SetFailed( "LL_L2I", "r != -1");
511
512 /* LL_L2UI -- Convert 64bit to unsigned 32bit */
513 LL_L2UI( resultU32, bigMinusOne );
514 if ( resultU32 != (PRUint32) minusOne )
515 SetFailed( "LL_L2UI", "r != -1");
516
517 LL_L2UI( resultU32, bigOne );
518 if ( resultU32 != (PRUint32) one )
519 SetFailed( "LL_L2UI", "r != 1");
520
521 /* LL_L2F -- Convert to 32bit floating point */
522 LL_L2F( resultF, bigOne );
523 if ( resultF != 1.0 )
524 SetFailed( "LL_L2F", "r != 1.0");
525
526 LL_L2F( resultF, bigMinusOne );
527 if ( resultF != -1.0 )
528 SetFailed( "LL_L2F", "r != 1.0");
529
530 /* LL_L2D -- Convert to 64bit floating point */
531 LL_L2D( resultD, bigOne );
532 if ( resultD != 1.0L )
533 SetFailed( "LL_L2D", "r != 1.0");
534
535 LL_L2D( resultD, bigMinusOne );
536 if ( resultD != -1.0L )
537 SetFailed( "LL_L2D", "r != -1.0");
538
539 /* LL_I2L -- Convert 32bit signed to 64bit signed */
540 LL_I2L( result, one );
541 if ( LL_CMP(result, !=, bigOne ))
542 SetFailed( "LL_I2L", "r != 1");
543
544 LL_I2L( result, minusOne );
545 if ( LL_CMP(result, !=, bigMinusOne ))
546 SetFailed( "LL_I2L", "r != -1");
547
548 /* LL_UI2L -- Convert 32bit unsigned to 64bit unsigned */
549 LL_UI2L( resultU, (PRUint32) one );
550 if ( LL_CMP(resultU, !=, bigOne ))
551 SetFailed( "LL_UI2L", "r != 1");
552
553 /* [lth.] This did not behave as expected, but it is correct
554 */
555 LL_UI2L( resultU, (PRUint32) minusOne );
556 if ( LL_CMP(resultU, !=, bigZeroFox ))
557 ResultFailed( "LL_UI2L", "r != -1", bigZeroFox, resultU);
558
559 /* LL_F2L -- Convert 32bit float to 64bit signed */
560 LL_F2L( result, 1.0 );
561 if ( LL_CMP(result, !=, bigOne ))
562 SetFailed( "LL_F2L", "r != 1");
563
564 LL_F2L( result, -1.0 );
565 if ( LL_CMP(result, !=, bigMinusOne ))
566 SetFailed( "LL_F2L", "r != -1");
567
568 /* LL_D2L -- Convert 64bit Float to 64bit signed */
569 LL_D2L( result, 1.0L );
570 if ( LL_CMP(result, !=, bigOne ))
571 SetFailed( "LL_D2L", "r != 1");
572
573 LL_D2L( result, -1.0L );
574 if ( LL_CMP(result, !=, bigMinusOne ))
575 SetFailed( "LL_D2L", "r != -1");
576
577 return;
578}
579
580static void ShiftCompileOnly()
581{
582 /*
583 ** This function is only compiled, never called.
584 ** The real test is to see if it compiles w/o
585 ** warnings. This is no small feat, by the way.
586 */
587 PRInt64 ia, ib;
588 PRUint64 ua, ub;
589 LL_SHR(ia, ib, 32);
590 LL_SHL(ia, ib, 32);
591
592 LL_USHR(ua, ub, 32);
593 LL_ISHL(ia, 49, 32);
594
595} /* ShiftCompileOnly */
596
597
598/*
599** TestShift() -- Test Shifting Operations
600**
601*/
602static void
603TestShift( void )
604{
605 static const PRInt64 largeTwoZero = LL_INIT( 0x00000002, 0x00000000 );
606 PRInt64 result;
607 PRUint64 resultU;
608
609 ReportProgress("Testing Shifting Operations\n");
610
611 /* LL_SHL -- Shift left algebraic */
612 LL_SHL( result, bigOne, one );
613 if ( LL_CMP( result, !=, bigTwo ))
614 ResultFailed( "LL_SHL", "r != 2", bigOne, result );
615
616 LL_SHL( result, bigTwo, thirtyTwo );
617 if ( LL_CMP( result, !=, largeTwoZero ))
618 ResultFailed( "LL_SHL", "r != twoZero", largeTwoZero, result);
619
620 /* LL_SHR -- Shift right algebraic */
621 LL_SHR( result, bigFoxZero, thirtyTwo );
622 if ( LL_CMP( result, !=, bigMinusOne ))
623 ResultFailed( "LL_SHR", "r != -1", bigMinusOne, result);
624
625 LL_SHR( result, bigTwo, one );
626 if ( LL_CMP( result, !=, bigOne ))
627 ResultFailed( "LL_SHR", "r != 1", bigOne, result);
628
629 LL_SHR( result, bigFoxFox, thirtyTwo );
630 if ( LL_CMP( result, !=, bigMinusOne ))
631 ResultFailed( "LL_SHR", "r != -1 (was ff,ff)", bigMinusOne, result);
632
633 /* LL_USHR -- Logical shift right */
634 LL_USHR( resultU, bigZeroFox, thirtyTwo );
635 if ( LL_UCMP( resultU, !=, bigZero ))
636 ResultFailed( "LL_USHR", "r != 0 ", bigZero, result);
637
638 LL_USHR( resultU, bigFoxFox, thirtyTwo );
639 if ( LL_UCMP( resultU, !=, bigZeroFox ))
640 ResultFailed( "LL_USHR", "r != 0 ", bigZeroFox, result);
641
642 /* LL_ISHL -- Shift a 32bit integer into a 64bit result */
643 LL_ISHL( resultU, minusOne, thirtyTwo );
644 if ( LL_UCMP( resultU, !=, bigFoxZero ))
645 ResultFailed( "LL_ISHL", "r != ff,00 ", bigFoxZero, result);
646
647 LL_ISHL( resultU, one, sixtyThree );
648 if ( LL_UCMP( resultU, !=, bigEightZero ))
649 ResultFailed( "LL_ISHL", "r != 80,00 ", bigEightZero, result);
650
651 LL_ISHL( resultU, one, sixteen );
652 if ( LL_UCMP( resultU, !=, big64K ))
653 ResultFailed( "LL_ISHL", "r != 64K ", big64K, resultU);
654
655 return;
656}
657
658
659/*
660** TestArithmetic() -- Test arithmetic operations.
661**
662*/
663static void
664TestArithmetic( void )
665{
666 PRInt64 largeVal = LL_INIT( 0x00000001, 0xffffffff );
667 PRInt64 largeValPlusOne = LL_INIT( 0x00000002, 0x00000000 );
668 PRInt64 largeValTimesTwo = LL_INIT( 0x00000003, 0xfffffffe );
669 PRInt64 largeMultCand = LL_INIT( 0x00000000, 0x7fffffff );
670 PRInt64 largeMinusMultCand = LL_INIT( 0xffffffff, 0x10000001 );
671 PRInt64 largeMultCandx64K = LL_INIT( 0x00007fff, 0xffff0000 );
672 PRInt64 largeNumSHL5 = LL_INIT( 0x0000001f, 0xffffffe0 );
673 PRInt64 result, result2;
674
675 /* Addition */
676 LL_ADD( result, bigOne, bigOne );
677 if ( LL_CMP( result, !=, bigTwo ))
678 ResultFailed( "LL_ADD", "r != 1 + 1", bigTwo, result);
679
680 LL_ADD( result, bigMinusOne, bigOne );
681 if ( LL_CMP( result, !=, bigZero ))
682 ResultFailed( "LL_ADD", "r != -1 + 1", bigOne, result);
683
684 LL_ADD( result, largeVal, bigOne );
685 if ( LL_CMP( result, !=, largeValPlusOne ))
686 ResultFailed( "LL_ADD", "lVP1 != lV + 1", largeValPlusOne, result);
687
688 /* Subtraction */
689 LL_SUB( result, bigOne, bigOne );
690 if ( LL_CMP( result, !=, bigZero ))
691 ResultFailed( "LL_SUB", "r != 1 - 1", bigZero, result);
692
693 LL_SUB( result, bigTwo, bigOne );
694 if ( LL_CMP( result, !=, bigOne ))
695 ResultFailed( "LL_SUB", "r != 2 - 1", bigOne, result);
696
697 LL_SUB( result, largeValPlusOne, bigOne );
698 if ( LL_CMP( result, !=, largeVal ))
699 ResultFailed( "LL_SUB", "r != lVP1 - 1", largeVal, result);
700
701
702 /* Multiply */
703 LL_MUL( result, largeVal, bigTwo );
704 if ( LL_CMP( result, !=, largeValTimesTwo ))
705 ResultFailed( "LL_MUL", "r != lV*2", largeValTimesTwo, result);
706
707 LL_MUL( result, largeMultCand, big64K );
708 if ( LL_CMP( result, !=, largeMultCandx64K ))
709 ResultFailed( "LL_MUL", "r != lV*64K", largeMultCandx64K, result);
710
711 LL_NEG( result2, largeMultCand );
712 LL_MUL( result, largeMultCand, bigMinusOne );
713 if ( LL_CMP( result, !=, result2 ))
714 ResultFailed( "LL_MUL", "r != -lMC", result2, result);
715
716 LL_SHL( result2, bigZeroFox, 5);
717 LL_MUL( result, bigZeroFox, bigThirtyTwo );
718 if ( LL_CMP( result, !=, largeNumSHL5 ))
719 ResultFailed( "LL_MUL", "r != 0f<<5", largeNumSHL5, result );
720
721
722
723 /* LL_DIV() Division */
724 LL_DIV( result, bigOne, bigOne);
725 if ( LL_CMP( result, !=, bigOne ))
726 ResultFailed( "LL_DIV", "1 != 1", bigOne, result);
727
728 LL_DIV( result, bigNumber, bigOne );
729 if ( LL_CMP( result, !=, bigNumber ))
730 ResultFailed( "LL_DIV", "r != n / 1", bigNumber, result);
731
732 LL_DIV( result, bigNumber, bigMinusOne );
733 if ( LL_CMP( result, !=, bigMinusNumber ))
734 ResultFailed( "LL_DIV", "r != n / -1", bigMinusNumber, result);
735
736 LL_DIV( result, bigMinusNumber, bigMinusOne );
737 if ( LL_CMP( result, !=, bigNumber ))
738 ResultFailed( "LL_DIV", "r != -n / -1", bigNumber, result);
739
740 LL_SHL( result2, bigZeroFox, 5 );
741 LL_DIV( result, result2, bigOne );
742 if ( LL_CMP( result, !=, result2 ))
743 ResultFailed( "LL_DIV", "0f<<5 != 0f<<5", result2, result);
744
745 LL_SHL( result2, bigZeroFox, 5 );
746 LL_NEG( result2, result2 );
747 LL_DIV( result, result2, bigOne );
748 if ( LL_CMP( result, !=, result2 ))
749 ResultFailed( "LL_DIV", "-0f<<5 != -0f<<5", result2, result);
750
751 LL_SHL( result2, bigZeroFox, 17 );
752 LL_DIV( result, result2, bigMinusOne );
753 LL_NEG( result2, result2 );
754 if ( LL_CMP( result, !=, result2 ))
755 ResultFailed( "LL_DIV", "-0f<<17 != -0f<<17", result2, result);
756
757
758 /* LL_MOD() Modulo Division */
759 LL_ADD( result2, bigThirtyTwo, bigOne );
760 LL_MOD( result, result2, bigSixTeen );
761 if ( LL_CMP( result, !=, bigOne ))
762 ResultFailed( "LL_MOD", "r != 1", bigSixTeen, result);
763
764
765 LL_MUL( result2, bigZeroFox, bigThirtyTwo );
766 LL_ADD( result2, result2, bigSixTeen);
767 LL_MOD( result, result2, bigThirtyTwo );
768 if ( LL_CMP( result, !=, bigSixTeen ))
769 ResultFailed( "LL_MOD", "r != 16", bigSixTeen, result);
770
771 /* LL_UDIVMOD */
772 LL_DIV( result, bigOne, bigOne);
773 if ( LL_CMP( result, !=, bigOne ))
774 ResultFailed( "LL_DIV", "r != 16", bigSixTeen, result);
775
776
777 return;
778}
779
780static void TestWellknowns(void)
781{
782 PRInt64 max = LL_MAXINT, min = LL_MININT, zero = LL_ZERO;
783 PRInt64 mmax = LL_MaxInt(), mmin = LL_MinInt(), mzero = LL_Zero();
784 if (LL_NE(max, mmax))
785 ResultFailed( "max, mmax", "max != mmax", max, mmax);
786 if (LL_NE(min, mmin))
787 ResultFailed( "min, mmin", "min != mmin", max, mmin);
788 if (LL_NE(zero, mzero))
789 ResultFailed( "zero, mzero", "zero != mzero", zero, mzero);
790} /* TestWellknowns */
791
792/*
793** Initialize() -- Initialize the test case
794**
795** Parse command line options
796**
797*/
798static PRIntn
799Initialize( PRIntn argc, char **argv )
800{
801 PLOptState *opt = PL_CreateOptState(argc, argv, "dvh");
802 PLOptStatus os;
803
804 /*
805 ** Parse command line options
806 */
807 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
808 {
809 if (PL_OPT_BAD == os) continue;
810 switch (opt->option)
811 {
812 case 'd': /* set debug mode */
813 debugMode = PR_TRUE;
814 break;
815
816 case 'v': /* set verbose mode */
817 verboseMode = PR_TRUE;
818 debugMode = PR_TRUE;
819 break;
820
821 case 'h': /* user wants some guidance */
822 default:
823 PR_fprintf(output, "You get help.\n");
824 return(1);
825 }
826 }
827 PL_DestroyOptState(opt);
828 return(0);
829}
830
831PRIntn main( int argc, char **argv )
832{
833 PR_STDIO_INIT();
834 output = PR_GetSpecialFD(PR_StandardError);
835
836 if ( Initialize( argc, argv ))
837 return(1);
838
839 TestAssignment();
840 TestComparisons();
841 TestLogicalOperations();
842 TestConversion();
843 TestShift();
844 TestArithmetic();
845 TestWellknowns();
846
847 /*
848 ** That's all folks!
849 */
850 if ( failedAlready )
851 {
852 PR_fprintf(output, "FAIL\n");\
853 }
854 else
855 {
856 PR_fprintf(output, "PASS\n");\
857 }
858 return failedAlready;
859} /* end main() */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette