aboutsummaryrefslogtreecommitdiff
path: root/src/regex/test_regex_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-25 18:07:22 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-25 18:08:27 +0200
commit7da98cf076e9c5101244dfbbf8c3ddff045d298e (patch)
treedb4b4b28d0864cf5f7d424c40f1e7f4d945ff726 /src/regex/test_regex_api.c
parentb96052f1d3b8bb05f1868bd809fcb6e4f6569a4c (diff)
downloadgnunet-7da98cf076e9c5101244dfbbf8c3ddff045d298e.tar.gz
gnunet-7da98cf076e9c5101244dfbbf8c3ddff045d298e.zip
integrate dnsparser and dnsstub and tun with libgnunetutil
Diffstat (limited to 'src/regex/test_regex_api.c')
-rw-r--r--src/regex/test_regex_api.c127
1 files changed, 0 insertions, 127 deletions
diff --git a/src/regex/test_regex_api.c b/src/regex/test_regex_api.c
deleted file mode 100644
index a08e2ed6d..000000000
--- a/src/regex/test_regex_api.c
+++ /dev/null
@@ -1,127 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero 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.
9
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.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18/**
19 * @file regex/test_regex_api.c
20 * @brief base test case for regex api (and DHT functions)
21 * @author Christian Grothoff
22 */
23#include "platform.h"
24#include "gnunet_util_lib.h"
25#include "gnunet_testing_lib.h"
26#include "gnunet_regex_service.h"
27
28
29/**
30 * How long until we really give up on a particular testcase portion?
31 */
32#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
33
34/**
35 * How long until we give up on any particular operation (and retry)?
36 */
37#define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
38
39
40static struct GNUNET_REGEX_Announcement *a;
41
42static struct GNUNET_REGEX_Search *s;
43
44static int ok = 1;
45
46static struct GNUNET_SCHEDULER_Task *die_task;
47
48
49static void
50end (void *cls)
51{
52 die_task = NULL;
53 GNUNET_REGEX_announce_cancel (a);
54 a = NULL;
55 GNUNET_REGEX_search_cancel (s);
56 s = NULL;
57 ok = 0;
58}
59
60
61static void
62end_badly ()
63{
64 die_task = NULL;
65 FPRINTF (stderr, "%s", "Testcase failed (timeout).\n");
66 GNUNET_REGEX_announce_cancel (a);
67 a = NULL;
68 GNUNET_REGEX_search_cancel (s);
69 s = NULL;
70 ok = 1;
71}
72
73
74/**
75 * Search callback function, invoked for every result that was found.
76 *
77 * @param cls Closure provided in GNUNET_REGEX_search.
78 * @param id Peer providing a regex that matches the string.
79 * @param get_path Path of the get request.
80 * @param get_path_length Lenght of get_path.
81 * @param put_path Path of the put request.
82 * @param put_path_length Length of the put_path.
83 */
84static void
85found_cb (void *cls,
86 const struct GNUNET_PeerIdentity *id,
87 const struct GNUNET_PeerIdentity *get_path,
88 unsigned int get_path_length,
89 const struct GNUNET_PeerIdentity *put_path,
90 unsigned int put_path_length)
91{
92 GNUNET_SCHEDULER_cancel (die_task);
93 die_task =
94 GNUNET_SCHEDULER_add_now (&end, NULL);
95}
96
97
98static void
99run (void *cls,
100 const struct GNUNET_CONFIGURATION_Handle *cfg,
101 struct GNUNET_TESTING_Peer *peer)
102{
103 die_task =
104 GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT,
105 &end_badly, NULL);
106 a = GNUNET_REGEX_announce (cfg,
107 "my long prefix - hello world(0|1)*",
108 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
109 5),
110 1);
111 s = GNUNET_REGEX_search (cfg,
112 "my long prefix - hello world0101",
113 &found_cb, NULL);
114}
115
116
117int
118main (int argc, char *argv[])
119{
120 if (0 != GNUNET_TESTING_peer_run ("test-regex-api",
121 "test_regex_api_data.conf",
122 &run, NULL))
123 return 1;
124 return ok;
125}
126
127/* end of test_regex_api.c */