nsprpub/pr/tests/testbit.c

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial