home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / lltest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  22.6 KB  |  733 lines

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