aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJukka Jylanki <jjylanki@imvu.com>2013-05-07 16:50:14 +0300
committerChad Austin <chad@imvu.com>2013-05-17 12:57:45 -0700
commitaf3c155db90051d9772ed2a1cc29f9701f7a9c6c (patch)
tree546c03e95180bbe3cac6f3eff21b9883ec551b1e /tests
parent45a122b5d045abfc6d927329aedba79ae465373a (diff)
Add new unit tests to ensure that the return values of interfaces implemented in JS don't leak memory.
Diffstat (limited to 'tests')
-rw-r--r--tests/embind/embind.test.js22
-rw-r--r--tests/embind/embind_test.cpp15
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index f9f035f2..0c4dc174 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1559,6 +1559,28 @@ module({
impl.delete();
});
+ test("returning null shared pointer from interfaces implemented in JS code does not leak", function() {
+ var impl = cm.AbstractClass.implement({
+ returnsSharedPtr: function() {
+ return null;
+ }
+ });
+ cm.callReturnsSharedPtrMethod(impl);
+ impl.delete();
+ // Let the memory leak test superfixture check that no leaks occurred.
+ });
+
+ test("returning a new shared pointer from interfaces implemented in JS code does not leak", function() {
+ var impl = cm.AbstractClass.implement({
+ returnsSharedPtr: function() {
+ return cm.embind_test_return_smart_derived_ptr();
+ }
+ });
+ cm.callReturnsSharedPtrMethod(impl);
+ impl.delete();
+ // Let the memory leak test superfixture check that no leaks occurred.
+ });
+
test("void methods work", function() {
var saved = {};
var impl = cm.AbstractClass.implement({
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index e8ca0338..72506346 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -1084,6 +1084,7 @@ public:
return "optional" + s;
}
+ virtual std::shared_ptr<Derived> returnsSharedPtr() = 0;
virtual void differentArguments(int i, double d, unsigned char f, double q, std::string) = 0;
};
@@ -1103,6 +1104,10 @@ public:
}, s);
}
+ std::shared_ptr<Derived> returnsSharedPtr() {
+ return call<std::shared_ptr<Derived> >("returnsSharedPtr");
+ }
+
void differentArguments(int i, double d, unsigned char f, double q, std::string s) {
return call<void>("differentArguments", i, d, f, q, s);
}
@@ -1116,6 +1121,10 @@ class ConcreteClass : public AbstractClass {
void differentArguments(int i, double d, unsigned char f, double q, std::string s) {
}
+
+ std::shared_ptr<Derived> returnsSharedPtr() {
+ return std::shared_ptr<Derived>();
+ }
};
std::shared_ptr<AbstractClass> getAbstractClass() {
@@ -1130,6 +1139,11 @@ std::string callOptionalMethod(AbstractClass& ac, std::string s) {
return ac.optionalMethod(s);
}
+void callReturnsSharedPtrMethod(AbstractClass& ac) {
+ std::shared_ptr<Derived> sp = ac.returnsSharedPtr();
+ // unused: sp
+}
+
void callDifferentArguments(AbstractClass& ac, int i, double d, unsigned char f, double q, std::string s) {
return ac.differentArguments(i, d, f, q, s);
}
@@ -1145,6 +1159,7 @@ EMSCRIPTEN_BINDINGS(interface_tests) {
function("getAbstractClass", &getAbstractClass);
function("callAbstractMethod", &callAbstractMethod);
function("callOptionalMethod", &callOptionalMethod);
+ function("callReturnsSharedPtrMethod", &callReturnsSharedPtrMethod);
function("callDifferentArguments", &callDifferentArguments);
}