Merge fixes from branch 'xorn'
[geda-gaf.git] / xorn / tests / storage / transient.c
blobb84e2a88436e47e4d241c379f6b22259fd6c8e5c
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. */
17 #include <xornstorage.h>
18 #include <assert.h>
19 #include <string.h>
21 #define NO_ERROR ((xorn_error_t) -1)
23 static struct xornsch_line line_data;
24 static struct xornsch_box box_data;
27 static void try_modify(xorn_revision_t rev, xorn_object_t existing_ob,
28 bool expected_result)
30 xorn_object_t ob0, ob1;
31 xorn_selection_t sel0, sel1;
32 xorn_error_t err;
33 xorn_error_t expected_err = expected_result
34 ? NO_ERROR : xorn_error_revision_not_transient;
36 err = NO_ERROR;
37 ob0 = xornsch_add_line(rev, &line_data, &err);
38 assert((ob0 != NULL) == expected_result);
39 assert(err == expected_err);
41 err = NO_ERROR;
42 assert((xornsch_set_box_data(rev, existing_ob, &box_data, &err) == 0)
43 == expected_result);
44 assert(err == expected_err);
46 err = NO_ERROR;
47 ob1 = xorn_copy_object(rev, rev, existing_ob, &err);
48 assert((ob1 != NULL) == expected_result);
49 assert(err == expected_err);
51 xorn_object_t del_ob = expected_result ? ob1 : existing_ob;
52 err = NO_ERROR;
53 assert((xorn_delete_object(rev, del_ob, &err) == 0)
54 == expected_result);
55 assert(err == expected_err);
56 assert(xorn_object_exists_in_revision(rev, del_ob)
57 == !expected_result);
59 sel0 = xorn_select_all(rev);
60 assert(sel0 != NULL);
62 err = NO_ERROR;
63 sel1 = xorn_copy_objects(rev, rev, sel0, &err);
64 assert((sel1 != NULL) == expected_result);
65 assert(err == expected_err);
66 xorn_free_selection(sel1);
68 err = NO_ERROR;
69 assert((xorn_delete_selected_objects(rev, sel0, &err) == 0)
70 == expected_result);
71 assert(err == expected_err);
72 assert(xorn_object_exists_in_revision(rev, existing_ob)
73 == !expected_result);
74 xorn_free_selection(sel0);
77 int main(void)
79 xorn_revision_t rev0, rev1, rev2;
80 xorn_object_t ob;
82 memset(&line_data, 0, sizeof line_data);
83 line_data.pos.x = 0;
84 line_data.pos.y = 1;
85 line_data.size.x = 3;
86 line_data.size.y = 2;
87 line_data.color = 3;
88 line_data.line.width = 1;
90 memset(&box_data, 0, sizeof box_data);
91 box_data.pos.x = 1;
92 box_data.pos.y = 1;
93 box_data.size.x = 2;
94 box_data.size.y = 2;
95 box_data.color = 3;
96 box_data.line.width = 1;
98 rev0 = xorn_new_revision(NULL);
99 assert(rev0 != NULL);
100 assert(xorn_revision_is_transient(rev0) == true);
101 xorn_finalize_revision(rev0);
102 assert(xorn_revision_is_transient(rev0) == false);
104 rev1 = xorn_new_revision(rev0);
105 assert(rev1 != NULL);
106 assert(xorn_revision_is_transient(rev1) == true);
108 ob = xornsch_add_line(rev1, &line_data, NULL);
109 assert(ob != NULL);
111 xorn_finalize_revision(rev1);
112 assert(xorn_revision_is_transient(rev1) == false);
114 try_modify(rev1, ob, false);
116 rev2 = xorn_new_revision(rev1);
117 assert(rev2 != NULL);
118 assert(xorn_revision_is_transient(rev2) == true);
120 try_modify(rev2, ob, true);
122 xorn_finalize_revision(rev2);
123 assert(xorn_revision_is_transient(rev2) == false);
125 xorn_free_revision(rev2);
126 xorn_free_revision(rev1);
127 xorn_free_revision(rev0);
128 return 0;