dia r4105 - in trunk: . plug-ins/python tests
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4105 - in trunk: . plug-ins/python tests
- Date: Sat, 9 Aug 2008 13:03:24 +0000 (UTC)
Author: hans
Date: Sat Aug 9 13:03:24 2008
New Revision: 4105
URL: http://svn.gnome.org/viewvc/dia?rev=4105&view=rev
Log:
2008-08-09 Hans Breuer <hans breuer org>
* tests/test-boundingbox.c : some bounding box unit test
tests/test-object.c tests/makefile.msc : updated
Added:
trunk/tests/test-boundingbox.c (contents, props changed)
Modified:
trunk/ChangeLog
trunk/plug-ins/python/Makefile.am
trunk/tests/makefile.msc
trunk/tests/test-objects.c
Modified: trunk/plug-ins/python/Makefile.am
==============================================================================
--- trunk/plug-ins/python/Makefile.am (original)
+++ trunk/plug-ins/python/Makefile.am Sat Aug 9 13:03:24 2008
@@ -80,6 +80,7 @@
EXTRA_DIST = \
python-startup.py \
\
+ autolayoutforce.py \
aobjects.py \
codegen.py \
diasvg.py \
Modified: trunk/tests/makefile.msc
==============================================================================
--- trunk/tests/makefile.msc (original)
+++ trunk/tests/makefile.msc Sat Aug 9 13:03:24 2008
@@ -14,6 +14,7 @@
DEFINES = -DHAVE_CONFIG_H
TESTS = \
+ test-boundingbox.exe \
test-objects.exe
all : $(TESTS)
@@ -23,4 +24,4 @@
$(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\\
+ for %p in ($(TESTS)) do set PATH=..\lib;%PATH% && %p ..\objects\standard\\
Added: trunk/tests/test-boundingbox.c
==============================================================================
--- (empty file)
+++ trunk/tests/test-boundingbox.c Sat Aug 9 13:03:24 2008
@@ -0,0 +1,138 @@
+/* test-boundingbo.c -- Unit test for Dia bounding box calculattions
+ * Copyright (C) 2008 Hans Breuer
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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>
+#include <math.h>
+
+#undef G_DISABLE_ASSERT
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "Dia"
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <glib/gtestutils.h>
+
+#include "libdia.h"
+
+/*
+ * To test DiaObject bounding boxes a nice approach would be to implment a BoundingboxRenderer
+ * which uses it's state while rendering objects via DiaObject::draw () to compare the bounding got
+ * dia_object_get_bounding_box (). For this to be integrated with test-objects.c it is kind of required
+ * that the bounding box primitives are working ...
+ */
+
+
+#include "boundingbox.h"
+#include "geometry.h"
+
+static BezPoint _bz1[2] = { /* SE */
+ /* x, y */
+ {BEZ_MOVE_TO, {0.0, 2.0} },
+ {BEZ_CURVE_TO, {0.0, 0.0}, {2.0, 0.0}, {2.0, 2.0} },
+};
+static BezPoint _bz2[2] = { /* SW */
+ /* x, y */
+ {BEZ_MOVE_TO, {-2.0, 2.0} },
+ {BEZ_CURVE_TO, {-2.0, 0.0}, {0.0, 0.0}, {0.0, 2.0} },
+};
+static BezPoint _bz3[2] = { /* NW */
+ /* x, y */
+ {BEZ_MOVE_TO, {-2.0, 0.0} },
+ {BEZ_CURVE_TO, {-2.0,-2.0}, {0.0,-2.0}, {0.0, 0.0} },
+};
+static BezPoint _bz4[2] = { /* NE */
+ /* x, y */
+ {BEZ_MOVE_TO, {0.0, 0.0} },
+ {BEZ_CURVE_TO, {0.0,-2.0}, {2.0,-2.0}, {2.0, 0.0} },
+};
+static BezPoint _bz5[2] = { /* swapped control points */
+ /* x, y */
+ {BEZ_MOVE_TO, {0.0, 2.0} },
+ {BEZ_CURVE_TO, {2.0, 0.0}, {0.0, 0.0}, {2.0, 2.0} },
+};
+static BezPoint _bz6[3] = {
+ {BEZ_MOVE_TO, {1.0, 2.0} },
+ {BEZ_CURVE_TO, {0.0, 2.0}, {0.0, 0.0}, {1.0, 0.0} },
+ {BEZ_CURVE_TO, {2.0, 0.0}, {2.0, 2.0}, {1.0, 2.0} },
+};
+static BezPoint _bz7[5] = {
+ { BEZ_MOVE_TO, {1,1} },
+ { BEZ_CURVE_TO, {0,0}, {0,2}, {1,1} },
+ { BEZ_CURVE_TO, {2,0}, {2,2}, {1,1} },
+ { BEZ_CURVE_TO, {0,0}, {2,0}, {1,1} },
+ { BEZ_CURVE_TO, {0,2}, {2,2}, {1,1} },
+};
+
+#define T (0.1)
+#define BEZ(x) sizeof(_bz ##x)/sizeof(BezPoint), _bz ##x
+
+static struct _TestBeziers {
+ int num;
+ BezPoint *pts;
+ Rectangle box;
+} _test_beziers[] = { /* top, left, bottom, right */
+ { BEZ(1), { 0.5-T, 0.0-T, 2.0+T, 2.0+T } },
+ { BEZ(2), { 0.5-T,-2.0-T, 2.0+T, 0.0+T } },
+ { BEZ(3), {-1.5-T,-2.0-T, 0.0+T, 0.0+T } },
+ { BEZ(4), {-1.5-T, 0.0-T, 0.0+T, 2.0+T } },
+ /* it only 'jumps' out of the box with a line width>0 */
+ { BEZ(5), { 0.5-T, 0.0-T, 2.0+T, 2.0+T } },
+ { BEZ(6), { 0.0-T, 0.2-T, 2.0+T, 1.8+T } },
+ { BEZ(7), { 0.25-T,0.25-T, 1.75+T, 1.75+T} },
+};
+#undef BEZ
+
+static void
+_check_one_bezier (const struct _TestBeziers *test)
+{
+ Rectangle rect;
+ PolyBBExtras extra = {0, T*.7, T*.7, T*.7, 0 };
+
+ polybezier_bbox (test->pts, test->num, &extra, FALSE, &rect);
+ g_assert (rectangle_in_rectangle (&test->box, &rect));
+}
+static void
+_add_bezier_tests (void)
+{
+ int i, num = sizeof(_test_beziers)/sizeof(struct _TestBeziers);
+
+ for (i = 0; i < num; ++i)
+ {
+ gchar *testpath = g_strdup_printf ("/Dia/BoundingBox/Bezier%d", i+1);
+ g_test_add_data_func (testpath, &_test_beziers[i], _check_one_bezier);
+ g_free (testpath);
+ }
+}
+
+int
+main (int argc, char** argv)
+{
+ GList *plugins = NULL;
+ int ret;
+
+ g_test_init (&argc, &argv, NULL);
+ /* not really needed - or are there message_warnings in the bbox code? */
+ libdia_init (DIA_MESSAGE_STDERR);
+
+ _add_bezier_tests ();
+
+ return g_test_run ();
+}
Modified: trunk/tests/test-objects.c
==============================================================================
--- trunk/tests/test-objects.c (original)
+++ trunk/tests/test-objects.c Sat Aug 9 13:03:24 2008
@@ -1,28 +1,29 @@
/* 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 program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU 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,
+ * This program 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU 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.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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>
+#include <math.h>
-//#undef G_DISABLE_ASSERT
+#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "Dia"
#include <glib.h>
#include <glib-object.h>
@@ -37,6 +38,7 @@
static gchar *_type_name = NULL;
const real EPSILON = 1e-6;
+int num_objects = 0;
static void
_test_creation (const DiaObjectType *type)
@@ -95,6 +97,10 @@
h2 = NULL;
/* handles properly set up? */
g_assert (o->handles[i] != NULL);
+ g_assert (o->handles[i]->connected_to == NULL); /* starts not connected */
+ g_assert ( o->handles[i]->type != HANDLE_NON_MOVABLE
+ || ( o->handles[i]->type == HANDLE_NON_MOVABLE /* always together? */
+ && o->handles[i]->connect_type == HANDLE_NONCONNECTABLE));
}
/* handles now destroyed */
g_assert (NULL == h1 && NULL == h2);
@@ -109,6 +115,54 @@
}
static void
+_test_copy (const DiaObjectType *type)
+{
+ Handle *h1 = NULL, *h2 = NULL;
+ Point from = {0, 0};
+ DiaObject *oc, *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
+ Rectangle bbox1, bbox2;
+ Point to = {0, 0};
+ int i;
+
+ g_assert (o != NULL && o->type != NULL);
+
+ /* does the object move ... ? */
+ from = o->position;
+ bbox1 = o->bounding_box;
+ oc = o->ops->copy (o);
+
+ g_assert (oc != NULL && oc->type == o->type && oc->ops == o->ops);
+
+ to = o->position;
+ bbox2 = o->bounding_box;
+
+ /* ... it should not */
+ g_assert (fabs(from.x - to.x) < EPSILON && fabs(from.y - to.y) < EPSILON);
+ g_assert ( fabs((bbox2.right - bbox2.left) - (bbox1.right - bbox1.left)) < EPSILON
+ && fabs((bbox2.bottom - bbox2.top) - (bbox1.bottom - bbox1.top)) < EPSILON);
+
+ /* is copying producing dangling pointers ? */
+ g_assert (o->num_handles == oc->num_handles);
+ for (i = 0; i < o->num_handles; ++i)
+ {
+ g_assert (oc->handles[i] != NULL && oc->handles[i] != o->handles[i]);
+ }
+
+ g_assert (o->num_connections == oc->num_connections);
+ for (i = 0; i < o->num_connections; ++i)
+ {
+ g_assert (oc->connections[i]->object == oc); /* owner set? */
+ g_assert (oc->connections[i] != NULL && oc->connections[i] != o->connections[i]);
+ }
+
+ /* check some further properties which must be copied ?*/
+
+ /* finally */
+ o->ops->destroy (o);
+ oc->ops->destroy (oc);
+}
+
+static void
_test_modification (const DiaObjectType *type)
{
Handle *h1 = NULL, *h2 = NULL;
@@ -153,16 +207,23 @@
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, "Copy");
+ g_test_add_data_func (testpath, type, _test_copy);
+ 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);
+
+ ++num_objects;
}
int
main (int argc, char** argv)
{
GList *plugins = NULL;
+ int ret;
/* not using gtk_test_init() means we can only test non-gtk facilities of objects */
g_type_init ();
@@ -189,5 +250,7 @@
object_registry_foreach (_ot_item, "/Dia/Objects");
- return g_test_run ();
+ ret = g_test_run ();
+ g_print ("Tested %d objects.\n", num_objects);
+ return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]