Newer
Older
NetAddr-IP / Lite / Util / t / hasbits.t
  1. # Before `make install' is performed this script should be runnable with
  2. # `make test'. After `make install' it should work as `perl test.pl'
  3.  
  4. ######################### We start with some black magic to print on failure.
  5. # Change 1..1 below to 1..last_test_to_print .
  6. # (It may become useful if the test is moved to ./t subdirectory.)
  7. $| = 1;
  8. END {print "1..1\nnot ok 1\n" unless $test;}
  9.  
  10. use NetAddr::IP::Util qw(
  11. ipv6_aton
  12. ipv6_n2x
  13. hasbits
  14. );
  15.  
  16. $test = 1;
  17.  
  18. sub ok {
  19. print "ok $test\n";
  20. ++$test;
  21. }
  22.  
  23. my @num = qw # input
  24. (
  25. ::
  26. 8000::
  27. 4000::
  28. 2000::
  29. 1000::
  30. 800::
  31. 400::
  32. 200::
  33. 100::
  34. 80::
  35. 40::
  36. 20::
  37. 10::
  38. 1::
  39. 0:8000::
  40. 0:4000::
  41. 0:2000::
  42. 0:1000::
  43. 0:800::
  44. 0:400::
  45. 0:200::
  46. 0:100::
  47. 0:80::
  48. 0:40::
  49. 0:20::
  50. 0:10::
  51. 0:1::
  52. 0:0:8000::
  53. 0:0:4000::
  54. 0:0:2000::
  55. 0:0:1000::
  56. 0:0:800::
  57. 0:0:400::
  58. 0:0:200::
  59. 0:0:100::
  60. 0:0:80::
  61. 0:0:40::
  62. 0:0:20::
  63. 0:0:10::
  64. 0:0:1::
  65. 0:0:0:8000::
  66. 0:0:0:4000::
  67. 0:0:0:2000::
  68. 0:0:0:1000::
  69. 0:0:0:800::
  70. 0:0:0:400::
  71. 0:0:0:200::
  72. 0:0:0:100::
  73. 0:0:0:80::
  74. 0:0:0:40::
  75. 0:0:0:20::
  76. 0:0:0:10::
  77. 0:0:0:1::
  78. ::8000:0:0:0
  79. ::4000:0:0:0
  80. ::2000:0:0:0
  81. ::1000:0:0:0
  82. ::800:0:0:0
  83. ::400:0:0:0
  84. ::200:0:0:0
  85. ::100:0:0:0
  86. ::80:0:0:0
  87. ::40:0:0:0
  88. ::20:0:0:0
  89. ::10:0:0:0
  90. ::1:0:0:0
  91. ::8000:0:0
  92. ::4000:0:0
  93. ::2000:0:0
  94. ::1000:0:0
  95. ::800:0:0
  96. ::400:0:0
  97. ::200:0:0
  98. ::100:0:0
  99. ::80:0:0
  100. ::40:0:0
  101. ::20:0:0
  102. ::10:0:0
  103. ::1:0:0
  104. ::8000:0
  105. ::4000:0
  106. ::2000:0
  107. ::1000:0
  108. ::800:0
  109. ::400:0
  110. ::200:0
  111. ::100:0
  112. ::80:0
  113. ::40:0
  114. ::20:0
  115. ::10:0
  116. ::1:0
  117. ::8000
  118. ::4000
  119. ::2000
  120. ::1000
  121. ::800
  122. ::400
  123. ::200
  124. ::100
  125. ::80
  126. ::40
  127. ::20
  128. ::10
  129. ::1
  130. ::8000:0:0:0:0
  131. ::8000:0:0:0:0:0
  132. ::8000:0:0:0:0:0:0
  133. 8000:0:0:0:0:0:0:0
  134. );
  135. # Insert your test code below (better if it prints "ok 13"
  136. # (correspondingly "not ok 13") depending on the success of chunk 13
  137. # of the test code):
  138. print '1..',(scalar @num), "\n";
  139.  
  140. foreach (@num) {
  141. my $bstr = ipv6_aton($_);
  142. my $rv = hasbits($bstr);
  143. my $exp = ($_ eq '::') ? 0:1;
  144. print "got: $rv, exp: $exp for ", ipv6_n2x($bstr), "\nnot "
  145. unless $rv eq $exp;
  146. &ok;
  147. }