swig/Examples/test-suite/javascript/cpp11_rvalue_reference_move_input_runme.js
William S Fulton e139a36511 SWIGTYPE && input typemaps now assume object has been moved
Replicated Java implementation.

Fully implemented for:
- C#
- D
- Guile
- Javascript (UTL)
- Lua
- MzScheme
- Octave (UTL)
- Perl (UTL)
- PHP
- Python (UTL)
- Ruby (UTL)
- Tcl (UTL)

PHP std::auto_ptr std::unique_ptr minor tweaks and testcase corrections
2022-08-31 19:40:14 +01:00

67 lines
3.1 KiB
JavaScript

var cpp11_rvalue_reference_move_input = require("cpp11_rvalue_reference_move_input");
{
// Function containing rvalue reference parameter
cpp11_rvalue_reference_move_input.Counter.reset_counts();
mo = new cpp11_rvalue_reference_move_input.MovableCopyable(222);
cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 0, 0, 0);
cpp11_rvalue_reference_move_input.MovableCopyable.movein(mo);
cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 1, 0, 2);
if (!cpp11_rvalue_reference_move_input.MovableCopyable.is_nullptr(mo))
throw new Error("is_nullptr failed");
delete mo;
cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 1, 0, 2);
}
{
// Move constructor test
cpp11_rvalue_reference_move_input.Counter.reset_counts();
mo = new cpp11_rvalue_reference_move_input.MovableCopyable(222);
cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 0, 0, 0);
mo_moved = new cpp11_rvalue_reference_move_input.MovableCopyable(mo);
cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 1, 0, 1);
if (!cpp11_rvalue_reference_move_input.MovableCopyable.is_nullptr(mo))
throw new Error("is_nullptr failed");
delete mo;
cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 1, 0, 1);
// delete mo_moved;
// cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 1, 0, 2);
// Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete
cpp11_rvalue_reference_move_input.MovableCopyable.movein(mo_moved);
cpp11_rvalue_reference_move_input.Counter.check_counts(1, 0, 0, 2, 0, 3);
}
{
// Move assignment operator test
cpp11_rvalue_reference_move_input.Counter.reset_counts();
mo111 = new cpp11_rvalue_reference_move_input.MovableCopyable(111);
mo222 = new cpp11_rvalue_reference_move_input.MovableCopyable(222);
cpp11_rvalue_reference_move_input.Counter.check_counts(2, 0, 0, 0, 0, 0);
mo111.MoveAssign(mo222);
cpp11_rvalue_reference_move_input.Counter.check_counts(2, 0, 0, 0, 1, 1);
if (!cpp11_rvalue_reference_move_input.MovableCopyable.is_nullptr(mo222))
throw new Error("is_nullptr failed");
delete mo222;
cpp11_rvalue_reference_move_input.Counter.check_counts(2, 0, 0, 0, 1, 1);
// delete mo111;
// cpp11_rvalue_reference_move_input.Counter.check_counts(2, 0, 0, 0, 1, 2);
// Above not deleting the C++ object(node v12) - can't reliably control GC - use the movein function instead to delete
cpp11_rvalue_reference_move_input.MovableCopyable.movein(mo111);
cpp11_rvalue_reference_move_input.Counter.check_counts(2, 0, 0, 1, 1, 3);
}
{
// null check
cpp11_rvalue_reference_move_input.Counter.reset_counts();
exception_thrown = false;
try {
cpp11_rvalue_reference_move_input.MovableCopyable.movein(null);
} catch (e) {
if (!e.message.includes("invalid null reference"))
throw new Error("incorrect exception message " + e.message);
exception_thrown = true;
}
if (!exception_thrown)
throw new Error("Should have thrown null error");
cpp11_rvalue_reference_move_input.Counter.check_counts(0, 0, 0, 0, 0, 0);
}