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