2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
16 * @file regex/test_regex_api.c
17 * @brief base test case for regex api (and DHT functions)
18 * @author Christian Grothoff
21 #include "gnunet_util_lib.h"
22 #include "gnunet_testing_lib.h"
23 #include "gnunet_regex_service.h"
27 * How long until we really give up on a particular testcase portion?
29 #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
32 * How long until we give up on any particular operation (and retry)?
34 #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
37 static struct GNUNET_REGEX_Announcement *a;
39 static struct GNUNET_REGEX_Search *s;
43 static struct GNUNET_SCHEDULER_Task *die_task;
50 GNUNET_REGEX_announce_cancel (a);
52 GNUNET_REGEX_search_cancel (s);
62 FPRINTF (stderr, "%s", "Testcase failed (timeout).\n");
63 GNUNET_REGEX_announce_cancel (a);
65 GNUNET_REGEX_search_cancel (s);
72 * Search callback function, invoked for every result that was found.
74 * @param cls Closure provided in GNUNET_REGEX_search.
75 * @param id Peer providing a regex that matches the string.
76 * @param get_path Path of the get request.
77 * @param get_path_length Lenght of get_path.
78 * @param put_path Path of the put request.
79 * @param put_path_length Length of the put_path.
83 const struct GNUNET_PeerIdentity *id,
84 const struct GNUNET_PeerIdentity *get_path,
85 unsigned int get_path_length,
86 const struct GNUNET_PeerIdentity *put_path,
87 unsigned int put_path_length)
89 GNUNET_SCHEDULER_cancel (die_task);
91 GNUNET_SCHEDULER_add_now (&end, NULL);
97 const struct GNUNET_CONFIGURATION_Handle *cfg,
98 struct GNUNET_TESTING_Peer *peer)
101 GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
103 a = GNUNET_REGEX_announce (cfg,
104 "my long prefix - hello world(0|1)*",
105 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
108 s = GNUNET_REGEX_search (cfg,
109 "my long prefix - hello world0101",
115 main (int argc, char *argv[])
117 if (0 != GNUNET_TESTING_peer_run ("test-regex-api",
118 "test_regex_api_data.conf",
124 /* end of test_regex_api.c */