diff options
author | Chad Austin <caustin@gmail.com> | 2014-03-07 00:38:05 -0800 |
---|---|---|
committer | Chad Austin <chad@chadaustin.me> | 2014-03-28 23:56:39 -0700 |
commit | 61849992b28d205eca211a2530ed752839f1c60f (patch) | |
tree | dbdec24061da4a098d736736facd659a6c8f8cb5 /tests | |
parent | 13e7b4cf2453c7332ed41297e4a7343747f2274f (diff) |
Add some unit tests that verify we can pass all kinds of primitive types through val::as
Diffstat (limited to 'tests')
-rw-r--r-- | tests/embind/embind.test.js | 13 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 15 |
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 5ca972be..67171822 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1938,10 +1938,21 @@ module({ derived.delete(); // Let the memory leak test superfixture check that no leaks occurred. }); + + test("val::as supports variety of types", function() { + assert.equal(true, cm.val_as_bool(true)); + assert.equal(127, cm.val_as_char(127)); + assert.equal(32767, cm.val_as_short(32767)); + assert.equal(65536, cm.val_as_int(65536)); + assert.equal(65536, cm.val_as_long(65536)); + assert.equal(10.5, cm.val_as_float(10.5)); + assert.equal(10.5, cm.val_as_double(10.5)); + }); }); /* global run_all_tests */ // If running as part of the emscripten test runner suite, and not as part of the IMVU suite, // we launch the test execution from here. IMVU suite uses its own dedicated mechanism instead of this. -if (typeof run_all_tests !== "undefined") +if (typeof run_all_tests !== "undefined") { run_all_tests(); +} diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 4efc4bd8..af8b2e8d 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -2304,3 +2304,18 @@ EMSCRIPTEN_BINDINGS(mixins) { .constructor<>() ); } + +template<typename T> +T val_as(const val& v) { + return v.as<T>(); +} + +EMSCRIPTEN_BINDINGS(val_as) { + function("val_as_bool", &val_as<bool>); + function("val_as_char", &val_as<char>); + function("val_as_short", &val_as<short>); + function("val_as_int", &val_as<int>); + function("val_as_long", &val_as<long>); + function("val_as_float", &val_as<float>); + function("val_as_double", &val_as<double>); +} |