From 1da1260af72b20126176e2b8f73f7b7fd5952ce1 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Tue, 12 Dec 2023 21:27:08 +0100 Subject: Split tests into unit and dw (graphical) Graphical tests for the dw (Dillo Widget) are moved to test/dw, while unit tests are placed into test/unit. All tests are compiled with "make check" but only the tests that can run without intervention and without a graphic display are executed. --- test/unit/identity.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/unit/identity.cc (limited to 'test/unit/identity.cc') diff --git a/test/unit/identity.cc b/test/unit/identity.cc new file mode 100644 index 00000000..a1a136eb --- /dev/null +++ b/test/unit/identity.cc @@ -0,0 +1,55 @@ +/* + * This small program tests how IdentifiableObject works with multiple + * inheritance ("diamond" inheritance, more precisely, since all + * classes have there root in IdentifiableObject.) + * + * Current status: With virtual superclasses, you get a class + * hierarchie "root -> A -> B -> C", so that the first part of this + * example works actually (C is a subclass of A and of B), but the + * second fails (it should print "false", but it is erroneously + * assumed that B is a subclass of A.) + */ + +#include "../lout/identity.hh" + +using namespace lout::identity; + +class A: virtual public IdentifiableObject +{ +public: + static int CLASS_ID; + inline A () { registerName ("A", &CLASS_ID); } +}; + +class B: virtual public IdentifiableObject +{ +public: + static int CLASS_ID; + inline B () { registerName ("B", &CLASS_ID); } +}; + +class C: public A, public B +{ +public: + static int CLASS_ID; + inline C () { registerName ("C", &CLASS_ID); } +}; + +int A::CLASS_ID = -1, B::CLASS_ID = -1, C::CLASS_ID = -1; + +int main (int argc, char *argv[]) +{ + printf ("A: %d, B: %d, C: %d\n", A::CLASS_ID, B::CLASS_ID, C::CLASS_ID); + + C x; + assert (x.instanceOf (A::CLASS_ID)); + assert (x.instanceOf (B::CLASS_ID)); + assert (x.instanceOf (C::CLASS_ID)); + printf ("x: %d\n", x.getClassId ()); + + B y; + printf ("y: %d; instance of A: %s\n", + y.getClassId (), y.instanceOf (B::CLASS_ID) ? "true" : "false"); + + return 0; +} -- cgit v1.2.3