testbit.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. ** File: lazyinit.c
  7. ** Description: Test the functions and macros declared in prbit.h
  8. **
  9. */
  10. #include "nspr.h"
  11. #define ErrorReport(x) { printf((x)); failed = 1; }
  12. prbitmap_t myMap[512/32] = { 0 };
  13. PRInt32 rc;
  14. PRInt32 i;
  15. PRIntn failed = 0;
  16. int main(int argc, char **argv)
  17. {
  18. /*
  19. ** Test bitmap things.
  20. */
  21. if ( PR_TEST_BIT( myMap, 0 )) {
  22. ErrorReport("Test 0.0: Failed\n");
  23. }
  24. if ( PR_TEST_BIT( myMap, 31 )) {
  25. ErrorReport("Test 0.1: Failed\n");
  26. }
  27. if ( PR_TEST_BIT( myMap, 128 )) {
  28. ErrorReport("Test 0.2: Failed\n");
  29. }
  30. if ( PR_TEST_BIT( myMap, 129 )) {
  31. ErrorReport("Test 0.3: Failed\n");
  32. }
  33. PR_SET_BIT( myMap, 0 );
  34. if ( !PR_TEST_BIT( myMap, 0 )) {
  35. ErrorReport("Test 1.0: Failed\n");
  36. }
  37. PR_CLEAR_BIT( myMap, 0 );
  38. if ( PR_TEST_BIT( myMap, 0 )) {
  39. ErrorReport("Test 1.0.1: Failed\n");
  40. }
  41. PR_SET_BIT( myMap, 31 );
  42. if ( !PR_TEST_BIT( myMap, 31 )) {
  43. ErrorReport("Test 1.1: Failed\n");
  44. }
  45. PR_CLEAR_BIT( myMap, 31 );
  46. if ( PR_TEST_BIT( myMap, 31 )) {
  47. ErrorReport("Test 1.1.1: Failed\n");
  48. }
  49. PR_SET_BIT( myMap, 128 );
  50. if ( !PR_TEST_BIT( myMap, 128 )) {
  51. ErrorReport("Test 1.2: Failed\n");
  52. }
  53. PR_CLEAR_BIT( myMap, 128 );
  54. if ( PR_TEST_BIT( myMap, 128 )) {
  55. ErrorReport("Test 1.2.1: Failed\n");
  56. }
  57. PR_SET_BIT( myMap, 129 );
  58. if ( !PR_TEST_BIT( myMap, 129 )) {
  59. ErrorReport("Test 1.3: Failed\n");
  60. }
  61. PR_CLEAR_BIT( myMap, 129 );
  62. if ( PR_TEST_BIT( myMap, 129 )) {
  63. ErrorReport("Test 1.3.1: Failed\n");
  64. }
  65. /*
  66. ** Test Ceiling and Floor functions and macros
  67. */
  68. if ((rc = PR_CeilingLog2(32)) != 5 ) {
  69. ErrorReport("Test 10.0: Failed\n");
  70. }
  71. if ((rc = PR_FloorLog2(32)) != 5 ) {
  72. ErrorReport("Test 10.1: Failed\n");
  73. }
  74. /*
  75. ** Evaluate results and exit
  76. */
  77. if (failed)
  78. {
  79. printf("FAILED\n");
  80. return(1);
  81. }
  82. else
  83. {
  84. printf("PASSED\n");
  85. return(0);
  86. }
  87. } /* end main() */
  88. /* end testbit.c */