diff options
Diffstat (limited to 'src/statistics/test_statistics_api.c')
-rw-r--r-- | src/statistics/test_statistics_api.c | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index 0c7bb3488..41f1ef562 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2012 GNUnet e.V. | 3 | Copyright (C) 2009, 2012, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -29,6 +29,21 @@ | |||
29 | 29 | ||
30 | static struct GNUNET_STATISTICS_Handle *h; | 30 | static struct GNUNET_STATISTICS_Handle *h; |
31 | 31 | ||
32 | static struct GNUNET_STATISTICS_GetHandle *g; | ||
33 | |||
34 | |||
35 | static void | ||
36 | do_shutdown () | ||
37 | { | ||
38 | if (NULL != g) | ||
39 | { | ||
40 | GNUNET_STATISTICS_get_cancel (g); | ||
41 | g = NULL; | ||
42 | } | ||
43 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | ||
44 | h = NULL; | ||
45 | } | ||
46 | |||
32 | 47 | ||
33 | static int | 48 | static int |
34 | check_1 (void *cls, | 49 | check_1 (void *cls, |
@@ -96,7 +111,8 @@ next_fin (void *cls, | |||
96 | { | 111 | { |
97 | int *ok = cls; | 112 | int *ok = cls; |
98 | 113 | ||
99 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 114 | g = NULL; |
115 | GNUNET_SCHEDULER_shutdown (); | ||
100 | GNUNET_assert (success == GNUNET_OK); | 116 | GNUNET_assert (success == GNUNET_OK); |
101 | *ok = 0; | 117 | *ok = 0; |
102 | } | 118 | } |
@@ -105,6 +121,7 @@ next_fin (void *cls, | |||
105 | static void | 121 | static void |
106 | next (void *cls, int success) | 122 | next (void *cls, int success) |
107 | { | 123 | { |
124 | g = NULL; | ||
108 | GNUNET_assert (success == GNUNET_OK); | 125 | GNUNET_assert (success == GNUNET_OK); |
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
110 | "Issuing GET request\n"); | 127 | "Issuing GET request\n"); |
@@ -122,15 +139,23 @@ run (void *cls, | |||
122 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 139 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
123 | { | 140 | { |
124 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); | 141 | h = GNUNET_STATISTICS_create ("test-statistics-api", cfg); |
142 | if (NULL == h) | ||
143 | { | ||
144 | GNUNET_break (0); | ||
145 | return; | ||
146 | } | ||
147 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
148 | NULL); | ||
125 | GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); | 149 | GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO); |
126 | GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); | 150 | GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO); |
127 | GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); | 151 | GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO); |
128 | GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); | 152 | GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES); |
129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n"); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
154 | "Issuing GET request\n"); | ||
130 | GNUNET_break (NULL != | 155 | GNUNET_break (NULL != |
131 | GNUNET_STATISTICS_get (h, NULL, "test-1", | 156 | (g = GNUNET_STATISTICS_get (h, NULL, "test-1", |
132 | &next, | 157 | &next, |
133 | &check_1, cls)); | 158 | &check_1, cls))); |
134 | } | 159 | } |
135 | 160 | ||
136 | 161 | ||
@@ -142,11 +167,13 @@ run_more (void *cls, | |||
142 | { | 167 | { |
143 | h = GNUNET_STATISTICS_create ("test-statistics-api", | 168 | h = GNUNET_STATISTICS_create ("test-statistics-api", |
144 | cfg); | 169 | cfg); |
170 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
171 | NULL); | ||
145 | GNUNET_break (NULL != | 172 | GNUNET_break (NULL != |
146 | GNUNET_STATISTICS_get (h, NULL, | 173 | (g = GNUNET_STATISTICS_get (h, NULL, |
147 | "test-3", | 174 | "test-3", |
148 | &next_fin, | 175 | &next_fin, |
149 | &check_3, cls)); | 176 | &check_3, cls))); |
150 | } | 177 | } |
151 | 178 | ||
152 | 179 | ||