aboutsummaryrefslogtreecommitdiffstats
path: root/tests/protocol.c
blob: 1d29db36509349d577fd0678b2b8a25ba6a5033c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* PipeWire AGL Cluster IPC
 *
 * Copyright © 2021 Collabora Ltd.
 *    @author Julian Bouzas <julian.bouzas@collabora.com>
 *
 * SPDX-License-Identifier: MIT
 */

#include "test.h"
#include <spa/pod/builder.h>
#include <spa/pod/parser.h>
#include <icipc.h>

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;
                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));
        }

        /* request */
        {
                struct spa_pod_int i = SPA_POD_INIT_Int(8);
                icipc_protocol_build_request(b, sizeof(b), "name",
                                             (struct spa_pod *)&i);
                const char *name = NULL;
                const struct spa_pod_int *value = NULL;
                test_bool_true(icipc_protocol_parse_request
                               (b, sizeof(b), &name,
                                (const struct spa_pod **)&value));
                test_str_eq(name, "name");
                test_cmpint(value->value, ==, 8);
        }

        /* reply error */
        {
                icipc_protocol_build_reply_error(b, sizeof(b), "error message");
                test_bool_true(icipc_protocol_is_reply_error(b, sizeof(b)));
                const char *msg = NULL;
                test_bool_true(icipc_protocol_parse_reply_error
                               (b, sizeof(b), &msg));
                test_str_eq(msg, "error message");
        }

        /* reply ok null value */
        {
                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));
        }

        /* reply ok */
        {
                struct spa_pod_int i = SPA_POD_INIT_Int(3);
                icipc_protocol_build_reply_ok(b, sizeof(b),
                                              (struct spa_pod *)&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);
        }
}

int main(int argc, char *argv[]) {
        test_icipc_protocol();
        return TEST_PASS;
}