netlist: Add `tedax' backend
[geda-gaf.git] / tests / storage / pointer.c
blobe4d8006ee6f33719a4258645c66dfb2856243b19
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 <xornstorage.h>
18 #include <assert.h>
19 #include <string.h>
21 static int refcnt0 = 0, refcnt1 = 0;
24 static void inc(int *val)
26 (*val)++;
29 static void dec(int *val)
31 (*val)--;
34 int main(void)
36 xorn_revision_t rev;
37 xorn_object_t ob0, ob1;
38 struct xornsch_component component_data;
39 struct xornsch_picture picture_data;
40 xorn_selection_t sel0, sel1;
42 assert(rev = xorn_new_revision(NULL));
44 memset(&component_data, 0, sizeof component_data);
45 component_data.symbol.ptr = &refcnt0;
46 component_data.symbol.incref = (void (*)(void *))inc;
47 component_data.symbol.decref = (void (*)(void *))dec;
49 assert(ob0 = xornsch_add_component(rev, &component_data, NULL));
50 assert(refcnt0 == 1);
52 memset(&picture_data, 0, sizeof picture_data);
53 picture_data.pixmap.ptr = &refcnt1;
54 picture_data.pixmap.incref = (void (*)(void *))inc;
55 picture_data.pixmap.decref = (void (*)(void *))dec;
57 assert(ob1 = xornsch_add_picture(rev, &picture_data, NULL));
58 assert(refcnt0 == 1);
59 assert(refcnt1 == 1);
61 assert(sel0 = xorn_select_all(rev));
62 assert(sel1 = xorn_copy_objects(rev, rev, sel0, NULL));
63 assert(refcnt0 != 0);
64 assert(refcnt1 != 0);
66 memset(&picture_data, 0, sizeof picture_data);
67 assert(xornsch_set_picture_data(rev, ob1, &picture_data, NULL) == 0);
68 assert(refcnt0 != 0);
69 assert(refcnt1 != 0);
71 assert(xorn_delete_selected_objects(rev, sel1, NULL) == 0);
72 assert(refcnt0 == 1);
73 assert(refcnt1 == 0);
74 xorn_free_selection(sel1);
75 xorn_free_selection(sel0);
77 xorn_free_revision(rev);
78 assert(refcnt0 == 0);
79 assert(refcnt1 == 0);
81 return 0;