2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file applications/fs/fsui/search_persistence_test.c
23 * @brief testcase for fsui download persistence for search
24 * @author Christian Grothoff
28 #include "gnunet_util.h"
29 #include "gnunet_fsui_lib.h"
31 #define DEBUG_VERBOSE GNUNET_NO
33 #define UPLOAD_PREFIX "/tmp/gnunet-fsui-search_persistence_test"
35 #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto FAILURE; }
37 static struct GNUNET_GE_Context *ectx;
39 static struct GNUNET_FSUI_Context *ctx;
40 static struct GNUNET_FSUI_SearchList *search;
41 static int have_error;
44 eventCallback (void *cls, const GNUNET_FSUI_Event * event)
48 case GNUNET_FSUI_search_suspended:
51 case GNUNET_FSUI_search_resumed:
53 printf ("Search resuming\n");
55 search = event->data.SearchResumed.sc.pos;
57 case GNUNET_FSUI_search_result:
59 printf ("Received search result\n");
62 case GNUNET_FSUI_upload_progress:
64 printf ("Upload is progressing (%llu/%llu)...\n",
65 event->data.UploadProgress.completed,
66 event->data.UploadProgress.total);
69 case GNUNET_FSUI_upload_completed:
71 printf ("Upload complete.\n");
74 case GNUNET_FSUI_unindex_progress:
76 printf ("Unindex is progressing (%llu/%llu)...\n",
77 event->data.UnindexProgress.completed,
78 event->data.UnindexProgress.total);
81 case GNUNET_FSUI_unindex_completed:
83 printf ("Unindex complete.\n");
86 case GNUNET_FSUI_unindex_error:
87 case GNUNET_FSUI_upload_error:
88 case GNUNET_FSUI_download_error:
89 fprintf (stderr, "Received ERROR: %d\n", event->type);
90 GNUNET_GE_BREAK (ectx, 0);
92 case GNUNET_FSUI_download_aborted:
94 printf ("Received download aborted event.\n");
97 case GNUNET_FSUI_unindex_suspended:
98 case GNUNET_FSUI_upload_suspended:
100 fprintf (stderr, "Received SUSPENDING: %d\n", event->type);
103 case GNUNET_FSUI_upload_started:
104 case GNUNET_FSUI_upload_stopped:
105 case GNUNET_FSUI_search_started:
106 case GNUNET_FSUI_search_aborted:
107 case GNUNET_FSUI_search_stopped:
108 case GNUNET_FSUI_search_update:
109 case GNUNET_FSUI_unindex_started:
110 case GNUNET_FSUI_unindex_stopped:
113 printf ("Unexpected event: %d\n", event->type);
119 #define FILESIZE (1024)
121 #define START_DAEMON 1
124 main (int argc, char *argv[])
130 struct GNUNET_ECRS_URI *uri = NULL;
137 struct GNUNET_GC_Configuration *cfg;
138 int suspendRestart = 0;
142 cfg = GNUNET_GC_create ();
143 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
145 GNUNET_GC_free (cfg);
149 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
150 GNUNET_GE_ASSERT (NULL, daemon > 0);
152 GNUNET_wait_for_daemon_running (NULL, cfg,
153 30 * GNUNET_CRON_SECONDS));
154 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
155 /* ACTUAL TEST CODE */
157 ctx = GNUNET_FSUI_start (NULL,
158 cfg, "search_persistence_test", 32, GNUNET_YES,
159 &eventCallback, NULL);
161 GNUNET_snprintf (keyword, 40, "+%s +%s", keywords[0], keywords[1]);
162 uri = GNUNET_ECRS_keyword_string_to_uri (ectx, keyword);
163 search = GNUNET_FSUI_search_start (ctx, 0, uri);
164 CHECK (search != NULL);
170 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
171 if ((suspendRestart > 0)
172 && (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 10) == 0))
176 printf ("Testing FSUI suspend-resume\n");
178 GNUNET_FSUI_stop (ctx); /* download possibly incomplete
179 at this point, thus testing resume */
180 CHECK (search == NULL);
181 ctx = GNUNET_FSUI_start (NULL,
183 "search_persistence_test", 32, GNUNET_YES,
184 &eventCallback, NULL);
186 printf ("Resumed...\n");
191 if (GNUNET_shutdown_test () == GNUNET_YES)
194 GNUNET_FSUI_search_abort (search);
195 GNUNET_FSUI_search_stop (search);
197 /* END OF TEST CODE */
200 GNUNET_FSUI_stop (ctx);
202 GNUNET_ECRS_uri_destroy (uri);
205 GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon));
207 GNUNET_GC_free (cfg);
210 return (ok == GNUNET_YES) ? 0 : 1;
213 /* end of search_persistence_test.c */