Use new text accessors.
[geda-gaf/berndj.git] / libgeda / tests / visitobject.c
blob76c0e37adb8a5282a5ffe4a9c13708d7f702636b
1 #include "config.h"
3 #include <glib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "libgeda_priv.h"
8 char const *test_page[] = {
9 "v 20080706 2",
10 "C 46400 48000 1 270 0 EMBEDDEDopamp.sym",
11 "[",
12 "P 600 1000 600 800 1 0 0",
13 "{",
14 "T 900 500 8 10 1 1 0 0 1",
15 "foo=bar",
16 "}",
17 "P 600 200 600 0 1 0 1",
18 "{",
19 "}",
20 "V 500 501 315 3 0 0 0 -1 -1 0 -1 -1 -1 -1 -1",
21 "L 600 200 400 400 3 0 0 0 -1 -1",
22 "L 600 800 400 600 3 0 0 0 -1 -1",
23 "L 400 700 400 300 3 0 0 0 -1 -1",
24 "L 400 500 184 500 3 0 0 0 -1 -1",
25 "L 600 200 564 272 3 0 0 0 -1 -1",
26 "L 600 200 528 236 3 0 0 0 -1 -1",
27 "L 528 236 564 272 3 0 0 0 -1 -1",
28 "]",
29 "", NULL
31 char prim_objs[] = "PTPVLLLLLLL*";
33 enum visit_result
34 summarize_object(OBJECT *o_current, void *context)
36 char **control = context;
38 switch (**control) {
39 case 'f':
40 /* Failure is idempotent. */
41 break;
42 case '*':
43 /* Visiting more objects than expected. */
44 **control = 'f';
45 break;
46 default:
47 if (o_current->type == **control) {
48 /* Skip to next object. */
49 *(*control)++ = 'p';
50 } else {
51 /* Mark failure, and don't skip past the test. */
52 **control = 'f';
54 break;
57 return VISIT_RES_OK;
60 int main()
62 TOPLEVEL *toplevel;
63 PAGE *page;
64 char *buf;
65 char *cursor = prim_objs;
67 libgeda_init(FALSE);
69 toplevel = s_toplevel_new();
70 toplevel->font_directory = "../../symbols/font";
71 page = s_page_new(toplevel, "test");
72 s_toplevel_goto_page(toplevel, page);
74 buf = g_strjoinv("\n", test_page);
75 o_read_buffer(toplevel, page->object_tail, buf, strlen(buf), "test");
76 g_free(buf);
78 s_visit_object(page->object_head->next, &summarize_object, &cursor,
79 VISIT_LINEAR, 1);
81 return(!!strcmp(prim_objs, "ppppppppppp*"));