aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2014-05-07 16:20:55 -0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2014-05-21 22:58:16 +0700
commit1bad0e2ae1038b9ae6ba362c73ca9d3fc8f17e11 (patch)
tree40ec5c3653f6498bf95b1898ddde3a8a856f26e2 /tests
parent6e7397193370ebad6be01438ab1e65223820e909 (diff)
give a good error message when a pure virtual function is not implemented in JavaScript
Diffstat (limited to 'tests')
-rw-r--r--tests/embind/embind.test.js25
-rw-r--r--tests/embind/embind_test.cpp2
2 files changed, 25 insertions, 2 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index fbcaf93d..8307677d 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1557,7 +1557,10 @@ module({
});
BaseFixture.extend("new-style class inheritance", function() {
- var Empty = cm.AbstractClass.extend("Empty", undefined);
+ var Empty = cm.AbstractClass.extend("Empty", {
+ abstractMethod: function() {
+ }
+ });
test("can extend, construct, and delete", function() {
var instance = new Empty;
@@ -1568,6 +1571,8 @@ module({
var HasProperty = cm.AbstractClass.extend("HasProperty", {
initialize: function(x) {
this.property = x;
+ },
+ abstractMethod: function() {
}
});
var instance = new HasProperty(10);
@@ -1642,6 +1647,8 @@ module({
test("can call parent implementation from within derived implementation", function() {
var parent = cm.AbstractClass;
var ExtendsOptionalMethod = parent.extend("ExtendsOptionalMethod", {
+ abstractMethod: function() {
+ },
optionalMethod: function(s) {
return "optionaljs_" + parent.prototype.optionalMethod.call(this, s);
},
@@ -1663,6 +1670,8 @@ module({
test("returning null shared pointer from interfaces implemented in JS code does not leak", function() {
var C = cm.AbstractClass.extend("C", {
+ abstractMethod: function() {
+ },
returnsSharedPtr: function() {
return null;
}
@@ -1675,6 +1684,8 @@ module({
test("returning a new shared pointer from interfaces implemented in JS code does not leak", function() {
var C = cm.AbstractClass.extend("C", {
+ abstractMethod: function() {
+ },
returnsSharedPtr: function() {
return cm.embind_test_return_smart_derived_ptr().deleteLater();
}
@@ -1688,6 +1699,8 @@ module({
test("void methods work", function() {
var saved = {};
var C = cm.AbstractClass.extend("C", {
+ abstractMethod: function() {
+ },
differentArguments: function(i, d, f, q, s) {
saved.i = i;
saved.d = d;
@@ -1714,6 +1727,8 @@ module({
test("returning a cached new shared pointer from interfaces implemented in JS code does not leak", function() {
var derived = cm.embind_test_return_smart_derived_ptr();
var C = cm.AbstractClass.extend("C", {
+ abstractMethod: function() {
+ },
returnsSharedPtr: function() {
return derived;
}
@@ -1724,6 +1739,14 @@ module({
derived.delete();
// Let the memory leak test superfixture check that no leaks occurred.
});
+
+ test("calling pure virtual function gives good error message", function() {
+ var C = cm.AbstractClass.extend("C", {});
+ var error = assert.throws(cm.PureVirtualError, function() {
+ new C;
+ });
+ assert.equal('Pure virtual function abstractMethod must be implemented in JavaScript', error.message);
+ });
});
BaseFixture.extend("registration order", function() {
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index e14a633b..1bfd0ef7 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -1161,7 +1161,7 @@ EMSCRIPTEN_BINDINGS(interface_tests) {
class_<AbstractClass>("AbstractClass")
.smart_ptr<std::shared_ptr<AbstractClass>>("shared_ptr<AbstractClass>")
.allow_subclass<AbstractClassWrapper>("AbstractClassWrapper")
- .function("abstractMethod", &AbstractClass::abstractMethod)
+ .function("abstractMethod", &AbstractClass::abstractMethod, pure_virtual())
// The select_overload is necessary because, otherwise, the C++ compiler
// cannot deduce the signature of the lambda function.
.function("optionalMethod", select_overload<std::string(AbstractClass&, std::string)>(