aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/test_plugin_peerstore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-14 00:31:02 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-14 00:31:02 +0100
commit8d71f909cb22fbf6774e4042309a8eb133af3bfc (patch)
tree0efc19ac24a6521f927772364f1379154d2d0cad /src/peerstore/test_plugin_peerstore.c
parent6e01dc4d91d072e8e58ba0140fb7f4ddd5109358 (diff)
downloadgnunet-8d71f909cb22fbf6774e4042309a8eb133af3bfc.tar.gz
gnunet-8d71f909cb22fbf6774e4042309a8eb133af3bfc.zip
convert sqlite peerstore to using libgnunetsq
Diffstat (limited to 'src/peerstore/test_plugin_peerstore.c')
-rw-r--r--src/peerstore/test_plugin_peerstore.c127
1 files changed, 85 insertions, 42 deletions
diff --git a/src/peerstore/test_plugin_peerstore.c b/src/peerstore/test_plugin_peerstore.c
index 179e32b52..62c06be8e 100644
--- a/src/peerstore/test_plugin_peerstore.c
+++ b/src/peerstore/test_plugin_peerstore.c
@@ -36,6 +36,11 @@ static int ok;
36static const char *plugin_name; 36static const char *plugin_name;
37 37
38 38
39static struct GNUNET_PEERSTORE_PluginFunctions *psp;
40
41static struct GNUNET_PeerIdentity p1;
42
43
39/** 44/**
40 * Function called when the service shuts down. Unloads our namestore 45 * Function called when the service shuts down. Unloads our namestore
41 * plugin. 46 * plugin.
@@ -47,8 +52,12 @@ unload_plugin (struct GNUNET_PEERSTORE_PluginFunctions *api)
47{ 52{
48 char *libname; 53 char *libname;
49 54
50 GNUNET_asprintf (&libname, "libgnunet_plugin_peer_%s", plugin_name); 55 GNUNET_asprintf (&libname,
51 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); 56 "libgnunet_plugin_peer_%s",
57 plugin_name);
58 GNUNET_break (NULL ==
59 GNUNET_PLUGIN_unload (libname,
60 api));
52 GNUNET_free (libname); 61 GNUNET_free (libname);
53} 62}
54 63
@@ -65,12 +74,18 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
65 struct GNUNET_PEERSTORE_PluginFunctions *ret; 74 struct GNUNET_PEERSTORE_PluginFunctions *ret;
66 char *libname; 75 char *libname;
67 76
68 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' peer plugin\n"), 77 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
78 _("Loading `%s' peer plugin\n"),
69 plugin_name); 79 plugin_name);
70 GNUNET_asprintf (&libname, "libgnunet_plugin_peerstore_%s", plugin_name); 80 GNUNET_asprintf (&libname,
71 if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) 81 "libgnunet_plugin_peerstore_%s",
82 plugin_name);
83 if (NULL == (ret = GNUNET_PLUGIN_load (libname,
84 (void*) cfg)))
72 { 85 {
73 FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); 86 FPRINTF (stderr,
87 "Failed to load plugin `%s'!\n",
88 plugin_name);
74 GNUNET_free (libname); 89 GNUNET_free (libname);
75 return NULL; 90 return NULL;
76 } 91 }
@@ -81,19 +96,28 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
81 96
82static void 97static void
83test_record (void *cls, 98test_record (void *cls,
84 const struct GNUNET_PEERSTORE_Record *record, 99 const struct GNUNET_PEERSTORE_Record *record,
85 const char *error) 100 const char *error)
86{ 101{
87 struct GNUNET_PeerIdentity *id = cls; 102 const struct GNUNET_PeerIdentity *id = cls;
88 char* testval = "test_val"; 103 const char* testval = "test_val";
89 104
90 if (NULL == record) 105 if (NULL == record)
106 {
107 unload_plugin (psp);
91 return; 108 return;
92 109 }
93 GNUNET_assert (0 == memcmp (record->peer, id, sizeof (struct GNUNET_PeerIdentity))); 110 GNUNET_assert (0 == memcmp (&record->peer,
94 GNUNET_assert (0 == strcmp ("subsys", record->sub_system)); 111 id,
95 GNUNET_assert (0 == strcmp ("key", record->key)); 112 sizeof (struct GNUNET_PeerIdentity)));
96 GNUNET_assert (0 == memcmp (testval, record->value, strlen (testval))); 113 GNUNET_assert (0 == strcmp ("subsys",
114 record->sub_system));
115 GNUNET_assert (0 == strcmp ("key",
116 record->key));
117 GNUNET_assert (0 == memcmp (testval,
118 record->value,
119 strlen (testval)));
120 ok = 0;
97} 121}
98 122
99 123
@@ -101,38 +125,52 @@ static void
101get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, 125get_record (struct GNUNET_PEERSTORE_PluginFunctions *psp,
102 const struct GNUNET_PeerIdentity *identity) 126 const struct GNUNET_PeerIdentity *identity)
103{ 127{
104 GNUNET_assert (GNUNET_OK == psp->iterate_records (psp->cls, 128 GNUNET_assert (GNUNET_OK ==
105 "subsys", identity, "key", &test_record, (void*)identity)); 129 psp->iterate_records (psp->cls,
130 "subsys",
131 identity,
132 "key",
133 &test_record,
134 (void*)identity));
106} 135}
107 136
137
108static void 138static void
109store_cont (void *cls, int status) 139store_cont (void *cls,
140 int status)
110{ 141{
111 GNUNET_assert (GNUNET_OK == status); 142 GNUNET_assert (GNUNET_OK == status);
143 get_record (psp,
144 &p1);
112} 145}
113 146
147
114static void 148static void
115put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp, struct GNUNET_PeerIdentity *identity) 149put_record (struct GNUNET_PEERSTORE_PluginFunctions *psp,
150 const struct GNUNET_PeerIdentity *identity)
116{ 151{
117 GNUNET_assert (GNUNET_OK == psp->store_record (psp->cls, 152 GNUNET_assert (GNUNET_OK ==
118 "subsys", 153 psp->store_record (psp->cls,
119 identity, 154 "subsys",
120 "key", "test_value", strlen ("test_value"), 155 identity,
121 GNUNET_TIME_absolute_get (), 156 "key",
122 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 157 "test_value",
123 &store_cont, 158 strlen ("test_value"),
124 identity)); 159 GNUNET_TIME_absolute_get (),
160 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
161 &store_cont,
162 NULL));
125} 163}
126 164
127 165
128static void 166static void
129run (void *cls, char *const *args, const char *cfgfile, 167run (void *cls,
168 char *const *args,
169 const char *cfgfile,
130 const struct GNUNET_CONFIGURATION_Handle *cfg) 170 const struct GNUNET_CONFIGURATION_Handle *cfg)
131{ 171{
132 struct GNUNET_PEERSTORE_PluginFunctions *psp;
133 struct GNUNET_PeerIdentity p1;
134 172
135 ok = 0; 173 ok = 1;
136 psp = load_plugin (cfg); 174 psp = load_plugin (cfg);
137 if (NULL == psp) 175 if (NULL == psp)
138 { 176 {
@@ -142,10 +180,8 @@ run (void *cls, char *const *args, const char *cfgfile,
142 return; 180 return;
143 } 181 }
144 memset (&p1, 1, sizeof (p1)); 182 memset (&p1, 1, sizeof (p1));
145 put_record (psp, &p1); 183 put_record (psp,
146 get_record (psp, &p1); 184 &p1);
147
148 unload_plugin (psp);
149} 185}
150 186
151 187
@@ -163,19 +199,26 @@ main (int argc, char *argv[])
163 GNUNET_GETOPT_OPTION_END 199 GNUNET_GETOPT_OPTION_END
164 }; 200 };
165 201
166 //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite");
167 GNUNET_log_setup ("test-plugin-peerstore", 202 GNUNET_log_setup ("test-plugin-peerstore",
168 "WARNING", 203 "WARNING",
169 NULL); 204 NULL);
170 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 205 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
171 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_peerstore_%s.conf", 206 GNUNET_snprintf (cfg_name,
207 sizeof (cfg_name),
208 "test_plugin_peerstore_%s.conf",
172 plugin_name); 209 plugin_name);
173 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 210 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
174 "test-plugin-peerstore", "nohelp", options, &run, NULL); 211 xargv,
212 "test-plugin-peerstore",
213 "nohelp",
214 options,
215 &run,
216 NULL);
175 if (ok != 0) 217 if (ok != 0)
176 FPRINTF (stderr, "Missed some testcases: %d\n", ok); 218 FPRINTF (stderr,
177 //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); 219 "Missed some testcases: %d\n",
220 ok);
178 return ok; 221 return ok;
179} 222}
180 223
181/* end of test_plugin_namestore.c */ 224/* end of test_plugin_peerstore.c */