diff options
Diffstat (limited to 'src/util/test_pseudonym.c')
-rw-r--r-- | src/util/test_pseudonym.c | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c index 0f68f9f05..dfdcbb1bb 100644 --- a/src/util/test_pseudonym.c +++ b/src/util/test_pseudonym.c | |||
@@ -48,10 +48,10 @@ iter (void *cls, | |||
48 | &id1, | 48 | &id1, |
49 | sizeof (GNUNET_HashCode))) && | 49 | sizeof (GNUNET_HashCode))) && |
50 | (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) | 50 | (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) |
51 | { | 51 | { |
52 | *ok = GNUNET_NO; | 52 | *ok = GNUNET_NO; |
53 | GNUNET_break (0); | 53 | GNUNET_break (0); |
54 | } | 54 | } |
55 | return GNUNET_OK; | 55 | return GNUNET_OK; |
56 | } | 56 | } |
57 | 57 | ||
@@ -62,25 +62,27 @@ noti_callback (void *cls, | |||
62 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 62 | const struct GNUNET_CONTAINER_MetaData *md, int rating) |
63 | { | 63 | { |
64 | int *ret = cls; | 64 | int *ret = cls; |
65 | |||
65 | (*ret)++; | 66 | (*ret)++; |
66 | return GNUNET_OK; | 67 | return GNUNET_OK; |
67 | } | 68 | } |
68 | 69 | ||
69 | static int | 70 | static int |
70 | fake_noti_callback (void *cls, | 71 | fake_noti_callback (void *cls, |
71 | const GNUNET_HashCode * | 72 | const GNUNET_HashCode * |
72 | pseudonym, | 73 | pseudonym, |
73 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 74 | const struct GNUNET_CONTAINER_MetaData *md, int rating) |
74 | { | 75 | { |
75 | int *ret = cls; | 76 | int *ret = cls; |
76 | (*ret)++; | 77 | |
77 | return GNUNET_OK; | 78 | (*ret)++; |
79 | return GNUNET_OK; | ||
78 | } | 80 | } |
79 | 81 | ||
80 | static int | 82 | static int |
81 | false_callback (void *cls, | 83 | false_callback (void *cls, |
82 | const GNUNET_HashCode *pseudonym, | 84 | const GNUNET_HashCode * pseudonym, |
83 | const struct GNUNET_CONTAINER_MetaData *md, int rating) | 85 | const struct GNUNET_CONTAINER_MetaData *md, int rating) |
84 | { | 86 | { |
85 | return GNUNET_OK; | 87 | return GNUNET_OK; |
86 | } | 88 | } |
@@ -102,11 +104,12 @@ main (int argc, char *argv[]) | |||
102 | char *name2; | 104 | char *name2; |
103 | char *name3; | 105 | char *name3; |
104 | char *noname; | 106 | char *noname; |
105 | int notiCount,fakenotiCount; | 107 | int notiCount, fakenotiCount; |
106 | int count; | 108 | int count; |
107 | static char m[1024 * 1024 * 10]; | 109 | static char m[1024 * 1024 * 10]; |
108 | memset (m, 'b', sizeof (m)); | 110 | |
109 | m[sizeof (m) - 1] = '\0'; | 111 | memset (m, 'b', sizeof (m)); |
112 | m[sizeof (m) - 1] = '\0'; | ||
110 | 113 | ||
111 | GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); | 114 | GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); |
112 | ok = GNUNET_YES; | 115 | ok = GNUNET_YES; |
@@ -114,31 +117,31 @@ main (int argc, char *argv[]) | |||
114 | (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); | 117 | (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); |
115 | cfg = GNUNET_CONFIGURATION_create (); | 118 | cfg = GNUNET_CONFIGURATION_create (); |
116 | if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) | 119 | if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) |
117 | { | 120 | { |
118 | GNUNET_CONFIGURATION_destroy (cfg); | 121 | GNUNET_CONFIGURATION_destroy (cfg); |
119 | GNUNET_break (0); | 122 | GNUNET_break (0); |
120 | return -1; | 123 | return -1; |
121 | } | 124 | } |
122 | notiCount = 0; | 125 | notiCount = 0; |
123 | fakenotiCount = 0; | 126 | fakenotiCount = 0; |
124 | count = 0; | 127 | count = 0; |
125 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, | 128 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, |
126 | &fake_noti_callback, &fakenotiCount); | 129 | &fake_noti_callback, |
127 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, | 130 | &fakenotiCount); |
128 | ¬i_callback, ¬iCount); | 131 | GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, |
132 | ¬iCount); | ||
129 | GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); | 133 | GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); |
130 | GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, &fakenotiCount); | 134 | GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, |
135 | &fakenotiCount); | ||
131 | 136 | ||
132 | /* ACTUAL TEST CODE */ | 137 | /* ACTUAL TEST CODE */ |
133 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); | 138 | old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); |
134 | meta = GNUNET_CONTAINER_meta_data_create (); | 139 | meta = GNUNET_CONTAINER_meta_data_create (); |
135 | GNUNET_CONTAINER_meta_data_insert (meta, | 140 | GNUNET_CONTAINER_meta_data_insert (meta, |
136 | "<test>", | 141 | "<test>", |
137 | EXTRACTOR_METATYPE_TITLE, | 142 | EXTRACTOR_METATYPE_TITLE, |
138 | EXTRACTOR_METAFORMAT_UTF8, | 143 | EXTRACTOR_METAFORMAT_UTF8, |
139 | "text/plain", | 144 | "text/plain", "test", strlen ("test") + 1); |
140 | "test", | ||
141 | strlen("test")+1); | ||
142 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); | 145 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); |
143 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); | 146 | GNUNET_PSEUDONYM_add (cfg, &id1, meta); |
144 | CHECK (notiCount == 1); | 147 | CHECK (notiCount == 1); |
@@ -152,13 +155,14 @@ main (int argc, char *argv[]) | |||
152 | CHECK (notiCount == 3); | 155 | CHECK (notiCount == 3); |
153 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); | 156 | newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); |
154 | CHECK (old < newVal); | 157 | CHECK (old < newVal); |
155 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, | 158 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, |
156 | "<test>", | 159 | "<test>", |
157 | EXTRACTOR_METATYPE_COMMENT, | 160 | EXTRACTOR_METATYPE_COMMENT, |
158 | EXTRACTOR_METAFORMAT_UTF8, | 161 | EXTRACTOR_METAFORMAT_UTF8, |
159 | "text/plain", | 162 | "text/plain", |
160 | m, | 163 | m, |
161 | strlen(m)+1)); | 164 | strlen (m) + |
165 | 1)); | ||
162 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); | 166 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); |
163 | GNUNET_PSEUDONYM_add (cfg, &id3, meta); | 167 | GNUNET_PSEUDONYM_add (cfg, &id3, meta); |
164 | name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3); | 168 | name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3); |
@@ -167,7 +171,7 @@ main (int argc, char *argv[]) | |||
167 | name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1); | 171 | name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1); |
168 | CHECK (name1 != NULL); | 172 | CHECK (name1 != NULL); |
169 | CHECK (0 != strcmp (name1, name2)); | 173 | CHECK (0 != strcmp (name1, name2)); |
170 | CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2)); | 174 | CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2)); |
171 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); | 175 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); |
172 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); | 176 | CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); |
173 | CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode))); | 177 | CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode))); |
@@ -192,7 +196,8 @@ FAILURE: | |||
192 | GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); | 196 | GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); |
193 | GNUNET_CONTAINER_meta_data_destroy (meta); | 197 | GNUNET_CONTAINER_meta_data_destroy (meta); |
194 | GNUNET_CONFIGURATION_destroy (cfg); | 198 | GNUNET_CONFIGURATION_destroy (cfg); |
195 | GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); | 199 | GNUNET_break (GNUNET_OK == |
200 | GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); | ||
196 | return (ok == GNUNET_YES) ? 0 : 1; | 201 | return (ok == GNUNET_YES) ? 0 : 1; |
197 | } | 202 | } |
198 | 203 | ||