netlist: Add `tedax' backend
[geda-gaf.git] / tests / storage / copy_object.c
blob9331597916c505cab9e60292db7e429bd8998525
1 /* Copyright (C) 2013-2017 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 "Setup.h"
18 #include <stdlib.h>
20 #define NO_ERROR ((xorn_error_t) -1)
23 int main(void)
25 xorn_revision_t rev0, rev1, rev2, rev3;
26 xorn_object_t ob0, ob1a, ob1b;
28 xorn_revision_t rev4;
29 xorn_object_t ob0copy;
30 xorn_error_t err;
32 xorn_object_t *objects;
33 size_t count;
35 setup(&rev0, &rev1, &rev2, &rev3, &ob0, &ob1a, &ob1b);
38 /* can't copy object which doesn't exist in source revision */
40 rev4 = xorn_new_revision(rev3);
41 assert(rev4 != NULL);
43 err = NO_ERROR;
44 ob0copy = xorn_copy_object(rev4, rev0, ob0, &err);
45 assert(ob0copy == NULL);
46 assert(err == xorn_error_object_doesnt_exist);
48 xorn_finalize_revision(rev4);
50 assert(xorn_get_objects(rev4, &objects, &count) == 0);
51 assert(objects != NULL);
52 assert(count == 2);
53 assert(objects[0] == ob0);
54 assert(objects[1] == ob1b);
55 free(objects);
57 xorn_free_revision(rev4);
60 /* can copy object otherwise */
62 rev4 = xorn_new_revision(rev3);
63 assert(rev4 != NULL);
65 err = NO_ERROR;
66 ob0copy = xorn_copy_object(rev4, rev1, ob0, &err);
67 assert(ob0copy != NULL);
68 assert(err == NO_ERROR);
70 xorn_finalize_revision(rev4);
72 assert(xorn_get_object_type(rev4, ob0copy) !=
73 xorn_get_object_type(rev4, ob0));
74 assert(xorn_get_object_type(rev4, ob0copy) ==
75 xorn_get_object_type(rev1, ob0));
77 assert(xorn_get_objects(rev4, &objects, &count) == 0);
78 assert(objects != NULL);
79 assert(count == 3);
80 assert(objects[0] == ob0);
81 assert(objects[1] == ob1b);
82 assert(objects[2] == ob0copy);
83 free(objects);
85 xorn_free_revision(rev4);
88 xorn_free_revision(rev3);
89 xorn_free_revision(rev2);
90 xorn_free_revision(rev1);
91 xorn_free_revision(rev0);
92 return 0;