@@ -1,5 +1,7 @@
-TESTS = config
-TESTS += midi_event
+TESTS = \
+ config \
+ midi_event \
+ ctl-elem-id
check_PROGRAMS = $(TESTS)
noinst_HEADERS = test.h
new file mode 100644
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// ctl-elem-id.c - a test program for equality and some comparison algorithms
+// for control element ID structure.
+//
+// Copyright (c) 2021 Takashi Sakamoto
+//
+// Licensed under the terms of the GNU General Public License, version 2.
+
+#include <stdlib.h>
+#include <stdint.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <unistd.h>
+
+#include "../include/asoundlib.h"
+
+int main()
+{
+ void (*entries[])(snd_ctl_elem_id_t *l, snd_ctl_elem_id_t *r) = {
+ };
+ int count = sizeof(entries) / sizeof(*entries);
+ int fd;
+ uint8_t *buf;
+ int i;
+
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd < 0)
+ return EXIT_FAILURE;
+
+ buf = calloc(snd_ctl_elem_id_sizeof(), 2);
+ if (buf == NULL)
+ goto error_urandom;
+
+ for (i = 0; i < count; ++i) {
+ snd_ctl_elem_id_t *l, *r;
+ ssize_t len;
+randomize:
+ len = read(fd, buf, snd_ctl_elem_id_sizeof() * 2);
+ if (len < 0)
+ goto error_memory;
+ l = (snd_ctl_elem_id_t *)buf;
+ r = (snd_ctl_elem_id_t *)(buf + snd_ctl_elem_id_sizeof());
+ if (!memcmp(l, r, snd_ctl_elem_id_sizeof()))
+ goto randomize;
+
+ entries[i](l, r);
+ }
+
+ free(buf);
+
+ return EXIT_SUCCESS;
+error_memory:
+ free(buf);
+error_urandom:
+ close(fd);
+ return EXIT_FAILURE;
+}
Some APIs are planned to add for equality check and comparison of a pair of control element IDs. The equality check and comparison are quite basic methods to operate data, thus it's preferable not to include any bug. This commit adds skeleton of test program for the APIs. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> --- test/lsb/Makefile.am | 6 +++-- test/lsb/ctl-elem-id.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 test/lsb/ctl-elem-id.c