aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/embind/embind.test.js12
-rw-r--r--tests/embind/embind_test.cpp16
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 539b837f..a577cd37 100755
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -608,6 +608,18 @@ module({
assert.throws(cm.BindingError, function() { new cm.MultipleCtors(1,2,3,4); });
});
+ test("overloading of free functions", function() {
+ var a = cm.overloaded_function(10);
+ assert.equal(a, 1);
+ var b = cm.overloaded_function(20, 20);
+ assert.equal(b, 2);
+ });
+
+ test("wrong number of arguments to an overloaded free function", function() {
+ assert.throws(cm.BindingError, function() { cm.overloaded_function(); });
+ assert.throws(cm.BindingError, function() { cm.overloaded_function(30, 30, 30); });
+ });
+
/*
test("can get templated member classes then call its member functions", function() {
var p = new cm.ContainsTemplatedMemberClass();
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index f23b9152..0ae1801a 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -1339,6 +1339,19 @@ public:
}
};
+int overloaded_function(int i)
+{
+ assert(i == 10);
+ return 1;
+}
+
+int overloaded_function(int i, int j)
+{
+ assert(i == 20);
+ assert(j == 20);
+ return 2;
+}
+
EMSCRIPTEN_BINDINGS(tests) {
register_js_interface();
@@ -1785,6 +1798,9 @@ EMSCRIPTEN_BINDINGS(tests) {
function("long_to_string", &long_to_string);
function("unsigned_long_to_string", &unsigned_long_to_string);
+ function("overloaded_function", (int(*)(int))&overloaded_function);
+ function("overloaded_function", (int(*)(int, int))&overloaded_function);
+
class_<MultipleCtors>("MultipleCtors")
.constructor<int>()
.constructor<int, int>()