diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/client-server.c | 45 | ||||
-rw-r--r-- | tests/protocol.c | 58 |
2 files changed, 71 insertions, 32 deletions
diff --git a/tests/client-server.c b/tests/client-server.c index 9954b86..f6e8fa5 100644 --- a/tests/client-server.c +++ b/tests/client-server.c @@ -8,12 +8,16 @@ #define _GNU_SOURCE #include "test.h" -#include <spa/pod/builder.h> -#include <spa/pod/parser.h> +#include "data.h" #include <icipc.h> #include <unistd.h> #include <pthread.h> +typedef struct DataInt { + struct icipc_data hdr; + int value; +} DataInt; + static inline char *new_address() { char *address = NULL; (void)asprintf(&address, "icipc-test-%d-%d", getpid(), rand()); @@ -25,20 +29,27 @@ static bool increment_request_handler( struct icipc_server *self, int client_fd, const char *name, - const struct spa_pod *args, + const struct icipc_data *args, void *data) { int32_t val = 0; - test_bool_true(spa_pod_is_int(args)); - test_bool_true(spa_pod_get_int(args, &val) == 0); - struct spa_pod_int res = SPA_POD_INIT_Int(val + 1); - return icipc_server_reply_ok(self, client_fd, (struct spa_pod *)&res); + test_cmpint(args->type, ==, (uint32_t) DATA_TYPE_INT); + test_cmpint(ICIPC_DATA_BODY_SIZE(args), ==, + ROUND_UP_TO_ALIGN(sizeof(int))); + val = *((const int*)ICIPC_DATA_BODY_CONST(args)); + + DataInt res = { + .hdr.size = sizeof(int), + .hdr.type = DATA_TYPE_INT, + .value = val + 1, + }; + return icipc_server_reply_ok(self, client_fd, (struct icipc_data *)&res); } static bool error_request_handler( struct icipc_server *self, int client_fd, const char *name, - const struct spa_pod *args, + const struct icipc_data *args, void *data) { return icipc_server_reply_error(self, client_fd, "error message"); } @@ -68,11 +79,13 @@ static void reply_handler( pthread_mutex_lock(&data->mutex); - const struct spa_pod *pod = + const struct icipc_data *args = icipc_client_send_request_finish(self, buffer, size, &data->error); - if (pod) { - test_bool_true(spa_pod_is_int(pod)); - test_bool_true(spa_pod_get_int(pod, &data->incremented) == 0); + if (args) { + test_cmpint(args->type, ==, (uint32_t) DATA_TYPE_INT); + test_cmpint(ICIPC_DATA_BODY_SIZE(args), ==, + ROUND_UP_TO_ALIGN(sizeof(int))); + data->incremented = *((const int*)ICIPC_DATA_BODY_CONST(args)); } data->n_replies++; pthread_cond_signal(&data->cond); @@ -100,9 +113,13 @@ static void test_icipc_server_client() { data.incremented = -1; data.error = NULL; data.n_replies = 0; - struct spa_pod_int i = SPA_POD_INIT_Int(3); + DataInt i = { + .hdr.size = sizeof(int), + .hdr.type = DATA_TYPE_INT, + .value = 3, + }; test_bool_true(icipc_client_send_request - (c, "INCREMENT", (struct spa_pod *)&i, reply_handler, + (c, "INCREMENT", (struct icipc_data *)&i, reply_handler, &data)); wait_for_reply(&data, 1); test_ptr_null(data.error); diff --git a/tests/protocol.c b/tests/protocol.c index 1d29db3..c0d28e7 100644 --- a/tests/protocol.c +++ b/tests/protocol.c @@ -7,36 +7,49 @@ */ #include "test.h" -#include <spa/pod/builder.h> -#include <spa/pod/parser.h> +#include "data.h" #include <icipc.h> +typedef struct DataInt { + struct icipc_data hdr; + int value; +} DataInt; + static void test_icipc_protocol() { uint8_t b[1024]; /* request null value */ { - icipc_protocol_build_request(b, sizeof(b), "name", NULL); const char *name = NULL; - const struct spa_pod *value = NULL; + const struct icipc_data *value = NULL; + + icipc_protocol_build_request(b, sizeof(b), "name", NULL); test_bool_true(icipc_protocol_parse_request (b, sizeof(b), &name, &value)); test_str_eq(name, "name"); - test_bool_true(spa_pod_is_none(value)); + test_cmpint(value->type, ==, (uint32_t) DATA_TYPE_NONE); } /* request */ { - struct spa_pod_int i = SPA_POD_INIT_Int(8); - icipc_protocol_build_request(b, sizeof(b), "name", - (struct spa_pod *)&i); + DataInt i = { + .hdr.size = sizeof(int), + .hdr.type = DATA_TYPE_INT, + .value = 8, + }; const char *name = NULL; - const struct spa_pod_int *value = NULL; + const struct icipc_data *value = NULL; + + icipc_protocol_build_request(b, sizeof(b), "name", + (struct icipc_data *)&i); test_bool_true(icipc_protocol_parse_request (b, sizeof(b), &name, - (const struct spa_pod **)&value)); + (const struct icipc_data **)&value)); test_str_eq(name, "name"); - test_cmpint(value->value, ==, 8); + test_cmpint(ICIPC_DATA_BODY_SIZE(value), ==, + ROUND_UP_TO_ALIGN(sizeof(int))); + test_cmpint(value->type, ==, (uint32_t) DATA_TYPE_INT); + test_cmpint(*((const int*)ICIPC_DATA_BODY_CONST(value)), ==, 8); } /* reply error */ @@ -51,25 +64,34 @@ static void test_icipc_protocol() { /* reply ok null value */ { + const struct icipc_data *value = NULL; + icipc_protocol_build_reply_ok(b, sizeof(b), NULL); test_bool_true(icipc_protocol_is_reply_ok(b, sizeof(b))); - const struct spa_pod *value = NULL; test_bool_true(icipc_protocol_parse_reply_ok (b, sizeof(b), &value)); test_ptr_notnull(value); - test_bool_true(spa_pod_is_none(value)); + test_cmpint(value->type, ==, (uint32_t) DATA_TYPE_NONE); } /* reply ok */ { - struct spa_pod_int i = SPA_POD_INIT_Int(3); + DataInt i = { + .hdr.size = sizeof(int), + .hdr.type = DATA_TYPE_INT, + .value = 3, + }; + const struct icipc_data *value = NULL; + icipc_protocol_build_reply_ok(b, sizeof(b), - (struct spa_pod *)&i); + (struct icipc_data *)&i); test_bool_true(icipc_protocol_is_reply_ok(b, sizeof(b))); - const struct spa_pod_int *value = NULL; test_bool_true(icipc_protocol_parse_reply_ok - (b, sizeof(b), (const struct spa_pod **)&value)); - test_cmpint(value->value, ==, 3); + (b, sizeof(b), (const struct icipc_data **)&value)); + test_cmpint(ICIPC_DATA_BODY_SIZE(value), ==, + ROUND_UP_TO_ALIGN(sizeof(int))); + test_cmpint(value->type, ==, (uint32_t) DATA_TYPE_INT); + test_cmpint(*((const int*)ICIPC_DATA_BODY_CONST(value)), ==, 3); } } |