summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/geometry/geometry.c49
-rw-r--r--src/geometry/geometry.h4
-rw-r--r--src/geometry/geometry.test.c116
3 files changed, 169 insertions, 0 deletions
diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c
index 2405ae9..0bc8602 100644
--- a/src/geometry/geometry.c
+++ b/src/geometry/geometry.c
@@ -156,3 +156,52 @@ void kai_release_source(struct ka_source_t s)
kai_release_float_array(s.float_array);
kai_release_accessor(s.accessor);
}
+
+
+int kai_read_input_unshared(struct ka_input_t *dest, struct kai_tag_t *src)
+{
+ CHECK_TAG_TYPE("input");
+
+ char *semantic = kai_tag_attr_to_dup(src, "semantic");
+ if (semantic == NULL) { return -1; }
+ char *source = kai_tag_attr_to_dup(src, "source");
+ if (source == NULL) { free(semantic); return -1; }
+
+ dest->shared = false;
+ dest->offset = 0;
+ dest->semantic = semantic;
+ dest->source = source;
+ dest->set = 0;
+
+ return 0;
+}
+
+int kai_read_input_shared(struct ka_input_t *dest, struct kai_tag_t *src)
+{
+ int result = kai_read_input_unshared(dest, src);
+ if (result != 0) { return result; }
+
+ long offset = kai_tag_attr_to_long(src, "offset", -1);
+ if (offset == -1) { return -1; }
+
+ dest->shared = true;
+ dest->offset = offset;
+
+ long set = kai_tag_attr_to_long(src, "set", -1);
+ if (set != -1) {
+ dest->use_set = true;
+ dest->set = set;
+ }
+ else {
+ dest->use_set = false;
+ }
+
+ return 0;
+}
+
+void kai_release_input(struct ka_input_t i)
+{
+ free(i.semantic);
+ free(i.source);
+}
+
diff --git a/src/geometry/geometry.h b/src/geometry/geometry.h
index fd6f8f3..4e260fa 100644
--- a/src/geometry/geometry.h
+++ b/src/geometry/geometry.h
@@ -16,4 +16,8 @@ void kai_release_accessor(struct ka_accessor_t a);
int kai_read_source(struct ka_source_t *dest, struct kai_tag_t *src);
void kai_release_source(struct ka_source_t s);
+int kai_read_input_unshared(struct ka_input_t *dest, struct kai_tag_t *src);
+int kai_read_input_shared(struct ka_input_t *dest, struct kai_tag_t *src);
+void kai_release_input(struct ka_input_t i);
+
#endif
diff --git a/src/geometry/geometry.test.c b/src/geometry/geometry.test.c
index 298de3a..f9dc3de 100644
--- a/src/geometry/geometry.test.c
+++ b/src/geometry/geometry.test.c
@@ -237,5 +237,121 @@ LILY_TEST("read source correctly")
#include LILY_PUSH_TEST()
+LILY_TEST("fail to read non-input (unshared) tag")
+{
+ struct kai_tag_t *t = kai_parse_string(
+ "<tag />"
+ );
+
+ struct ka_input_t input_unshared;
+ int result = kai_read_input_unshared(&input_unshared, t);
+ CHECK_EQ(result, -1, "%d");
+
+ kai_tag_destroy(t);
+}
+#include LILY_PUSH_TEST()
+
+
+LILY_TEST("fail to read input (unshared) tag with no specified semantic or source")
+{
+ struct kai_tag_t *t = kai_parse_string(
+ "<input />"
+ );
+
+ struct ka_input_t input_unshared;
+ int result = kai_read_input_unshared(&input_unshared, t);
+ CHECK_EQ(result, -1, "%d");
+ kai_tag_destroy(t);
+
+ t = kai_parse_string(
+ "<input semantic=\"xxx\" />"
+ );
+ result = kai_read_input_unshared(&input_unshared, t);
+ CHECK_EQ(result, -1, "%d");
+ kai_tag_destroy(t);
+
+ t = kai_parse_string(
+ "<input source=\"xxx\" />"
+ );
+ result = kai_read_input_unshared(&input_unshared, t);
+ CHECK_EQ(result, -1, "%d");
+ kai_tag_destroy(t);
+}
+#include LILY_PUSH_TEST()
+
+
+LILY_TEST("read input (unshared)")
+{
+ struct kai_tag_t *t = kai_parse_string(
+ "<input semantic=\"xxx\" source=\"yyy\" />"
+ );
+
+ struct ka_input_t input_unshared;
+ int result = kai_read_input_unshared(&input_unshared, t);
+ kai_tag_destroy(t);
+
+ CHECK_EQ(result, 0, "%d");
+ CHECK_EQ(input_unshared.shared, false, "%d");
+ CHECK_EQS(input_unshared.semantic, "xxx");
+ CHECK_EQS(input_unshared.source, "yyy");
+
+ kai_release_input(input_unshared);
+}
+#include LILY_PUSH_TEST()
+
+
+LILY_TEST("fail to read input (shared) with no offset")
+{
+ struct kai_tag_t *t = kai_parse_string(
+ "<input semantic=\"xxx\" source=\"yyy\" />"
+ );
+
+ struct ka_input_t input_shared;
+ int result = kai_read_input_shared(&input_shared, t);
+ kai_tag_destroy(t);
+ kai_release_input(input_shared);
+
+ CHECK_EQ(result, -1, "%d");
+}
+#include LILY_PUSH_TEST()
+
+
+LILY_TEST("read input (shared)")
+{
+ struct kai_tag_t *t = kai_parse_string(
+ "<input semantic=\"xxx\" source=\"yyy\" offset=\"10\" />"
+ );
+
+ struct ka_input_t input_shared;
+ int result = kai_read_input_shared(&input_shared, t);
+ kai_tag_destroy(t);
+
+ CHECK_EQ(result, 0, "%d");
+ CHECK_EQ(input_shared.shared, true, "%d");
+ CHECK_EQ(input_shared.offset, 10, "%d");
+ CHECK_EQS(input_shared.semantic, "xxx");
+ CHECK_EQS(input_shared.source, "yyy");
+ CHECK_EQ(input_shared.use_set, false, "%d");
+ kai_release_input(input_shared);
+
+ t = kai_parse_string(
+ "<input semantic=\"xxx\" source=\"yyy\" offset=\"10\" set=\"4\" />"
+ );
+
+ result = kai_read_input_shared(&input_shared, t);
+ kai_tag_destroy(t);
+
+ CHECK_EQ(result, 0, "%d");
+ CHECK_EQ(input_shared.shared, true, "%d");
+ CHECK_EQ(input_shared.offset, 10, "%d");
+ CHECK_EQS(input_shared.semantic, "xxx");
+ CHECK_EQS(input_shared.source, "yyy");
+ CHECK_EQ(input_shared.use_set, true, "%d");
+ CHECK_EQ(input_shared.set, 4, "%d");
+ kai_release_input(input_shared);
+}
+#include LILY_PUSH_TEST()
+
+
#define LILY_FILE_END
#include LILY_REGISTER_TESTS()