Back to index

lightning-sunbird  0.9+nobinonly
lltest.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037  
00038 /*
00039 ** testll.c -- test suite for 64bit integer (longlong) operations
00040 **
00041 ** Summary: testll [-d] | [-h]
00042 **
00043 ** Where:
00044 ** -d       set debug mode on; displays individual test failures
00045 ** -v       verbose mode; displays progress in test, plus -d
00046 ** -h       gives usage message.
00047 **
00048 ** Description:
00049 ** lltest.c tests the functions defined in NSPR 2.0's prlong.h.
00050 ** 
00051 ** Successive tests begin to depend on other LL functions working
00052 ** correctly. So, ... Do not change the order of the tests as run
00053 ** from main().
00054 ** 
00055 ** Caveats:
00056 ** Do not even begin to think that this is an exhaustive test!
00057 **
00058 ** These tests try a little of everything, but not all boundary
00059 ** conditions and limits are tested.
00060 ** You want better coverage? ... Add it.
00061 **
00062 ** ---
00063 ** Author: Lawrence Hardiman <larryh@netscape.com>.
00064 ** ---
00065 ** Revision History:
00066 ** 01-Oct-1997. Original implementation.
00067 **
00068 */
00069 
00070 #include "nspr.h"
00071 #include "plgetopt.h"
00072 
00073 /* --- Local Definitions --- */
00074 #define ReportProgress(m) if (verboseMode) PR_fprintf(output, (m));
00075 
00076 
00077 /* --- Global variables --- */
00078 static PRIntn  failedAlready = 0;
00079 static PRFileDesc* output = NULL;
00080 static PRBool  debugMode = PR_FALSE;
00081 static PRBool  verboseMode = PR_FALSE;
00082 
00083 /*
00084 ** Constants used in tests.
00085 */
00086 const PRInt64 bigZero        = LL_INIT( 0, 0 );
00087 const PRInt64 bigOne         = LL_INIT( 0, 1 );
00088 const PRInt64 bigTwo         = LL_INIT( 0, 2 );
00089 const PRInt64 bigSixTeen     = LL_INIT( 0, 16 );        
00090 const PRInt64 bigThirtyTwo   = LL_INIT( 0, 32 );        
00091 const PRInt64 bigMinusOne    = LL_INIT( 0xffffffff, 0xffffffff );
00092 const PRInt64 bigMinusTwo    = LL_INIT( 0xffffffff, 0xfffffffe );
00093 const PRInt64 bigNumber      = LL_INIT( 0x7fffffff, 0xffffffff );
00094 const PRInt64 bigMinusNumber = LL_INIT( 0x80000000, 0x00000001 );
00095 const PRInt64 bigMaxInt32    = LL_INIT( 0x00000000, 0x7fffffff );
00096 const PRInt64 big2To31       = LL_INIT( 0x00000000, 0x80000000 );
00097 const PRUint64 bigZeroFox    = LL_INIT( 0x00000000, 0xffffffff );
00098 const PRUint64 bigFoxFox     = LL_INIT( 0xffffffff, 0xffffffff );
00099 const PRUint64 bigFoxZero    = LL_INIT( 0xffffffff, 0x00000000 );
00100 const PRUint64 bigEightZero  = LL_INIT( 0x80000000, 0x00000000 );
00101 const PRUint64 big64K        = LL_INIT( 0x00000000, 0x00010000 );
00102 const PRInt64 bigInt0        = LL_INIT( 0x01a00000, 0x00001000 );
00103 const PRInt64 bigInt1        = LL_INIT( 0x01a00000, 0x00001100 );
00104 const PRInt64 bigInt2        = LL_INIT( 0x01a00000, 0x00000100 );
00105 const PRInt64 bigInt3        = LL_INIT( 0x01a00001, 0x00001000 );
00106 const PRInt64 bigInt4        = LL_INIT( 0x01a00001, 0x00001100 );
00107 const PRInt64 bigInt5        = LL_INIT( 0x01a00001, 0x00000100 );
00108 const PRInt64 bigInt6        = LL_INIT( 0xb1a00000, 0x00001000 );
00109 const PRInt64 bigInt7        = LL_INIT( 0xb1a00000, 0x00001100 );
00110 const PRInt64 bigInt8        = LL_INIT( 0xb1a00000, 0x00000100 );
00111 const PRInt64 bigInt9        = LL_INIT( 0xb1a00001, 0x00001000 );
00112 const PRInt64 bigInt10       = LL_INIT( 0xb1a00001, 0x00001100 );
00113 const PRInt64 bigInt11       = LL_INIT( 0xb1a00001, 0x00000100 );
00114 const PRInt32 one = 1l;
00115 const PRInt32 minusOne = -1l;
00116 const PRInt32 sixteen  = 16l;
00117 const PRInt32 thirtyTwo = 32l;
00118 const PRInt32   sixtyThree = 63l;
00119 
00120 /*
00121 ** SetFailed() -- Report individual test failure
00122 **
00123 */
00124 static void
00125 SetFailed( char *what, char *how )
00126 {
00127     failedAlready = 1;
00128     if ( debugMode )
00129         PR_fprintf(output, "%s: failed: %s\n", what, how );
00130     return;
00131 }
00132 
00133 static void
00134 ResultFailed( char *what, char *how, PRInt64 expected, PRInt64 got)
00135 {
00136     if ( debugMode)
00137     {
00138         SetFailed( what, how );
00139         PR_fprintf(output, "Expected: 0x%llx   Got: 0x%llx\n", expected, got );
00140     }
00141     return;
00142 }    
00143 
00144 
00145 /*
00146 ** TestAssignment() -- Test the assignment
00147 */
00148 static void TestAssignment( void )
00149 {
00150     PRInt64 zero = LL_Zero();
00151     PRInt64 min = LL_MinInt();
00152     PRInt64 max = LL_MaxInt();
00153     if (!LL_EQ(zero, bigZero))
00154         SetFailed("LL_EQ(zero, bigZero)", "!=");
00155     if (!LL_CMP(max, >, min))
00156         SetFailed("LL_CMP(max, >, min)", "!>");
00157 }
00158 
00159 /*
00160 ** TestComparisons() -- Test the longlong comparison operations
00161 */
00162 static void    
00163 TestComparisons( void )
00164 {
00165     ReportProgress("Testing Comparisons Operations\n");
00166          
00167     /* test for zero */   
00168     if ( !LL_IS_ZERO( bigZero ))
00169         SetFailed( "LL_IS_ZERO", "Zero is not zero" );
00170         
00171     if ( LL_IS_ZERO( bigOne ))
00172         SetFailed( "LL_IS_ZERO", "One tests as zero" );
00173     
00174     if ( LL_IS_ZERO( bigMinusOne ))
00175         SetFailed( "LL_IS_ZERO", "Minus One tests as zero" );
00176         
00177     /* test equal */
00178     if ( !LL_EQ( bigZero, bigZero ))
00179         SetFailed( "LL_EQ", "zero EQ zero");
00180         
00181     if ( !LL_EQ( bigOne, bigOne ))
00182         SetFailed( "LL_EQ", "one EQ one" );
00183         
00184     if ( !LL_EQ( bigNumber, bigNumber ))
00185         SetFailed( "LL_EQ", "bigNumber EQ bigNumber" );
00186         
00187     if ( !LL_EQ( bigMinusOne, bigMinusOne ))
00188         SetFailed( "LL_EQ", "minus one EQ minus one");
00189     
00190     if ( LL_EQ( bigZero, bigOne ))
00191         SetFailed( "LL_EQ", "zero EQ one");
00192         
00193     if ( LL_EQ( bigOne, bigZero ))
00194         SetFailed( "LL_EQ", "one EQ zero" );
00195         
00196     if ( LL_EQ( bigMinusOne, bigOne ))
00197         SetFailed( "LL_EQ", "minus one EQ one");
00198         
00199     if ( LL_EQ( bigNumber, bigOne ))
00200         SetFailed( "LL_EQ", "bigNumber EQ one");
00201     
00202     /* test not equal */
00203     if ( LL_NE( bigZero, bigZero ))
00204         SetFailed( "LL_NE", "0 NE 0");
00205     
00206     if ( LL_NE( bigOne, bigOne ))
00207         SetFailed( "LL_NE", "1 NE 1");
00208     
00209     if ( LL_NE( bigMinusOne, bigMinusOne ))
00210         SetFailed( "LL_NE", "-1 NE -1");
00211     
00212     if ( LL_NE( bigNumber, bigNumber ))
00213         SetFailed( "LL_NE", "n NE n");
00214     
00215     if ( LL_NE( bigMinusNumber, bigMinusNumber ))
00216         SetFailed( "LL_NE", "-n NE -n");
00217         
00218     if ( !LL_NE( bigZero, bigOne))
00219         SetFailed( "LL_NE", "0 NE 1");
00220     
00221     if ( !LL_NE( bigOne, bigMinusNumber))
00222         SetFailed( "LL_NE", "1 NE -n");
00223         
00224     /* Greater than or equal to zero */
00225     if ( !LL_GE_ZERO( bigZero ))
00226         SetFailed( "LL_GE_ZERO", "0");
00227     
00228     if ( !LL_GE_ZERO( bigOne ))
00229         SetFailed( "LL_GE_ZERO", "1");
00230     
00231     if ( !LL_GE_ZERO( bigNumber ))
00232         SetFailed( "LL_GE_ZERO", "n");
00233     
00234     if ( LL_GE_ZERO( bigMinusOne ))
00235         SetFailed( "LL_GE_ZERO", "-1");
00236         
00237     if ( LL_GE_ZERO( bigMinusNumber ))
00238         SetFailed( "LL_GE_ZERO", "-n");
00239         
00240     /* Algebraic Compare two values */
00241     if ( !LL_CMP( bigZero, ==, bigZero ))
00242         SetFailed( "LL_CMP", "0 == 0");
00243     
00244     if ( LL_CMP( bigZero, >, bigZero ))
00245         SetFailed( "LL_CMP", "0 > 0");
00246         
00247     if ( LL_CMP( bigZero, <, bigZero ))
00248         SetFailed( "LL_CMP", "0 < 0");
00249         
00250     if ( LL_CMP( bigNumber, <, bigOne ))
00251         SetFailed( "LL_CMP", "n < 1");
00252         
00253     if ( !LL_CMP( bigNumber, >, bigOne ))
00254         SetFailed( "LL_CMP", "n <= 1");
00255         
00256     if ( LL_CMP( bigOne, >, bigNumber ))
00257         SetFailed( "LL_CMP", "1 > n");
00258         
00259     if ( LL_CMP( bigMinusNumber, >, bigNumber ))
00260         SetFailed( "LL_CMP", "-n > n");
00261         
00262     if ( LL_CMP( bigNumber, !=, bigNumber))
00263         SetFailed( "LL_CMP", "n != n");
00264 
00265     if ( !LL_CMP( bigMinusOne, >, bigMinusTwo ))
00266         SetFailed( "LL_CMP", "-1 <= -2");
00267 
00268     if ( !LL_CMP( bigMaxInt32, <, big2To31 ))
00269         SetFailed( "LL_CMP", "Max 32-bit signed int >= 2^31");
00270 
00271     /* Two positive numbers */
00272     if ( !LL_CMP( bigInt0, <=, bigInt0 ))
00273         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00274 
00275     if ( !LL_CMP( bigInt0, <=, bigInt1 ))
00276         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00277 
00278     if ( LL_CMP( bigInt0, <=, bigInt2 ))
00279         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00280 
00281     if ( !LL_CMP( bigInt0, <=, bigInt3 ))
00282         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00283 
00284     if ( !LL_CMP( bigInt0, <=, bigInt4 ))
00285         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00286 
00287     if ( !LL_CMP( bigInt0, <=, bigInt5 ))
00288         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00289 
00290     /* Two negative numbers */
00291     if ( !LL_CMP( bigInt6, <=, bigInt6 ))
00292         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00293 
00294     if ( !LL_CMP( bigInt6, <=, bigInt7 ))
00295         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00296 
00297     if ( LL_CMP( bigInt6, <=, bigInt8 ))
00298         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00299 
00300     if ( !LL_CMP( bigInt6, <=, bigInt9 ))
00301         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00302 
00303     if ( !LL_CMP( bigInt6, <=, bigInt10 ))
00304         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00305 
00306     if ( !LL_CMP( bigInt6, <=, bigInt11 ))
00307         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00308 
00309     /* One positive, one negative */
00310     if ( LL_CMP( bigInt0, <=, bigInt6 ))
00311         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00312 
00313     if ( LL_CMP( bigInt0, <=, bigInt7 ))
00314         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00315 
00316     if ( LL_CMP( bigInt0, <=, bigInt8 ))
00317         SetFailed( "LL_CMP", "LL_CMP(<=) failed");
00318 
00319     /* Bitwise Compare two numbers */
00320     if ( !LL_UCMP( bigZero, ==, bigZero ))
00321         SetFailed( "LL_UCMP", "0 == 0");
00322     
00323     if ( LL_UCMP( bigZero, >, bigZero ))
00324         SetFailed( "LL_UCMP", "0 > 0");
00325         
00326     if ( LL_UCMP( bigZero, <, bigZero ))
00327         SetFailed( "LL_UCMP", "0 < 0");
00328         
00329     if ( LL_UCMP( bigNumber, <, bigOne ))
00330         SetFailed( "LL_UCMP", "n < 1");
00331         
00332     if ( !LL_UCMP( bigNumber, >, bigOne ))
00333         SetFailed( "LL_UCMP", "n < 1");
00334         
00335     if ( LL_UCMP( bigOne, >, bigNumber ))
00336         SetFailed( "LL_UCMP", "1 > n");
00337         
00338     if ( LL_UCMP( bigMinusNumber, <, bigNumber ))
00339         SetFailed( "LL_UCMP", "-n < n");
00340 
00341     /* Two positive numbers */
00342     if ( !LL_UCMP( bigInt0, <=, bigInt0 ))
00343         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00344 
00345     if ( !LL_UCMP( bigInt0, <=, bigInt1 ))
00346         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00347 
00348     if ( LL_UCMP( bigInt0, <=, bigInt2 ))
00349         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00350 
00351     if ( !LL_UCMP( bigInt0, <=, bigInt3 ))
00352         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00353 
00354     if ( !LL_UCMP( bigInt0, <=, bigInt4 ))
00355         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00356 
00357     if ( !LL_UCMP( bigInt0, <=, bigInt5 ))
00358         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00359 
00360     /* Two negative numbers */
00361     if ( !LL_UCMP( bigInt6, <=, bigInt6 ))
00362         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00363 
00364     if ( !LL_UCMP( bigInt6, <=, bigInt7 ))
00365         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00366 
00367     if ( LL_UCMP( bigInt6, <=, bigInt8 ))
00368         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00369 
00370     if ( !LL_UCMP( bigInt6, <=, bigInt9 ))
00371         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00372 
00373     if ( !LL_UCMP( bigInt6, <=, bigInt10 ))
00374         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00375 
00376     if ( !LL_UCMP( bigInt6, <=, bigInt11 ))
00377         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00378 
00379     /* One positive, one negative */
00380     if ( !LL_UCMP( bigInt0, <=, bigInt6 ))
00381         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00382 
00383     if ( !LL_UCMP( bigInt0, <=, bigInt7 ))
00384         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00385 
00386     if ( !LL_UCMP( bigInt0, <=, bigInt8 ))
00387         SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
00388 
00389     return;
00390 }
00391 
00392 /*
00393 **  TestLogicalOperations() -- Tests for AND, OR, ...
00394 **
00395 */
00396 static void
00397 TestLogicalOperations( void )
00398 {
00399     PRUint64    result, result2;
00400     
00401     ReportProgress("Testing Logical Operations\n");
00402     
00403     /* Test AND */
00404     LL_AND( result, bigZero, bigZero );
00405     if ( !LL_IS_ZERO( result ))
00406         ResultFailed( "LL_AND", "0 & 0", bigZero, result );
00407     
00408     LL_AND( result, bigOne, bigOne );
00409     if ( LL_IS_ZERO( result ))
00410         ResultFailed( "LL_AND", "1 & 1", bigOne, result );
00411 
00412     LL_AND( result, bigZero, bigOne );
00413     if ( !LL_IS_ZERO( result ))
00414         ResultFailed( "LL_AND", "1 & 1", bigZero, result );
00415 
00416     LL_AND( result, bigMinusOne, bigMinusOne );
00417     if ( !LL_UCMP( result, ==, bigMinusOne ))
00418         ResultFailed( "LL_AND", "-1 & -1", bigMinusOne, result );
00419         
00420     /* test OR */
00421     LL_OR( result, bigZero, bigZero );
00422     if ( !LL_IS_ZERO( result ))
00423         ResultFailed( "LL_OR", "0 | 1", bigZero, result);
00424     
00425     LL_OR( result, bigZero, bigOne );
00426     if ( LL_IS_ZERO( result ))
00427         ResultFailed( "LL_OR", "0 | 1", bigOne, result );
00428     
00429     LL_OR( result, bigZero, bigMinusNumber );
00430     if ( !LL_UCMP( result, ==, bigMinusNumber ))
00431         ResultFailed( "LL_OR", "0 | -n", bigMinusNumber, result);
00432     
00433     LL_OR( result, bigMinusNumber, bigZero );
00434     if ( !LL_UCMP( result, ==, bigMinusNumber ))
00435         ResultFailed( "LL_OR", "-n | 0", bigMinusNumber, result );
00436     
00437     /* test XOR */
00438     LL_XOR( result, bigZero, bigZero );
00439     if ( LL_UCMP( result, !=, bigZero ))
00440         ResultFailed( "LL_XOR", "0 ^ 0", bigZero, result);
00441     
00442     LL_XOR( result, bigOne, bigZero );
00443     if ( LL_UCMP( result, !=, bigOne ))
00444         ResultFailed( "LL_XOR", "1 ^ 0", bigZero, result );
00445         
00446     LL_XOR( result, bigMinusNumber, bigZero );
00447     if ( LL_UCMP( result, !=, bigMinusNumber ))
00448         ResultFailed( "LL_XOR", "-n ^ 0", bigMinusNumber, result );
00449     
00450     LL_XOR( result, bigMinusNumber, bigMinusNumber );
00451     if ( LL_UCMP( result, !=, bigZero ))
00452         ResultFailed( "LL_XOR", "-n ^ -n", bigMinusNumber, result);
00453         
00454     /* test OR2.  */
00455     result = bigZero;
00456     LL_OR2( result, bigOne );
00457     if ( LL_UCMP( result, !=, bigOne ))
00458         ResultFailed( "LL_OR2", "(r=0) |= 1", bigOne, result);
00459         
00460     result = bigOne;
00461     LL_OR2( result, bigNumber );
00462     if ( LL_UCMP( result, !=, bigNumber ))
00463         ResultFailed( "LL_OR2", "(r=1) |= n", bigNumber, result);
00464 
00465     result = bigMinusNumber;
00466     LL_OR2( result, bigMinusNumber );
00467     if ( LL_UCMP( result, !=, bigMinusNumber ))
00468         ResultFailed( "LL_OR2", "(r=-n) |= -n", bigMinusNumber, result);
00469 
00470     /* test NOT */
00471     LL_NOT( result, bigMinusNumber);
00472     LL_NOT( result2, result);
00473     if ( LL_UCMP( result2, !=, bigMinusNumber ))
00474         ResultFailed( "LL_NOT", "r != ~(~-n)", bigMinusNumber, result);
00475             
00476     /* test Negation */
00477     LL_NEG( result, bigMinusNumber );
00478     LL_NEG( result2, result );
00479     if ( LL_CMP( result2, !=, bigMinusNumber ))
00480         ResultFailed( "LL_NEG", "r != -(-(-n))", bigMinusNumber, result);
00481 
00482     return;
00483 }
00484 
00485 
00486 
00487 /*
00488 **  TestConversion() -- Test Conversion Operations
00489 **
00490 */
00491 static void
00492 TestConversion( void )
00493 {
00494     PRInt64     result;
00495     PRInt64     resultU;
00496     PRInt32     result32;
00497     PRUint32    resultU32;
00498     float       resultF;
00499     PRFloat64   resultD;
00500     
00501     ReportProgress("Testing Conversion Operations\n");
00502     
00503     /* LL_L2I  -- Convert to signed 32bit */
00504     LL_L2I(result32, bigOne );
00505     if ( result32 != one )  
00506         SetFailed( "LL_L2I", "r != 1");
00507     
00508     LL_L2I(result32, bigMinusOne );
00509     if ( result32 != minusOne )  
00510         SetFailed( "LL_L2I", "r != -1");
00511     
00512     /* LL_L2UI -- Convert 64bit to unsigned 32bit */
00513     LL_L2UI( resultU32, bigMinusOne );
00514     if ( resultU32 != (PRUint32) minusOne )
00515         SetFailed( "LL_L2UI", "r != -1");
00516     
00517     LL_L2UI( resultU32, bigOne );
00518     if ( resultU32 != (PRUint32) one )
00519         SetFailed( "LL_L2UI", "r != 1");
00520         
00521     /* LL_L2F  -- Convert to 32bit floating point */
00522     LL_L2F( resultF, bigOne );
00523     if ( resultF != 1.0 )
00524         SetFailed( "LL_L2F", "r != 1.0");
00525         
00526     LL_L2F( resultF, bigMinusOne );
00527     if ( resultF != -1.0 )
00528         SetFailed( "LL_L2F", "r != 1.0");
00529     
00530     /* LL_L2D  -- Convert to 64bit floating point */
00531     LL_L2D( resultD, bigOne );
00532     if ( resultD != 1.0L )
00533         SetFailed( "LL_L2D", "r != 1.0");
00534         
00535     LL_L2D( resultD, bigMinusOne );
00536     if ( resultD != -1.0L )
00537         SetFailed( "LL_L2D", "r != -1.0");
00538         
00539     /* LL_I2L  -- Convert 32bit signed to 64bit signed */
00540     LL_I2L( result, one );
00541     if ( LL_CMP(result, !=, bigOne ))
00542         SetFailed( "LL_I2L", "r != 1");
00543         
00544     LL_I2L( result, minusOne );
00545     if ( LL_CMP(result, !=, bigMinusOne ))
00546         SetFailed( "LL_I2L", "r != -1");
00547         
00548     /* LL_UI2L -- Convert 32bit unsigned to 64bit unsigned */
00549     LL_UI2L( resultU, (PRUint32) one );
00550     if ( LL_CMP(resultU, !=, bigOne ))
00551         SetFailed( "LL_UI2L", "r != 1");
00552         
00553     /* [lth.] This did not behave as expected, but it is correct 
00554     */
00555     LL_UI2L( resultU, (PRUint32) minusOne );
00556     if ( LL_CMP(resultU, !=, bigZeroFox ))
00557         ResultFailed( "LL_UI2L", "r != -1", bigZeroFox, resultU);
00558         
00559     /* LL_F2L  -- Convert 32bit float to 64bit signed */
00560     LL_F2L( result, 1.0 );
00561     if ( LL_CMP(result, !=, bigOne ))
00562         SetFailed( "LL_F2L", "r != 1");
00563         
00564     LL_F2L( result, -1.0 );
00565     if ( LL_CMP(result, !=, bigMinusOne ))
00566         SetFailed( "LL_F2L", "r != -1");
00567     
00568     /* LL_D2L  -- Convert 64bit Float to 64bit signed */
00569     LL_D2L( result, 1.0L );
00570     if ( LL_CMP(result, !=, bigOne ))
00571         SetFailed( "LL_D2L", "r != 1");
00572         
00573     LL_D2L( result, -1.0L );
00574     if ( LL_CMP(result, !=, bigMinusOne ))
00575         SetFailed( "LL_D2L", "r != -1");
00576 
00577     return;
00578 }
00579 
00580 static void ShiftCompileOnly()
00581 {
00582     /*
00583     ** This function is only compiled, never called.
00584     ** The real test is to see if it compiles w/o
00585     ** warnings. This is no small feat, by the way.
00586     */
00587     PRInt64 ia, ib;
00588     PRUint64 ua, ub;
00589     LL_SHR(ia, ib, 32);
00590     LL_SHL(ia, ib, 32);
00591 
00592     LL_USHR(ua, ub, 32);
00593     LL_ISHL(ia, 49, 32);
00594 
00595 }  /* ShiftCompileOnly */
00596    
00597 
00598 /*
00599 **  TestShift() -- Test Shifting Operations
00600 **
00601 */
00602 static void
00603 TestShift( void )
00604 {
00605     static const PRInt64 largeTwoZero = LL_INIT( 0x00000002, 0x00000000 );
00606     PRInt64     result;
00607     PRUint64    resultU;
00608 
00609     ReportProgress("Testing Shifting Operations\n");
00610     
00611     /* LL_SHL  -- Shift left algebraic */
00612     LL_SHL( result, bigOne, one );
00613     if ( LL_CMP( result, !=, bigTwo ))
00614         ResultFailed( "LL_SHL", "r != 2", bigOne, result );
00615     
00616     LL_SHL( result, bigTwo, thirtyTwo );
00617     if ( LL_CMP( result, !=, largeTwoZero ))
00618         ResultFailed( "LL_SHL", "r != twoZero", largeTwoZero, result);
00619     
00620     /* LL_SHR  -- Shift right algebraic */
00621     LL_SHR( result, bigFoxZero, thirtyTwo );
00622     if ( LL_CMP( result, !=, bigMinusOne ))
00623         ResultFailed( "LL_SHR", "r != -1", bigMinusOne, result);
00624     
00625     LL_SHR( result, bigTwo, one );
00626     if ( LL_CMP( result, !=, bigOne ))
00627         ResultFailed( "LL_SHR", "r != 1", bigOne, result);
00628 
00629     LL_SHR( result, bigFoxFox, thirtyTwo );
00630     if ( LL_CMP( result, !=, bigMinusOne ))
00631         ResultFailed( "LL_SHR", "r != -1 (was ff,ff)", bigMinusOne, result);
00632     
00633     /* LL_USHR -- Logical shift right */
00634     LL_USHR( resultU, bigZeroFox, thirtyTwo );
00635     if ( LL_UCMP( resultU, !=, bigZero ))
00636         ResultFailed( "LL_USHR", "r != 0 ", bigZero, result);
00637     
00638     LL_USHR( resultU, bigFoxFox, thirtyTwo );
00639     if ( LL_UCMP( resultU, !=, bigZeroFox ))
00640         ResultFailed( "LL_USHR", "r != 0 ", bigZeroFox, result);
00641     
00642     /* LL_ISHL -- Shift a 32bit integer into a 64bit result */
00643     LL_ISHL( resultU, minusOne, thirtyTwo );
00644     if ( LL_UCMP( resultU, !=, bigFoxZero ))
00645         ResultFailed( "LL_ISHL", "r != ff,00 ", bigFoxZero, result);
00646     
00647     LL_ISHL( resultU, one, sixtyThree );
00648     if ( LL_UCMP( resultU, !=, bigEightZero ))
00649         ResultFailed( "LL_ISHL", "r != 80,00 ", bigEightZero, result);
00650     
00651     LL_ISHL( resultU, one, sixteen );
00652     if ( LL_UCMP( resultU, !=, big64K ))
00653         ResultFailed( "LL_ISHL", "r != 64K ", big64K, resultU);
00654     
00655     return;
00656 }    
00657 
00658 
00659 /*
00660 **  TestArithmetic() -- Test arithmetic operations.
00661 **
00662 */
00663 static void
00664 TestArithmetic( void )
00665 {
00666     PRInt64 largeVal          = LL_INIT( 0x00000001, 0xffffffff );
00667     PRInt64 largeValPlusOne   = LL_INIT( 0x00000002, 0x00000000 );
00668     PRInt64 largeValTimesTwo  = LL_INIT( 0x00000003, 0xfffffffe );
00669     PRInt64 largeMultCand     = LL_INIT( 0x00000000, 0x7fffffff );
00670     PRInt64 largeMinusMultCand = LL_INIT( 0xffffffff, 0x10000001 );
00671     PRInt64 largeMultCandx64K = LL_INIT( 0x00007fff, 0xffff0000 );
00672     PRInt64 largeNumSHL5      = LL_INIT( 0x0000001f, 0xffffffe0 );        
00673     PRInt64 result, result2;
00674 
00675     /* Addition */    
00676     LL_ADD( result, bigOne, bigOne );
00677     if ( LL_CMP( result, !=, bigTwo ))
00678         ResultFailed( "LL_ADD", "r != 1 + 1", bigTwo, result);
00679 
00680     LL_ADD( result, bigMinusOne, bigOne );
00681     if ( LL_CMP( result, !=, bigZero ))
00682         ResultFailed( "LL_ADD", "r != -1 + 1", bigOne, result);
00683 
00684     LL_ADD( result, largeVal, bigOne );
00685     if ( LL_CMP( result, !=, largeValPlusOne ))
00686         ResultFailed( "LL_ADD", "lVP1 != lV + 1", largeValPlusOne, result);
00687             
00688     /* Subtraction */
00689     LL_SUB( result, bigOne, bigOne );
00690     if ( LL_CMP( result, !=, bigZero ))
00691         ResultFailed( "LL_SUB", "r != 1 - 1", bigZero, result);
00692             
00693     LL_SUB( result, bigTwo, bigOne );
00694     if ( LL_CMP( result, !=, bigOne ))
00695         ResultFailed( "LL_SUB", "r != 2 - 1", bigOne, result);
00696             
00697     LL_SUB( result, largeValPlusOne, bigOne );
00698     if ( LL_CMP( result, !=, largeVal ))
00699         ResultFailed( "LL_SUB", "r != lVP1 - 1", largeVal, result);
00700             
00701     
00702     /* Multiply */
00703     LL_MUL( result, largeVal, bigTwo );
00704     if ( LL_CMP( result, !=, largeValTimesTwo ))
00705         ResultFailed( "LL_MUL", "r != lV*2", largeValTimesTwo, result);
00706     
00707     LL_MUL( result, largeMultCand, big64K );
00708     if ( LL_CMP( result, !=, largeMultCandx64K ))
00709         ResultFailed( "LL_MUL", "r != lV*64K", largeMultCandx64K, result);
00710         
00711     LL_NEG( result2, largeMultCand );
00712     LL_MUL( result, largeMultCand, bigMinusOne );
00713     if ( LL_CMP( result, !=, result2  ))
00714         ResultFailed( "LL_MUL", "r != -lMC", result2, result);
00715 
00716     LL_SHL( result2, bigZeroFox, 5);
00717     LL_MUL( result, bigZeroFox, bigThirtyTwo );
00718     if ( LL_CMP( result, !=, largeNumSHL5  ))
00719         ResultFailed( "LL_MUL", "r != 0f<<5", largeNumSHL5, result );
00720 
00721     
00722 
00723     /* LL_DIV() Division */
00724     LL_DIV( result, bigOne, bigOne);
00725     if ( LL_CMP( result, !=, bigOne ))
00726         ResultFailed( "LL_DIV", "1 != 1", bigOne, result);
00727     
00728     LL_DIV( result, bigNumber, bigOne );
00729     if ( LL_CMP( result, !=, bigNumber  ))
00730         ResultFailed( "LL_DIV", "r != n / 1", bigNumber, result);
00731 
00732     LL_DIV( result, bigNumber, bigMinusOne );
00733     if ( LL_CMP( result, !=, bigMinusNumber  ))
00734         ResultFailed( "LL_DIV", "r != n / -1", bigMinusNumber, result);
00735 
00736     LL_DIV( result, bigMinusNumber, bigMinusOne );
00737     if ( LL_CMP( result, !=, bigNumber  ))
00738         ResultFailed( "LL_DIV", "r != -n / -1", bigNumber, result);
00739         
00740     LL_SHL( result2, bigZeroFox, 5 );
00741     LL_DIV( result, result2, bigOne );
00742     if ( LL_CMP( result, !=, result2  ))
00743         ResultFailed( "LL_DIV", "0f<<5 != 0f<<5", result2, result);
00744     
00745     LL_SHL( result2, bigZeroFox, 5 );
00746     LL_NEG( result2, result2 );
00747     LL_DIV( result, result2, bigOne );
00748     if ( LL_CMP( result, !=, result2  ))
00749         ResultFailed( "LL_DIV", "-0f<<5 != -0f<<5", result2, result);
00750     
00751     LL_SHL( result2, bigZeroFox, 17 );
00752     LL_DIV( result, result2, bigMinusOne );
00753     LL_NEG( result2, result2 );
00754     if ( LL_CMP( result, !=, result2  ))
00755         ResultFailed( "LL_DIV", "-0f<<17 != -0f<<17", result2, result);
00756     
00757     
00758     /* LL_MOD() Modulo Division */
00759     LL_ADD( result2, bigThirtyTwo, bigOne );
00760     LL_MOD( result, result2, bigSixTeen );
00761     if ( LL_CMP( result, !=, bigOne ))
00762         ResultFailed( "LL_MOD", "r != 1", bigSixTeen, result);
00763     
00764     
00765     LL_MUL( result2, bigZeroFox, bigThirtyTwo );
00766     LL_ADD( result2, result2, bigSixTeen);
00767     LL_MOD( result, result2, bigThirtyTwo );
00768     if ( LL_CMP( result, !=, bigSixTeen ))
00769         ResultFailed( "LL_MOD", "r != 16", bigSixTeen, result);
00770 
00771     /* LL_UDIVMOD */
00772     LL_DIV( result, bigOne, bigOne);
00773     if ( LL_CMP( result, !=, bigOne ))
00774         ResultFailed( "LL_DIV", "r != 16", bigSixTeen, result);
00775     
00776 
00777     return;
00778 } 
00779 
00780 static void TestWellknowns(void)
00781 {
00782     PRInt64 max = LL_MAXINT, min = LL_MININT, zero = LL_ZERO;
00783     PRInt64 mmax = LL_MaxInt(), mmin = LL_MinInt(), mzero = LL_Zero();
00784     if (LL_NE(max, mmax))
00785         ResultFailed( "max, mmax", "max != mmax", max, mmax);
00786     if (LL_NE(min, mmin))
00787         ResultFailed( "min, mmin", "min != mmin", max, mmin);
00788     if (LL_NE(zero, mzero))
00789         ResultFailed( "zero, mzero", "zero != mzero", zero, mzero);
00790 }  /* TestWellknowns */ 
00791 
00792 /*
00793 ** Initialize() -- Initialize the test case
00794 **
00795 ** Parse command line options
00796 **
00797 */
00798 static PRIntn
00799 Initialize( PRIntn argc, char **argv )
00800 {
00801     PLOptState *opt = PL_CreateOptState(argc, argv, "dvh");
00802     PLOptStatus os;
00803 
00804     /*
00805     ** Parse command line options
00806     */    
00807     while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
00808     {
00809         if (PL_OPT_BAD == os) continue;
00810         switch (opt->option)
00811         {
00812         case 'd':  /* set debug mode */
00813             debugMode = PR_TRUE;
00814             break;
00815             
00816         case 'v':  /* set verbose mode */
00817             verboseMode = PR_TRUE;
00818             debugMode = PR_TRUE;
00819             break;
00820             
00821         case 'h':  /* user wants some guidance */
00822         default:
00823             PR_fprintf(output, "You get help.\n");
00824             return(1);
00825         }
00826     }
00827     PL_DestroyOptState(opt);
00828     return(0);
00829 }    
00830 
00831 PRIntn main( int argc, char **argv )
00832 {
00833     PR_STDIO_INIT();
00834     output = PR_GetSpecialFD(PR_StandardError);
00835 
00836     if ( Initialize( argc, argv ))
00837         return(1);
00838 
00839     TestAssignment();
00840     TestComparisons();
00841     TestLogicalOperations();
00842     TestConversion();
00843     TestShift();
00844     TestArithmetic();
00845     TestWellknowns();
00846     
00847     /*
00848     ** That's all folks!
00849     */
00850     if ( failedAlready )
00851     {
00852         PR_fprintf(output, "FAIL\n");\
00853     } 
00854     else
00855     {
00856         PR_fprintf(output, "PASS\n");\
00857     }
00858     return failedAlready;
00859 } /* end main() */