Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
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/. */
6 /*
7 ** File: lazyinit.c
8 ** Description: Test the functions and macros declared in prbit.h
9 **
10 */
12 #include "nspr.h"
14 #define ErrorReport(x) { printf((x)); failed = 1; }
16 prbitmap_t myMap[512/32] = { 0 };
18 PRInt32 rc;
19 PRInt32 i;
20 PRIntn failed = 0;
22 int main(int argc, char **argv)
23 {
24 /*
25 ** Test bitmap things.
26 */
27 if ( PR_TEST_BIT( myMap, 0 ))
28 ErrorReport("Test 0.0: Failed\n");
30 if ( PR_TEST_BIT( myMap, 31 ))
31 ErrorReport("Test 0.1: Failed\n");
33 if ( PR_TEST_BIT( myMap, 128 ))
34 ErrorReport("Test 0.2: Failed\n");
36 if ( PR_TEST_BIT( myMap, 129 ))
37 ErrorReport("Test 0.3: Failed\n");
40 PR_SET_BIT( myMap, 0 );
41 if ( !PR_TEST_BIT( myMap, 0 ))
42 ErrorReport("Test 1.0: Failed\n");
44 PR_CLEAR_BIT( myMap, 0 );
45 if ( PR_TEST_BIT( myMap, 0 ))
46 ErrorReport("Test 1.0.1: Failed\n");
48 PR_SET_BIT( myMap, 31 );
49 if ( !PR_TEST_BIT( myMap, 31 ))
50 ErrorReport("Test 1.1: Failed\n");
52 PR_CLEAR_BIT( myMap, 31 );
53 if ( PR_TEST_BIT( myMap, 31 ))
54 ErrorReport("Test 1.1.1: Failed\n");
56 PR_SET_BIT( myMap, 128 );
57 if ( !PR_TEST_BIT( myMap, 128 ))
58 ErrorReport("Test 1.2: Failed\n");
60 PR_CLEAR_BIT( myMap, 128 );
61 if ( PR_TEST_BIT( myMap, 128 ))
62 ErrorReport("Test 1.2.1: Failed\n");
64 PR_SET_BIT( myMap, 129 );
65 if ( !PR_TEST_BIT( myMap, 129 ))
66 ErrorReport("Test 1.3: Failed\n");
68 PR_CLEAR_BIT( myMap, 129 );
69 if ( PR_TEST_BIT( myMap, 129 ))
70 ErrorReport("Test 1.3.1: Failed\n");
73 /*
74 ** Test Ceiling and Floor functions and macros
75 */
76 if ((rc = PR_CeilingLog2(32)) != 5 )
77 ErrorReport("Test 10.0: Failed\n");
79 if ((rc = PR_FloorLog2(32)) != 5 )
80 ErrorReport("Test 10.1: Failed\n");
83 /*
84 ** Evaluate results and exit
85 */
86 if (failed)
87 {
88 printf("FAILED\n");
89 return(1);
90 }
91 else
92 {
93 printf("PASSED\n");
94 return(0);
95 }
96 } /* end main() */
97 /* end testbit.c */