⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lltest.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    LL_OR( result, bigMinusNumber, bigZero );    if ( !LL_UCMP( result, ==, bigMinusNumber ))        ResultFailed( "LL_OR", "-n | 0", bigMinusNumber, result );        /* test XOR */    LL_XOR( result, bigZero, bigZero );    if ( LL_UCMP( result, !=, bigZero ))        ResultFailed( "LL_XOR", "0 ^ 0", bigZero, result);        LL_XOR( result, bigOne, bigZero );    if ( LL_UCMP( result, !=, bigOne ))        ResultFailed( "LL_XOR", "1 ^ 0", bigZero, result );            LL_XOR( result, bigMinusNumber, bigZero );    if ( LL_UCMP( result, !=, bigMinusNumber ))        ResultFailed( "LL_XOR", "-n ^ 0", bigMinusNumber, result );        LL_XOR( result, bigMinusNumber, bigMinusNumber );    if ( LL_UCMP( result, !=, bigZero ))        ResultFailed( "LL_XOR", "-n ^ -n", bigMinusNumber, result);            /* test OR2.  */    result = bigZero;    LL_OR2( result, bigOne );    if ( LL_UCMP( result, !=, bigOne ))        ResultFailed( "LL_OR2", "(r=0) |= 1", bigOne, result);            result = bigOne;    LL_OR2( result, bigNumber );    if ( LL_UCMP( result, !=, bigNumber ))        ResultFailed( "LL_OR2", "(r=1) |= n", bigNumber, result);    result = bigMinusNumber;    LL_OR2( result, bigMinusNumber );    if ( LL_UCMP( result, !=, bigMinusNumber ))        ResultFailed( "LL_OR2", "(r=-n) |= -n", bigMinusNumber, result);    /* test NOT */    LL_NOT( result, bigMinusNumber);    LL_NOT( result2, result);    if ( LL_UCMP( result2, !=, bigMinusNumber ))        ResultFailed( "LL_NOT", "r != ~(~-n)", bigMinusNumber, result);                /* test Negation */    LL_NEG( result, bigMinusNumber );    LL_NEG( result2, result );    if ( LL_CMP( result2, !=, bigMinusNumber ))        ResultFailed( "LL_NEG", "r != -(-(-n))", bigMinusNumber, result);    return;}/***  TestConversion() -- Test Conversion Operations***/static voidTestConversion( void ){    PRInt64     result;    PRInt64     resultU;    PRInt32     result32;    PRUint32    resultU32;    float       resultF;    PRFloat64   resultD;        ReportProgress("Testing Conversion Operations\n");        /* LL_L2I  -- Convert to signed 32bit */    LL_L2I(result32, bigOne );    if ( result32 != one )          SetFailed( "LL_L2I", "r != 1");        LL_L2I(result32, bigMinusOne );    if ( result32 != minusOne )          SetFailed( "LL_L2I", "r != -1");        /* LL_L2UI -- Convert 64bit to unsigned 32bit */    LL_L2UI( resultU32, bigMinusOne );    if ( resultU32 != (PRUint32) minusOne )        SetFailed( "LL_L2UI", "r != -1");        LL_L2UI( resultU32, bigOne );    if ( resultU32 != (PRUint32) one )        SetFailed( "LL_L2UI", "r != 1");            /* LL_L2F  -- Convert to 32bit floating point */    LL_L2F( resultF, bigOne );    if ( resultF != 1.0 )        SetFailed( "LL_L2F", "r != 1.0");            LL_L2F( resultF, bigMinusOne );    if ( resultF != -1.0 )        SetFailed( "LL_L2F", "r != 1.0");        /* LL_L2D  -- Convert to 64bit floating point */    LL_L2D( resultD, bigOne );    if ( resultD != 1.0L )        SetFailed( "LL_L2D", "r != 1.0");            LL_L2D( resultD, bigMinusOne );    if ( resultD != -1.0L )        SetFailed( "LL_L2D", "r != -1.0");            /* LL_I2L  -- Convert 32bit signed to 64bit signed */    LL_I2L( result, one );    if ( LL_CMP(result, !=, bigOne ))        SetFailed( "LL_I2L", "r != 1");            LL_I2L( result, minusOne );    if ( LL_CMP(result, !=, bigMinusOne ))        SetFailed( "LL_I2L", "r != -1");            /* LL_UI2L -- Convert 32bit unsigned to 64bit unsigned */    LL_UI2L( resultU, (PRUint32) one );    if ( LL_CMP(resultU, !=, bigOne ))        SetFailed( "LL_UI2L", "r != 1");            /* [lth.] This did not behave as expected, but it is correct     */    LL_UI2L( resultU, (PRUint32) minusOne );    if ( LL_CMP(resultU, !=, bigZeroFox ))        ResultFailed( "LL_UI2L", "r != -1", bigZeroFox, resultU);            /* LL_F2L  -- Convert 32bit float to 64bit signed */    LL_F2L( result, 1.0 );    if ( LL_CMP(result, !=, bigOne ))        SetFailed( "LL_F2L", "r != 1");            LL_F2L( result, -1.0 );    if ( LL_CMP(result, !=, bigMinusOne ))        SetFailed( "LL_F2L", "r != -1");        /* LL_D2L  -- Convert 64bit Float to 64bit signed */    LL_D2L( result, 1.0L );    if ( LL_CMP(result, !=, bigOne ))        SetFailed( "LL_D2L", "r != 1");            LL_D2L( result, -1.0L );    if ( LL_CMP(result, !=, bigMinusOne ))        SetFailed( "LL_D2L", "r != -1");    return;}static void ShiftCompileOnly(){    /*    ** This function is only compiled, never called.    ** The real test is to see if it compiles w/o    ** warnings. This is no small feat, by the way.    */    PRInt64 ia, ib;    PRUint64 ua, ub;    LL_SHR(ia, ib, 32);    LL_SHL(ia, ib, 32);    LL_USHR(ua, ub, 32);    LL_ISHL(ia, 49, 32);}  /* ShiftCompileOnly */   /***  TestShift() -- Test Shifting Operations***/static voidTestShift( void ){    static const PRInt64 largeTwoZero = LL_INIT( 0x00000002, 0x00000000 );    PRInt64     result;    PRUint64    resultU;    ReportProgress("Testing Shifting Operations\n");        /* LL_SHL  -- Shift left algebraic */    LL_SHL( result, bigOne, one );    if ( LL_CMP( result, !=, bigTwo ))        ResultFailed( "LL_SHL", "r != 2", bigOne, result );        LL_SHL( result, bigTwo, thirtyTwo );    if ( LL_CMP( result, !=, largeTwoZero ))        ResultFailed( "LL_SHL", "r != twoZero", largeTwoZero, result);        /* LL_SHR  -- Shift right algebraic */    LL_SHR( result, bigFoxZero, thirtyTwo );    if ( LL_CMP( result, !=, bigMinusOne ))        ResultFailed( "LL_SHR", "r != -1", bigMinusOne, result);        LL_SHR( result, bigTwo, one );    if ( LL_CMP( result, !=, bigOne ))        ResultFailed( "LL_SHR", "r != 1", bigOne, result);    LL_SHR( result, bigFoxFox, thirtyTwo );    if ( LL_CMP( result, !=, bigMinusOne ))        ResultFailed( "LL_SHR", "r != -1 (was ff,ff)", bigMinusOne, result);        /* LL_USHR -- Logical shift right */    LL_USHR( resultU, bigZeroFox, thirtyTwo );    if ( LL_UCMP( resultU, !=, bigZero ))        ResultFailed( "LL_USHR", "r != 0 ", bigZero, result);        LL_USHR( resultU, bigFoxFox, thirtyTwo );    if ( LL_UCMP( resultU, !=, bigZeroFox ))        ResultFailed( "LL_USHR", "r != 0 ", bigZeroFox, result);        /* LL_ISHL -- Shift a 32bit integer into a 64bit result */    LL_ISHL( resultU, minusOne, thirtyTwo );    if ( LL_UCMP( resultU, !=, bigFoxZero ))        ResultFailed( "LL_ISHL", "r != ff,00 ", bigFoxZero, result);        LL_ISHL( resultU, one, sixtyThree );    if ( LL_UCMP( resultU, !=, bigEightZero ))        ResultFailed( "LL_ISHL", "r != 80,00 ", bigEightZero, result);        LL_ISHL( resultU, one, sixteen );    if ( LL_UCMP( resultU, !=, big64K ))        ResultFailed( "LL_ISHL", "r != 64K ", big64K, resultU);        return;}    /***  TestArithmetic() -- Test arithmetic operations.***/static voidTestArithmetic( void ){    PRInt64 largeVal          = LL_INIT( 0x00000001, 0xffffffff );    PRInt64 largeValPlusOne   = LL_INIT( 0x00000002, 0x00000000 );    PRInt64 largeValTimesTwo  = LL_INIT( 0x00000003, 0xfffffffe );    PRInt64 largeMultCand     = LL_INIT( 0x00000000, 0x7fffffff );    PRInt64 largeMinusMultCand = LL_INIT( 0xffffffff, 0x10000001 );    PRInt64 largeMultCandx64K = LL_INIT( 0x00007fff, 0xffff0000 );    PRInt64 largeNumSHL5      = LL_INIT( 0x0000001f, 0xffffffe0 );            PRInt64 result, result2;    /* Addition */        LL_ADD( result, bigOne, bigOne );    if ( LL_CMP( result, !=, bigTwo ))        ResultFailed( "LL_ADD", "r != 1 + 1", bigTwo, result);    LL_ADD( result, bigMinusOne, bigOne );    if ( LL_CMP( result, !=, bigZero ))        ResultFailed( "LL_ADD", "r != -1 + 1", bigOne, result);    LL_ADD( result, largeVal, bigOne );    if ( LL_CMP( result, !=, largeValPlusOne ))        ResultFailed( "LL_ADD", "lVP1 != lV + 1", largeValPlusOne, result);                /* Subtraction */    LL_SUB( result, bigOne, bigOne );    if ( LL_CMP( result, !=, bigZero ))        ResultFailed( "LL_SUB", "r != 1 - 1", bigZero, result);                LL_SUB( result, bigTwo, bigOne );    if ( LL_CMP( result, !=, bigOne ))        ResultFailed( "LL_SUB", "r != 2 - 1", bigOne, result);                LL_SUB( result, largeValPlusOne, bigOne );    if ( LL_CMP( result, !=, largeVal ))        ResultFailed( "LL_SUB", "r != lVP1 - 1", largeVal, result);                    /* Multiply */    LL_MUL( result, largeVal, bigTwo );    if ( LL_CMP( result, !=, largeValTimesTwo ))        ResultFailed( "LL_MUL", "r != lV*2", largeValTimesTwo, result);        LL_MUL( result, largeMultCand, big64K );    if ( LL_CMP( result, !=, largeMultCandx64K ))        ResultFailed( "LL_MUL", "r != lV*64K", largeMultCandx64K, result);            LL_NEG( result2, largeMultCand );    LL_MUL( result, largeMultCand, bigMinusOne );    if ( LL_CMP( result, !=, result2  ))        ResultFailed( "LL_MUL", "r != -lMC", result2, result);    LL_SHL( result2, bigZeroFox, 5);    LL_MUL( result, bigZeroFox, bigThirtyTwo );    if ( LL_CMP( result, !=, largeNumSHL5  ))        ResultFailed( "LL_MUL", "r != 0f<<5", largeNumSHL5, result );        /* LL_DIV() Division */    LL_DIV( result, bigOne, bigOne);    if ( LL_CMP( result, !=, bigOne ))        ResultFailed( "LL_DIV", "1 != 1", bigOne, result);        LL_DIV( result, bigNumber, bigOne );    if ( LL_CMP( result, !=, bigNumber  ))        ResultFailed( "LL_DIV", "r != n / 1", bigNumber, result);    LL_DIV( result, bigNumber, bigMinusOne );    if ( LL_CMP( result, !=, bigMinusNumber  ))        ResultFailed( "LL_DIV", "r != n / -1", bigMinusNumber, result);    LL_DIV( result, bigMinusNumber, bigMinusOne );    if ( LL_CMP( result, !=, bigNumber  ))        ResultFailed( "LL_DIV", "r != -n / -1", bigNumber, result);            LL_SHL( result2, bigZeroFox, 5 );    LL_DIV( result, result2, bigOne );    if ( LL_CMP( result, !=, result2  ))        ResultFailed( "LL_DIV", "0f<<5 != 0f<<5", result2, result);        LL_SHL( result2, bigZeroFox, 5 );    LL_NEG( result2, result2 );    LL_DIV( result, result2, bigOne );    if ( LL_CMP( result, !=, result2  ))        ResultFailed( "LL_DIV", "-0f<<5 != -0f<<5", result2, result);        LL_SHL( result2, bigZeroFox, 17 );    LL_DIV( result, result2, bigMinusOne );    LL_NEG( result2, result2 );    if ( LL_CMP( result, !=, result2  ))        ResultFailed( "LL_DIV", "-0f<<17 != -0f<<17", result2, result);            /* LL_MOD() Modulo Division */    LL_ADD( result2, bigThirtyTwo, bigOne );    LL_MOD( result, result2, bigSixTeen );    if ( LL_CMP( result, !=, bigOne ))        ResultFailed( "LL_MOD", "r != 1", bigSixTeen, result);            LL_MUL( result2, bigZeroFox, bigThirtyTwo );    LL_ADD( result2, result2, bigSixTeen);    LL_MOD( result, result2, bigThirtyTwo );    if ( LL_CMP( result, !=, bigSixTeen ))        ResultFailed( "LL_MOD", "r != 16", bigSixTeen, result);    /* LL_UDIVMOD */    LL_DIV( result, bigOne, bigOne);    if ( LL_CMP( result, !=, bigOne ))        ResultFailed( "LL_DIV", "r != 16", bigSixTeen, result);        return;} static void TestWellknowns(void){    PRInt64 max = LL_MAXINT, min = LL_MININT, zero = LL_ZERO;    PRInt64 mmax = LL_MaxInt(), mmin = LL_MinInt(), mzero = LL_Zero();    if (LL_NE(max, mmax))        ResultFailed( "max, mmax", "max != mmax", max, mmax);    if (LL_NE(min, mmin))        ResultFailed( "min, mmin", "min != mmin", max, mmin);    if (LL_NE(zero, mzero))        ResultFailed( "zero, mzero", "zero != mzero", zero, mzero);}  /* TestWellknowns */ /*** Initialize() -- Initialize the test case**** Parse command line options***/static PRIntnInitialize( PRIntn argc, char **argv ){    PLOptState *opt = PL_CreateOptState(argc, argv, "dvh");    PLOptStatus os;    /*    ** Parse command line options    */        while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))    {        if (PL_OPT_BAD == os) continue;        switch (opt->option)        {        case 'd':  /* set debug mode */            debugMode = PR_TRUE;            break;                    case 'v':  /* set verbose mode */            verboseMode = PR_TRUE;            debugMode = PR_TRUE;            break;                    case 'h':  /* user wants some guidance */        default:            PR_fprintf(output, "You get help.\n");            return(1);        }    }    PL_DestroyOptState(opt);    return(0);}    PRIntn main( int argc, char **argv ){    PR_STDIO_INIT();    output = PR_GetSpecialFD(PR_StandardError);    if ( Initialize( argc, argv ))        return(1);    TestAssignment();    TestComparisons();    TestLogicalOperations();    TestConversion();    TestShift();    TestArithmetic();    TestWellknowns();        /*    ** That's all folks!    */    if ( failedAlready )    {        PR_fprintf(output, "FAIL\n");\    }     else    {        PR_fprintf(output, "PASS\n");\    }    return failedAlready;} /* end main() */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -