aboutsummaryrefslogtreecommitdiff
path: root/tests/embind
diff options
context:
space:
mode:
Diffstat (limited to 'tests/embind')
-rw-r--r--tests/embind/embind.test.js12
-rw-r--r--tests/embind/embind_test.cpp37
2 files changed, 49 insertions, 0 deletions
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>());