PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1.3.35/Examples/test-suite/perl5/default_args_runme.pl

#
Perl | 161 lines | 132 code | 25 blank | 4 comment | 59 complexity | e47c0e00930168bd3ae8aa55a3f04339 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. use default_args;
  2. $true = 1;
  3. $false = 0;
  4. if (default_args::anonymous() != 7771) {
  5. die "anonymous (1) failed";
  6. }
  7. if (default_args::anonymous(1234) != 1234) {
  8. die "anonymous (2) failed";
  9. }
  10. if (default_args::booltest() != $true) {
  11. die "booltest (1) failed";
  12. }
  13. if (default_args::booltest($true) != $true) {
  14. die "booltest (2) failed";
  15. }
  16. if (default_args::booltest($false) != $false) {
  17. die "booltest (3) failed";
  18. }
  19. $ec = new default_args::EnumClass();
  20. if ($ec->blah() != $true) {
  21. die "EnumClass failed";
  22. }
  23. if (default_args::casts1() != null) {
  24. die "casts1 failed";
  25. }
  26. if (default_args::casts2() ne "Hello") {
  27. die "casts2 failed";
  28. }
  29. if (default_args::casts1("Ciao") ne "Ciao") {
  30. die "casts1 not default failed";
  31. }
  32. if (default_args::chartest1() ne 'x') {
  33. die "chartest1 failed";
  34. }
  35. if (default_args::chartest2() != '\0') {
  36. die "chartest2 failed";
  37. }
  38. if (default_args::chartest1('y') ne 'y') {
  39. die "chartest1 not default failed";
  40. }
  41. if (default_args::chartest1('y') ne 'y') {
  42. die "chartest1 not default failed";
  43. }
  44. if (default_args::reftest1() != 42) {
  45. die "reftest1 failed";
  46. }
  47. if (default_args::reftest1(400) != 400) {
  48. die "reftest1 not default failed";
  49. }
  50. if (default_args::reftest2() ne "hello") {
  51. die "reftest2 failed";
  52. }
  53. # rename
  54. $foo = new default_args::Foo();
  55. $foo->newname();
  56. $foo->newname(10);
  57. $foo->renamed3arg(10, 10.0);
  58. $foo->renamed2arg(10);
  59. $foo->renamed1arg();
  60. # exception specifications
  61. eval { default_args::exceptionspec() };
  62. if (!$@) {
  63. die "exceptionspec 1 failed";
  64. }
  65. eval { default_args::exceptionspec(-1) };
  66. if (!$@) {
  67. die "exceptionspec 2 failed";
  68. }
  69. eval { default_args::exceptionspec(100) };
  70. if (!$@) {
  71. die "exceptionspec 3 failed";
  72. }
  73. $ex = new default_args::Except($false);
  74. eval { $ex.exspec() };
  75. if (!$@) {
  76. die "exspec 1 failed";
  77. }
  78. eval { $ex.exspec(-1) };
  79. if (!$@) {
  80. die "exspec 2 failed";
  81. }
  82. eval { $ex.exspec(100) };
  83. if (!$@) {
  84. die "exspec 3 failed";
  85. }
  86. eval { $ex = new default_args::Except($true) };
  87. if (!$@) {
  88. die "Except constructor 1 failed";
  89. }
  90. eval { $ex = new default_args::Except($true, -2) };
  91. if (!$@) {
  92. die "Except constructor 2 failed";
  93. }
  94. #Default parameters in static class methods
  95. if (default_args::Statics::staticmethod() != 10+20+30) {
  96. die "staticmethod 1 failed";
  97. }
  98. if (default_args::Statics::staticmethod(100) != 100+20+30) {
  99. die "staticmethod 2 failed";
  100. }
  101. if (default_args::Statics::staticmethod(100,200,300) != 100+200+300) {
  102. die "staticmethod 3 failed";
  103. }
  104. $tricky = new default_args::Tricky();
  105. if ($tricky->privatedefault() != 200) {
  106. die "privatedefault failed";
  107. }
  108. if ($tricky->protectedint() != 2000) {
  109. die "protectedint failed";
  110. }
  111. if ($tricky->protecteddouble() != 987.654) {
  112. die "protecteddouble failed";
  113. }
  114. if ($tricky->functiondefault() != 500) {
  115. die "functiondefault failed";
  116. }
  117. if ($tricky->contrived() ne 'X') {
  118. die "contrived failed";
  119. }
  120. if (default_args::constructorcall()->{val} != -1) {
  121. die "constructorcall test 1 failed";
  122. }
  123. if (default_args::constructorcall(new default_args::Klass(2222))->{val} != 2222) {
  124. die "constructorcall test 2 failed";
  125. }
  126. if (default_args::constructorcall(new default_args::Klass())->{val} != -1) {
  127. die "constructorcall test 3 failed";
  128. }
  129. # const methods
  130. $cm = new default_args::ConstMethods();
  131. if ($cm->coo() != 20) {
  132. die "coo test 1 failed";
  133. }
  134. if ($cm->coo(1.0) != 20) {
  135. die "coo test 2 failed";
  136. }