Use new text accessors.
[geda-gaf/berndj.git] / libgeda / tests / visitnorecurse.c
blobc356a9f06f2c559c58c143a21d1c12448029f6d0
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 "L 46400 49000 47400 49000 3 9 9 9 -1 -1",
30 "", NULL
32 char prim_objs[] = "CL*";
34 enum visit_result
35 summarize_object(OBJECT *o_current, void *context)
37 char **control = context;
39 switch (**control) {
40 case 'f':
41 /* Failure is idempotent. */
42 break;
43 case '*':
44 /* Visiting more objects than expected. */
45 **control = 'f';
46 break;
47 default:
48 if (o_current->type == **control) {
49 /* Skip to next object. */
50 *(*control)++ = 'p';
51 } else {
52 /* Mark failure, and don't skip past the test. */
53 **control = 'f';
55 break;
58 if (o_current->type == OBJ_COMPLEX) {
59 return VISIT_RES_NORECURSE;
62 return VISIT_RES_OK;
65 int main()
67 TOPLEVEL *toplevel;
68 PAGE *page;
69 char *buf;
70 char *cursor = prim_objs;
72 libgeda_init(FALSE);
74 toplevel = s_toplevel_new();
75 toplevel->font_directory = "../../symbols/font";
76 page = s_page_new(toplevel, "test");
77 s_toplevel_goto_page(toplevel, page);
79 buf = g_strjoinv("\n", test_page);
80 o_read_buffer(toplevel, page->object_tail, buf, strlen(buf), "test");
81 g_free(buf);
83 s_visit_page(page, &summarize_object, &cursor, VISIT_PREFIX, 0);
85 fprintf(stderr, "prim_objs = %s\n", prim_objs);
86 return(!!strcmp(prim_objs, "pp*"));