Use new text accessors.
[geda-gaf/berndj.git] / libgeda / tests / connections.c
blob1c2ce9692df1777c9795711f2eb2670664802bd5
1 #include "config.h"
3 #include <glib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "libgeda_priv.h"
8 char const *connections_test_data[] = {
9 "v 20080706 2",
10 "N 48200 45600 49300 45600 4",
11 "N 49300 45600 49300 46300 4",
12 "", NULL
15 static enum visit_result update_object(OBJECT *o, void *userdata)
17 PAGE *page = userdata;
19 /* This would also be a place to emit page signals. */
20 s_conn_update_object(page, o);
22 return VISIT_RES_OK;
25 int main()
27 TOPLEVEL *toplevel;
28 PAGE *page;
29 OBJECT *o_current, *net1, *net2;
30 CONN *conn;
31 char *buf;
33 libgeda_init(FALSE);
35 toplevel = s_toplevel_new();
36 page = s_page_new(toplevel, "test");
37 s_toplevel_goto_page(toplevel, page);
39 buf = g_strjoinv("\n", connections_test_data);
40 o_read_buffer(toplevel, toplevel->page_current->object_tail,
41 buf, strlen(buf), "test");
42 g_free(buf);
44 s_visit_page(page, &update_object, page, VISIT_ANY, 1);
46 /* Basic sanity checks. */
47 o_current = page->object_head->next;
48 if (o_current->type != OBJ_NET) {
49 return 1;
51 if (!o_current->next || o_current->next->type != OBJ_NET) {
52 return 1;
54 net1 = o_current;
55 net2 = o_current->next;
57 /* The real meat of this test: nets should be connected at first. */
59 if (!net1->conn_list || g_list_length(net1->conn_list) != 1) {
60 return 1;
63 conn = net1->conn_list->data;
64 if (conn->other_object != net2 ||
65 conn->type != CONN_ENDPOINT ||
66 conn->x != 49300 || conn->y != 45600 ||
67 conn->whichone != GRIP_2 ||
68 conn->other_whichone != GRIP_1) {
69 return 1;
72 if (!net2->conn_list || g_list_length(net2->conn_list) != 1) {
73 return 1;
75 conn = net2->conn_list->data;
76 if (conn->other_object != net1 ||
77 conn->type != CONN_ENDPOINT ||
78 conn->x != 49300 || conn->y != 45600 ||
79 conn->whichone != GRIP_1 ||
80 conn->other_whichone != GRIP_2) {
81 return 1;
84 /* And then the connection must break. */
85 s_basic_move_grip(net1, GRIP_2, 49200, 45600);
86 s_conn_update_object(page, net1);
88 if (net1->conn_list || net2->conn_list) {
89 return 1;
92 return 0;