tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testbit.c (2215B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 /*
      7 ** File:        lazyinit.c
      8 ** Description: Test the functions and macros declared in prbit.h
      9 **
     10 */
     11 
     12 #include "nspr.h"
     13 
     14 #define ErrorReport(x) \
     15  {                    \
     16    printf((x));       \
     17    failed = 1;        \
     18  }
     19 
     20 prbitmap_t myMap[512 / 32] = {0};
     21 
     22 PRInt32 rc;
     23 PRInt32 i;
     24 PRIntn failed = 0;
     25 
     26 int main(int argc, char** argv) {
     27  /*
     28  ** Test bitmap things.
     29  */
     30  if (PR_TEST_BIT(myMap, 0)) {
     31    ErrorReport("Test 0.0: Failed\n");
     32  }
     33 
     34  if (PR_TEST_BIT(myMap, 31)) {
     35    ErrorReport("Test 0.1: Failed\n");
     36  }
     37 
     38  if (PR_TEST_BIT(myMap, 128)) {
     39    ErrorReport("Test 0.2: Failed\n");
     40  }
     41 
     42  if (PR_TEST_BIT(myMap, 129)) {
     43    ErrorReport("Test 0.3: Failed\n");
     44  }
     45 
     46  PR_SET_BIT(myMap, 0);
     47  if (!PR_TEST_BIT(myMap, 0)) {
     48    ErrorReport("Test 1.0: Failed\n");
     49  }
     50 
     51  PR_CLEAR_BIT(myMap, 0);
     52  if (PR_TEST_BIT(myMap, 0)) {
     53    ErrorReport("Test 1.0.1: Failed\n");
     54  }
     55 
     56  PR_SET_BIT(myMap, 31);
     57  if (!PR_TEST_BIT(myMap, 31)) {
     58    ErrorReport("Test 1.1: Failed\n");
     59  }
     60 
     61  PR_CLEAR_BIT(myMap, 31);
     62  if (PR_TEST_BIT(myMap, 31)) {
     63    ErrorReport("Test 1.1.1: Failed\n");
     64  }
     65 
     66  PR_SET_BIT(myMap, 128);
     67  if (!PR_TEST_BIT(myMap, 128)) {
     68    ErrorReport("Test 1.2: Failed\n");
     69  }
     70 
     71  PR_CLEAR_BIT(myMap, 128);
     72  if (PR_TEST_BIT(myMap, 128)) {
     73    ErrorReport("Test 1.2.1: Failed\n");
     74  }
     75 
     76  PR_SET_BIT(myMap, 129);
     77  if (!PR_TEST_BIT(myMap, 129)) {
     78    ErrorReport("Test 1.3: Failed\n");
     79  }
     80 
     81  PR_CLEAR_BIT(myMap, 129);
     82  if (PR_TEST_BIT(myMap, 129)) {
     83    ErrorReport("Test 1.3.1: Failed\n");
     84  }
     85 
     86  /*
     87  ** Test Ceiling and Floor functions and macros
     88  */
     89  if ((rc = PR_CeilingLog2(32)) != 5) {
     90    ErrorReport("Test 10.0: Failed\n");
     91  }
     92 
     93  if ((rc = PR_FloorLog2(32)) != 5) {
     94    ErrorReport("Test 10.1: Failed\n");
     95  }
     96 
     97  /*
     98  ** Evaluate results and exit
     99  */
    100  if (failed) {
    101    printf("FAILED\n");
    102    return (1);
    103  } else {
    104    printf("PASSED\n");
    105    return (0);
    106  }
    107 } /* end main() */
    108 /* end testbit.c */