[dia] [unit test] fix mismatch between PropDescription and PropOffset



commit dce6d44254e1a95f06204ba02e08a78b95bd9348
Author: Hans Breuer <hans breuer org>
Date:   Sun Nov 30 23:07:35 2014 +0100

    [unit test] fix mismatch between PropDescription and PropOffset
    
    Some objects described themselves to be Element, but were indeed OrthConn.
    Few of these issues were originally found by visual inspection of
    "Object Types.dia" (from otypes.py). But with the new test more mismatches
    were found and fixed.

 lib/standard-path.c       |    1 +
 objects/FS/flow-ortho.c   |    4 ++--
 objects/FS/flow.c         |    4 ++--
 objects/FS/function.c     |    2 +-
 objects/UML/implements.c  |    1 +
 objects/network/bus.c     |    4 ++--
 objects/network/wanlink.c |    4 ++--
 tests/test-objects.c      |   29 +++++++++++++++++++++++++----
 8 files changed, 36 insertions(+), 13 deletions(-)
---
diff --git a/lib/standard-path.c b/lib/standard-path.c
index 0da1645..23224fc 100644
--- a/lib/standard-path.c
+++ b/lib/standard-path.c
@@ -145,6 +145,7 @@ static PropOffset stdpath_offsets[] = {
   { PROP_STDNAME_LINE_WIDTH, PROP_STDTYPE_LINE_WIDTH, offsetof(StdPath, line_width) },
   { "line_colour", PROP_TYPE_COLOUR, offsetof(StdPath, line_color) },
   { "line_style", PROP_TYPE_LINESTYLE, offsetof(StdPath, line_style), offsetof(StdPath, dashlength) },
+  { "line_join", PROP_TYPE_ENUM, offsetof(StdPath, line_join) },
   { "line_caps", PROP_TYPE_ENUM, offsetof(StdPath, line_caps) },
   { "fill_colour", PROP_TYPE_COLOUR, offsetof(StdPath, fill_color) },
   { "show_background", PROP_TYPE_BOOL, offsetof(StdPath, show_background) },
diff --git a/objects/FS/flow-ortho.c b/objects/FS/flow-ortho.c
index 7905a38..06bd337 100644
--- a/objects/FS/flow-ortho.c
+++ b/objects/FS/flow-ortho.c
@@ -162,7 +162,7 @@ static PropEnumData prop_orthflow_type_data[] = {
 };
 
 static PropDescription orthflow_props[] = {
-  ELEMENT_COMMON_PROPERTIES,
+  ORTHCONN_COMMON_PROPERTIES,
   { "type", PROP_TYPE_ENUM, PROP_FLAG_VISIBLE,
     N_("Type:"), NULL, prop_orthflow_type_data },
   { "text", PROP_TYPE_TEXT, 0, NULL, NULL },
@@ -184,7 +184,7 @@ orthflow_describe_props(Orthflow *mes)
 }
 
 static PropOffset orthflow_offsets[] = {
-  OBJECT_COMMON_PROPERTIES_OFFSETS,
+  ORTHCONN_COMMON_PROPERTIES_OFFSETS,
   { "type", PROP_TYPE_ENUM, offsetof(Orthflow, type) },
   { "text", PROP_TYPE_TEXT, offsetof (Orthflow, text) },
   { "text_alignment", PROP_TYPE_ENUM, offsetof(Orthflow,text),offsetof(Text,alignment) },
diff --git a/objects/FS/flow.c b/objects/FS/flow.c
index b60914c..07086e8 100644
--- a/objects/FS/flow.c
+++ b/objects/FS/flow.c
@@ -139,7 +139,7 @@ static PropEnumData prop_flow_type_data[] = {
 };
 
 static PropDescription flow_props[] = {
-  OBJECT_COMMON_PROPERTIES,
+  CONNECTION_COMMON_PROPERTIES,
   { "type", PROP_TYPE_ENUM, PROP_FLAG_VISIBLE,
     N_("Type:"), NULL, prop_flow_type_data },
   { "text", PROP_TYPE_TEXT, 0, NULL, NULL },
@@ -161,7 +161,7 @@ flow_describe_props(Flow *mes)
 }
 
 static PropOffset flow_offsets[] = {
-  OBJECT_COMMON_PROPERTIES_OFFSETS,
+  CONNECTION_COMMON_PROPERTIES_OFFSETS,
   { "type", PROP_TYPE_ENUM, offsetof(Flow, type) },
   { "text", PROP_TYPE_TEXT, offsetof (Flow, text) },
   { "text_alignment", PROP_TYPE_ENUM, offsetof(Flow,text),offsetof(Text,alignment) },
diff --git a/objects/FS/function.c b/objects/FS/function.c
index b34fe18..3376455 100644
--- a/objects/FS/function.c
+++ b/objects/FS/function.c
@@ -158,7 +158,7 @@ function_describe_props(Function *mes)
 }
 
 static PropOffset function_offsets[] = {
-  OBJECT_COMMON_PROPERTIES_OFFSETS,
+  ELEMENT_COMMON_PROPERTIES_OFFSETS,
   { "wish function", PROP_TYPE_BOOL, offsetof(Function, is_wish) },
   { "user function", PROP_TYPE_BOOL, offsetof(Function, is_user) },
   { "text", PROP_TYPE_TEXT, offsetof (Function, text) },
diff --git a/objects/UML/implements.c b/objects/UML/implements.c
index a830644..4475f0e 100644
--- a/objects/UML/implements.c
+++ b/objects/UML/implements.c
@@ -149,6 +149,7 @@ implements_describe_props(Implements *implements)
 static PropOffset implements_offsets[] = {
   CONNECTION_COMMON_PROPERTIES_OFFSETS,
   { "text", PROP_TYPE_STRING, offsetof(Implements, text) },
+  { "name", PROP_TYPE_STRING, offsetof(Implements, text) },
   { "text_font", PROP_TYPE_FONT, offsetof(Implements, font) },
   { PROP_STDNAME_TEXT_HEIGHT, PROP_STDTYPE_TEXT_HEIGHT, offsetof(Implements, font_height) },
   { "text_colour",PROP_TYPE_COLOUR,offsetof(Implements, text_color) },
diff --git a/objects/network/bus.c b/objects/network/bus.c
index 86d2a0c..1734a31 100644
--- a/objects/network/bus.c
+++ b/objects/network/bus.c
@@ -132,7 +132,7 @@ static ObjectOps bus_ops = {
 };
 
 static PropDescription bus_props[] = {
-  OBJECT_COMMON_PROPERTIES,
+  CONNECTION_COMMON_PROPERTIES,
   PROP_STD_LINE_COLOUR,
   PROP_DESC_END
 };
@@ -146,7 +146,7 @@ bus_describe_props(Bus *bus)
 }
 
 static PropOffset bus_offsets[] = {
-  OBJECT_COMMON_PROPERTIES_OFFSETS,
+  CONNECTION_COMMON_PROPERTIES_OFFSETS,
   { "line_colour", PROP_TYPE_COLOUR, offsetof(Bus, line_color) },
   { NULL, 0, 0 }
 };
diff --git a/objects/network/wanlink.c b/objects/network/wanlink.c
index 61b4c1f..b503b6c 100644
--- a/objects/network/wanlink.c
+++ b/objects/network/wanlink.c
@@ -114,7 +114,7 @@ DiaObjectType wanlink_type =
 };
 
 static PropDescription wanlink_props[] = {
-  OBJECT_COMMON_PROPERTIES,
+  CONNECTION_COMMON_PROPERTIES,
   { "width", PROP_TYPE_REAL, PROP_FLAG_VISIBLE,
     N_("Width"), NULL, NULL },
   PROP_STD_LINE_COLOUR,
@@ -131,7 +131,7 @@ wanlink_describe_props(WanLink *wanlink)
 }
 
 static PropOffset wanlink_offsets[] = {
-  OBJECT_COMMON_PROPERTIES_OFFSETS,
+  CONNECTION_COMMON_PROPERTIES_OFFSETS,
   { "width", PROP_TYPE_REAL, offsetof(WanLink, width) },
   { "line_colour", PROP_TYPE_COLOUR, offsetof(WanLink, line_color) },
   { "fill_colour", PROP_TYPE_COLOUR, offsetof(WanLink, fill_color) },
diff --git a/tests/test-objects.c b/tests/test-objects.c
index 0a85e0f..30858b7 100644
--- a/tests/test-objects.c
+++ b/tests/test-objects.c
@@ -69,10 +69,31 @@ _test_creation (gconstpointer user_data)
   {
     const PropDescription *pdesc = o->ops->describe_props (o);
     /* get all properties */
-    GPtrArray *plist = prop_list_from_descs (pdesc, pdtpp_true);
-    
-    g_assert (plist != NULL);
-    prop_list_free(plist);
+    GPtrArray *props = prop_list_from_descs (pdesc, pdtpp_true);
+    int num_described = props->len;
+    int num_used = 0;
+
+    /* Indirect check of object's private PropDescription and PropOffset array.
+     * Both arrays should be same length (reference the same properties).
+     * But the latter is only visible as parameter to object_get_props_from_offsets(),
+     * at least for objects not intialzing DiaObjectType::prop_offsets
+     */
+    o->ops->get_props (o, props);
+    for (i = 0; i < num_described; ++i) {
+      Property *prop = (Property*)g_ptr_array_index(props,i);
+      if ((prop->experience & PXP_NOTSET) == 0)
+        ++num_used;
+      else if ((prop->descr->flags & PROP_FLAG_WIDGET_ONLY) != 0)
+       ++num_used; /* ... but not expected to be set */
+      else if (strcmp (prop->descr->type, PROP_TYPE_STATIC) == 0)
+       ++num_used; /* also not to be set */
+      else
+       g_print ("Not set '%s'\n", prop->descr->name);
+    }
+    g_assert_cmpint (num_used, ==, num_described);
+
+    g_assert (props != NULL);
+    prop_list_free(props);
   }
   /* not implemented anywhere */
   g_assert (o->ops->edit_text == NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]