diff options
Diffstat (limited to 'src/regex/test_regex_api.c')
-rw-r--r-- | src/regex/test_regex_api.c | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/src/regex/test_regex_api.c b/src/regex/test_regex_api.c index 2ee24800a..eaae8c682 100644 --- a/src/regex/test_regex_api.c +++ b/src/regex/test_regex_api.c | |||
@@ -31,12 +31,13 @@ | |||
31 | /** | 31 | /** |
32 | * How long until we really give up on a particular testcase portion? | 32 | * How long until we really give up on a particular testcase portion? |
33 | */ | 33 | */ |
34 | #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 600) | 34 | #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ |
35 | 600) | ||
35 | 36 | ||
36 | /** | 37 | /** |
37 | * How long until we give up on any particular operation (and retry)? | 38 | * How long until we give up on any particular operation (and retry)? |
38 | */ | 39 | */ |
39 | #define BASE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) | 40 | #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) |
40 | 41 | ||
41 | 42 | ||
42 | static struct GNUNET_REGEX_Announcement *a; | 43 | static struct GNUNET_REGEX_Announcement *a; |
@@ -49,25 +50,25 @@ static struct GNUNET_SCHEDULER_Task *die_task; | |||
49 | 50 | ||
50 | 51 | ||
51 | static void | 52 | static void |
52 | end(void *cls) | 53 | end (void *cls) |
53 | { | 54 | { |
54 | die_task = NULL; | 55 | die_task = NULL; |
55 | GNUNET_REGEX_announce_cancel(a); | 56 | GNUNET_REGEX_announce_cancel (a); |
56 | a = NULL; | 57 | a = NULL; |
57 | GNUNET_REGEX_search_cancel(s); | 58 | GNUNET_REGEX_search_cancel (s); |
58 | s = NULL; | 59 | s = NULL; |
59 | ok = 0; | 60 | ok = 0; |
60 | } | 61 | } |
61 | 62 | ||
62 | 63 | ||
63 | static void | 64 | static void |
64 | end_badly() | 65 | end_badly () |
65 | { | 66 | { |
66 | die_task = NULL; | 67 | die_task = NULL; |
67 | fprintf(stderr, "%s", "Testcase failed (timeout).\n"); | 68 | fprintf (stderr, "%s", "Testcase failed (timeout).\n"); |
68 | GNUNET_REGEX_announce_cancel(a); | 69 | GNUNET_REGEX_announce_cancel (a); |
69 | a = NULL; | 70 | a = NULL; |
70 | GNUNET_REGEX_search_cancel(s); | 71 | GNUNET_REGEX_search_cancel (s); |
71 | s = NULL; | 72 | s = NULL; |
72 | ok = 1; | 73 | ok = 1; |
73 | } | 74 | } |
@@ -84,44 +85,45 @@ end_badly() | |||
84 | * @param put_path_length Length of the put_path. | 85 | * @param put_path_length Length of the put_path. |
85 | */ | 86 | */ |
86 | static void | 87 | static void |
87 | found_cb(void *cls, | 88 | found_cb (void *cls, |
88 | const struct GNUNET_PeerIdentity *id, | 89 | const struct GNUNET_PeerIdentity *id, |
89 | const struct GNUNET_PeerIdentity *get_path, | 90 | const struct GNUNET_PeerIdentity *get_path, |
90 | unsigned int get_path_length, | 91 | unsigned int get_path_length, |
91 | const struct GNUNET_PeerIdentity *put_path, | 92 | const struct GNUNET_PeerIdentity *put_path, |
92 | unsigned int put_path_length) | 93 | unsigned int put_path_length) |
93 | { | 94 | { |
94 | GNUNET_SCHEDULER_cancel(die_task); | 95 | GNUNET_SCHEDULER_cancel (die_task); |
95 | die_task = | 96 | die_task = |
96 | GNUNET_SCHEDULER_add_now(&end, NULL); | 97 | GNUNET_SCHEDULER_add_now (&end, NULL); |
97 | } | 98 | } |
98 | 99 | ||
99 | 100 | ||
100 | static void | 101 | static void |
101 | run(void *cls, | 102 | run (void *cls, |
102 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 103 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
103 | struct GNUNET_TESTING_Peer *peer) | 104 | struct GNUNET_TESTING_Peer *peer) |
104 | { | 105 | { |
105 | die_task = | 106 | die_task = |
106 | GNUNET_SCHEDULER_add_delayed(TOTAL_TIMEOUT, | 107 | GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, |
107 | &end_badly, NULL); | 108 | &end_badly, NULL); |
108 | a = GNUNET_REGEX_announce(cfg, | 109 | a = GNUNET_REGEX_announce (cfg, |
109 | "my long prefix - hello world(0|1)*", | 110 | "my long prefix - hello world(0|1)*", |
110 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 111 | GNUNET_TIME_relative_multiply ( |
111 | 5), | 112 | GNUNET_TIME_UNIT_SECONDS, |
112 | 1); | 113 | 5), |
113 | s = GNUNET_REGEX_search(cfg, | 114 | 1); |
114 | "my long prefix - hello world0101", | 115 | s = GNUNET_REGEX_search (cfg, |
115 | &found_cb, NULL); | 116 | "my long prefix - hello world0101", |
117 | &found_cb, NULL); | ||
116 | } | 118 | } |
117 | 119 | ||
118 | 120 | ||
119 | int | 121 | int |
120 | main(int argc, char *argv[]) | 122 | main (int argc, char *argv[]) |
121 | { | 123 | { |
122 | if (0 != GNUNET_TESTING_peer_run("test-regex-api", | 124 | if (0 != GNUNET_TESTING_peer_run ("test-regex-api", |
123 | "test_regex_api_data.conf", | 125 | "test_regex_api_data.conf", |
124 | &run, NULL)) | 126 | &run, NULL)) |
125 | return 1; | 127 | return 1; |
126 | return ok; | 128 | return ok; |
127 | } | 129 | } |