dia r4102 - in trunk: . bindings lib objects objects/UML objects/standard tests
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4102 - in trunk: . bindings lib objects objects/UML objects/standard tests
- Date: Sat, 2 Aug 2008 09:00:18 +0000 (UTC)
Author: hans
Date: Sat Aug 2 09:00:18 2008
New Revision: 4102
URL: http://svn.gnome.org/viewvc/dia?rev=4102&view=rev
Log:
2008-08-02 Hans Breuer <hans breuer org>
* lib/libdia.def : updated exports
* lib/libdia.h : C++ guards
* bindings/dia-extra.cpp : simplification by use of libdia_init()
* bindings/dia-object.h bindings/dia-properties.h : mark binding
internal helpers as such
* lib/orth_conn.h : small docu update
* objects/makefile.msc : remove bondgraph here as well
* objects/standard/bezier.c objects/standard/polyline.c
objects/standard/zigzagline.c objects/UML/actor.c : correct
bounding box calculation
* tests/test-objects.c tests/makefile.msc : start of unit tests
Added:
trunk/tests/makefile.msc (contents, props changed)
trunk/tests/test-objects.c (contents, props changed)
Modified:
trunk/ChangeLog
trunk/bindings/dia-extra.cpp
trunk/bindings/dia-object.h
trunk/bindings/dia-properties.h
trunk/lib/libdia.def
trunk/lib/libdia.h
trunk/lib/orth_conn.h
trunk/objects/UML/actor.c
trunk/objects/makefile.msc
trunk/objects/standard/bezier.c
trunk/objects/standard/polyline.c
trunk/objects/standard/zigzagline.c
Modified: trunk/bindings/dia-extra.cpp
==============================================================================
--- trunk/bindings/dia-extra.cpp (original)
+++ trunk/bindings/dia-extra.cpp Sat Aug 2 09:00:18 2008
@@ -31,44 +31,7 @@
#include "properties.h"
#include "object.h"
#include "plug-ins.h"
-
-/*
- * copied from ../app/diaconv.c
- */
-static void
-#ifdef _MSC_VER
-__cdecl
-#endif
-stderr_message_internal(const char *title, ShowAgainStyle, const char *fmt,
- va_list *args, va_list *args2)
-{
- static gchar *buf = NULL;
- static gint alloc = 0;
- gint len;
-
- len = format_string_length_upper_bound (fmt, args);
-
- if (len >= alloc) {
- if (buf)
- g_free (buf);
-
- alloc = nearest_pow (MAX(len + 1, 1024));
-
- buf = g_new (char, alloc);
- }
-
- vsprintf (buf, fmt, *args2);
-
- fprintf(stderr,
- "%s %s: %s\n",
- "",title,buf);
-}
-
-static void
-dia_extra_redirect (void)
-{
- set_message_func(&stderr_message_internal);
-}
+#include "libdia.h"
/*!
*
@@ -81,11 +44,8 @@
void dia::register_plugins ()
{
g_type_init();
- dia_extra_redirect();
- printf ("ATTENTION: crashing may be caused by the other pydia extension picked up here.");
- //FIXME: Dia's init functions need to be cleaned - and made aware of multiple calls ...
- stdprops_init();
+
+ libdia_init (DIA_MESSAGE_STDERR);
- object_registry_init();
dia_register_plugins ();
}
Modified: trunk/bindings/dia-object.h
==============================================================================
--- trunk/bindings/dia-object.h (original)
+++ trunk/bindings/dia-object.h Sat Aug 2 09:00:18 2008
@@ -29,7 +29,7 @@
//! instead of doing this I'd like better accessor support in SWIG
const int version;
- //! construct from underlying type
+ //! \internal construct from underlying type
ObjectType (::DiaObjectType* ot);
//! create a default initialized object
Object* create (double x, double y, dia::Handle** h1 = 0, dia::Handle** h2 = 0) const;
@@ -54,7 +54,7 @@
class Object
{
public :
- //! trying to be compatible
+ //! trying to be compatible (otherwise this would not be public)
const Properties properties;
//! access to this objects connection points
const Connections connections;
@@ -63,14 +63,14 @@
//! the wrapped type (factory)
const ObjectType type;
- //! direct property access
+ //! direct property access for compatibility and convenience
::_Rectangle* bbox () const;
- //! create an object wrapper - object previously registered from a plug-in
+ //! \internal create an object wrapper - object previously registered from a plug-in
Object (DiaObject*);
- //! destroying the proxy, not the underlying object
+ //! \internal destroying the proxy, not the underlying object
~Object ();
- //! not to be wrapped - just used internally
+ //! \internal not to be wrapped - just used internally
DiaObject* Self() const { return self; }
//! real destruction
void destroy ();
Modified: trunk/bindings/dia-properties.h
==============================================================================
--- trunk/bindings/dia-properties.h (original)
+++ trunk/bindings/dia-properties.h Sat Aug 2 09:00:18 2008
@@ -21,7 +21,7 @@
class IProperty
{
public :
- //! to make delete delete the real thing
+ //! \internal to make delete delete the real thing
virtual ~IProperty () {}
//! getter depending on the type of the property
virtual bool get (int*) const { return false; }
Modified: trunk/lib/libdia.def
==============================================================================
--- trunk/lib/libdia.def (original)
+++ trunk/lib/libdia.def Sat Aug 2 09:00:18 2008
@@ -301,6 +301,7 @@
dia_register_builtin_plugin
dia_register_plugin
dia_register_plugins
+ dia_register_plugins_in_dir
dia_renderer_get_type
dia_renderer_get_width_pixels
Modified: trunk/lib/libdia.h
==============================================================================
--- trunk/lib/libdia.h (original)
+++ trunk/lib/libdia.h Sat Aug 2 09:00:18 2008
@@ -1,3 +1,10 @@
+#ifndef LIBDIA_H
+#define LIBDIA_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
enum DiaInitFlags
{
DIA_INTERACTIVE = (1<<0),
@@ -6,3 +13,5 @@
void libdia_init (guint flags);
+G_END_DECLS
+#endif /*LIBDIA_H */
Modified: trunk/lib/orth_conn.h
==============================================================================
--- trunk/lib/orth_conn.h (original)
+++ trunk/lib/orth_conn.h Sat Aug 2 09:00:18 2008
@@ -36,7 +36,7 @@
*/
struct _OrthConn {
/* DiaObject must be first because this is a 'subclass' of it. */
- DiaObject object;
+ DiaObject object; /*!< inheritance */
int numpoints; /* >= 3 */
Point *points; /* [numpoints] */
Modified: trunk/objects/UML/actor.c
==============================================================================
--- trunk/objects/UML/actor.c (original)
+++ trunk/objects/UML/actor.c Sat Aug 2 09:00:18 2008
@@ -308,6 +308,8 @@
p.x += elem->width/2;
p.y += actor_height + actor->text->ascent;
text_set_position(actor->text, &p);
+ /* may have moved */
+ text_calc_boundingbox(actor->text, &text_box);
/* Add bounding box for text: */
rectangle_union(&obj->bounding_box, &text_box);
Modified: trunk/objects/makefile.msc
==============================================================================
--- trunk/objects/makefile.msc (original)
+++ trunk/objects/makefile.msc Sat Aug 2 09:00:18 2008
@@ -1,6 +1,6 @@
!IFNDEF PACKAGE
-PLUGINS = aadl bondgraph chronogram custom er flowchart fs grafcet \
+PLUGINS = aadl chronogram custom er flowchart fs grafcet \
Istar Jackson Kaos misc network sadt SISSI standard uml \
Database custom_lines
Modified: trunk/objects/standard/bezier.c
==============================================================================
--- trunk/objects/standard/bezier.c (original)
+++ trunk/objects/standard/bezier.c Sat Aug 2 09:00:18 2008
@@ -455,8 +455,6 @@
bezierconn_set_points(bez, bcd->num_points, bcd->points);
}
- bezierline_update_data(bezierline);
-
bezierline->line_width = attributes_get_default_linewidth();
bezierline->line_color = attributes_get_foreground();
attributes_get_default_line_style(&bezierline->line_style,
@@ -466,6 +464,9 @@
*handle1 = bez->object.handles[0];
*handle2 = bez->object.handles[3];
+
+ bezierline_update_data(bezierline);
+
return &bezierline->bez.object;
}
Modified: trunk/objects/standard/polyline.c
==============================================================================
--- trunk/objects/standard/polyline.c (original)
+++ trunk/objects/standard/polyline.c Sat Aug 2 09:00:18 2008
@@ -365,8 +365,6 @@
}
- polyline_update_data(polyline);
-
polyline->line_width = attributes_get_default_linewidth();
polyline->line_color = attributes_get_foreground();
attributes_get_default_line_style(&polyline->line_style,
@@ -375,6 +373,8 @@
polyline->end_arrow = attributes_get_default_end_arrow();
polyline->corner_radius = 0.0;
+ polyline_update_data(polyline);
+
return &polyline->poly.object;
}
@@ -409,6 +409,8 @@
newpolyline->absolute_start_gap = polyline->absolute_start_gap;
newpolyline->absolute_end_gap = polyline->absolute_end_gap;
+ polyline_update_data(newpolyline);
+
return &newpolyline->poly.object;
}
Modified: trunk/objects/standard/zigzagline.c
==============================================================================
--- trunk/objects/standard/zigzagline.c (original)
+++ trunk/objects/standard/zigzagline.c Sat Aug 2 09:00:18 2008
@@ -260,8 +260,6 @@
orthconn_init(orth, startpoint);
- zigzagline_update_data(zigzagline);
-
zigzagline->line_width = attributes_get_default_linewidth();
zigzagline->line_color = attributes_get_foreground();
attributes_get_default_line_style(&zigzagline->line_style,
@@ -272,6 +270,9 @@
*handle1 = orth->handles[0];
*handle2 = orth->handles[orth->numpoints-2];
+
+ zigzagline_update_data(zigzagline);
+
return &zigzagline->orth.object;
}
Added: trunk/tests/makefile.msc
==============================================================================
--- (empty file)
+++ trunk/tests/makefile.msc Sat Aug 2 09:00:18 2008
@@ -0,0 +1,26 @@
+## Makefile for building the GLib test programs with Microsoft C
+## Use: nmake -f makefile.msc check
+
+TOP = ..\..
+
+!INCLUDE $(TOP)\glib\build\win32\make.msc
+
+################################################################
+
+INCLUDES = -FImsvc_recommended_pragmas.h -I .. -I ..\lib $(GLIB_CFLAGS) \
+# the following dependencies should _not_ be necessary to include object.h \
+ $(GTK2_CFLAGS) $(LIBXML2_CFLAGS)
+
+DEFINES = -DHAVE_CONFIG_H
+
+TESTS = \
+ test-objects.exe
+
+all : $(TESTS)
+
+.c.exe :
+ $(CC) $(CFLAGS) -c $<
+ $(CC) $(CFLAGS) -Fe$@ $< ..\lib\libdia.lib $(GLIB_LIBS) $(LDFLAGS) user32.lib /subsystem:console
+
+check: all
+ for %p in ($(TESTS)) do set PATH=..\lib;%PATH% && %p ..\objects\\
Added: trunk/tests/test-objects.c
==============================================================================
--- (empty file)
+++ trunk/tests/test-objects.c Sat Aug 2 09:00:18 2008
@@ -0,0 +1,193 @@
+/* test-objects.c -- Unit test for Dia object implmentations
+ * Copyright (C) 2008 Hans Breuer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#include <string.h>
+
+//#undef G_DISABLE_ASSERT
+#undef G_LOG_DOMAIN
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <glib/gtestutils.h>
+
+#include "object.h"
+#include "plug-ins.h"
+#include "libdia.h"
+
+/* allows to select specific objects for testing */
+static gchar *_type_name = NULL;
+const real EPSILON = 1e-6;
+
+
+static void
+_test_creation (const DiaObjectType *type)
+{
+ int i;
+ Handle *h1 = NULL, *h2 = NULL;
+ Point point = {0, 0};
+ DiaObject *o = type->ops->create (&point, type->default_user_data, &h1, &h2);
+
+ g_assert (o != NULL && o->type != NULL);
+ /* NOT always: o->type == type, e.g. compatibility names for creation */
+
+ /* check mandatory object ops */
+ g_assert ( o->ops != NULL
+ && o->ops->destroy != NULL
+ && o->ops->draw != NULL
+ && o->ops->distance_from != NULL
+ && o->ops->selectf != NULL
+ && o->ops->copy != NULL
+ && o->ops->move != NULL
+ && o->ops->move_handle != NULL
+ && o->ops->apply_properties_from_dialog != NULL
+ );
+ g_assert (o->ops->get_object_menu == NULL || o->ops->get_object_menu(o, &point) != NULL);
+
+ /* can we really assume everthing complies with standard props nowadays? */
+ g_assert ( o->ops->describe_props
+ && o->ops->get_props
+ && o->ops->set_props);
+ {
+ 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);
+ }
+ /* not implmeneted anywhere */
+ g_assert (o->ops->edit_text == NULL);
+ /* I think this is mandatory */
+ g_assert (o->ops->apply_properties_list != NULL);
+
+ /* bounding box must be initialized */
+ g_assert (o->bounding_box.left <= o->bounding_box.right);
+ g_assert (o->bounding_box.top <= o->bounding_box.bottom);
+ /* object position must (should?) be in bounding box */
+ g_assert (o->bounding_box.left <= o->position.x && o->position.x <= o->bounding_box.right);
+ g_assert (o->bounding_box.top <= o->position.y && o->position.y <= o->bounding_box.bottom);
+
+ /* both handles can be NULL, but if not hey must belong to the object */
+ for (i = 0; i < o->num_handles; ++i)
+ {
+ if (h1 != NULL && h1 == o->handles[i])
+ h1 = NULL;
+ if (h2 != NULL && h2 == o->handles[i])
+ h2 = NULL;
+ /* handles properly set up? */
+ g_assert (o->handles[i] != NULL);
+ }
+ /* handles now destroyed */
+ g_assert (NULL == h1 && NULL == h2);
+
+ for (i = 0; i < o->num_connections; ++i)
+ {
+ g_assert (o->connections[i] != NULL);
+ }
+
+ /* finally */
+ o->ops->destroy (o);
+}
+
+static void
+_test_modification (const DiaObjectType *type)
+{
+ Handle *h1 = NULL, *h2 = NULL;
+ Point from = {0, 0};
+ DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
+ Rectangle bbox1, bbox2;
+ Point to = {10, 10};
+
+ /* does the object move ... ? */
+ from = o->position;
+ bbox1 = o->bounding_box;
+ /* ... not (= hack used to force an update call) */
+ o->ops->move (o, &o->position);
+ bbox2 = o->bounding_box;
+ g_assert ( fabs((bbox2.right - bbox2.left) - (bbox1.right - bbox1.left)) < EPSILON
+ && fabs((bbox2.bottom - bbox2.top) - (bbox1.bottom - bbox1.top)) < EPSILON);
+ /* .... really: without changing size ? */
+ bbox1 = o->bounding_box;
+ o->ops->move (o, &to);
+ bbox2 = o->bounding_box;
+ g_assert ( fabs((bbox2.right - bbox2.left) - (bbox1.right - bbox1.left)) < EPSILON
+ && fabs((bbox2.bottom - bbox2.top) - (bbox1.bottom - bbox1.top)) < EPSILON);
+
+
+ /* finally */
+ o->ops->destroy (o);
+}
+
+/*
+ * A dictionary interface to all registered object(-types)
+ */
+static void
+_ot_item (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ gchar *name = (gchar *)key;
+ DiaObjectType *type = (DiaObjectType *)value;
+ const gchar *base = (const gchar *)user_data;
+ gchar *testpath;
+
+ testpath = g_strdup_printf ("%s/%s/%s", base, name, "Creation");
+ g_test_add_data_func (testpath, type, _test_creation);
+ g_free (testpath);
+
+ testpath = g_strdup_printf ("%s/%s/%s", base, name, "Modification");
+ g_test_add_data_func (testpath, type, _test_modification);
+ g_free (testpath);
+}
+
+int
+main (int argc, char** argv)
+{
+ GList *plugins = NULL;
+
+ /* not using gtk_test_init() means we can only test non-gtk facilities of objects */
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ libdia_init (DIA_MESSAGE_STDERR);
+
+ /* todo: improve command line parsing */
+ if (argc > 1)
+ {
+ const gchar* path = argv[1];
+
+ if (g_file_test (path, G_FILE_TEST_IS_DIR))
+ dia_register_plugins_in_dir (path);
+ else
+ dia_register_plugin (path);
+ }
+ else
+ {
+ dia_register_plugins ();
+ }
+ plugins = dia_list_plugins ();
+ g_assert (g_list_length (plugins) > 0);
+
+ object_registry_foreach (_ot_item, "/Dia/Objects");
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]