From 622f76becf4b8cbf4a56daa913070487481b87cf Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Wed, 8 Jan 2014 22:51:33 +0100 Subject: Added tests for multiple inheritance. --- tests/exec/Makefile | 3 ++ tests/exec/multisuper1.cpp | 57 ++++++++++++++++++++++++++++++++++ tests/exec/multisuper1.out | 4 +++ tests/exec/multisuper2.cpp | 68 +++++++++++++++++++++++++++++++++++++++++ tests/exec/multisuper2.out | 6 ++++ tests/exec/multisuper3.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++ tests/exec/multisuper3.out | 12 ++++++++ 7 files changed, 226 insertions(+) create mode 100644 tests/exec/multisuper1.cpp create mode 100644 tests/exec/multisuper1.out create mode 100644 tests/exec/multisuper2.cpp create mode 100644 tests/exec/multisuper2.out create mode 100644 tests/exec/multisuper3.cpp create mode 100644 tests/exec/multisuper3.out (limited to 'tests') diff --git a/tests/exec/Makefile b/tests/exec/Makefile index b260ba0..afe0fdc 100644 --- a/tests/exec/Makefile +++ b/tests/exec/Makefile @@ -1,3 +1,6 @@ +%.out: %.cpp + g++ -o /tmp/tmp_exec_test $^ && /tmp/tmp_exec_test > $@ && rm /tmp/tmp_exec_test + %: %.cpp g++ -o $@ $^ diff --git a/tests/exec/multisuper1.cpp b/tests/exec/multisuper1.cpp new file mode 100644 index 0000000..48014f7 --- /dev/null +++ b/tests/exec/multisuper1.cpp @@ -0,0 +1,57 @@ +#include + +class A { + public: + int y; + A(); + int f(int x); +}; + +class B { + public: + int z; + B(); + int g(int x); +}; + +class C : public A, public B { + public: + int q; + C(); + int f(int x); +}; + +A::A() { + y = 12; +} + +B::B() { + z = 7; +} + +C::C() { + q = 11; +} + +int A::f(int x) { + return x * y; +} + +int B::g(int x) { + return x * z; +} + +int C::f(int x) { + return x * q; +} + +int main() { + C test; + std::cout << "C.f(1) = " << test.f(1) << "\n"; + std::cout << "C.g(1) = " << test.g(1) << "\n"; + A *q = &test; + std::cout << "A.f(1) = " << q->f(1) << "\n"; + B *r = &test; + std::cout << "B.g(1) = " << r->g(1) << "\n"; +} + diff --git a/tests/exec/multisuper1.out b/tests/exec/multisuper1.out new file mode 100644 index 0000000..0298410 --- /dev/null +++ b/tests/exec/multisuper1.out @@ -0,0 +1,4 @@ +C.f(1) = 11 +C.g(1) = 7 +A.f(1) = 12 +B.g(1) = 7 diff --git a/tests/exec/multisuper2.cpp b/tests/exec/multisuper2.cpp new file mode 100644 index 0000000..42d51ac --- /dev/null +++ b/tests/exec/multisuper2.cpp @@ -0,0 +1,68 @@ +#include + +class A { + public: + int y; + A(); + virtual int f(int x); +}; + +class B { + public: + int z; + B(); + int g(int x); +}; + +class C : public A, public B { + public: + int q; + C(); + virtual int f(int x); + int g(int x); +}; + +A::A() { + y = 12; +} + +B::B() { + z = 7; +} + +C::C() { + q = 11; +} + +int A::f(int x) { + return x * y; +} + +int B::g(int x) { + return x * z; +} + +int C::f(int x) { + return x * q; +} + +int C::g(int x) { + return x * q * 404; +} + +int main() { + A test2; + std::cout << "A.f(1) = " << test2.f(1) << "\n"; + + B test3; + std::cout << "B.g(1) = " << test3.g(1) << "\n"; + + C test; + std::cout << "C.f(1) = " << test.f(1) << "\n"; + std::cout << "C.g(1) = " << test.g(1) << "\n"; + A *q = &test; + std::cout << "(C as A).f(1) = " << q->f(1) << "\n"; + B *r = &test; + std::cout << "(C as B).g(1) = " << r->g(1) << "\n"; +} + diff --git a/tests/exec/multisuper2.out b/tests/exec/multisuper2.out new file mode 100644 index 0000000..c850040 --- /dev/null +++ b/tests/exec/multisuper2.out @@ -0,0 +1,6 @@ +A.f(1) = 12 +B.g(1) = 7 +C.f(1) = 11 +C.g(1) = 4444 +(C as A).f(1) = 11 +(C as B).g(1) = 7 diff --git a/tests/exec/multisuper3.cpp b/tests/exec/multisuper3.cpp new file mode 100644 index 0000000..55f4c45 --- /dev/null +++ b/tests/exec/multisuper3.cpp @@ -0,0 +1,76 @@ +#include + +class A { + public: + int y; + A(); + virtual int f(int x); +}; + +class B { + public: + int z; + B(); + int g(int x); +}; + +class C : public A, public B { + public: + int q; + C(); + virtual int f(int x); + int g(int x); +}; + +A::A() { + y = 12; +} + +B::B() { + z = 7; +} + +C::C() { + q = 11; +} + +int A::f(int xopia) { + y++; + return xopia * y; +} + +int B::g(int xulliver) { + z++; + return xulliver * z; +} + +int C::f(int xerod) { + return xerod * q; +} + +int C::g(int xavon) { + return xavon * q * 404; +} + +int main() { + A test2; + std::cout << "A.f(1) = " << test2.f(1) << "\n"; + + B test3; + std::cout << "B.g(1) = " << test3.g(1) << "\n"; + + C test; + std::cout << "C.f(1) = " << test.f(1) << "\n"; + std::cout << "C.g(1) = " << test.g(1) << "\n"; + A *q = &test; + std::cout << "(C as A).f(1) = " << q->f(1) << "\n"; + std::cout << "C.f(1) = " << test.f(1) << "\n"; + std::cout << "(C as A).f(1) = " << q->f(1) << "\n"; + std::cout << "C.f(1) = " << test.f(1) << "\n"; + B *r = &test; + std::cout << "(C as B).g(1) = " << r->g(1) << "\n"; + std::cout << "C.g(1) = " << test.g(1) << "\n"; + std::cout << "(C as B).g(1) = " << r->g(1) << "\n"; + std::cout << "C.g(1) = " << test.g(1) << "\n"; +} + diff --git a/tests/exec/multisuper3.out b/tests/exec/multisuper3.out new file mode 100644 index 0000000..cead147 --- /dev/null +++ b/tests/exec/multisuper3.out @@ -0,0 +1,12 @@ +A.f(1) = 13 +B.g(1) = 8 +C.f(1) = 11 +C.g(1) = 4444 +(C as A).f(1) = 11 +C.f(1) = 11 +(C as A).f(1) = 11 +C.f(1) = 11 +(C as B).g(1) = 8 +C.g(1) = 4444 +(C as B).g(1) = 9 +C.g(1) = 4444 -- cgit v1.2.3 From 56fdab2ff0caaaa88a152ef06aef821f432fe488 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Wed, 8 Jan 2014 22:54:39 +0100 Subject: Added args1 and args2 test. --- tests/exec/args1.cpp | 13 +++++++++++++ tests/exec/args1.out | 2 ++ tests/exec/args2.cpp | 15 +++++++++++++++ tests/exec/args2.out | 2 ++ 4 files changed, 32 insertions(+) create mode 100644 tests/exec/args1.cpp create mode 100644 tests/exec/args1.out create mode 100644 tests/exec/args2.cpp create mode 100644 tests/exec/args2.out (limited to 'tests') diff --git a/tests/exec/args1.cpp b/tests/exec/args1.cpp new file mode 100644 index 0000000..52edd82 --- /dev/null +++ b/tests/exec/args1.cpp @@ -0,0 +1,13 @@ +#include + +int f(int a, int b, int c, int d, int e, int f) { + std::cout << "a = " << a << ", b = " << b << + ", c = " << c << ", d = " << d << ", e = " << + e << ", f = " << f << "\n"; + return a + b + c + d + e + f; +} + +int main() { + int x = f(1, 2, 3, 4, 5, 6); + std::cout << "x = " << x << "\n"; +} diff --git a/tests/exec/args1.out b/tests/exec/args1.out new file mode 100644 index 0000000..34f8b2d --- /dev/null +++ b/tests/exec/args1.out @@ -0,0 +1,2 @@ +a = 1, b = 2, c = 3, d = 4, e = 5, f = 6 +x = 21 diff --git a/tests/exec/args2.cpp b/tests/exec/args2.cpp new file mode 100644 index 0000000..1d2efee --- /dev/null +++ b/tests/exec/args2.cpp @@ -0,0 +1,15 @@ +#include + +int test(int a) { + int *b = &a; + *b = *b + 42; + return a; +} + +int main() { + int x = 0; + int y = test(x); + std::cout << "x = " << x << "\n"; + std::cout << "y = " << y << "\n"; +} + diff --git a/tests/exec/args2.out b/tests/exec/args2.out new file mode 100644 index 0000000..7921196 --- /dev/null +++ b/tests/exec/args2.out @@ -0,0 +1,2 @@ +x = 0 +y = 42 -- cgit v1.2.3