new test
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5322 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5f88de8fe7
commit
32a8e14507
3 changed files with 313 additions and 0 deletions
177
Examples/test-suite/contract.i
Normal file
177
Examples/test-suite/contract.i
Normal file
|
|
@ -0,0 +1,177 @@
|
|||
%module contract
|
||||
|
||||
|
||||
%contract test_preassert(int a, int b) {
|
||||
require:
|
||||
a > 0;
|
||||
b > 0;
|
||||
}
|
||||
|
||||
%contract test_postassert(int a) {
|
||||
ensure:
|
||||
test_postassert > 0;
|
||||
}
|
||||
|
||||
%contract test_prepost(int a, int b) {
|
||||
require:
|
||||
a > 0;
|
||||
ensure:
|
||||
test_prepost > 0;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
int test_preassert(int x, int y) {
|
||||
if ((x > 0) && (y > 0)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_postassert(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int test_prepost(int x, int y) {
|
||||
return x+y;
|
||||
}
|
||||
%}
|
||||
|
||||
/* Class tests */
|
||||
|
||||
%contract Foo::test_preassert(int x, int y) {
|
||||
require:
|
||||
x > 0;
|
||||
y > 0;
|
||||
}
|
||||
|
||||
%contract Foo::test_postassert(int a) {
|
||||
ensure:
|
||||
test_postassert > 0;
|
||||
}
|
||||
|
||||
%contract Foo::test_prepost(int a, int b) {
|
||||
require:
|
||||
a > 0;
|
||||
ensure:
|
||||
test_prepost > 0;
|
||||
}
|
||||
|
||||
%contract Foo::stest_prepost(int a, int b) {
|
||||
require:
|
||||
a > 0;
|
||||
ensure:
|
||||
stest_prepost > 0;
|
||||
}
|
||||
|
||||
%contract Bar::test_prepost(int c, int d) {
|
||||
require:
|
||||
d > 0;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
class Foo {
|
||||
public:
|
||||
virtual int test_preassert(int x, int y) {
|
||||
if ((x > 0) && (y > 0)) return 1;
|
||||
return 0;
|
||||
}
|
||||
virtual int test_postassert(int x) {
|
||||
return x;
|
||||
}
|
||||
virtual int test_prepost(int x, int y) {
|
||||
return x+y;
|
||||
}
|
||||
static int stest_prepost(int x, int y) {
|
||||
return x+y;
|
||||
}
|
||||
};
|
||||
|
||||
class Bar : public Foo {
|
||||
public:
|
||||
virtual int test_prepost(int x, int y) {
|
||||
return x+y;
|
||||
}
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
/* Multiple inheritance test */
|
||||
|
||||
%contract A::foo(int i, int j, int k, int l, int m) {
|
||||
require:
|
||||
i > 0;
|
||||
j > 0;
|
||||
ensure:
|
||||
foo > 0;
|
||||
}
|
||||
|
||||
%contract B::bar(int x, int y, int z, int w, int v) {
|
||||
require:
|
||||
w > 0;
|
||||
v > 0;
|
||||
ensure:
|
||||
bar > 0;
|
||||
}
|
||||
|
||||
%contract C::foo(int a, int b, int c, int d, int e) {
|
||||
require:
|
||||
c > 0;
|
||||
d > 0;
|
||||
ensure:
|
||||
foo > 0;
|
||||
}
|
||||
|
||||
%contract D::foo(int, int, int, int, int x) {
|
||||
require:
|
||||
x > 0;
|
||||
}
|
||||
|
||||
%contract D::bar(int a, int b, int c, int, int) {
|
||||
require:
|
||||
a > 0;
|
||||
b > 0;
|
||||
c > 0;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
class A {
|
||||
public:
|
||||
virtual int foo(int a, int b, int c, int d, int e) {
|
||||
if ((a > 0) && (b > 0) && (c > 0) && (d > 0) && (e > 0)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class B {
|
||||
public:
|
||||
virtual int bar(int a, int b, int c, int d, int e) {
|
||||
if ((a > 0) && (b > 0) && (c > 0) && (d > 0) && (e > 0)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class C : public A, public B {
|
||||
public:
|
||||
virtual int foo(int a, int b, int c, int d, int e) {
|
||||
return A::foo(a,b,c,d,e);
|
||||
}
|
||||
virtual int bar(int a, int b, int c, int d, int e) {
|
||||
return B::bar(a,b,c,d,e);
|
||||
}
|
||||
};
|
||||
|
||||
class D : public C {
|
||||
public:
|
||||
public:
|
||||
virtual int foo(int a, int b, int c, int d, int e) {
|
||||
return C::foo(a,b,c,d,e);
|
||||
}
|
||||
virtual int bar(int a, int b, int c, int d, int e) {
|
||||
return C::bar(a,b,c,d,e);
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue