Newer
Older
NetAddr-IP / Lite / t / over_copy.t
@Michael Robinton Michael Robinton on 21 Oct 2014 1 KB Import of MIKER/NetAddr-IP-4.020 from CPAN.
  1.  
  2. #use diagnostics;
  3. use NetAddr::IP::Lite 0.10;
  4. *Ones = \&NetAddr::IP::Lite::Ones;
  5. use NetAddr::IP::Util qw(
  6. ipv6_aton
  7. shiftleft
  8. );
  9. $| = 1;
  10.  
  11. print "1..8\n";
  12.  
  13. my $test = 1;
  14. sub ok() {
  15. print 'ok ',$test++,"\n";
  16. }
  17.  
  18. my $ip24 = '1.2.3.4/24';
  19. my $o = new NetAddr::IP::Lite($ip24);
  20. my $c = $o;
  21.  
  22. ## test 1 validate original
  23. my $txto = sprintf("%s",$o);
  24. my $txtc = sprintf("%s",$c);
  25. print "orig... got: $txto, exp: $ip24\nnot "
  26. unless $txto eq $ip24;
  27. &ok;
  28.  
  29. ## test 2
  30. print "copy... got: $txtc, exp: $ip24\nnot "
  31. unless $txtc eq $ip24;
  32. &ok;
  33.  
  34. my $ip28 = '1.2.3.4/28';
  35. my $mask = shiftleft(Ones(),32 - 28);
  36.  
  37. $c->{mask} = $mask;
  38. $txto = sprintf("%s",$o);
  39. $txtc = sprintf("%s",$c);
  40.  
  41. ## overload does not unlink originals in this case
  42. ## test 3 validate original
  43. $txto = sprintf("%s",$o);
  44. $txtc = sprintf("%s",$c);
  45. print "orig... got: $txto, exp: $ip28\nnot "
  46. unless $txto eq $ip28;
  47. &ok;
  48.  
  49. ## test 4
  50. print "copy... got: $txtc, exp: $ip28\nnot "
  51. unless $txtc eq $ip28;
  52. &ok;
  53.  
  54. my $ip265 = '1.2.3.5/26';
  55. my $ip285 = '1.2.3.5/28';
  56. $mask = shiftleft(Ones(),32 - 26);
  57.  
  58. ## test 5 overload seperates variables
  59. $c++;
  60. ## validate original
  61. $txto = sprintf("%s",$o);
  62. $txtc = sprintf("%s",$c);
  63. print "orig... got: $txto, exp: $ip28\nnot "
  64. unless $txto eq $ip28;
  65. &ok;
  66.  
  67. ## test 6 check mutated copy
  68. print "copy... got: $txtc, exp: $ip285\nnot "
  69. unless $txtc eq $ip285;
  70. &ok;
  71.  
  72. ## test 7 check seperation
  73. $c->{mask} = $mask;
  74. ## validate original
  75. $txto = sprintf("%s",$o);
  76. $txtc = sprintf("%s",$c);
  77. print "orig... got: $txto, exp: $ip28\nnot "
  78. unless $txto eq $ip28;
  79. &ok;
  80.  
  81. ## test 8 check mutated copy
  82. print "copy... got: $txtc, exp: $ip265\nnot "
  83. unless $txtc eq $ip265;
  84. &ok;
  85.