diff options
Diffstat (limited to 'src/util/test_pseudonym.c')
-rw-r--r-- | src/util/test_pseudonym.c | 109 |
1 files changed, 70 insertions, 39 deletions
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c index 56159be1c..2586aadd0 100644 --- a/src/util/test_pseudonym.c +++ b/src/util/test_pseudonym.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2005--2013 Christian Grothoff (and other contributing authors) |
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 |
@@ -23,7 +23,6 @@ | |||
23 | * @brief testcase for pseudonym.c | 23 | * @brief testcase for pseudonym.c |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_common.h" | 27 | #include "gnunet_common.h" |
29 | #include "gnunet_container_lib.h" | 28 | #include "gnunet_container_lib.h" |
@@ -35,16 +34,17 @@ | |||
35 | 34 | ||
36 | static struct GNUNET_CONTAINER_MetaData *meta; | 35 | static struct GNUNET_CONTAINER_MetaData *meta; |
37 | 36 | ||
38 | static struct GNUNET_HashCode id1; | 37 | static struct GNUNET_PseudonymIdentifier id1; |
38 | |||
39 | 39 | ||
40 | static int | 40 | static int |
41 | iter (void *cls, const struct GNUNET_HashCode * pseudonym, | 41 | iter (void *cls, const struct GNUNET_PseudonymIdentifier * pseudonym, |
42 | const char *name, const char *unique_name, | 42 | const char *name, const char *unique_name, |
43 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 43 | const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) |
44 | { | 44 | { |
45 | int *ok = cls; | 45 | int *ok = cls; |
46 | 46 | ||
47 | if ((0 == memcmp (pseudonym, &id1, sizeof (struct GNUNET_HashCode))) && | 47 | if ((0 == memcmp (pseudonym, &id1, sizeof (struct GNUNET_PseudonymIdentifier))) && |
48 | (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) | 48 | (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) |
49 | { | 49 | { |
50 | *ok = GNUNET_NO; | 50 | *ok = GNUNET_NO; |
@@ -53,10 +53,11 @@ iter (void *cls, const struct GNUNET_HashCode * pseudonym, | |||
53 | return GNUNET_OK; | 53 | return GNUNET_OK; |
54 | } | 54 | } |
55 | 55 | ||
56 | |||
56 | static int | 57 | static int |
57 | noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym, | 58 | noti_callback (void *cls, const struct GNUNET_PseudonymIdentifier * pseudonym, |
58 | const char *name, const char *unique_name, | 59 | const char *name, const char *unique_name, |
59 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 60 | const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) |
60 | { | 61 | { |
61 | int *ret = cls; | 62 | int *ret = cls; |
62 | 63 | ||
@@ -64,10 +65,11 @@ noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym, | |||
64 | return GNUNET_OK; | 65 | return GNUNET_OK; |
65 | } | 66 | } |
66 | 67 | ||
68 | |||
67 | static int | 69 | static int |
68 | fake_noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym, | 70 | fake_noti_callback (void *cls, const struct GNUNET_PseudonymIdentifier * pseudonym, |
69 | const char *name, const char *unique_name, | 71 | const char *name, const char *unique_name, |
70 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 72 | const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) |
71 | { | 73 | { |
72 | int *ret = cls; | 74 | int *ret = cls; |
73 | 75 | ||
@@ -75,24 +77,30 @@ fake_noti_callback (void *cls, const struct GNUNET_HashCode * pseudonym, | |||
75 | return GNUNET_OK; | 77 | return GNUNET_OK; |
76 | } | 78 | } |
77 | 79 | ||
78 | static int | 80 | |
79 | false_callback (void *cls, const struct GNUNET_HashCode * pseudonym, | 81 | static void |
80 | const char *name, const char *unique_name, | 82 | create_pseu (struct GNUNET_PseudonymIdentifier *pseu) |
81 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | ||
82 | { | 83 | { |
83 | return GNUNET_OK; | 84 | struct GNUNET_PseudonymHandle *ph; |
85 | |||
86 | ph = GNUNET_PSEUDONYM_create (NULL); | ||
87 | GNUNET_PSEUDONYM_get_identifier (ph, pseu); | ||
88 | GNUNET_PSEUDONYM_destroy (ph); | ||
84 | } | 89 | } |
85 | 90 | ||
86 | int | 91 | |
87 | main (int argc, char *argv[]) | 92 | /** |
93 | * Testcase for meta data / ranking IO routines. | ||
94 | */ | ||
95 | static int | ||
96 | test_io () | ||
88 | { | 97 | { |
89 | int ok; | 98 | int ok; |
90 | struct GNUNET_HashCode rid1; | 99 | struct GNUNET_PseudonymIdentifier rid1; |
91 | struct GNUNET_HashCode id2; | 100 | struct GNUNET_PseudonymIdentifier id2; |
92 | struct GNUNET_HashCode rid2; | 101 | struct GNUNET_PseudonymIdentifier rid2; |
93 | struct GNUNET_HashCode fid; | 102 | struct GNUNET_PseudonymIdentifier fid; |
94 | struct GNUNET_HashCode id3; | 103 | struct GNUNET_PseudonymIdentifier id3; |
95 | |||
96 | int old; | 104 | int old; |
97 | int newVal; | 105 | int newVal; |
98 | struct GNUNET_CONFIGURATION_Handle *cfg; | 106 | struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -104,8 +112,9 @@ main (int argc, char *argv[]) | |||
104 | char *noname; | 112 | char *noname; |
105 | int noname_is_a_dup; | 113 | int noname_is_a_dup; |
106 | int notiCount, fakenotiCount; | 114 | int notiCount, fakenotiCount; |
107 | int count; | ||
108 | static char m[1024 * 1024 * 10]; | 115 | static char m[1024 * 1024 * 10]; |
116 | struct GNUNET_PSEUDONYM_DiscoveryHandle *dh1; | ||
117 | struct GNUNET_PSEUDONYM_DiscoveryHandle *dh2; | ||
109 | 118 | ||
110 | memset (m, 'b', sizeof (m)); | 119 | memset (m, 'b', sizeof (m)); |
111 | m[sizeof (m) - 1] = '\0'; | 120 | m[sizeof (m) - 1] = '\0'; |
@@ -122,14 +131,11 @@ main (int argc, char *argv[]) | |||
122 | } | 131 | } |
123 | notiCount = 0; | 132 | notiCount = 0; |
124 | fakenotiCount = 0; | 133 | fakenotiCount = 0; |
125 | count = 0; | 134 | dh1 = GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, |
126 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, | 135 | &fakenotiCount); |
127 | &fakenotiCount); | 136 | dh2 = GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, |
128 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, | 137 | ¬iCount); |
129 | ¬iCount); | 138 | GNUNET_PSEUDONYM_discovery_callback_unregister (dh1); |
130 | GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); | ||
131 | GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, | ||
132 | &fakenotiCount); | ||
133 | 139 | ||
134 | /* ACTUAL TEST CODE */ | 140 | /* ACTUAL TEST CODE */ |
135 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); | 141 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); |
@@ -137,7 +143,7 @@ main (int argc, char *argv[]) | |||
137 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, | 143 | GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, |
138 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 144 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
139 | "test", strlen ("test") + 1); | 145 | "test", strlen ("test") + 1); |
140 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); | 146 | create_pseu (&id1); |
141 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); | 147 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); |
142 | CHECK (notiCount == 1); | 148 | CHECK (notiCount == 1); |
143 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); | 149 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); |
@@ -145,7 +151,7 @@ main (int argc, char *argv[]) | |||
145 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); | 151 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); |
146 | CHECK (old < newVal); | 152 | CHECK (old < newVal); |
147 | old = newVal; | 153 | old = newVal; |
148 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id2); | 154 | create_pseu (&id2); |
149 | GNUNET_PSEUDONYM_add (cfg, &id2, meta); | 155 | GNUNET_PSEUDONYM_add (cfg, &id2, meta); |
150 | CHECK (notiCount == 3); | 156 | CHECK (notiCount == 3); |
151 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); | 157 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); |
@@ -156,7 +162,7 @@ main (int argc, char *argv[]) | |||
156 | EXTRACTOR_METAFORMAT_UTF8, | 162 | EXTRACTOR_METAFORMAT_UTF8, |
157 | "text/plain", m, | 163 | "text/plain", m, |
158 | strlen (m) + 1)); | 164 | strlen (m) + 1)); |
159 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); | 165 | create_pseu (&id3); |
160 | GNUNET_PSEUDONYM_add (cfg, &id3, meta); | 166 | GNUNET_PSEUDONYM_add (cfg, &id3, meta); |
161 | GNUNET_PSEUDONYM_get_info (cfg, &id3, NULL, NULL, &name3, NULL); | 167 | GNUNET_PSEUDONYM_get_info (cfg, &id3, NULL, NULL, &name3, NULL); |
162 | CHECK (name3 != NULL); | 168 | CHECK (name3 != NULL); |
@@ -173,10 +179,10 @@ main (int argc, char *argv[]) | |||
173 | CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); | 179 | CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); |
174 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2_unique, &rid2)); | 180 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2_unique, &rid2)); |
175 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1_unique, &rid1)); | 181 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1_unique, &rid1)); |
176 | CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_HashCode))); | 182 | CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_PseudonymIdentifier))); |
177 | CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_HashCode))); | 183 | CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_PseudonymIdentifier))); |
178 | 184 | ||
179 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid); | 185 | create_pseu (&fid); |
180 | GNUNET_log_skip (1, GNUNET_NO); | 186 | GNUNET_log_skip (1, GNUNET_NO); |
181 | CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0)); | 187 | CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0)); |
182 | GNUNET_log_skip (0, GNUNET_NO); | 188 | GNUNET_log_skip (0, GNUNET_NO); |
@@ -195,7 +201,7 @@ main (int argc, char *argv[]) | |||
195 | GNUNET_free (noname); | 201 | GNUNET_free (noname); |
196 | /* END OF TEST CODE */ | 202 | /* END OF TEST CODE */ |
197 | FAILURE: | 203 | FAILURE: |
198 | GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); | 204 | GNUNET_PSEUDONYM_discovery_callback_unregister (dh2); |
199 | GNUNET_CONTAINER_meta_data_destroy (meta); | 205 | GNUNET_CONTAINER_meta_data_destroy (meta); |
200 | GNUNET_CONFIGURATION_destroy (cfg); | 206 | GNUNET_CONFIGURATION_destroy (cfg); |
201 | GNUNET_break (GNUNET_OK == | 207 | GNUNET_break (GNUNET_OK == |
@@ -203,4 +209,29 @@ FAILURE: | |||
203 | return (ok == GNUNET_YES) ? 0 : 1; | 209 | return (ok == GNUNET_YES) ? 0 : 1; |
204 | } | 210 | } |
205 | 211 | ||
212 | |||
213 | static int | ||
214 | test_crypto () | ||
215 | { | ||
216 | struct GNUNET_PseudonymHandle *ph; | ||
217 | |||
218 | ph = GNUNET_PSEUDONYM_create (NULL); | ||
219 | // FIXME: call sign, verify APIs... | ||
220 | GNUNET_PSEUDONYM_destroy (ph); | ||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | |||
225 | int | ||
226 | main (int argc, char *argv[]) | ||
227 | { | ||
228 | if (0 != test_io ()) | ||
229 | return 1; | ||
230 | if (0 != test_crypto ()) | ||
231 | return 1; | ||
232 | |||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | |||
206 | /* end of test_pseudoynm.c */ | 237 | /* end of test_pseudoynm.c */ |