Newer
Older
NetAddr-IP / Lite / Util / t / ipv4_inet.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..13\n"; }
  9. END {print "not ok 1\n" unless $loaded;}
  10.  
  11. #use diagnostics;
  12. use NetAddr::IP::Util qw(
  13. inet_ntoa
  14. inet_aton
  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. ## test 2 add stuff to buffer
  33. my @num = # addr
  34. qw(
  35. 0.0.0.0
  36. 255.255.255.255
  37. 1.2.3.4
  38. 10.253.230.9
  39. );
  40.  
  41. foreach (@num) {
  42. my @digs = split(/\./,$_);
  43. my $pkd = pack('C4',@digs);
  44. my $naddr = inet_aton($_);
  45. my $addr = join('.',unpack('C4',$naddr));
  46. my $num = inet_ntoa($pkd);
  47.  
  48. print "bits do not match\nnot "
  49. unless $naddr eq $pkd;
  50. &ok;
  51.  
  52. print "inet_aton: $addr, exp: $_\nnot "
  53. unless $addr eq $_;
  54. &ok;
  55.  
  56. print "inet_ntoa: $num, exp: $_\nnot "
  57. unless $num eq $_;
  58. &ok;
  59. }