1 /* Copyright (C) 2013-2020 Roland Lutz
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 static void assert_object_location_fails(xorn_revision_t rev
, xorn_object_t ob
)
24 static const xorn_object_t magic0
= (xorn_object_t
)0x1234;
25 static const unsigned int magic1
= 0x5678;
27 xorn_object_t attached_to
= magic0
;
28 unsigned int position
= magic1
;
30 assert(xorn_get_object_location(rev
, ob
, NULL
, NULL
) == -1);
32 assert(xorn_get_object_location(rev
, ob
, &attached_to
, NULL
) == -1);
33 assert(attached_to
== magic0
);
35 assert(xorn_get_object_location(rev
, ob
, NULL
, &position
) == -1);
36 assert(position
== magic1
);
38 assert(xorn_get_object_location(rev
, ob
, &attached_to
,
40 assert(attached_to
== magic0
);
41 assert(position
== magic1
);
44 static void assert_object_location(xorn_revision_t rev
, xorn_object_t ob
,
45 xorn_object_t assert_attached_to
,
46 unsigned int assert_position
)
48 xorn_object_t attached_to
;
49 unsigned int position
;
51 assert(xorn_get_object_location(rev
, ob
, NULL
, NULL
) == 0);
53 assert(xorn_get_object_location(rev
, ob
, &attached_to
, NULL
) == 0);
54 assert(attached_to
== assert_attached_to
);
56 assert(xorn_get_object_location(rev
, ob
, NULL
, &position
) == 0);
57 assert(position
== assert_position
);
62 assert(xorn_get_object_location(rev
, ob
, &attached_to
,
64 assert(attached_to
== assert_attached_to
);
65 assert(position
== assert_position
);
68 static void check_order(void)
70 xorn_revision_t rev0
, rev1
, rev2
, rev3
, rev4
;
71 xorn_object_t ob0
, ob1a
, ob1b
, ob2
;
72 struct xornsch_arc arc_data
;
74 setup(&rev0
, &rev1
, &rev2
, &rev3
, &ob0
, &ob1a
, &ob1b
);
76 assert_object_location_fails(rev0
, ob0
);
77 assert_object_location_fails(rev0
, ob1a
);
78 assert_object_location_fails(rev0
, ob1b
);
80 assert_object_location(rev1
, ob0
, NULL
, 0);
81 assert_object_location_fails(rev1
, ob1a
);
82 assert_object_location_fails(rev1
, ob1b
);
84 assert_object_location(rev2
, ob0
, NULL
, 0);
85 assert_object_location(rev2
, ob1a
, NULL
, 1);
86 assert_object_location(rev2
, ob1b
, NULL
, 2);
88 assert_object_location(rev3
, ob0
, NULL
, 0);
89 assert_object_location_fails(rev3
, ob1a
);
90 assert_object_location(rev3
, ob1b
, NULL
, 1);
92 rev4
= xorn_new_revision(rev3
);
94 memset(&arc_data
, 0, sizeof arc_data
);
95 assert(xornsch_set_arc_data(rev4
, ob1a
, &arc_data
, NULL
) == 0);
97 assert_object_location(rev4
, ob0
, NULL
, 0);
98 assert_object_location(rev4
, ob1a
, NULL
, 2);
99 assert_object_location(rev4
, ob1b
, NULL
, 1);
101 ob2
= xorn_copy_object(rev4
, rev1
, ob0
, NULL
);
104 assert_object_location(rev4
, ob0
, NULL
, 0);
105 assert_object_location(rev4
, ob1a
, NULL
, 2);
106 assert_object_location(rev4
, ob1b
, NULL
, 1);
107 assert_object_location(rev4
, ob2
, NULL
, 3);
109 assert(xorn_delete_object(rev4
, ob0
, NULL
) == 0);
111 assert_object_location_fails(rev4
, ob0
);
112 assert_object_location(rev4
, ob1a
, NULL
, 1);
113 assert_object_location(rev4
, ob1b
, NULL
, 0);
114 assert_object_location(rev4
, ob2
, NULL
, 2);
116 xorn_free_revision(rev4
);
117 xorn_free_revision(rev3
);
118 xorn_free_revision(rev2
);
119 xorn_free_revision(rev1
);
120 xorn_free_revision(rev0
);
123 static void check_attach(void)
126 xorn_object_t N
, a
, b
;
127 struct xornsch_net net_data
;
128 struct xornsch_text text_data
;
130 assert(rev
= xorn_new_revision(NULL
));
132 memset(&net_data
, 0, sizeof net_data
);
133 assert(N
= xornsch_add_net(rev
, &net_data
, NULL
));
135 memset(&text_data
, 0, sizeof text_data
);
136 assert(a
= xornsch_add_text(rev
, &text_data
, NULL
));
137 assert(b
= xornsch_add_text(rev
, &text_data
, NULL
));
139 assert_object_location(rev
, N
, _
, 0);
140 assert_object_location(rev
, a
, _
, 1);
141 assert_object_location(rev
, b
, _
, 2);
143 assert(xorn_relocate_object(rev
, a
, N
, _
, NULL
) == 0);
145 assert_object_location(rev
, N
, _
, 0);
146 assert_object_location(rev
, a
, N
, 0);
147 assert_object_location(rev
, b
, _
, 1);
149 assert(xorn_relocate_object(rev
, b
, N
, _
, NULL
) == 0);
151 assert_object_location(rev
, N
, _
, 0);
152 assert_object_location(rev
, a
, N
, 0);
153 assert_object_location(rev
, b
, N
, 1);
155 assert(xorn_relocate_object(rev
, b
, N
, a
, NULL
) == 0);
157 assert_object_location(rev
, N
, _
, 0);
158 assert_object_location(rev
, a
, N
, 1);
159 assert_object_location(rev
, b
, N
, 0);
161 assert(xorn_relocate_object(rev
, a
, _
, N
, NULL
) == 0);
163 assert_object_location(rev
, N
, _
, 1);
164 assert_object_location(rev
, a
, _
, 0);
165 assert_object_location(rev
, b
, N
, 0);
167 xorn_free_revision(rev
);