PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-25/SWIG/Examples/test-suite/perl5/unions_runme.pl

#
Perl | 49 lines | 31 code | 11 blank | 7 comment | 10 complexity | 718626017462267612a28e792004ff90 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # This is the union runtime testcase. It ensures that values within a
  2. # union embedded within a struct can be set and read correctly.
  3. use unions;
  4. # Create new instances of SmallStruct and BigStruct for later use
  5. $small = new unions::SmallStruct();
  6. $small->{jill} = 200;
  7. $big = new unions::BigStruct();
  8. $big->{smallstruct} = $small;
  9. $big->{jack} = 300;
  10. # Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
  11. # Ensure values in EmbeddedUnionTest are set correctly for each.
  12. $eut = new unions::EmbeddedUnionTest();
  13. # First check the SmallStruct in EmbeddedUnionTest
  14. $eut->{number} = 1;
  15. $eut->{uni}->{small} = $small;
  16. $Jill1 = $eut->{uni}->{small}->{jill};
  17. if ($Jill1 != 200) {
  18. die "Runtime test1 failed. eut.uni.small.jill=" , $Jill1, "\n";
  19. }
  20. $Num1 = $eut->{number};
  21. if ($Num1 != 1) {
  22. die "Runtime test2 failed. eut.number=" , $Num1, "\n";
  23. }
  24. # Secondly check the BigStruct in EmbeddedUnionTest
  25. $eut->{number} = 2;
  26. $eut->{uni}->{big} = $big;
  27. $Jack1 = $eut->{uni}->{big}->{jack};
  28. if ($Jack1 != 300) {
  29. die "Runtime test3 failed. eut.uni.big.jack=" , $Jack1, "\n";
  30. }
  31. $Jill2 = $eut->{uni}->{big}->{smallstruct}->{jill};
  32. if ($Jill2 != 200) {
  33. die "Runtime test4 failed. eut.uni.big.smallstruct.jill=" , $Jill2, "\n";
  34. }
  35. $Num2 = $eut->{number};
  36. if ($Num2 != 2) {
  37. die "Runtime test5 failed. eut.number=" , $Num2, "\n";
  38. }