diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-04 11:06:52 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-04 11:06:52 +0000 |
commit | 4371b0fcd9b50f78ca27ac48adf2f4663b2dfc9b (patch) | |
tree | 05c40696267088fa94cdb0a94b3c079b38ea8ed2 /src/peerstore/test_peerstore_api_store.c | |
parent | ef494e57d189e2b7c038104e44398d11026ff6a6 (diff) | |
download | gnunet-4371b0fcd9b50f78ca27ac48adf2f4663b2dfc9b.tar.gz gnunet-4371b0fcd9b50f78ca27ac48adf2f4663b2dfc9b.zip |
peerstore: indentation
Diffstat (limited to 'src/peerstore/test_peerstore_api_store.c')
-rw-r--r-- | src/peerstore/test_peerstore_api_store.c | 175 |
1 files changed, 74 insertions, 101 deletions
diff --git a/src/peerstore/test_peerstore_api_store.c b/src/peerstore/test_peerstore_api_store.c index 53ace3d4a..06ad34756 100644 --- a/src/peerstore/test_peerstore_api_store.c +++ b/src/peerstore/test_peerstore_api_store.c | |||
@@ -39,182 +39,155 @@ static char *val3 = "test_peerstore_api_store_val3--"; | |||
39 | 39 | ||
40 | int count = 0; | 40 | int count = 0; |
41 | 41 | ||
42 | int test3_cont2(void *cls, | 42 | int |
43 | struct GNUNET_PEERSTORE_Record *record, | 43 | test3_cont2 (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
44 | char *emsg) | ||
45 | { | 44 | { |
46 | if(NULL != emsg) | 45 | if (NULL != emsg) |
47 | return GNUNET_NO; | 46 | return GNUNET_NO; |
48 | if(NULL != record) | 47 | if (NULL != record) |
49 | { | 48 | { |
50 | GNUNET_assert((strlen(val3) + 1) == record->value_size); | 49 | GNUNET_assert ((strlen (val3) + 1) == record->value_size); |
51 | GNUNET_assert(0 == strcmp((char *)val3, (char *)record->value)); | 50 | GNUNET_assert (0 == strcmp ((char *) val3, (char *) record->value)); |
52 | count++; | 51 | count++; |
53 | return GNUNET_YES; | 52 | return GNUNET_YES; |
54 | } | 53 | } |
55 | GNUNET_assert(count == 1); | 54 | GNUNET_assert (count == 1); |
56 | ok = 0; | 55 | ok = 0; |
57 | GNUNET_PEERSTORE_disconnect(h, GNUNET_YES); | 56 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); |
58 | GNUNET_SCHEDULER_shutdown(); | 57 | GNUNET_SCHEDULER_shutdown (); |
59 | return GNUNET_YES; | 58 | return GNUNET_YES; |
60 | } | 59 | } |
61 | 60 | ||
61 | |||
62 | static void | 62 | static void |
63 | test3_cont(void *cls, int success) | 63 | test3_cont (void *cls, int success) |
64 | { | 64 | { |
65 | if(GNUNET_YES != success) | 65 | if (GNUNET_YES != success) |
66 | return; | 66 | return; |
67 | count = 0; | 67 | count = 0; |
68 | GNUNET_PEERSTORE_iterate(h, | 68 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, GNUNET_TIME_UNIT_SECONDS, |
69 | subsystem, | 69 | &test3_cont2, NULL); |
70 | &pid, | ||
71 | key, | ||
72 | GNUNET_TIME_UNIT_SECONDS, | ||
73 | &test3_cont2, | ||
74 | NULL); | ||
75 | } | 70 | } |
76 | 71 | ||
72 | |||
77 | /** | 73 | /** |
78 | * Replace the previous 2 records | 74 | * Replace the previous 2 records |
79 | */ | 75 | */ |
80 | static void | 76 | static void |
81 | test3() | 77 | test3 () |
82 | { | 78 | { |
83 | GNUNET_PEERSTORE_store(h, | 79 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val3, strlen (val3) + 1, |
84 | subsystem, | 80 | GNUNET_TIME_UNIT_FOREVER_ABS, |
85 | &pid, | 81 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, &test3_cont, |
86 | key, | 82 | NULL); |
87 | val3, | ||
88 | strlen(val3) + 1, | ||
89 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
90 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
91 | &test3_cont, | ||
92 | NULL); | ||
93 | } | 83 | } |
94 | 84 | ||
95 | int test2_cont2(void *cls, | 85 | |
96 | struct GNUNET_PEERSTORE_Record *record, | 86 | int |
97 | char *emsg) | 87 | test2_cont2 (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
98 | { | 88 | { |
99 | if(NULL != emsg) | 89 | if (NULL != emsg) |
100 | return GNUNET_NO; | 90 | return GNUNET_NO; |
101 | if(NULL != record) | 91 | if (NULL != record) |
102 | { | 92 | { |
103 | GNUNET_assert(((strlen(val1) + 1) == record->value_size) | 93 | GNUNET_assert (((strlen (val1) + 1) == record->value_size) || |
104 | || ((strlen(val2) + 1) == record->value_size)); | 94 | ((strlen (val2) + 1) == record->value_size)); |
105 | GNUNET_assert((0 == strcmp((char *)val1, (char *)record->value)) | 95 | GNUNET_assert ((0 == strcmp ((char *) val1, (char *) record->value)) || |
106 | || (0 == strcmp((char *)val2, (char *)record->value))); | 96 | (0 == strcmp ((char *) val2, (char *) record->value))); |
107 | count++; | 97 | count++; |
108 | return GNUNET_YES; | 98 | return GNUNET_YES; |
109 | } | 99 | } |
110 | GNUNET_assert(count == 2); | 100 | GNUNET_assert (count == 2); |
111 | count = 0; | 101 | count = 0; |
112 | test3(); | 102 | test3 (); |
113 | return GNUNET_YES; | 103 | return GNUNET_YES; |
114 | } | 104 | } |
115 | 105 | ||
106 | |||
116 | static void | 107 | static void |
117 | test2_cont(void *cls, int success) | 108 | test2_cont (void *cls, int success) |
118 | { | 109 | { |
119 | if(GNUNET_YES != success) | 110 | if (GNUNET_YES != success) |
120 | return; | 111 | return; |
121 | count = 0; | 112 | count = 0; |
122 | GNUNET_PEERSTORE_iterate(h, | 113 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, GNUNET_TIME_UNIT_SECONDS, |
123 | subsystem, | 114 | &test2_cont2, NULL); |
124 | &pid, | ||
125 | key, | ||
126 | GNUNET_TIME_UNIT_SECONDS, | ||
127 | &test2_cont2, | ||
128 | NULL); | ||
129 | } | 115 | } |
130 | 116 | ||
117 | |||
131 | /** | 118 | /** |
132 | * Test storing a second value with the same key | 119 | * Test storing a second value with the same key |
133 | */ | 120 | */ |
134 | void test2() | 121 | void |
122 | test2 () | ||
135 | { | 123 | { |
136 | GNUNET_PEERSTORE_store(h, | 124 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val2, strlen (val2) + 1, |
137 | subsystem, | 125 | GNUNET_TIME_UNIT_FOREVER_ABS, |
138 | &pid, | 126 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, &test2_cont, |
139 | key, | 127 | NULL); |
140 | val2, | ||
141 | strlen(val2) + 1, | ||
142 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
143 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | ||
144 | &test2_cont, | ||
145 | NULL); | ||
146 | } | 128 | } |
147 | 129 | ||
148 | int test1_cont2(void *cls, | 130 | |
149 | struct GNUNET_PEERSTORE_Record *record, | 131 | int |
150 | char *emsg) | 132 | test1_cont2 (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) |
151 | { | 133 | { |
152 | if(NULL != emsg) | 134 | if (NULL != emsg) |
153 | return GNUNET_NO; | 135 | return GNUNET_NO; |
154 | if(NULL != record) | 136 | if (NULL != record) |
155 | { | 137 | { |
156 | GNUNET_assert((strlen(val1) + 1) == record->value_size); | 138 | GNUNET_assert ((strlen (val1) + 1) == record->value_size); |
157 | GNUNET_assert(0 == strcmp((char *)val1, (char *)record->value)); | 139 | GNUNET_assert (0 == strcmp ((char *) val1, (char *) record->value)); |
158 | count++; | 140 | count++; |
159 | return GNUNET_YES; | 141 | return GNUNET_YES; |
160 | } | 142 | } |
161 | GNUNET_assert(count == 1); | 143 | GNUNET_assert (count == 1); |
162 | count = 0; | 144 | count = 0; |
163 | test2(); | 145 | test2 (); |
164 | return GNUNET_YES; | 146 | return GNUNET_YES; |
165 | } | 147 | } |
166 | 148 | ||
149 | |||
167 | static void | 150 | static void |
168 | test1_cont(void *cls, int success) | 151 | test1_cont (void *cls, int success) |
169 | { | 152 | { |
170 | if(GNUNET_YES != success) | 153 | if (GNUNET_YES != success) |
171 | return; | 154 | return; |
172 | count = 0; | 155 | count = 0; |
173 | GNUNET_PEERSTORE_iterate(h, | 156 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, GNUNET_TIME_UNIT_SECONDS, |
174 | subsystem, | 157 | &test1_cont2, NULL); |
175 | &pid, | ||
176 | key, | ||
177 | GNUNET_TIME_UNIT_SECONDS, | ||
178 | &test1_cont2, | ||
179 | NULL); | ||
180 | } | 158 | } |
181 | 159 | ||
160 | |||
182 | /** | 161 | /** |
183 | * Store a single record | 162 | * Store a single record |
184 | */ | 163 | */ |
185 | static void | 164 | static void |
186 | test1() | 165 | test1 () |
187 | { | 166 | { |
188 | GNUNET_PEERSTORE_store(h, | 167 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val1, strlen (val1) + 1, |
189 | subsystem, | 168 | GNUNET_TIME_UNIT_FOREVER_ABS, |
190 | &pid, | 169 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, &test1_cont, |
191 | key, | 170 | NULL); |
192 | val1, | ||
193 | strlen(val1) + 1, | ||
194 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
195 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
196 | &test1_cont, | ||
197 | NULL); | ||
198 | } | 171 | } |
199 | 172 | ||
173 | |||
200 | static void | 174 | static void |
201 | run (void *cls, | 175 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, |
202 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 176 | struct GNUNET_TESTING_Peer *peer) |
203 | struct GNUNET_TESTING_Peer *peer) | ||
204 | { | 177 | { |
205 | h = GNUNET_PEERSTORE_connect(cfg); | 178 | h = GNUNET_PEERSTORE_connect (cfg); |
206 | GNUNET_assert(NULL != h); | 179 | GNUNET_assert (NULL != h); |
207 | memset (&pid, 1, sizeof (pid)); | 180 | memset (&pid, 1, sizeof (pid)); |
208 | test1(); | 181 | test1 (); |
209 | } | 182 | } |
210 | 183 | ||
184 | |||
211 | int | 185 | int |
212 | main (int argc, char *argv[]) | 186 | main (int argc, char *argv[]) |
213 | { | 187 | { |
214 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | 188 | if (0 != |
215 | "peerstore", | 189 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", "peerstore", |
216 | "test_peerstore_api_data.conf", | 190 | "test_peerstore_api_data.conf", &run, NULL)) |
217 | &run, NULL)) | ||
218 | return 1; | 191 | return 1; |
219 | return ok; | 192 | return ok; |
220 | } | 193 | } |