summaryrefslogtreecommitdiffstats
path: root/tests/protocol.c
diff options
context:
space:
mode:
authorJulian Bouzas <julian.bouzas@collabora.com>2021-04-20 04:08:58 -0400
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2021-07-28 13:19:02 +0300
commitf25bb13718f334bc0c96d29ea9f3a57c0a6f3a34 (patch)
treeeaa30eafe2df92e3d5d75571d022c3a775246bff /tests/protocol.c
parent7bf96bda703dd157385cbb175ec90bd6f38af404 (diff)
lib: add wpipc library
Simple library that uses sockets for inter-process communication. It provides an API to create server and client objects. Users can add custom handlers in the server, and clients can send requests for those custom handlers. Signed-off-by: George Kiagiadakis <george.kiagiadakis@collabora.com>
Diffstat (limited to 'tests/protocol.c')
-rw-r--r--tests/protocol.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/protocol.c b/tests/protocol.c
new file mode 100644
index 0000000..5e272a1
--- /dev/null
+++ b/tests/protocol.c
@@ -0,0 +1,77 @@
+/* PipeWire AGL Cluster IPC
+ *
+ * Copyright © 2021 Collabora Ltd.
+ * @author Julian Bouzas <julian.bouzas@collabora.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <glib.h>
+#include <spa/pod/builder.h>
+#include <spa/pod/parser.h>
+#include <icipc/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;
+ g_assert_true (icipc_protocol_parse_request (b, sizeof(b), &name, &value));
+ g_assert_cmpstr (name, ==, "name");
+ g_assert_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;
+ g_assert_true (icipc_protocol_parse_request (b, sizeof(b), &name, (const struct spa_pod **)&value));
+ g_assert_cmpstr (name, ==, "name");
+ g_assert_cmpint (value->value, ==, 8);
+ }
+
+ /* reply error */
+ {
+ icipc_protocol_build_reply_error (b, sizeof(b), "error message");
+ g_assert_true (icipc_protocol_is_reply_error (b, sizeof(b)));
+ const char *msg = NULL;
+ g_assert_true (icipc_protocol_parse_reply_error (b, sizeof(b), &msg));
+ g_assert_cmpstr (msg, ==, "error message");
+ }
+
+ /* reply ok null value */
+ {
+ icipc_protocol_build_reply_ok (b, sizeof(b), NULL);
+ g_assert_true (icipc_protocol_is_reply_ok (b, sizeof(b)));
+ const struct spa_pod *value = NULL;
+ g_assert_true (icipc_protocol_parse_reply_ok (b, sizeof(b), &value));
+ g_assert_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);
+ g_assert_true (icipc_protocol_is_reply_ok (b, sizeof(b)));
+ const struct spa_pod_int *value = NULL;
+ g_assert_true (icipc_protocol_parse_reply_ok (b, sizeof(b), (const struct spa_pod **)&value));
+ g_assert_cmpint (value->value, ==, 3);
+ }
+}
+
+gint
+main (gint argc, gchar *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/icipc/icipc-protocol", test_icipc_protocol);
+
+ return g_test_run ();
+}