aboutsummaryrefslogtreecommitdiff
path: root/src/hello/test_hello-uri.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-01-12 20:30:37 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-19 12:39:55 +0100
commitaf252f5c3d4e62f4db39bbc65f3eea4f853d04bc (patch)
tree616629ee96494f49469162563ee6c90424c871e9 /src/hello/test_hello-uri.c
parent3e3081cfd22f5dacbeaba2843131c4aec530b562 (diff)
downloadgnunet-af252f5c3d4e62f4db39bbc65f3eea4f853d04bc.tar.gz
gnunet-af252f5c3d4e62f4db39bbc65f3eea4f853d04bc.zip
-conclude hello-uri implementation and test
Diffstat (limited to 'src/hello/test_hello-uri.c')
-rw-r--r--src/hello/test_hello-uri.c176
1 files changed, 176 insertions, 0 deletions
diff --git a/src/hello/test_hello-uri.c b/src/hello/test_hello-uri.c
new file mode 100644
index 000000000..295c08ea3
--- /dev/null
+++ b/src/hello/test_hello-uri.c
@@ -0,0 +1,176 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file hello/test_hello-uri.c
22 * @brief test for helper library for handling URI-based HELLOs
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_signatures.h"
27#include "gnunet_hello_uri_lib.h"
28#include "gnunet_util_lib.h"
29
30
31/**
32 * Check for expected URIs.
33 *
34 * @param cls a `unsigned int*`, bitmask set to found URIs
35 * @param uri URI to check for
36 */
37static void
38check_uris (void *cls,
39 const char *uri)
40{
41 unsigned int *found = cls;
42
43 if (0 == strcmp (uri,
44 "test://address"))
45 *found |= 1;
46 else if (0 == strcmp (uri,
47 "test://more"))
48 *found |= 2;
49 else
50 *found = (unsigned int) -1;
51}
52
53
54int
55main (int argc,
56 char *argv[])
57{
58 struct GNUNET_PeerIdentity pid;
59 struct GNUNET_HELLO_Builder *b;
60 struct GNUNET_CRYPTO_EddsaPrivateKey priv;
61
62 GNUNET_log_setup ("test-hell-uri",
63 "WARNING",
64 NULL);
65 GNUNET_CRYPTO_eddsa_key_create (&priv);
66 GNUNET_CRYPTO_eddsa_key_get_public (&priv,
67 &pid.public_key);
68 b = GNUNET_HELLO_builder_new (&pid);
69 GNUNET_assert (GNUNET_SYSERR ==
70 GNUNET_HELLO_builder_add_address (b,
71 "invalid"));
72 GNUNET_assert (GNUNET_SYSERR ==
73 GNUNET_HELLO_builder_add_address (b,
74 "i%v://bla"));
75 GNUNET_assert (GNUNET_SYSERR ==
76 GNUNET_HELLO_builder_add_address (b,
77 "://empty"));
78 GNUNET_assert (GNUNET_OK ==
79 GNUNET_HELLO_builder_add_address (b,
80 "test://address"));
81 GNUNET_assert (GNUNET_NO ==
82 GNUNET_HELLO_builder_add_address (b,
83 "test://address"));
84 GNUNET_assert (GNUNET_OK ==
85 GNUNET_HELLO_builder_add_address (b,
86 "test://more"));
87 {
88 void *block;
89 size_t block_size = 0;
90 struct GNUNET_HELLO_Builder *b2;
91 struct GNUNET_PeerIdentity p2;
92 unsigned int found;
93
94 GNUNET_assert (GNUNET_NO ==
95 GNUNET_HELLO_builder_to_block (b,
96 &priv,
97 NULL,
98 &block_size));
99 GNUNET_assert (GNUNET_NO ==
100 GNUNET_HELLO_builder_to_block (b,
101 &priv,
102 NULL,
103 &block_size));
104 GNUNET_assert (0 != block_size);
105 block = GNUNET_malloc (block_size);
106 GNUNET_assert (GNUNET_OK ==
107 GNUNET_HELLO_builder_to_block (b,
108 &priv,
109 block,
110 &block_size));
111 b2 = GNUNET_HELLO_builder_from_block (block,
112 block_size);
113 GNUNET_free (block);
114 GNUNET_assert (NULL != b2);
115 found = 0;
116 GNUNET_HELLO_builder_iterate (b2,
117 &p2,
118 &check_uris,
119 &found);
120 GNUNET_assert (3 == found);
121 GNUNET_assert (0 ==
122 GNUNET_memcmp (&p2,
123 &pid));
124 GNUNET_HELLO_builder_free (b2);
125 }
126
127 {
128 char *url;
129 struct GNUNET_HELLO_Builder *b2;
130 struct GNUNET_PeerIdentity p2;
131 unsigned int found;
132
133 url = GNUNET_HELLO_builder_to_url (b,
134 &priv);
135 b2 = GNUNET_HELLO_builder_from_url (url);
136 GNUNET_free (url);
137 GNUNET_assert (NULL != b2);
138 found = 0;
139 GNUNET_HELLO_builder_iterate (b2,
140 &p2,
141 &check_uris,
142 &found);
143 GNUNET_assert (3 == found);
144 GNUNET_assert (0 ==
145 GNUNET_memcmp (&p2,
146 &pid));
147 GNUNET_HELLO_builder_free (b2);
148 }
149
150 {
151 struct GNUNET_MQ_Envelope *env;
152 struct GNUNET_HELLO_Builder *b2;
153 struct GNUNET_PeerIdentity p2;
154 unsigned int found;
155
156 env = GNUNET_HELLO_builder_to_env (b,
157 &priv);
158 b2 = GNUNET_HELLO_builder_from_msg (GNUNET_MQ_env_get_msg (env));
159 GNUNET_free (env);
160 GNUNET_assert (NULL != b2);
161 found = 0;
162 GNUNET_HELLO_builder_iterate (b2,
163 &p2,
164 &check_uris,
165 &found);
166 GNUNET_assert (3 == found);
167 GNUNET_assert (0 ==
168 GNUNET_memcmp (&p2,
169 &pid));
170 GNUNET_HELLO_builder_free (b2);
171 }
172
173
174 GNUNET_HELLO_builder_free (b);
175 return 0;
176}