aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core/test_i64_varargs.in1
-rw-r--r--tests/core/test_i64_varargs.out4
-rw-r--r--tests/embind/embind.test.js12
-rw-r--r--tests/embind/embind_test.cpp37
-rw-r--r--tests/fs/test_emptyPath.c14
-rw-r--r--tests/fs/test_emptyPath.out2
-rw-r--r--tests/test_core.py6
-rw-r--r--tests/test_other.py12
8 files changed, 86 insertions, 2 deletions
diff --git a/tests/core/test_i64_varargs.in b/tests/core/test_i64_varargs.in
index 7d2e4267..a0cbec64 100644
--- a/tests/core/test_i64_varargs.in
+++ b/tests/core/test_i64_varargs.in
@@ -16,6 +16,7 @@ int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start,
}
int main(int argc, char **argv) {
+ argv[0] = "...";
for (int i = 0; i < argc; i++) {
int64_t x;
if (i % 123123 == 0)
diff --git a/tests/core/test_i64_varargs.out b/tests/core/test_i64_varargs.out
index 8c7b7843..01832abc 100644
--- a/tests/core/test_i64_varargs.out
+++ b/tests/core/test_i64_varargs.out
@@ -1,6 +1,6 @@
-in/this.program
+.
nada
-1536
+1504
a
nada
5760
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 432202ff..f1de1a12 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -604,6 +604,18 @@ module({
c.delete();
});
+ test("can pass unique_ptr", function() {
+ var p = cm.embind_test_return_unique_ptr(42);
+ var m = cm.embind_test_accept_unique_ptr(p);
+ assert.equal(42, m);
+ });
+
+ test("can pass unique_ptr to constructor", function() {
+ var c = new cm.embind_test_construct_class_with_unique_ptr(42);
+ assert.equal(42, c.getValue());
+ c.delete();
+ });
+
test("can get member classes then call its member functions", function() {
var p = new cm.ParentClass();
var c = p.getBigClass();
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 30267994..7ac321a8 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -856,6 +856,32 @@ void emval_test_call_function(val v, int i, float f, TupleVector tv, StructVecto
v(i, f, tv, sv);
}
+class UniquePtrToConstructor {
+public:
+ UniquePtrToConstructor(std::unique_ptr<int> p)
+ : value(*p)
+ {}
+
+ int getValue() const {
+ return value;
+ }
+
+private:
+ int value;
+};
+
+std::unique_ptr<int> embind_test_return_unique_ptr(int v) {
+ return std::unique_ptr<int>(new int(v));
+}
+
+UniquePtrToConstructor* embind_test_construct_class_with_unique_ptr(int v) {
+ return new UniquePtrToConstructor(embind_test_return_unique_ptr(v));
+}
+
+int embind_test_accept_unique_ptr(std::unique_ptr<int> p) {
+ return *p.get();
+}
+
std::unique_ptr<ValHolder> emval_test_return_unique_ptr() {
return std::unique_ptr<ValHolder>(new ValHolder(val::object()));
}
@@ -1175,6 +1201,8 @@ struct AbstractClassWithConstructor {
: s(s)
{}
+ virtual ~AbstractClassWithConstructor() {};
+
virtual std::string abstractMethod() = 0;
std::string concreteMethod() {
return s;
@@ -1818,6 +1846,15 @@ EMSCRIPTEN_BINDINGS(tests) {
function("embind_test_accept_small_class_instance", &embind_test_accept_small_class_instance);
function("embind_test_accept_big_class_instance", &embind_test_accept_big_class_instance);
+ class_<UniquePtrToConstructor>("UniquePtrToConstructor")
+ .constructor<std::unique_ptr<int>>()
+ .function("getValue", &UniquePtrToConstructor::getValue)
+ ;
+
+ function("embind_test_construct_class_with_unique_ptr", embind_test_construct_class_with_unique_ptr, allow_raw_pointer<ret_val>());
+ function("embind_test_return_unique_ptr", embind_test_return_unique_ptr);
+ function("embind_test_accept_unique_ptr", embind_test_accept_unique_ptr);
+
function("embind_test_return_raw_base_ptr", embind_test_return_raw_base_ptr, allow_raw_pointer<ret_val>());
function("embind_test_return_raw_derived_ptr_as_base", embind_test_return_raw_derived_ptr_as_base, allow_raw_pointer<ret_val>());
function("embind_test_return_raw_sibling_derived_ptr_as_base", embind_test_return_raw_sibling_derived_ptr_as_base, allow_raw_pointer<ret_val>());
diff --git a/tests/fs/test_emptyPath.c b/tests/fs/test_emptyPath.c
new file mode 100644
index 00000000..27d56ea1
--- /dev/null
+++ b/tests/fs/test_emptyPath.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+int main() {
+ FILE* f1 = fopen("s", "r");
+ if (f1 == NULL) {
+ printf("file 's' not found!\n");
+ }
+
+ FILE* f2 = fopen("", "r");
+ if (f2 == NULL) {
+ printf("file '' not found!\n");
+ }
+ return 0;
+}
diff --git a/tests/fs/test_emptyPath.out b/tests/fs/test_emptyPath.out
new file mode 100644
index 00000000..78352877
--- /dev/null
+++ b/tests/fs/test_emptyPath.out
@@ -0,0 +1,2 @@
+file 's' not found!
+file '' not found!
diff --git a/tests/test_core.py b/tests/test_core.py
index 08e3594e..137e5e4a 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -4348,6 +4348,12 @@ def process(filename):
out = path_from_root('tests', 'fs', 'test_writeFile.out')
self.do_run_from_file(src, out)
+ def test_fs_emptyPath(self):
+ if self.emcc_args is None: return self.skip('requires emcc')
+ src = path_from_root('tests', 'fs', 'test_emptyPath.c')
+ out = path_from_root('tests', 'fs', 'test_emptyPath.out')
+ self.do_run_from_file(src, out)
+
def test_fs_append(self):
if self.emcc_args is None: return self.skip('requires emcc')
src = open(path_from_root('tests', 'fs', 'test_append.c'), 'r').read()
diff --git a/tests/test_other.py b/tests/test_other.py
index 14c3f00b..4fb90b1a 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -2892,3 +2892,15 @@ int main(int argc, char **argv) {
Popen([PYTHON, EMCC, 'src.cpp']).communicate()
self.assertContained('read: 0\nfile size is 104\n', run_js('a.out.js'))
+ def test_argv0_node(self):
+ open('code.cpp', 'w').write(r'''
+#include <stdio.h>
+int main(int argc, char **argv) {
+ printf("I am %s.\n", argv[0]);
+ return 0;
+}
+''')
+
+ Popen([PYTHON, EMCC, 'code.cpp']).communicate()
+ self.assertContained('I am ' + self.get_dir().replace('\\', '/') + '/a.out.js', run_js('a.out.js', engine=NODE_JS).replace('\\', '/'))
+