Newer
Older
NetAddr-IP / Lite / Util / t / 4to6.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..5\n"; }
  9. END {print "not ok 1\n" unless $loaded;}
  10.  
  11. use NetAddr::IP::Util qw(
  12. inet_aton
  13. ipv6_n2d
  14. ipv6_aton
  15. ipv4to6
  16. mask4to6
  17. );
  18.  
  19. $loaded = 1;
  20. print "ok 1\n";
  21. ######################### End of black magic.
  22.  
  23. # Insert your test code below (better if it prints "ok 13"
  24. # (correspondingly "not ok 13") depending on the success of chunk 13
  25. # of the test code):
  26.  
  27. $test = 2;
  28.  
  29. sub ok {
  30. print "ok $test\n";
  31. ++$test;
  32. }
  33.  
  34. my $nip = inet_aton('1.2.3.4');
  35. my $exp = '0:0:0:0:0:0:1.2.3.4';
  36.  
  37. ## test 2 check 4->6 conversion
  38. my $nipv6 = ipv4to6($nip);
  39. my $ipv6 = ipv6_n2d($nipv6);
  40. print "got: $ipv6\nexp: $exp\nnot "
  41. unless $ipv6 eq $exp;
  42. &ok;
  43.  
  44.  
  45. ## test 3 check mask4->6 extension
  46. $exp = 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:1.2.3.4';
  47. $nipv6 = mask4to6($nip);
  48. $ipv6 = ipv6_n2d($nipv6);
  49. print "got: $ipv6\nexp: $exp\nnot "
  50. unless $ipv6 eq $exp;
  51. &ok;
  52.  
  53. ## test 4 check bad length
  54. $nip = pack("H9",0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09);
  55. eval {
  56. ipv4to6($nip);
  57. };
  58. print "ipv4to6 accepted bad argument length\nnot "
  59. unless $@ && $@ =~ /Bad arg.+ipv4to6/;
  60. &ok;
  61.  
  62. ## test 5 check bad length
  63. eval {
  64. mask4to6($nip);
  65. };
  66. print "mask4to6 accepted bad argument length\nnot "
  67. unless $@ && $@ =~ /Bad arg.+mask4to6/;
  68. &ok;
  69.