#include #include "../src/service.h" #include #include #define AFB_BINDING_VERSION 3 #include struct afb_req_x2 *reqhandle; START_TEST(PreInit) { ck_assert_int_eq(bindingServicePreInit(afbBindingV3root), 0); } END_TEST START_TEST(Init) { ck_assert_int_eq(bindingServiceInit(afbBindingV3root), 0); } END_TEST START_TEST(SerialInit) { ck_assert_int_eq(serial_init(), 0); } END_TEST START_TEST(VirtualRead) { virtual_read(reqhandle); ck_assert_int_eq(virtual_read_status, 0); } END_TEST /** sending log messages */ void vverbose( struct afb_api_x3 *api, int level, const char *file, int line, const char * func, const char *fmt, va_list args) { vprintf(fmt, args); } /** log a message for the request */ void vverbose_req ( struct afb_req_x2 *req, int level, const char *file, int line, const char * func, const char *fmt, va_list args) { vprintf(fmt, args); } /** make subscription of the client of the request to the event */ int subscribe_event_x2(struct afb_req_x2 *req, struct afb_event_x2 *event) { } /** make subscription of the client of the request to the event */ int unsubscribe_event_x2(struct afb_req_x2 *req, struct afb_event_x2 *event) { } /** reply to the request */ void reply(struct afb_req_x2 *req, struct json_object *obj, const char *error, const char *info) { } /** get the json */ struct json_object *json(struct afb_req_x2 *req) { } int push(struct afb_event_x2 *event, struct json_object *obj){ } /** broadcast the event */ int broadcast(struct afb_event_x2 *event, struct json_object *obj) { } struct afb_event_x2_itf test_itf_event_x2 = { .broadcast = broadcast, .push = push }; /** creates an event of 'name' */ struct afb_event_x2 *event_make(struct afb_api_x3 *api, const char *name) { struct afb_event_x2 *event = calloc(1, sizeof(struct afb_event_x2)); event->itf = (struct afb_event_x2_itf *)calloc(1, sizeof(struct afb_event_x2_itf)); event->itf = &test_itf_event_x2; return event; } struct afb_api_x3_itf test_itf_api_x3 = { .vverbose = vverbose, .event_make = event_make }; struct afb_req_x2_itf test_itf_req_x2 = { .vverbose = vverbose_req, .subscribe_event_x2 = subscribe_event_x2, .unsubscribe_event_x2 = unsubscribe_event_x2, .json = json, .reply = reply }; struct afb_api_x3 *test_api_create(const char *name) { printf("----test_api_create----"); struct afb_api_x3 *api = calloc(1, sizeof(struct afb_api_x3)); if (api != NULL) api->apiname = name; api->logmask = 6; api->itf = (struct afb_api_x3_itf *)calloc(1, sizeof(struct afb_api_x3_itf)); api->itf = &test_itf_api_x3; return api; } struct afb_req_x2 *test_req_create(const char *verb, const char *api ) { printf("----test_req_create----"); struct afb_req_x2 *req = calloc(1, sizeof(struct afb_req_x2)); if (req != NULL) { req->api = afbBindingV3root; req->called_api = api; req->called_verb = verb; } req->itf = (struct afb_req_x2_itf *)calloc(1, sizeof(struct afb_req_x2_itf)); req->itf = &test_itf_req_x2; return req; } void init_test_root_api_x3() { afbBindingV3root = test_api_create("radar"); } void init_test_root_req_x2() { reqhandle = test_req_create("virtual_read", "radar"); } Suite *radar_service_suite(void) { Suite *s; TCase *tc_service_init; TCase *tc_serial_ops; s = suite_create("RadarService"); tc_service_init = tcase_create("ServiceInitialization"); tc_serial_ops = tcase_create("SerialPort"); tcase_add_test(tc_service_init, PreInit); tcase_add_test(tc_service_init, Init); tcase_add_test(tc_serial_ops, SerialInit); tcase_add_test(tc_serial_ops, VirtualRead); suite_add_tcase(s, tc_service_init); suite_add_tcase(s, tc_serial_ops); return s; } int main(void) { int no_failed = 0; Suite *s; SRunner *runner; s = radar_service_suite(); runner = srunner_create(s); init_test_root_api_x3(); init_test_root_req_x2(); srunner_run_all(runner, CK_VERBOSE); no_failed = srunner_ntests_failed(runner); srunner_free(runner); return (no_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }