summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
Diffstat (limited to 'test/example')
-rw-r--r--test/example/c-api-kitchen-sink.c23
-rw-r--r--test/example/c-api-kitchen-sink.txt11
2 files changed, 33 insertions, 1 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index 444ed9384..ace95177a 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -1,11 +1,15 @@
+// We always need asserts here
+#ifdef NDEBUG
+#undef NDEBUG
+#endif
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <binaryen-c.h>
-
// kitchen sink, tests the full API
@@ -467,9 +471,26 @@ void test_interpret() {
BinaryenModuleDispose(module);
}
+void test_nonvalid() {
+ // create a module that fails to validate
+ BinaryenModuleRef module = BinaryenModuleCreate();
+
+ BinaryenFunctionTypeRef v = BinaryenAddFunctionType(module, "v", BinaryenNone(), NULL, 0);
+ BinaryenType localTypes[] = { BinaryenInt32() };
+ BinaryenFunctionRef func = BinaryenAddFunction(module, "func", v, localTypes, 1,
+ BinaryenSetLocal(module, 0, makeInt64(module, 1234)) // wrong type!
+ );
+
+ BinaryenModulePrint(module);
+ printf("validation: %d\n", BinaryenModuleValidate(module));
+
+ BinaryenModuleDispose(module);
+}
+
int main() {
test_core();
test_relooper();
test_binaries();
test_interpret();
+ test_nonvalid();
}
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 42610c2cc..d4eb5e337 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -713,3 +713,14 @@ module loaded from binary form:
)
)
(i32.const 1234)
+(module
+ (memory 0)
+ (type $v (func))
+ (func $func (type $v)
+ (local $0 i32)
+ (set_local $0
+ (i64.const 1234)
+ )
+ )
+)
+validation: 0