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>
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
,
30 xorn_object_t ob0
, ob1
;
31 xorn_selection_t sel0
, sel1
;
33 xorn_error_t expected_err
= expected_result
34 ? NO_ERROR
: xorn_error_revision_not_transient
;
37 ob0
= xornsch_add_line(rev
, &line_data
, &err
);
38 assert((ob0
!= NULL
) == expected_result
);
39 assert(err
== expected_err
);
42 assert((xornsch_set_box_data(rev
, existing_ob
, &box_data
, &err
) == 0)
44 assert(err
== expected_err
);
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
;
53 assert((xorn_delete_object(rev
, del_ob
, &err
) == 0)
55 assert(err
== expected_err
);
56 assert(xorn_object_exists_in_revision(rev
, del_ob
)
59 sel0
= xorn_select_all(rev
);
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
);
69 assert((xorn_delete_selected_objects(rev
, sel0
, &err
) == 0)
71 assert(err
== expected_err
);
72 assert(xorn_object_exists_in_revision(rev
, existing_ob
)
74 xorn_free_selection(sel0
);
79 xorn_revision_t rev0
, rev1
, rev2
;
82 memset(&line_data
, 0, sizeof line_data
);
88 line_data
.line
.width
= 1;
90 memset(&box_data
, 0, sizeof box_data
);
96 box_data
.line
.width
= 1;
98 rev0
= xorn_new_revision(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
);
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
);