Newer
Older
NetAddr-IP / Lite / Util / t / badd.t
@Michael Robinton Michael Robinton on 21 Oct 2014 1 KB Import of MIKER/NetAddr-IP-4.020 from CPAN.
  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. );
  14.  
  15. $test = 1;
  16.  
  17. sub ok {
  18. print "ok $test\n";
  19. ++$test;
  20. }
  21.  
  22. my @addr =
  23. qw( :: 0:0:0:0:0:0:0:0
  24. ::: undef
  25. foo undef
  26. ::foo undef
  27. foo:: undef
  28. abc::def::9 undef
  29. abcd1:: undef
  30. abcd:: abcd:0:0:0:0:0:0:0
  31. ::abcde undef
  32. :a:b:c:d:1:2:3:4 undef
  33. :a:b:c:d undef
  34. a:b:c:d:1:2:3:4: undef
  35. a:b:c:d:1:2:3:4:: undef
  36. ::a:b:c:d:1:2:3:4 undef
  37. ::a:b:c:d:1:2:3 0:a:b:c:d:1:2:3
  38. ::a:b:c:d:1:2:3: undef
  39. :a:b:c:d:1:2:3:: undef
  40. a:b:c:d:1:2:3:: a:b:c:d:1:2:3:0
  41. );
  42.  
  43. my $x = @addr/2;
  44.  
  45. # notify TEST about number of tests
  46. # Insert your test code below (better if it prints "ok 13"
  47. # (correspondingly "not ok 13") depending on the success of chunk 13
  48. # of the test code):
  49.  
  50. print '1..',$x,"\n";
  51.  
  52. for ($x = 0;$x <= $#addr; $x+=2) {
  53. my $bstr = ipv6_aton($addr[$x]);
  54. if ($addr[$x +1] =~ /undef/) {
  55. print "unexpected return value for $addr[$x]: $_\nnot "
  56. if ($_ = ipv6_aton && (ipv6_n2x($_) || 'not defined'));
  57. } else {
  58. my $rv = ipv6_aton($addr[$x]);
  59. unless ($rv) {
  60. print "got undefined value for $addr[$x]\nnot ";
  61. }
  62. else {
  63. $rv = ipv6_n2x($rv) || 'not defined';
  64. print "got: $rv, exp: $addr[$x +1]\nnot "
  65. unless $rv eq uc $addr[$x +1];
  66. }
  67. }
  68. &ok;
  69. }