nsprpub/pr/tests/testbit.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/testbit.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 +** File:        lazyinit.c
    1.11 +** Description: Test the functions and macros declared in prbit.h
    1.12 +**
    1.13 +*/
    1.14 +
    1.15 +#include "nspr.h"
    1.16 +
    1.17 +#define ErrorReport(x) { printf((x)); failed = 1; }
    1.18 +
    1.19 +prbitmap_t myMap[512/32] = { 0 };
    1.20 +
    1.21 +PRInt32 rc;
    1.22 +PRInt32 i;
    1.23 +PRIntn  failed = 0;
    1.24 +
    1.25 +int main(int argc, char **argv)
    1.26 +{
    1.27 +    /*
    1.28 +    ** Test bitmap things.
    1.29 +    */
    1.30 +    if ( PR_TEST_BIT( myMap, 0 ))
    1.31 +        ErrorReport("Test 0.0: Failed\n");
    1.32 +
    1.33 +    if ( PR_TEST_BIT( myMap, 31 ))
    1.34 +        ErrorReport("Test 0.1: Failed\n");
    1.35 +
    1.36 +    if ( PR_TEST_BIT( myMap, 128 ))
    1.37 +        ErrorReport("Test 0.2: Failed\n");
    1.38 +
    1.39 +    if ( PR_TEST_BIT( myMap, 129 ))
    1.40 +        ErrorReport("Test 0.3: Failed\n");
    1.41 +
    1.42 +
    1.43 +    PR_SET_BIT( myMap, 0 );
    1.44 +    if ( !PR_TEST_BIT( myMap, 0 ))
    1.45 +        ErrorReport("Test 1.0: Failed\n");
    1.46 +
    1.47 +    PR_CLEAR_BIT( myMap, 0 );
    1.48 +    if ( PR_TEST_BIT( myMap, 0 ))
    1.49 +        ErrorReport("Test 1.0.1: Failed\n");
    1.50 +
    1.51 +    PR_SET_BIT( myMap, 31 );
    1.52 +    if ( !PR_TEST_BIT( myMap, 31 ))
    1.53 +        ErrorReport("Test 1.1: Failed\n");
    1.54 +
    1.55 +    PR_CLEAR_BIT( myMap, 31 );
    1.56 +    if ( PR_TEST_BIT( myMap, 31 ))
    1.57 +        ErrorReport("Test 1.1.1: Failed\n");
    1.58 +
    1.59 +    PR_SET_BIT( myMap, 128 );
    1.60 +    if ( !PR_TEST_BIT( myMap, 128 ))
    1.61 +        ErrorReport("Test 1.2: Failed\n");
    1.62 +
    1.63 +    PR_CLEAR_BIT( myMap, 128 );
    1.64 +    if ( PR_TEST_BIT( myMap, 128 ))
    1.65 +        ErrorReport("Test 1.2.1: Failed\n");
    1.66 +
    1.67 +    PR_SET_BIT( myMap, 129 );
    1.68 +    if ( !PR_TEST_BIT( myMap, 129 ))
    1.69 +        ErrorReport("Test 1.3: Failed\n");
    1.70 +
    1.71 +    PR_CLEAR_BIT( myMap, 129 );
    1.72 +    if ( PR_TEST_BIT( myMap, 129 ))
    1.73 +        ErrorReport("Test 1.3.1: Failed\n");
    1.74 +
    1.75 +
    1.76 +    /*
    1.77 +    ** Test Ceiling and Floor functions and macros
    1.78 +    */
    1.79 +    if ((rc = PR_CeilingLog2(32)) != 5 )
    1.80 +        ErrorReport("Test 10.0: Failed\n");
    1.81 +
    1.82 +    if ((rc = PR_FloorLog2(32)) != 5 )
    1.83 +        ErrorReport("Test 10.1: Failed\n");
    1.84 +
    1.85 +
    1.86 +    /*
    1.87 +    ** Evaluate results and exit
    1.88 +    */
    1.89 +    if (failed)
    1.90 +      {
    1.91 +        printf("FAILED\n");
    1.92 +        return(1);
    1.93 +      }
    1.94 +    else
    1.95 +      {
    1.96 +        printf("PASSED\n");
    1.97 +        return(0);
    1.98 +      }
    1.99 +}  /* end main() */
   1.100 +/* end testbit.c */

mercurial