aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-05-02 15:34:27 -0700
committerChad Austin <chad@imvu.com>2013-05-02 18:56:18 -0700
commit2d628d429053984a3a463a9746c2b042f31e4361 (patch)
tree1926f29cb2336648dddc29c7c3032a6a32c8b30b
parent58352074e51c15bd108a71a3c31354206d488eee (diff)
Add a test for interface methods that return void.
-rwxr-xr-xtests/embind/embind.test.js23
-rw-r--r--tests/embind/embind_test.cpp40
2 files changed, 52 insertions, 11 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 2f407471..69f933fa 100755
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1558,6 +1558,29 @@ module({
assert.equal("optionalfoo", cm.callOptionalMethod(impl, "foo"));
impl.delete();
});
+
+ test("void methods work", function() {
+ var saved = {};
+ var impl = cm.AbstractClass.implement({
+ differentArguments: function(i, d, f, q, s) {
+ saved.i = i;
+ saved.d = d;
+ saved.f = f;
+ saved.q = q;
+ saved.s = s;
+ }
+ });
+
+ cm.callDifferentArguments(impl, 1, 2, 3, 4, "foo");
+
+ assert.deepEqual(saved, {
+ i: 1,
+ d: 2,
+ f: 3,
+ q: 4,
+ s: "foo",
+ });
+ });
});
BaseFixture.extend("registration order", function() {
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 21fbee65..23761efc 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -1083,6 +1083,8 @@ public:
virtual std::string optionalMethod(std::string s) const {
return "optional" + s;
}
+
+ virtual void differentArguments(int i, double d, unsigned char f, double q, std::string) = 0;
};
EMSCRIPTEN_SYMBOL(optionalMethod);
@@ -1094,17 +1096,26 @@ public:
std::string abstractMethod() const {
return call<std::string>("abstractMethod");
}
+
std::string optionalMethod(std::string s) const {
return optional_call<std::string>(optionalMethod_symbol, [&] {
return AbstractClass::optionalMethod(s);
}, s);
}
+
+ void differentArguments(int i, double d, unsigned char f, double q, std::string s) {
+ return call<void>("differentArguments", i, d, f, q, s);
+ }
};
class ConcreteClass : public AbstractClass {
std::string abstractMethod() const {
return "from concrete";
}
+
+
+ void differentArguments(int i, double d, unsigned char f, double q, std::string s) {
+ }
};
std::shared_ptr<AbstractClass> getAbstractClass() {
@@ -1119,6 +1130,24 @@ std::string callOptionalMethod(AbstractClass& ac, std::string s) {
return ac.optionalMethod(s);
}
+void callDifferentArguments(AbstractClass& ac, int i, double d, unsigned char f, double q, std::string s) {
+ return ac.differentArguments(i, d, f, q, s);
+}
+
+EMSCRIPTEN_BINDINGS(interface_tests) {
+ class_<AbstractClass>("AbstractClass")
+ .smart_ptr<std::shared_ptr<AbstractClass>>()
+ .allow_subclass<AbstractClassWrapper>()
+ .function("abstractMethod", &AbstractClass::abstractMethod)
+ .function("optionalMethod", &AbstractClass::optionalMethod)
+ ;
+
+ function("getAbstractClass", &getAbstractClass);
+ function("callAbstractMethod", &callAbstractMethod);
+ function("callOptionalMethod", &callOptionalMethod);
+ function("callDifferentArguments", &callDifferentArguments);
+}
+
class HasExternalConstructor {
public:
HasExternalConstructor(const std::string& str)
@@ -1750,17 +1779,6 @@ EMSCRIPTEN_BINDINGS(tests) {
function("embind_test_new_Object", &embind_test_new_Object);
function("embind_test_new_factory", &embind_test_new_factory);
- class_<AbstractClass>("AbstractClass")
- .smart_ptr<std::shared_ptr<AbstractClass>>()
- .allow_subclass<AbstractClassWrapper>()
- .function("abstractMethod", &AbstractClass::abstractMethod)
- .function("optionalMethod", &AbstractClass::optionalMethod)
- ;
-
- function("getAbstractClass", &getAbstractClass);
- function("callAbstractMethod", &callAbstractMethod);
- function("callOptionalMethod", &callOptionalMethod);
-
class_<HasExternalConstructor>("HasExternalConstructor")
.constructor(&createHasExternalConstructor)
.function("getString", &HasExternalConstructor::getString)