Newer
Older
NetAddr-IP / Lite / Util / t / bcdn2bin.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.  
  8. BEGIN { $| = 1; print "1..25\n"; }
  9. END {print "not ok 1\n" unless $loaded;}
  10.  
  11. use NetAddr::IP::Util qw(
  12. ipv6_n2x
  13. bcdn2bin
  14. );
  15.  
  16. $loaded = 1;
  17. print "ok 1\n";
  18. ######################### End of black magic.
  19.  
  20. # Insert your test code below (better if it prints "ok 13"
  21. # (correspondingly "not ok 13") depending on the success of chunk 13
  22. # of the test code):
  23.  
  24. $test = 2;
  25.  
  26. sub ok {
  27. print "ok $test\n";
  28. ++$test;
  29. }
  30.  
  31. my @num = # input expected
  32. qw(
  33. 0 0:0:0:0:0:0:0:0
  34. 2147483648 0:0:0:0:0:0:8000:0
  35. 4294967296 0:0:0:0:0:1:0:0
  36. 8589934592 0:0:0:0:0:2:0:0
  37. 10000000000 0:0:0:0:0:2:540B:E400
  38. 17179869184 0:0:0:0:0:4:0:0
  39. 34359738368 0:0:0:0:0:8:0:0
  40. 68719476736 0:0:0:0:0:10:0:0
  41. 137438953472 0:0:0:0:0:20:0:0
  42. 274877906944 0:0:0:0:0:40:0:0
  43. 549755813888 0:0:0:0:0:80:0:0
  44. 1099511627776 0:0:0:0:0:100:0:0
  45. 2199023255552 0:0:0:0:0:200:0:0
  46. 4398046511104 0:0:0:0:0:400:0:0
  47. 8796093022208 0:0:0:0:0:800:0:0
  48. 17592186044416 0:0:0:0:0:1000:0:0
  49. 35184372088832 0:0:0:0:0:2000:0:0
  50. 70368744177664 0:0:0:0:0:4000:0:0
  51. 140737488355328 0:0:0:0:0:8000:0:0
  52. 9223372036854775808 0:0:0:0:8000:0:0:0
  53. 604462909807314587353088 0:0:0:8000:0:0:0:0
  54. 39614081257132168796771975168 0:0:8000:0:0:0:0:0
  55. 2596148429267413814265248164610048 0:8000:0:0:0:0:0:0
  56. 170141183460469231731687303715884105728 8000:0:0:0:0:0:0:0
  57. );
  58.  
  59. ## tests 2 - 9 check pack correct
  60.  
  61. #use Devel::Peek 'Dump';
  62.  
  63. for (my $i=0;$i<@num;$i+=2) {
  64. print $num[$i],"\n";
  65. my $pkd = pack("H*",$num[$i]);
  66. my $len = length($num[$i]);
  67. #Dump($pkd);
  68. my $bits = bcdn2bin($pkd,$len);
  69. my $ip = ipv6_n2x($bits);
  70. print "got: $ip\nexp: $num[$i +1]\nnot "
  71. unless $ip eq $num[$i +1];
  72. &ok;
  73. }