Newer
Older
NetAddr-IP / Lite / Util / t / leftshift.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..9\n"; }
  9. END {print "not ok 1\n" unless $loaded;}
  10.  
  11. use NetAddr::IP::Util qw(
  12. ipv6_aton
  13. ipv6_n2x
  14. shiftleft
  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 = # input shift expected
  33. qw(
  34. 1::1 none 1:0:0:0:0:0:0:1
  35. 1::1 0 1:0:0:0:0:0:0:1
  36. 1::1 1 2:0:0:0:0:0:0:2
  37. 1::1 2 4:0:0:0:0:0:0:4
  38. 1::1 3 8:0:0:0:0:0:0:8
  39. 1::1 15 8000:0:0:0:0:0:0:8000
  40. 1::1 16 0:0:0:0:0:0:1:0
  41. 1::1 128 0:0:0:0:0:0:0:0
  42. );
  43.  
  44. for (my $i=0;$i < @num;$i+=3) {
  45. my $bstr = ipv6_aton($num[$i]);
  46. my $rv;
  47. if ($num[$i +1] =~ /\D/) {
  48. $rv = shiftleft($bstr);
  49. }
  50. else {
  51. $rv = shiftleft($bstr,$num[$i +1]);
  52. }
  53. my $exp = $num[$i+2];
  54. my $got = ipv6_n2x($rv);
  55. print "got: $got, exp: $exp\nnot "
  56. unless $got eq $exp;
  57. &ok;
  58. }