Use new text accessors.
[geda-gaf/berndj.git] / libgeda / tests / searchobject.c
bloba4bf3df548b61212bb21e1ed9feab64b320f6f06
1 #include "config.h"
3 #include <glib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "libgeda_priv.h"
8 char const *symbol_data[] = {
9 "v 20031231 2",
10 "L 300 0 200 200 3 0 0 0 -1 -1",
11 "T 300 400 5 10 0 0 0 0 1",
12 "device=RESISTOR",
13 "P 900 100 750 100 1 0 0",
14 "{",
15 "T 800 150 5 8 0 1 0 0 1",
16 "pinnumber=2",
17 "}",
18 "P 0 100 152 100 1 0 0",
19 "{",
20 "T 100 150 5 8 0 1 0 0 1",
21 "pinnumber=1",
22 "}",
23 "L 201 200 150 100 3 0 0 0 -1 -1",
24 "T 200 300 8 10 0 1 0 0 1",
25 "refdes=R?",
26 "T 0 0 8 10 0 1 0 0 1",
27 "pins=2",
28 "", NULL
31 int main()
33 TOPLEVEL *toplevel;
34 PAGE *page;
35 OBJECT *o;
36 CLibSymbol *clib;
37 char *symbol_buf, *attrib_value;
39 libgeda_init(FALSE);
41 symbol_buf = g_strjoinv("\n", symbol_data);
42 s_clib_add_memory(symbol_buf, "resistor");
44 toplevel = s_toplevel_new();
45 page = s_page_new(toplevel, "test");
46 s_toplevel_goto_page(toplevel, page);
48 clib = s_clib_get_symbol_by_name("resistor");
50 o = o_complex_new(toplevel, 'C', WHITE, 100, 100, 0, 0, clib, "foo", 1);
51 g_free(symbol_buf);
53 attrib_value = o_attrib_search_object(o, "pinnumber", 0);
54 if (!attrib_value || strcmp(attrib_value, "2") != 0) {
55 printf("pinnumber[0] = %s\n", attrib_value ? attrib_value : "NULL");
56 return 1;
58 g_free(attrib_value);
60 attrib_value = o_attrib_search_object(o, "pinnumber", 2);
61 if (!attrib_value || strcmp(attrib_value, "1") != 0) {
62 printf("pinnumber[1] = %s\n", attrib_value ? attrib_value : "NULL");
63 return 1;
65 g_free(attrib_value);
67 attrib_value = o_attrib_search_object(o, "pinnumber", 4);
68 if (attrib_value) {
69 printf("pinnumber[2] = %s\n", attrib_value ? attrib_value : "NULL");
70 g_free(attrib_value);
71 return 1;
74 return 0;