File: test-objects.c

package info (click to toggle)
dia 0.97.3%2Bgit20160930-9
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 54,372 kB
  • sloc: ansic: 155,065; xml: 16,326; python: 6,641; cpp: 4,935; makefile: 3,833; sh: 540; perl: 137; sed: 19
file content (1125 lines) | stat: -rw-r--r-- 41,217 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
/* test-objects.c -- Unit test for Dia object implmentations
 * Copyright (C) 2008-2014 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 "object.h"
#include "plug-ins.h"
#include "dialib.h"
#include "create.h"
#include "properties.h"
#include "diapathrenderer.h"

const real EPSILON = 1e-6;
int num_objects = 0;

static void
_test_creation (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  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
	    );
  
  /* can we really assume everything 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 *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_printerr ("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);
  /* 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);

  g_assert (o->num_handles > 0);
  /* both handles can be NULL, but if not they 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);
      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 found */
  g_assert (NULL == h1 && NULL == h2);

  for (i = 0; i < o->num_connections; ++i)
    {
      g_assert (o->connections[i] != NULL);
      g_assert (o->connections[i]->object == o); /* owner set? */
      g_assert ((o->connections[i]->directions & ~DIR_ALL) == 0); /* known directions */
      g_assert ((o->connections[i]->flags & ~CP_FLAGS_MAIN) == 0); /* known flags */
    }

  /* finally */
  o->ops->destroy (o);
  g_free (o);
}

static void
_test_copy (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  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;
  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);
  g_free (o);
  oc->ops->destroy (oc);
  g_free (oc);
}

/* small helper to just throw it away */
static void
_object_change_free(ObjectChange *change)
{
  if (change) { /* usually this is NULL for move */
    if (change->free) {
      change->free(change);
      g_free(change);
    }
  }
}

static void
_test_movement (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point from = {5, 5};
  DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
  Rectangle bbox1, bbox2;
  Point to = {10, 10};
  ObjectChange *change;
  Point pos;
  real epsilon;
  Point *handle_positions;
  Point *cp_positions;
  guint i;
  /* With the use here the number of connections can not change.
   * Declaring and using it const avoids misinterpretation of scan-build
   * about the first and second loop over it being different.
   */
  const int num_connections = o->num_connections;
  /* same for the number of handles */
  const int num_handles = o->num_handles;

  /* does the object move ... ? */
  from = o->position;
  bbox1 = o->bounding_box;
  /* ... not (= hack used to force an update call) */
  change = o->ops->move (o, &o->position);
  if (change) /* usually this is NULL for move */
    _object_change_free(change);
  g_assert (num_connections == o->num_connections);
  bbox2 = o->bounding_box;
  if (   strcmp (type->name, "Cybernetics - b-sens") == 0
      || strcmp (type->name, "Cybernetics - l-sens") == 0
      || strcmp (type->name, "Cybernetics - r-sens") == 0
      || strcmp (type->name, "Cybernetics - t-sens") == 0
      ) /* not nice, but also not a reason to fail */
    epsilon = 0.5 + EPSILON;
  else
    epsilon = EPSILON;

  g_assert_cmpfloat (fabs(fabs(bbox2.right - bbox2.left) - fabs(bbox1.right - bbox1.left)), <, epsilon);
  g_assert_cmpfloat (fabs(fabs(bbox2.bottom - bbox2.top) - fabs(bbox1.bottom - bbox1.top)), <, epsilon);
  /* .... really: without changing size ? */
  pos = o->position;
  bbox1 = o->bounding_box;
  /* remember handle and connection point positions ... */
  handle_positions = g_alloca (sizeof(Point) * num_handles);
  /* at least one handle is mandatory */
  g_assert (num_handles > 0);
  for (i = 0; i < num_handles; ++i)
    handle_positions[i] = o->handles[i]->pos;
  cp_positions = g_alloca (sizeof(Point) * o->num_connections);
  for (i = 0; i < num_connections; ++i)
    cp_positions[i] = o->connections[i]->pos;

  change = o->ops->move (o, &to);
  if (change) /* usually this is NULL for move */
    _object_change_free(change);
  g_assert (num_connections == o->num_connections);
  /* does the position reflect the move? */
  g_assert_cmpfloat (fabs(fabs(pos.x - o->position.x) - fabs(from.x - to.x)), <, EPSILON);
  g_assert_cmpfloat (fabs(fabs(pos.y - o->position.y) - fabs(from.y - to.y)), <, EPSILON);
  /* ... also for handles and connection points? */
  for (i = 0; i < num_handles; ++i)
    {
      g_assert_cmpfloat (fabs(fabs(handle_positions[i].x - o->handles[i]->pos.x) - fabs(from.x - to.x)), <, EPSILON);
      g_assert_cmpfloat (fabs(fabs(handle_positions[i].y - o->handles[i]->pos.y) - fabs(from.y - to.y)), <, EPSILON);
    }
  for (i = 0; i < num_connections; ++i)
    {
      g_assert_cmpfloat (fabs(fabs(cp_positions[i].x - o->connections[i]->pos.x) - fabs(from.x - to.x)), <, EPSILON);
      g_assert_cmpfloat (fabs(fabs(cp_positions[i].y - o->connections[i]->pos.y) - fabs(from.y - to.y)), <, EPSILON);
    }

  bbox2 = o->bounding_box;
  /* test fails e.g. for 'Cisco - Web cluster' probably due to bezier-bbox-issues: bug 568115 */
  if (/* FIXME: this shape should be simple enough to actually fix the bug */
         strcmp (type->name, "Assorted - Heart") == 0 /* height off 0.05 */
      || strstr (type->name, "Bugs -") == type->name)
    g_test_message ("SKIPPED %s! ", type->name);
  else
    {
      g_assert_cmpfloat (fabs((bbox2.right - bbox2.left) - fabs(bbox1.right - bbox1.left)), <, EPSILON);
      g_assert_cmpfloat (fabs((bbox2.bottom - bbox2.top) - fabs(bbox1.bottom - bbox1.top)), <, EPSILON);
    }
  /* finally */
  o->ops->destroy (o);
  g_free (o);
}

static void
_test_change (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point from = {0, 0};
  DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);

  if (o->ops->apply_properties_list) {
    ObjectChange *change;
    /* get description */
    const PropDescription *descs = o->ops->describe_props (o);
    /* get unset value vector */ 
    GPtrArray *props = prop_list_from_descs (descs, pdtpp_is_visible);
    /* fill it with this objects values */
    o->ops->get_props (o, props);
    /* apply it back to the object - maybe we should do some change first? */
    change = o->ops->apply_properties_list (o, props);
    prop_list_free (props);
    if (change) {
      /* maybe we should do something interesting first? */
      _object_change_free(change);
    } else {
      g_printerr ("'%s' - no undo?\n", o->type->name);
    }
  }
  /* finally */
  o->ops->destroy (o);
  g_free (o);
}
static void
_test_move_handle (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point from = {0, 0};
  DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
  DiaObject *o2 = NULL;
  ObjectChange *change;
  ConnectionPoint *cp = NULL;
  gint i;

  if (h1)
    {
      /* The first handle is used to connect - if possible.
       * Only very few object return in unconnectable handle, namely:
       *   "Standard - Beziergon", "Standard - Path", "Standard - Polygon",
       *   "Database - Compound",
       *   "GRAFCET - Condition",
       *   "Misc - Ngon",
       *   "Network - Radio Cell"
       * This is not a bug in these object implementations, because other
       * uses are possible ...
       */
      if (h1->connect_type != HANDLE_CONNECTABLE)
        g_test_message ("Handle 1 not connectable");

    }

  if (h2) /* not mandatory to return one */
    {
      Point to = h2->pos;
      to.x += 1.0; to.y += 1.0;
      change = o->ops->move_handle(o, h2, &to, NULL, HANDLE_MOVE_CREATE_FINAL, 0);
      /* the API would allow, but it gave at least a leak at app/create_object.c */
      if (change)
        {
          g_test_message ("CHANGE ");
          _object_change_free(change);
        }
      h2 = NULL;
    }
  /* find a good handle to move */
  for (i = 0; i < o->num_handles; ++i)
    {
      
      if (o->handles[i]->type == HANDLE_MAJOR_CONTROL)
        {
          h2 = o->handles[i];
	  if (h2->connect_type == HANDLE_CONNECTABLE)
	    {
	      o2 = create_standard_box (5.0, 5.0, 2.0, 2.0);
	      if (!o2) {
		/* this may happen if Standard objects are not included */
		g_test_message ("SKIPPED connect test.");
		break;
	      }
	      g_assert(o2->num_connections > 0);
	      cp = o2->connections[0];
	      object_connect(o, h2, cp);
	    }
	  break;
	}
    }
  /* second move */
  if (h2)
    {
      Point to = h2->pos;
      Rectangle bb_org = o->bounding_box;
      from = to;
      to.x += 1.0; to.y += 1.0;
      if (cp)
        {
	  change = o->ops->move_handle(o, h2, &to, cp, HANDLE_MOVE_CONNECTED, 0);
	  /* again the API would allow, but it gave at least a leak at app/connectionpoint_ops.c */
	  g_assert (change == NULL);
	}
      else
        {
	  change = o->ops->move_handle(o, h2, &to, NULL, HANDLE_MOVE_USER_FINAL, 0);
	  if (change) /* still not mandatory */
	    {
	      to.x -= 1.0; to.y -= 1.0;
	      change->revert(change, NULL);
	      _object_change_free(change);
	      if (TRUE) /* move_handle undo is handled on the application level ;( */
		/* NOP */;
	      else
		g_assert(   fabs(to.x - o->handles[i]->pos.x) < EPSILON
			 && fabs(to.y - o->handles[i]->pos.y) < EPSILON);
	    }
	}
      /* moving back to the original position must restore the original object */
      change = o->ops->move_handle(o, h2, &from, NULL, HANDLE_MOVE_USER_FINAL, 0);
      _object_change_free(change); /* custom_move_handle() might return a change */
      if (   strcmp (type->name, "UML - Lifeline") == 0
	  || strcmp (type->name, "Standard - Outline") == 0)
	{
	  g_test_message ("No restore by '%s'::move_handle", type->name);
	}
      else
	{
	  g_assert_cmpfloat (fabs(o->bounding_box.top - bb_org.top), <, EPSILON);
	  g_assert_cmpfloat (fabs(o->bounding_box.left - bb_org.left), <, EPSILON);
	  g_assert_cmpfloat (fabs(o->bounding_box.right - bb_org.right), <, EPSILON);
	  g_assert_cmpfloat (fabs(o->bounding_box.bottom - bb_org.bottom), <, EPSILON);
	}
      h2 = NULL;
    }
  /* finally */
  o->ops->destroy (o);
  g_free (o);
  if (o2) {
    o2->ops->destroy (o2);
    g_free (o2);
  }
}
static void
_test_connectionpoint_consistency (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point pos = {0, 0};
  Point center;
  DiaObject *o = type->ops->create (&pos, type->default_user_data, &h1, &h2);
  ObjectChange *change;
  int i;
  gboolean any_dir_set = FALSE;
  ConnectionPoint *cp_prev = NULL;

  change = dia_object_set_string (o, NULL, "Test me!");
  _object_change_free (change);

  for (i = 0; i < o->num_connections; ++i) {
    ConnectionPoint *cp = o->connections[i];
    if (cp->directions != DIR_NONE)
      any_dir_set = TRUE;
  }
  if (!any_dir_set) {
    /* should be connection */
    int start_end = 0; /* counter */
    for (i = 0; i < o->num_handles; ++i) {
      Handle *h = o->handles[i];
      if (h->id == HANDLE_MOVE_STARTPOINT || h->id == HANDLE_MOVE_ENDPOINT)
        ++start_end;
    }
    if (start_end < 2 && o->num_connections > 0)
      g_printerr ("'%s' with no directions\n", type->name);
    return;
  }

  pos = o->position;
  center.x = (o->bounding_box.right + o->bounding_box.left) / 2;
  center.y = (o->bounding_box.bottom + o->bounding_box.top) / 2;

  for (i = 0; i < o->num_connections; ++i) {
    ConnectionPoint *cp = o->connections[i];
    if (cp->directions == DIR_ALL) {
      /* Use this as misplaced mainpoint check ...
       * - some shapes should never have got a main point, but removing these
       *   now would produce complaints if they were used in diagrams
       * - the main point should be within the object, which can't work for
       *   an object consisting of only lines ...
       * - some main points where just placed automatically and got fixed
       *   after identified with this check
       */
      if (   strcmp (type->name, "chemeng - coil") == 0
          || strcmp (type->name, "chemeng - coilv") == 0
          || strcmp (type->name, "chemeng - doublepipe") == 0
          || strcmp (type->name, "chemeng - pneum") == 0
          || strcmp (type->name, "chemeng - pneumv") == 0
          || strcmp (type->name, "chemeng - pnuemv") == 0
          || strcmp (type->name, "chemeng - spray") == 0
          || strcmp (type->name, "Circuit - Horizontal Powersource (European)") == 0
          || strcmp (type->name, "Circuit - NMOS Transistor (European)") == 0
          || strcmp (type->name, "Circuit - NPN Transistor") == 0
          || strcmp (type->name, "Circuit - PMOS Transistor (European)") == 0
          || strcmp (type->name, "Circuit - PNP Transistor") == 0
          || strcmp (type->name, "Circuit - Vertical Capacitor") == 0
          || strcmp (type->name, "Circuit - Vertical Powersource (European)") == 0
          || strcmp (type->name, "Civil - Preliminary Clarification Tank") == 0
          || strcmp (type->name, "Civil - Reference Line") == 0
          || strcmp (type->name, "Civil - Aerator") == 0
          || strcmp (type->name, "Civil - Basin") == 0
          || strcmp (type->name, "Civil - Final-Settling Basin") == 0
          || strcmp (type->name, "Small Extension Node") == 0 /* MSE */
         )
        g_printerr ("'%s' main-cp misplaced!\n", type->name);
      else
        g_assert (o->ops->distance_from (o, &cp->pos) == 0 && "within");
      continue;
    }
    if (   strcmp (type->name, "chronogram - reference") == 0
        || strcmp (type->name, "BPMN - Data-Object") == 0
        || strcmp (type->name, "Optics - Scope") == 0
        || strcmp (type->name, "Optics - Spectrum") == 0
        || strcmp (type->name, "GRAFCET - Transition") == 0
        || strcmp (type->name, "Standard - Polygon") == 0
        || strcmp (type->name, "GRAFCET - Action") == 0)
      continue; /* undecided */
    /* Some things which should not be set */
    if (cp->pos.x > center.x)
      g_assert ((cp->directions & DIR_WEST) == 0);
    else if (cp->pos.x < center.x)
      g_assert ((cp->directions & DIR_EAST) == 0);
    if (cp->pos.y > center.y)
      g_assert ((cp->directions & DIR_NORTH) == 0);
    else if (cp->pos.y < center.y)
      g_assert ((cp->directions & DIR_SOUTH) == 0);
  }

  if (o->num_connections > 1)
    cp_prev = o->connections[o->num_connections-1];
  for (i = 0; i < o->num_connections; ++i) {
    ConnectionPoint *cp = o->connections[i];
    if (cp_prev) {
      /* if the previous cp had the same coordinate x or y it should have the same direction */
      if (   strcmp (type->name, "GRAFCET - Vergent") == 0
	  || strcmp (type->name, "Standard - Polygon") == 0)
	continue; /* not a hard requirement */
      /* not with main point which usually has DIR_ALL */
      if (cp_prev->directions != DIR_ALL && cp->directions != DIR_ALL) {
	if (cp_prev->pos.x == cp->pos.x)
	  g_assert_cmpint ((cp_prev->directions & (DIR_WEST|DIR_EAST)), ==, (cp->directions & (DIR_WEST|DIR_EAST)));
	if (cp_prev->pos.y == cp->pos.y)
	  g_assert_cmpint ((cp_prev->directions & (DIR_NORTH|DIR_SOUTH)), ==, (cp->directions & (DIR_NORTH|DIR_SOUTH)));
      }
      cp_prev = cp;
    }
  }
  /* every connection point should be in bounds of the object */
  for (i = 0; i < o->num_connections; ++i) {
    ConnectionPoint *cp = o->connections[i];
#if 1
    if (   strcmp (type->name, "Racks - Label Anchors 42U") == 0
        || strcmp (type->name, "Civil - Horizontal Rest") == 0
        || strcmp (type->name, "Cisco - Data Center Switch") == 0
        || strcmp (type->name, "Civil - Bivalent Vertical Rest") == 0
        || strcmp (type->name, "Cisco - VIP") == 0
        || strcmp (type->name, "Building Site - Proportioning Batcher") == 0
        || strcmp (type->name, "Civil - Gas Bottle") == 0
        || strcmp (type->name, "Civil - Water Level") == 0
        || strcmp (type->name, "UML - Classicon") == 0
        || strcmp (type->name, "scene graph - field") == 0
        || strcmp (type->name, "Cisco - Telecommuter") == 0
        || strcmp (type->name, "Civil - Vertical Rest") == 0
        || strcmp (type->name, "Cisco - PC Adapter Card") == 0
        || strcmp (type->name, "Civil - Reference Line") == 0
        || strcmp (type->name, "Cisco - Dot-Dot") == 0
        || strcmp (type->name, "Cisco - WLAN controller") == 0
        || strstr (type->name, "Bugs -") == type->name)
      break; /* kind of wasteful to check for every connection */
    g_assert (   o->ops->distance_from (o, &cp->pos) < 0.01
              || distance_rectangle_point (&o->bounding_box, &cp->pos) < 0.01);
#else
    /* generate exception list - after all it is legal to have CPs out of bounds */
    if (   o->ops->distance_from (o, &cp->pos) >= 0.01
        && distance_rectangle_point (&o->bounding_box, &cp->pos) >= 0.01) {
      g_printerr ("        || strcmp (type->name, \"%s\") == 0\n", type->name);
      break;
    }
#endif
  }
  /* finally */
  o->ops->destroy (o);  
  g_free (o);
}
static void
_test_object_menu (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point from = {0, 0};
  DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
  int i;

  /* the method itself is optional */
  if (!o->ops->get_object_menu) {
    g_test_message ("SKIPPED (n.i.)!");
  } else {
    DiaMenu *menu = (o->ops->get_object_menu)(o, &from); /* clicked_pos should not matter much */
    /* strangely enough I found a crash with menu==NULL today ;) */
    int num_items = menu ? menu->num_items : 0;

    for (i = 0; i < num_items; ++i) {
      DiaMenuItem *item;

      /* Every call below might update availability of the active items */
      menu = (o->ops->get_object_menu)(o, &from);
      item = &menu->items[i];

      if (item->text) /* the second form is a submenu, see: "FS - Function" */
        g_assert (item->callback != NULL || ((DiaMenu*)item->callback_data)->num_items > 0);
      else
        g_assert (item->callback == NULL && "Separator with callback?");

      g_assert ((item->active & ~(DIAMENU_ACTIVE|DIAMENU_TOGGLE|DIAMENU_TOGGLE_ON)) == 0);

      /* if we have a callback active, call it */
      if (item->callback && (item->active & DIAMENU_ACTIVE))
      {
	ObjectChange *change;

	/* g_test_message() does not show normally */
	g_test_message ("\n\tCalling '%s'...", item->text);
	change = (item->callback)(o, &from, item->callback_data);
	if (!change) {
	  g_test_message ("Undo/redo missing: %s\n", item->text);
	} else {
	  /* Don't just call _object_change_free(change);
	   * For 'Convert to *' this will screw up (destroy) the object 
	   * at hand'. So revert first, afterwards destroy the change.
	   * The object parameter is deprecated, but still necessary!
	   */
	  (change->revert)(change, o);
#if 0
	  /* XXX: Even more needs to be done to keep sane objects, see object_change_revert()
	   * in app/undo.c. AFAICT this is only needed to compensate for orthconn_set_points()
	   * while that does not update the object itself (which it does nowadays).
	   */
	  {
	    /* Make sure object updates its data: */
	    Point p = o->position;
	    (o->ops->move)(o,&p);
	  }
#endif
	  _object_change_free(change);
	}
      }
    }
  }
  /* finally */
  o->ops->destroy (o);  
  g_free (o);
}

static void
_test_draw (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point from = {0, 0};
  DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
  /* using DiaPathRender for drawing internally */
  DiaObject *p;

  p = create_standard_path_from_object (o);
  if (p) /* play safe, maybe it can not be converted? */
    {
      const Rectangle *obb = dia_object_get_bounding_box (o);
      const Rectangle *pbb = dia_object_get_bounding_box (p);
      real epsilon = 0.2; /* XXX: smaller value needs longer exception list */

      /* Bounding boxes of these objects should be close, if not
       * this could be either some miscalculation within the object
       * implementation (update_data?) or some more generic problem
       * with DiaPathRenderer
       */
      if (!rectangle_in_rectangle (obb, pbb))
	{
#if 0
	  /* Generate exceptions list below with ./test-objects -q */
	  real ov = MAX(fabs (obb->top - pbb->top), fabs (obb->left - pbb->left));
	  ov = MAX(ov, fabs (obb->right - pbb->right));
	  ov = MAX(ov, fabs (obb->bottom - pbb->bottom));
	  if (ov >= epsilon)
	    g_printerr ("\t  else if (strcmp (type->name, \"%s\") == 0)\n"
		        "\t    epsilon = %.2g;\n", type->name, ov + 0.01);
#else
	  /* drawing _outside_ of objects's bounding box */
	  if (strcmp (type->name, "T-Junction") == 0)
	    epsilon = 0.2;
	  else if (strcmp (type->name, "Cisco - Edge Label Switch Router with NetFlow") == 0)
	    epsilon = 0.22;
	  else if (strcmp (type->name, "Cisco - SSL Terminator") == 0)
	    epsilon = 0.23;
	  else if (strcmp (type->name, "Cisco - VPN concentrator") == 0)
	    epsilon = 0.24;
	  else if (strcmp (type->name, "Cisco - End Office") == 0)
	    epsilon = 0.24;
	  else if (strcmp (type->name, "Cisco - Printer") == 0)
	    epsilon = 0.26;
	  else if (strcmp (type->name, "Circuit - Vertical Resistor") == 0)
	    epsilon = 0.26; /* win32: pass */
	  else if (strcmp (type->name, "Circuit - Horizontal Resistor") == 0)
	    epsilon = 0.26; /* win32: pass */
	  else if (strcmp (type->name, "Cisco - Location server") == 0)
	    epsilon = 0.27; /* win32: pass */
	  else if (strcmp (type->name, "Cisco - System controller") == 0)
	    epsilon = 0.27; /* win32: pass */
	  else if (strcmp (type->name, "Cisco - Pager") == 0)
	    epsilon = 0.28;
	  else if (strcmp (type->name, "Cisco - IAD router") == 0)
	    epsilon = 0.28;
	  else if (strcmp (type->name, "Cisco - Newton") == 0)
	    epsilon = 0.28;
	  else if (strcmp (type->name, "Cisco - Truck") == 0)
	    epsilon = 0.29;
	  else if (strcmp (type->name, "ER - Relationship") == 0)
	    epsilon = 0.29;
	  else if (strcmp (type->name, "Network - Base Station") == 0)
	    epsilon = 0.31; /* win32: pass */
	  else if (strcmp (type->name, "Cisco - Protocol Translator") == 0)
	    epsilon = 0.66; /* win32: 0.30 */
	  else if (strcmp (type->name, "Cisco - Cellular phone") == 0)
	    epsilon = 0.32; /* win32: pass */
	  else if (strcmp (type->name, "UML - Constraint") == 0)
	    epsilon = 0.33; /* win32: pass */
	  else if (strcmp (type->name, "UML - Message") == 0)
	    epsilon = 0.50; /* win32: 0.39 */
	  else if (strcmp (type->name, "Cisco - ICM") == 0)
	    epsilon = 0.34;
	  else if (strcmp (type->name, "Cisco - Access Gateway") == 0)
	    epsilon = 0.39; /* win32: pass */
	  else if (strcmp (type->name, "chemeng - SaT-floatinghead") == 0)
	    epsilon = 0.40;
	  else if (strcmp (type->name, "chemeng - kettle") == 0)
	    epsilon = 0.42;
	  else if (strcmp (type->name, "Cisco - NetRanger") == 0)
	    epsilon = 0.42; /* win32: pass */
	  else if (strcmp (type->name, "Cisco - Mac Woman") == 0)
	    epsilon = 0.47; /* win32: 0.43 */
	  else if (strcmp (type->name, "Pneum - press") == 0)
	    epsilon = 0.45; /* win32: 0.44 */
	  else if (strcmp (type->name, "Pneum - presspn") == 0)
	    epsilon = 0.44;
	  else if (strcmp (type->name, "Pneum - presshy") == 0)
	    epsilon = 0.44;
	  else if (strcmp (type->name, "Cisco - Optical Transport") == 0)
	    epsilon = 0.48; /* win32: 0.47 */
	  else if (strcmp (type->name, "Jackson - phenomenon") == 0)
	    epsilon = 0.51; /* osx: 0.39 */
	  else if (strcmp (type->name, "Cisco - Speaker") == 0)
	    epsilon = 0.58; /* win32: 0.57 */
	  else if (strcmp (type->name, "Cisco - 6705") == 0)
	    epsilon = 0.64;
	  else if (strcmp (type->name, "KAOS - mbr") == 0)
	    epsilon = 0.70; /* win32: 0.69 */
	  else if (strcmp (type->name, "FS - Flow") == 0)
	    epsilon = 0.73; /* osx: 0.58 */
	  else if (strcmp (type->name, "SADT - arrow") == 0)
	    epsilon = 0.75; /* win32: 0.74 */
	  else if (strcmp (type->name, "Network - WAN Connection") == 0)
	    epsilon = 0.86;
	  else if (strcmp (type->name, "Network - General Printer") == 0)
	    epsilon = 0.92;
	  else if (strcmp (type->name, "UML - Constraint") == 0)
	    epsilon = 1.1;
	  else if (strcmp (type->name, "Pneum - SEIJack") == 0)
	    epsilon = 1.1;
	  else if (strcmp (type->name, "Pneum - SEOJack") == 0)
	    epsilon = 1.1;
	  else if (strcmp (type->name, "Pneum - DEJack") == 0)
	    epsilon = 1.1; /* osx: 0.9 */
	  else if (strcmp (type->name, "SDL - Comment") == 0)
	    epsilon = 3.5; /* osx: 3.1 */

	  g_assert_cmpfloat (fabs (obb->top - pbb->top), <, epsilon);
	  g_assert_cmpfloat (fabs (obb->left - pbb->left), <, epsilon);
	  g_assert_cmpfloat (fabs (obb->right - pbb->right), <, epsilon);
	  g_assert_cmpfloat (fabs (obb->bottom - pbb->bottom), <, epsilon);
#endif
	}
      /* destroy path object */
      p->ops->destroy (p);
      g_free (p);
    }
  else
    {
      g_test_message ("SKIPPED (no path from %s)! ", type->name);
    }
  /* finally */
  o->ops->destroy (o);
  g_free (o);
}

static void
_test_distance_from (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point from = {0, 0};
  DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
  const Rectangle *ebox;
  Point center;
  real width, height;
  Point test;
  real outside = 0.01; /* tolerance value for being outside */

  /* This shall work for all objects so it does not check for full correctness,
   * but is currently tolerant enough for element and connection objects.
   * If it fails either the bounding calculation is bogus or distance_from method.
   */
  /* Outside of the enclosing (bounding) box can not be inside the object */
  ebox = dia_object_get_enclosing_box (o);
  center.x = (ebox->left + ebox->right) / 2;
  center.y = (ebox->top + ebox->bottom) / 2;
  width = ebox->right - ebox->left;
  height = ebox->bottom - ebox->top;

  /* Some custom objects still fail this check otherwise */
  if (   strcmp (type->name, "Civil - Gas Bottle") == 0
      || strcmp (type->name, "Cybernetics - l-sens") == 0)
    outside += 0.1;

  test.y = center.y;
  test.x = center.x - width/2 - outside;
  g_assert (o->ops->distance_from (o, &test) > 0 && "left");
  test.x = center.x + width/2 + outside;
  g_assert (o->ops->distance_from (o, &test) > 0 && "right");
  test.x = center.x;
  test.y = center.y - height/2 - outside;
  g_assert (o->ops->distance_from (o, &test) > 0 && "top");
  test.y = center.y + height/2 + outside;
  g_assert (o->ops->distance_from (o, &test) > 0 && "bottom");

  /* finally */
  o->ops->destroy (o);
  g_free (o);
}

#include "lib/prop_geomtypes.h" /* BezPointarrayProperty */

/* there is no v-table entry for Add/Delete (Corner|Segment)
 * so we have to search the object menu
 */
static ObjectChange *
_change_point (DiaObject *o, const gchar *verb, Point *pt)
{
  int i;
  ObjectMenuFunc omf = o->ops->get_object_menu;
  DiaMenu *menu = omf ? (omf)(o, pt) : NULL;
  /* strangely enough I found a crash with menu==NULL today ;) */
  int num_items = menu ? menu->num_items : 0;

  for (i = 0; i < num_items; ++i) {
    DiaMenuItem *item = &menu->items[i];

    if (item->text && strncmp (item->text, verb, strlen(verb)) == 0) {
      if (item->callback && (item->active & DIAMENU_ACTIVE))
	return (item->callback)(o, pt, item->callback_data);
    }
  }
  return NULL;
}


static Point
_bez_between (const BezPoint *a, const BezPoint *b)
{
  Point r = {
    ((a->type == BEZ_CURVE_TO ? a->p3.x : a->p1.x) + (b->type == BEZ_CURVE_TO ? b->p3.x : b->p1.x))/2,
    ((a->type == BEZ_CURVE_TO ? a->p3.y : a->p1.y) + (b->type == BEZ_CURVE_TO ? b->p3.y : b->p1.y))/2,
  };
  return r;
}

static void
_test_segments (gconstpointer user_data)
{
  const DiaObjectType *type = (const DiaObjectType *)user_data;
  Handle *h1 = NULL, *h2 = NULL;
  Point from = {0, 0};
  DiaObject *o = type->ops->create (&from, type->default_user_data, &h1, &h2);
  Property *prop;

  /* only few object support to add/remove objects, filter to these objects first */
  if ((prop = object_prop_by_name_type (o, "bez_points", PROP_TYPE_BEZPOINTARRAY)) != NULL) {
    /* get the points array to compare against */
    GArray *d1 = ((BezPointarrayProperty *)prop)->bezpointarray_data;
    /* add and delete some points */
    int n;
    for (n = 0; n < d1->len - 1; ++n) {
      ObjectChange *ch1, *ch2;
      from = _bez_between (&g_array_index(d1, BezPoint, n), &g_array_index(d1, BezPoint, n+1));
      if ((ch1 = _change_point (o, "Add ", &from)) != NULL) {
	int i;
	Property *prop2 = object_prop_by_name_type (o, "bez_points", PROP_TYPE_BEZPOINTARRAY);
	GArray *d2 = ((BezPointarrayProperty *)prop2)->bezpointarray_data;
	g_assert (d1->len == d2->len - 1);
	ch2 = _change_point (o, "Delete ", &from);
	prop2->ops->free (prop2);
	/* adding and deleting the same point shall lead to the initial state */
	prop2 = object_prop_by_name_type (o, "bez_points", PROP_TYPE_BEZPOINTARRAY);
	d2 = ((BezPointarrayProperty *)prop2)->bezpointarray_data;
	for (i = 0; i < d1->len; ++i) {
	  BezPoint *bp1 = &g_array_index(d1, BezPoint, i);
	  BezPoint *bp2 = &g_array_index(d2, BezPoint, i);
	  g_assert_cmpfloat (fabs (bp1->p1.x - bp2->p1.x), <, EPSILON); /* for all types of BezPoint */
	  g_assert_cmpfloat (fabs (bp1->p1.y - bp2->p1.y), <, EPSILON); /* - " - */
	  g_assert (bp1->type == bp2->type);
	  if (bp1->type != BEZ_CURVE_TO)
	    continue;
	  g_assert_cmpfloat (fabs (bp1->p2.x - bp2->p2.x), <, EPSILON);
	  g_assert_cmpfloat (fabs (bp1->p2.y - bp2->p2.y), <, EPSILON);
	  g_assert_cmpfloat (fabs (bp1->p3.x - bp2->p3.x), <, EPSILON);
	  g_assert_cmpfloat (fabs (bp1->p3.y - bp2->p3.y), <, EPSILON);
	}
	prop2->ops->free (prop2);
	/* Check if undo is reconstructing the object, too */
	(ch2->revert)(ch2, o);
	_object_change_free(ch2);
	(ch1->revert)(ch1, o);
	_object_change_free(ch1);
	prop2 = object_prop_by_name_type (o, "bez_points", PROP_TYPE_BEZPOINTARRAY);
	d2 = ((BezPointarrayProperty *)prop2)->bezpointarray_data;
	for (i = 0; i < d1->len; ++i) {
	  BezPoint *bp1 = &g_array_index(d1, BezPoint, i);
	  BezPoint *bp2 = &g_array_index(d2, BezPoint, i);
	  g_assert_cmpfloat (fabs (bp1->p1.x - bp2->p1.x), <, EPSILON); /* for all types of BezPoint */
	  g_assert_cmpfloat (fabs (bp1->p1.y - bp2->p1.y), <, EPSILON); /* - " - */
	  g_assert (bp1->type == bp2->type);
	  if (bp1->type != BEZ_CURVE_TO)
	    continue;
	  g_assert_cmpfloat (fabs (bp1->p2.x - bp2->p2.x), <, EPSILON);
	  g_assert_cmpfloat (fabs (bp1->p2.y - bp2->p2.y), <, EPSILON);
	  g_assert_cmpfloat (fabs (bp1->p3.x - bp2->p3.x), <, EPSILON);
	  g_assert_cmpfloat (fabs (bp1->p3.y - bp2->p3.y), <, EPSILON);
	}
	prop2->ops->free (prop2);
      }
    }
  } else if ((prop = object_prop_by_name_type (o, "poly_points", PROP_TYPE_POINTARRAY)) != NULL) {
    /* ToDo: the assumption does not hold for "orth_points", check if it should.  */
    /* get the points array to compare against */
    GArray *d1 = ((PointarrayProperty *)prop)->pointarray_data;
    /* add and delete some points */
    int n;
    for (n = 0; n < d1->len - 1; ++n) {
      ObjectChange *ch1, *ch2;
      from.x = (g_array_index(d1, Point, n).x + g_array_index(d1, Point, n+1).x) / 2;
      from.y = (g_array_index(d1, Point, n).y + g_array_index(d1, Point, n+1).y) / 2;
      if ((ch1 = _change_point (o, "Add ", &from)) != NULL) {
	int i;
	GArray *d2;
	Property *prop2 = object_prop_by_name_type (o, "poly_points", PROP_TYPE_POINTARRAY);
	d2 = ((PointarrayProperty *)prop2)->pointarray_data;
	g_assert (d1->len == d2->len - 1);
	ch2 = _change_point (o, "Delete ", &from);
	prop2->ops->free (prop2);
	/* adding and deleting the same point shall lead to the initial state */
	prop2 = object_prop_by_name_type (o, "poly_points", PROP_TYPE_POINTARRAY);
	d2 = ((PointarrayProperty *)prop2)->pointarray_data;
	for (i = 0; i < d1->len; ++i) {
	  Point p1 = g_array_index(d1, Point, i);
	  Point p2 = g_array_index(d2, Point, i);
	  g_assert_cmpfloat (fabs (p1.x - p2.x), <, EPSILON);
	  g_assert_cmpfloat (fabs (p1.y - p2.y), <, EPSILON);
	}
	prop2->ops->free (prop2);
	/* Check if undo is reconstructing the object, too */
	(ch2->revert)(ch2, o);
	_object_change_free(ch2);
	(ch1->revert)(ch1, o);
	_object_change_free(ch1);
	prop2 = object_prop_by_name_type (o, "poly_points", PROP_TYPE_POINTARRAY);
	d2 = ((PointarrayProperty *)prop2)->pointarray_data;
	for (i = 0; i < d1->len; ++i) {
	  Point p1 = g_array_index(d1, Point, i);
	  Point p2 = g_array_index(d2, Point, i);
	  g_assert_cmpfloat (fabs (p1.x - p2.x), <, EPSILON);
	  g_assert_cmpfloat (fabs (p1.y - p2.y), <, EPSILON);
	}
	prop2->ops->free (prop2);
      }
    }
  } else {
    g_test_message ("n.a. ");
  }
  if (prop)
    prop->ops->free (prop);
  /* finally */
  o->ops->destroy (o);
  g_free (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, "Copy");
  g_test_add_data_func (testpath, type, _test_copy);
  g_free (testpath);

  testpath = g_strdup_printf ("%s/%s/%s", base, name, "Movement");
  g_test_add_data_func (testpath, type, _test_movement);
  g_free (testpath);

  testpath = g_strdup_printf ("%s/%s/%s", base, name, "Change");
  g_test_add_data_func (testpath, type, _test_change);
  g_free (testpath);
  
  testpath = g_strdup_printf ("%s/%s/%s", base, name, "MoveHandle");
  g_test_add_data_func (testpath, type, _test_move_handle);
  g_free (testpath);

  testpath = g_strdup_printf ("%s/%s/%s", base, name, "ConnectionPoints");
  g_test_add_data_func (testpath, type, _test_connectionpoint_consistency);
  g_free (testpath);

  testpath = g_strdup_printf ("%s/%s/%s", base, name, "ObjectMenu");
  g_test_add_data_func (testpath, type, _test_object_menu);
  g_free (testpath);

  testpath = g_strdup_printf ("%s/%s/%s", base, name, "Draw");
  g_test_add_data_func (testpath, type, _test_draw);
  g_free (testpath);

  testpath = g_strdup_printf ("%s/%s/%s", base, name, "DistanceFrom");
  g_test_add_data_func (testpath, type, _test_distance_from);
  g_free (testpath);

  testpath = g_strdup_printf ("%s/%s/%s", base, name, "Segments");
  g_test_add_data_func (testpath, type, _test_segments);
  g_free (testpath);

  ++num_objects;
}

#ifdef G_OS_WIN32
#define Rectangle win32Rectangle
#include <windows.h>
#endif

int
main (int argc, char** argv)
{
  GList *plugins = NULL;
  int ret = 0;

#ifdef G_OS_WIN32
  /* No dialog if it fails, please. */
  SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
#endif

#if !GLIB_CHECK_VERSION(2,36,0)
  g_type_init ();
#endif
  /* not using gtk_test_init() means we can only test non-gtk facilities of objects */
  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
    {
      /* avoid loading objects/plug-ins form the users home directory */
      g_setenv ("HOME", "/tmp", TRUE);
      dia_register_plugins ();
    }
  plugins = dia_list_plugins ();
  g_assert (g_list_length (plugins) > 0);

  object_registry_foreach (_ot_item, "/Dia/Objects");

  ret = g_test_run ();
  g_printerr ("%d objects.\n", num_objects);

  return ret;
}

#ifdef _MSC_VER
int _matherr( struct _exception *except )
{
  const char *type;

#define CASE(x) case _ ##x : type=#x; break
  switch (except->type) {
  CASE(DOMAIN); 
  CASE(SING);
  CASE(UNDERFLOW);
  CASE(OVERFLOW);
  CASE(TLOSS);
  CASE(PLOSS);
  }
#undef CASE
  g_warning ("%s %s(%f, %f)", type, except->name, except->arg1, except->arg2);
  return 0;
}
#endif