1 #include <beagle/beagle.h>
5 test_daemon_information (BeagleClient
*client
)
7 BeagleDaemonInformationRequest
*request
;
8 BeagleResponse
*response
;
10 request
= beagle_daemon_information_request_new ();
11 response
= beagle_client_send_request (client
, BEAGLE_REQUEST (request
), NULL
);
13 g_object_unref (request
);
14 g_object_unref (response
);
16 g_print ("Beagle version: %s\n", beagle_daemon_information_response_get_version (BEAGLE_DAEMON_INFORMATION_RESPONSE (response
)));
18 g_print ("%s\n", beagle_daemon_information_response_get_human_readable_status (BEAGLE_DAEMON_INFORMATION_RESPONSE (response
)));
23 test_shutdown (BeagleClient
*client
)
25 BeagleShutdownRequest
*request
;
26 BeagleResponse
*response
;
28 request
= beagle_shutdown_request_new ();
29 response
= beagle_client_send_request (client
, BEAGLE_REQUEST (request
), NULL
);
35 hits_added_cb (BeagleQuery
*query
, BeagleHitsAddedResponse
*response
, BeagleClient
*client
)
38 BeagleSnippetRequest
*snippet
;
40 hits
= beagle_hits_added_response_get_hits (response
);
41 snippet
= beagle_snippet_request_new ();
43 g_print ("%d\n", g_slist_length (beagle_query_get_stemmed_text (query
)));
45 beagle_snippet_request_set_query (snippet
, query
);
47 while (hits
!= NULL
) {
48 BeagleHit
*hit
= hits
->data
;
52 g_print ("added %s\n", beagle_hit_get_uri (hit
));
54 beagle_snippet_request_set_hit (snippet
, hit
);
56 resp
= beagle_client_send_request (client
, BEAGLE_REQUEST (snippet
), &err
);
58 g_print ("got error: %s\n",
64 g_print ("getting a snippet: %s\n",
65 beagle_snippet_response_get_snippet (BEAGLE_SNIPPET_RESPONSE (resp
)));
66 g_object_unref (resp
);
72 g_object_unref (snippet
);
77 hits_subtracted_cb (BeagleQuery
*query
, BeagleHitsSubtractedResponse
*response
)
81 uris
= beagle_hits_subtracted_response_get_uris (response
);
82 while (uris
!= NULL
) {
83 char *uri
= uris
->data
;
85 g_print ("removed: %s\n", uri
);
92 finished_cb (BeagleQuery
*query
, BeagleFinishedResponse
*response
, GMainLoop
*loop
)
94 g_print ("finished!\n");
95 g_main_loop_quit (loop
);
99 test_live_query (BeagleClient
*client
)
104 loop
= g_main_loop_new (NULL
, FALSE
);
106 query
= beagle_query_new ();
107 g_signal_connect (query
, "hits-added",
108 G_CALLBACK (hits_added_cb
), client
);
109 g_signal_connect (query
, "hits-subtracted",
110 G_CALLBACK (hits_subtracted_cb
), NULL
);
111 g_signal_connect (query
, "finished",
112 G_CALLBACK (finished_cb
), loop
);
114 beagle_query_add_text (query
, "gnome");
116 beagle_client_send_request_async (client
, BEAGLE_REQUEST (query
), NULL
);
118 g_main_loop_run (loop
);
119 g_print ("back from main loop!\n");
120 g_object_unref (query
);
125 test_indexer (BeagleClient
*client
)
127 BeagleIndexable
*indexable
;
128 BeagleProperty
*prop
;
129 BeagleIndexingServiceRequest
*request
;
131 indexable
= beagle_indexable_new ("uid:richard");
133 prop
= beagle_property_new ("sliff", "sloff");
134 beagle_indexable_add_property (indexable
, prop
);
136 request
= beagle_indexing_service_request_new ();
137 beagle_indexing_service_request_add (request
, indexable
);
138 beagle_client_send_request (client
, BEAGLE_REQUEST (request
), NULL
);
146 BeagleClient
*client
;
150 client
= beagle_client_new (NULL
);
152 g_print ("testing indexer\n");
153 test_indexer (client
);
155 g_print ("testing daemon information\n");
156 test_daemon_information (client
);
158 g_print ("testing live query\n");
159 test_live_query (client
);
161 g_print ("good bye!\n");
162 g_object_unref (client
);
164 /* test_shutdown (client);*/