Newer
Older
NetAddr-IP / Lite / Util / t / ipv6_any2n.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..4\n"; }
  9. END {print "not ok 1\n" unless $loaded;}
  10.  
  11. use NetAddr::IP::Util qw(
  12. ipv6_aton
  13. ipv6_n2x
  14. inet_any2n
  15. );
  16.  
  17. $loaded = 1;
  18. print "ok 1\n";
  19. ######################### End of black magic.
  20.  
  21. # Insert your test code below (better if it prints "ok 13"
  22. # (correspondingly "not ok 13") depending on the success of chunk 13
  23. # of the test code):
  24.  
  25. $test = 2;
  26.  
  27. sub ok {
  28. print "ok $test\n";
  29. ++$test;
  30. }
  31.  
  32. my @num = qw # input expected
  33. ( a1b2:c3d4:e5d6:f7e8:08f9:190a:2a1b:3b4c A1B2:C3D4:E5D6:F7E8:8F9:190A:2A1B:3B4C
  34. 1.2.3.4 0:0:0:0:0:0:102:304
  35. A1B2:C3D4:E5D6:F7E8:08F9:190A:1.2.3.4 A1B2:C3D4:E5D6:F7E8:8F9:190A:102:304
  36. );
  37.  
  38. my $ff = ipv6_aton($num[1]);
  39. for(my $i=0;$i<@num;$i+=2) {
  40. my $num = $num[$i];
  41. my $bstr = inet_any2n($num);
  42. my $rv = ipv6_n2x($bstr);
  43. my $exp = $num[$i +1];
  44. print "got: $rv\nexp: $exp\nnot "
  45. unless $rv eq $exp;
  46. &ok;
  47. }