28 #include <gtest/gtest.h>
32 #define CASE hpd_daemon_api
45 int option_errors[21];
58 last_module_data = module_data;
77 if (strcmp(option->name,
"mod-opt1")) module_data->
option_errors[1] = 1;
79 if (option->arg !=
nullptr) module_data->
option_errors[3] = 1;
81 if (strcmp(option->doc,
"Option 1")) module_data->
option_errors[5] = 1;
84 if (strcmp(option->name,
"mod-opt2")) module_data->
option_errors[7] = 1;
86 if (option->arg !=
nullptr) module_data->
option_errors[9] = 1;
88 if (strcmp(option->doc,
"Option 2")) module_data->
option_errors[11] = 1;
91 if (option->name !=
nullptr) module_data->
option_errors[13] = 1;
93 if (option->arg !=
nullptr) module_data->
option_errors[15] = 1;
95 if (option->doc !=
nullptr) module_data->
option_errors[17] = 1;
129 if (strcmp(name,
"opt1") == 0) module_data->
opt1_called = ++module_data->
next;
130 else if (strcmp(name,
"opt2") == 0) module_data->
opt2_called = ++module_data->
next;
145 ASSERT_EQ(hpd->
loop,
nullptr);
147 ASSERT_TRUE(TAILQ_EMPTY(&hpd->
modules));
149 ASSERT_EQ(hpd->
options,
nullptr);
160 ASSERT_EQ(loop, hpd->
loop);
169 (
char *)
"/usr/local/bin/hpd",
177 timer.repeat = 0.250;
180 ev_timer_again(loop, &timer);
190 const char *
id =
"mod";
196 ASSERT_FALSE(TAILQ_EMPTY(&hpd->
modules));
197 ASSERT_NE((module = TAILQ_FIRST(&hpd->
modules)),
nullptr);
198 ASSERT_EQ(module->
hpd, hpd);
203 ASSERT_EQ(module->
def.
on_start, module_def.on_start);
204 ASSERT_EQ(module->
def.
on_stop, module_def.on_stop);
206 ASSERT_EQ(strcmp(module->
id,
id), 0);
207 ASSERT_EQ(module->
data,
nullptr);
208 ASSERT_EQ(last_module_data,
nullptr);
218 (
char *)
"/usr/local/bin/hpd",
221 const char *
id =
"mod";
229 timer.repeat = 0.250;
231 ev_timer_again(loop, &timer);
233 ASSERT_EQ(last_module_data,
nullptr);
235 ASSERT_NE(hpd->
loop,
nullptr);
236 ASSERT_NE(last_module_data,
nullptr);
242 ASSERT_EQ(last_module_data->
start_loop, loop);
243 ASSERT_EQ(last_module_data->
stop_loop, loop);
244 free(last_module_data);
245 last_module_data =
nullptr;
255 (
char *)
"/usr/local/bin/hpd",
258 const char *
id =
"mod";
266 timer.repeat = 0.250;
268 ev_timer_again(loop, &timer);
270 ASSERT_EQ(last_module_data,
nullptr);
272 ASSERT_NE(hpd->
loop,
nullptr);
273 ASSERT_NE(last_module_data,
nullptr);
279 ASSERT_EQ(last_module_data->
start_loop, loop);
280 ASSERT_EQ(last_module_data->
stop_loop, loop);
283 for (
int i = 0; i < 21; i++)
285 free(last_module_data);
286 last_module_data =
nullptr;
296 (
char *)
"/usr/local/bin/hpd",
297 (
char *)
"--mod-opt1",
300 const char *
id =
"mod";
308 timer.repeat = 0.250;
310 ev_timer_again(loop, &timer);
312 ASSERT_EQ(last_module_data,
nullptr);
314 ASSERT_NE(hpd->
loop,
nullptr);
315 ASSERT_NE(last_module_data,
nullptr);
323 ASSERT_EQ(last_module_data->
start_loop, loop);
324 ASSERT_EQ(last_module_data->
stop_loop, loop);
327 for (
int i = 0; i < 21; i++)
329 free(last_module_data);
330 last_module_data =
nullptr;
340 (
char *)
"/usr/local/bin/hpd",
341 (
char *)
"--mod-opt1",
342 (
char *)
"--mod-opt2",
345 const char *
id =
"mod";
353 timer.repeat = 0.250;
355 ev_timer_again(loop, &timer);
357 ASSERT_EQ(last_module_data,
nullptr);
359 ASSERT_NE(hpd->
loop,
nullptr);
360 ASSERT_NE(last_module_data,
nullptr);
368 ASSERT_EQ(last_module_data->
start_loop, loop);
369 ASSERT_EQ(last_module_data->
stop_loop, loop);
372 for (
int i = 0; i < 21; i++)
374 free(last_module_data);
375 last_module_data =
nullptr;
const hpd_module_t ** option2module
hpd_error_t hpd_start(hpd_t *hpd, int argc, char *argv[])
hpd_parse_opt_f on_parse_opt
struct argp_option hpd_argp_option_t
static hpd_error_t on_stop(void *data, hpd_t *hpd)
hpd_error_t hpd_module_add_option(const hpd_module_t *context, const char *name, const char *arg, int flags, const char *doc)
[hpd_t functions]
TEST(CASE, hpd_allocation)
static hpd_error_t on_parse_opt(void *data, const char *name, const char *)
hpd_argp_option_t * options
hpd_configuration_t * configuration
enum hpd_error hpd_error_t
[Application API Callbacks]
static hpd_error_t on_start(void *data, hpd_t *hpd)
static hpd_error_t on_create_add_options(void **data, const hpd_module_t *context)
static module_data_t * last_module_data
hpd_error_t hpd_module(hpd_t *hpd, const char *id, const hpd_module_def_t *module_def)
static void stop_hpd(hpd_ev_loop_t *loop, ev_timer *w, int revents)
hpd_error_t hpd_stop(hpd_t *hpd)
static struct ev_loop * loop
static hpd_error_t on_destroy(void *data)
hpd_error_t hpd_alloc(hpd_t **hpd)
[hpd_t functions]
hpd_ev_loop_t * stop_loop
hpd_ev_loop_t * start_loop
struct ev_loop hpd_ev_loop_t
static hpd_error_t on_create(void **data, const hpd_module_t *)
hpd_error_t hpd_get_loop(hpd_t *hpd, hpd_ev_loop_t **loop)
hpd_error_t hpd_free(hpd_t *hpd)