diff options
author | Sebastian Geerken <devnull@localhost> | 2014-09-18 23:11:55 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-09-18 23:11:55 +0200 |
commit | 11a3b3104e4818e6332b0ce0e9dbbfdf7fa93e71 (patch) | |
tree | ecf089ace8b2964d3283d39954dcd9e71767693c /test | |
parent | 0552cad5ee37dacf33559fe4db4d4cde7f4fca76 (diff) |
Test.
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/identity.cc | 45 |
2 files changed, 49 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 3b474466..fd3252dc 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -25,6 +25,7 @@ noinst_PROGRAMS = \ dw-resource-test \ dw-ui-test \ containers \ + identity \ shapes \ cookies \ liang \ @@ -191,6 +192,9 @@ shapes_LDADD = \ containers_SOURCES = containers.cc containers_LDADD = $(top_builddir)/lout/liblout.a +identity_SOURCES = identity.cc +identity_LDADD = $(top_builddir)/lout/liblout.a + cookies_SOURCES = cookies.c cookies_LDADD = \ $(top_builddir)/dpip/libDpip.a \ diff --git a/test/identity.cc b/test/identity.cc new file mode 100644 index 00000000..ea1f4603 --- /dev/null +++ b/test/identity.cc @@ -0,0 +1,45 @@ +/* + * This small program tests how IdentifiableObject works with multiple + * inheritance ("diamond" inheritance, more precisely, since all + * classes have there root in IdentifiableObject.) With virtual + * superclasses, this example works actually (for comprehensible + * reasons), but I'm not sure about more compex class hierarchies. + */ + +#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[]) +{ + C x; + assert (x.instanceOf (A::CLASS_ID)); + assert (x.instanceOf (B::CLASS_ID)); + assert (x.instanceOf (C::CLASS_ID)); + printf ("A: %d, B: %d, C: %d, x: %d\n", + A::CLASS_ID, B::CLASS_ID, C::CLASS_ID, x.getClassId ()); + return 0; +} |