aboutsummaryrefslogtreecommitdiffstats
path: root/ns/ext/contexts/test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-11-20 23:08:57 +0000
committerDavid Robillard <d@drobilla.net>2011-11-20 23:08:57 +0000
commit725d4a404b838da6b67d9da66228a1125bddef57 (patch)
treea1daab3d767c85b1b67ff3a9eb60d54721b2e5fc /ns/ext/contexts/test.c
parent5ae0165d6d0420e95e22c1451e319b9e83398c28 (diff)
downloadlv2-725d4a404b838da6b67d9da66228a1125bddef57.tar.xz
Lay out repository structure to match include and URI structure.
Treat lv2core like all the other specifications in gendoc.py.
Diffstat (limited to 'ns/ext/contexts/test.c')
-rw-r--r--ns/ext/contexts/test.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/ns/ext/contexts/test.c b/ns/ext/contexts/test.c
new file mode 100644
index 0000000..ca41a10
--- /dev/null
+++ b/ns/ext/contexts/test.c
@@ -0,0 +1,67 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <limits.h>
+#include <assert.h>
+#include <unistd.h>
+#include "contexts.h"
+
+#define TEST_ASSERT(check) do {\
+ if (!(check)) {\
+ fprintf(stderr, "Failure at line %d: %s\n", __LINE__, #check);\
+ assert(false);\
+ _exit(1);\
+ }\
+} while (0)
+
+#define NUM_PORTS 64
+
+void
+print_flags(void* flags)
+{
+ for (int i = NUM_PORTS; i >= 0; --i)
+ printf((lv2_contexts_port_is_valid(flags, i)) ? "1" : "0");
+ printf("\n");
+}
+
+
+int
+main()
+{
+ uint64_t flags = 0;
+ print_flags(&flags);
+
+ lv2_contexts_set_port_valid(&flags, 16);
+ print_flags(&flags);
+ for (int i = 0; i < NUM_PORTS; ++i) {
+ if (i == 16) {
+ TEST_ASSERT(lv2_contexts_port_is_valid(&flags, i));
+ } else {
+ TEST_ASSERT(!lv2_contexts_port_is_valid(&flags, i));
+ }
+ }
+
+ lv2_contexts_set_port_valid(&flags, 46);
+ lv2_contexts_set_port_valid(&flags, 0);
+ print_flags(&flags);
+ for (int i = 0; i < NUM_PORTS; ++i) {
+ if (i == 0 || i == 16 || i == 46) {
+ TEST_ASSERT(lv2_contexts_port_is_valid(&flags, i));
+ } else {
+ TEST_ASSERT(!lv2_contexts_port_is_valid(&flags, i));
+ }
+ }
+
+ lv2_contexts_unset_port_valid(&flags, 16);
+ print_flags(&flags);
+ for (int i = 0; i < NUM_PORTS; ++i) {
+ if (i == 0 || i == 46) {
+ TEST_ASSERT(lv2_contexts_port_is_valid(&flags, i));
+ } else {
+ TEST_ASSERT(!lv2_contexts_port_is_valid(&flags, i));
+ }
+ }
+
+ return 0;
+}
+