~ubuntu-branches/ubuntu/oneiric/swig1.3/oneiric

« back to all changes in this revision

Viewing changes to Examples/test-suite/perl5/default_args_runme.pl

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-11-10 16:29:56 UTC
  • mfrom: (1.2.8 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20081110162956-xue6itkuqhbza87s
Tags: 1.3.36-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop pike and libchicken-dev from the build-depends 
    (both are universe)
  - Use python2.5 instead of python2.4.
  - use php5
  - Clean Runtime/ as well.
  - debian/Rules (clean): Remove Lib/ocaml/swigp4.ml.
  - drop "--without-mzscheme", we don't have it in our build-depends

Show diffs side-by-side

added added

removed removed

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