aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am4
-rw-r--r--test/dw_simple_container.cc280
-rw-r--r--test/dw_simple_container.hh4
-rw-r--r--test/identity.cc55
4 files changed, 203 insertions, 140 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/dw_simple_container.cc b/test/dw_simple_container.cc
index e19511a6..94dec2d5 100644
--- a/test/dw_simple_container.cc
+++ b/test/dw_simple_container.cc
@@ -27,190 +27,192 @@ using namespace lout::misc;
namespace dw {
-int SimpleContainer::CLASS_ID = -1;
+ int SimpleContainer::CLASS_ID = -1;
-// ----------------------------------------------------------------------
+ // ----------------------------------------------------------------------
-SimpleContainer::SimpleContainerIterator::SimpleContainerIterator
+ SimpleContainer::SimpleContainerIterator::SimpleContainerIterator
(SimpleContainer *simpleContainer, Content::Type mask, bool atEnd) :
- Iterator (simpleContainer, mask, atEnd)
-{
- content.type = atEnd ? Content::END : Content::START;
-}
+ Iterator (simpleContainer, mask, atEnd)
+ {
+ content.type = atEnd ? Content::END : Content::START;
+ }
-lout::object::Object *SimpleContainer::SimpleContainerIterator::clone ()
-{
- SimpleContainerIterator *sci =
- new SimpleContainerIterator ((SimpleContainer*)getWidget(),
- getMask(), false);
- sci->content = content;
- return sci;
-}
+ lout::object::Object *SimpleContainer::SimpleContainerIterator::clone ()
+ {
+ SimpleContainerIterator *sci =
+ new SimpleContainerIterator ((SimpleContainer*)getWidget(),
+ getMask(), false);
+ sci->content = content;
+ return sci;
+ }
-int SimpleContainer::SimpleContainerIterator::index ()
-{
- switch (content.type) {
- case Content::START:
- return 0;
- case Content::WIDGET_IN_FLOW:
- return 1;
- case Content::END:
- return 2;
- default:
- assertNotReached ();
- return 0;
+ int SimpleContainer::SimpleContainerIterator::index ()
+ {
+ switch (content.type) {
+ case Content::START:
+ return 0;
+ case Content::WIDGET_IN_FLOW:
+ return 1;
+ case Content::END:
+ return 2;
+ default:
+ assertNotReached ();
+ return 0;
+ }
}
-}
-int SimpleContainer::SimpleContainerIterator::compareTo
+ int SimpleContainer::SimpleContainerIterator::compareTo
(lout::object::Comparable *other)
-{
- return index () - ((SimpleContainerIterator*)other)->index ();
-}
+ {
+ return index () - ((SimpleContainerIterator*)other)->index ();
+ }
-bool SimpleContainer::SimpleContainerIterator::next ()
-{
- SimpleContainer *simpleContainer = (SimpleContainer*)getWidget();
+ bool SimpleContainer::SimpleContainerIterator::next ()
+ {
+ SimpleContainer *simpleContainer = (SimpleContainer*)getWidget();
- if (content.type == Content::END)
- return false;
+ if (content.type == Content::END)
+ return false;
- // simple containers only contain widgets:
- if ((getMask() & Content::WIDGET_IN_FLOW) == 0) {
- content.type = Content::END;
- return false;
- }
+ // simple containers only contain widgets:
+ if ((getMask() & Content::WIDGET_IN_FLOW) == 0) {
+ content.type = Content::END;
+ return false;
+ }
- if (content.type == Content::START) {
- if (simpleContainer->child != NULL) {
- content.type = Content::WIDGET_IN_FLOW;
- content.widget = simpleContainer->child;
- return true;
- } else {
+ if (content.type == Content::START) {
+ if (simpleContainer->child != NULL) {
+ content.type = Content::WIDGET_IN_FLOW;
+ content.widget = simpleContainer->child;
+ return true;
+ } else {
+ content.type = Content::END;
+ return false;
+ }
+ } else /* if (content.type == Content::WIDGET) */ {
content.type = Content::END;
return false;
}
- } else /* if (content.type == Content::WIDGET) */ {
- content.type = Content::END;
- return false;
}
-}
-bool SimpleContainer::SimpleContainerIterator::prev ()
-{
- SimpleContainer *simpleContainer = (SimpleContainer*)getWidget();
+ bool SimpleContainer::SimpleContainerIterator::prev ()
+ {
+ SimpleContainer *simpleContainer = (SimpleContainer*)getWidget();
- if (content.type == Content::START)
- return false;
+ if (content.type == Content::START)
+ return false;
- // simple containers only contain widgets:
- if ((getMask() & Content::WIDGET_IN_FLOW) == 0) {
- content.type = Content::START;
- return false;
- }
+ // simple containers only contain widgets:
+ if ((getMask() & Content::WIDGET_IN_FLOW) == 0) {
+ content.type = Content::START;
+ return false;
+ }
- if (content.type == Content::END) {
- if (simpleContainer->child != NULL) {
- content.type = Content::WIDGET_IN_FLOW;
- content.widget = simpleContainer->child;
- return true;
- } else {
+ if (content.type == Content::END) {
+ if (simpleContainer->child != NULL) {
+ content.type = Content::WIDGET_IN_FLOW;
+ content.widget = simpleContainer->child;
+ return true;
+ } else {
+ content.type = Content::START;
+ return false;
+ }
+ } else /* if (content.type == Content::WIDGET) */ {
content.type = Content::START;
return false;
}
- } else /* if (content.type == Content::WIDGET) */ {
- content.type = Content::START;
- return false;
}
-}
-void SimpleContainer::SimpleContainerIterator::highlight (int start,
- int end,
- HighlightLayer layer)
-{
- /** todo Needs this an implementation? */
-}
+ void SimpleContainer::SimpleContainerIterator::highlight (int start,
+ int end,
+ HighlightLayer layer)
+ {
+ /** todo Needs this an implementation? */
+ }
-void SimpleContainer::SimpleContainerIterator::unhighlight (int direction,
- HighlightLayer
- layer)
-{
- /** todo Needs this an implementation? */
-}
+ void SimpleContainer::SimpleContainerIterator::unhighlight (int direction,
+ HighlightLayer
+ layer)
+ {
+ /** todo Needs this an implementation? */
+ }
-void SimpleContainer::SimpleContainerIterator::getAllocation (int start,
- int end,
- Allocation
- *allocation)
-{
- /** \bug Not implemented. */
-}
+ void SimpleContainer::SimpleContainerIterator::getAllocation (int start,
+ int end,
+ Allocation
+ *allocation)
+ {
+ /** \bug Not implemented. */
+ }
-// ----------------------------------------------------------------------
+ // ----------------------------------------------------------------------
-SimpleContainer::SimpleContainer ()
-{
- registerName ("dw::SimpleContainer", &CLASS_ID);
- child = NULL;
-}
+ SimpleContainer::SimpleContainer ()
+ {
+ registerName ("dw::SimpleContainer", &CLASS_ID);
+ child = NULL;
+ }
-SimpleContainer::~SimpleContainer ()
-{
- if (child)
- delete child;
-}
+ SimpleContainer::~SimpleContainer ()
+ {
+ if (child)
+ delete child;
+ }
-void SimpleContainer::sizeRequestImpl (Requisition *requisition)
-{
- Requisition childReq;
- if (child)
- child->sizeRequest (&childReq);
- else
- childReq.width = childReq.ascent = childReq.descent = 0;
+ void SimpleContainer::sizeRequestImpl (Requisition *requisition)
+ {
+ Requisition childReq;
+ if (child)
+ child->sizeRequest (&childReq);
+ else
+ childReq.width = childReq.ascent = childReq.descent = 0;
- requisition->width = childReq.width + boxDiffWidth ();
- requisition->ascent = childReq.ascent + boxOffsetY ();
- requisition->descent = childReq.descent + boxRestHeight ();
+ requisition->width = childReq.width + boxDiffWidth ();
+ requisition->ascent = childReq.ascent + boxOffsetY ();
+ requisition->descent = childReq.descent + boxRestHeight ();
- correctRequisition (requisition, splitHeightPreserveAscent);
-}
+ correctRequisition (requisition, splitHeightPreserveAscent);
+ }
-void SimpleContainer::getExtremesImpl (Extremes *extremes)
-{
- Extremes childExtr;
- if (child)
- child->getExtremes (&childExtr);
- else
- childExtr.minWidth = childExtr.maxWidth = 0;
+ void SimpleContainer::getExtremesImpl (Extremes *extremes)
+ {
+ Extremes childExtr;
+ if (child)
+ child->getExtremes (&childExtr);
+ else
+ childExtr.minWidth = childExtr.maxWidth = 0;
- extremes->minWidth = childExtr.minWidth + boxDiffWidth ();
- extremes->maxWidth = childExtr.maxWidth + boxDiffWidth ();
+ extremes->minWidth = childExtr.minWidth + boxDiffWidth ();
+ extremes->maxWidth = childExtr.maxWidth + boxDiffWidth ();
- correctExtremes (extremes);
-}
+ correctExtremes (extremes);
+ }
-void SimpleContainer::sizeAllocateImpl (Allocation *allocation)
-{
- Allocation childAlloc;
-
- if (child) {
- childAlloc.x = allocation->x + boxOffsetX ();
- childAlloc.y = allocation->y + boxOffsetY ();
- childAlloc.width = allocation->width - boxDiffWidth ();
- childAlloc.ascent = allocation->ascent - boxOffsetY ();
- childAlloc.descent = allocation->descent - boxRestHeight ();
- child->sizeAllocate (&childAlloc);
+ void SimpleContainer::sizeAllocateImpl (Allocation *allocation)
+ {
+ Allocation childAlloc;
+
+ if (child) {
+ childAlloc.x = allocation->x + boxOffsetX ();
+ childAlloc.y = allocation->y + boxOffsetY ();
+ childAlloc.width = allocation->width - boxDiffWidth ();
+ childAlloc.ascent = allocation->ascent - boxOffsetY ();
+ childAlloc.descent = allocation->descent - boxRestHeight ();
+ child->sizeAllocate (&childAlloc);
+ }
}
-}
-void SimpleContainer::draw (View *view, Rectangle *area)
+void SimpleContainer::draw (View *view, Rectangle *area,
+ StackingIteratorStack *iteratorStack,
+ Widget **interruptedWidget)
{
drawWidgetBox (view, area, false);
Rectangle childArea;
if (child && child->intersects (area, &childArea))
- child->draw (view, &childArea);
+ child->drawTotal (view, &childArea, iteratorStack, interruptedWidget);
}
Iterator *SimpleContainer::iterator (Content::Type mask, bool atEnd)
diff --git a/test/dw_simple_container.hh b/test/dw_simple_container.hh
index fdb67bec..423b1fab 100644
--- a/test/dw_simple_container.hh
+++ b/test/dw_simple_container.hh
@@ -44,7 +44,9 @@ public:
SimpleContainer ();
~SimpleContainer ();
- void draw (core::View *view, core::Rectangle *area);
+ void draw (core::View *view, core::Rectangle *area,
+ core::StackingIteratorStack *iteratorStack,
+ Widget **interruptedWidget);
core::Iterator *iterator (core::Content::Type mask, bool atEnd);
void removeChild (Widget *child);
diff --git a/test/identity.cc b/test/identity.cc
new file mode 100644
index 00000000..a1a136eb
--- /dev/null
+++ b/test/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;
+}