| 1 |
|
| #include <catch2/catch_test_macros.hpp> |
| 2 |
|
| #include <xs/function.h> |
| 3 |
|
| #include <thread> |
| 4 |
|
| |
| 5 |
|
| using namespace xs; |
| 6 |
|
| using namespace panda; |
| 7 |
|
| |
| 8 |
|
| struct RefOnly { |
| 9 |
|
| string s; |
| 10 |
1 |
| RefOnly (string s) : s(s) {} |
| 11 |
|
| }; |
| 12 |
|
| |
| 13 |
|
| struct RefAny { |
| 14 |
|
| string s; |
| 15 |
3 |
| RefAny (string s) : s(s) {} |
| 16 |
|
| }; |
| 17 |
|
| |
| 18 |
|
| namespace xs { |
| 19 |
|
| template<> struct Typemap<RefOnly&> : TypemapBase<RefOnly&> { |
| 20 |
1 |
| static RefOnly in (const Simple& arg) { |
| 21 |
1 |
▶ | return RefOnly(arg.as_string() + "_in"); |
Branch: 3 branches
| Branch | True | False | Total |
| return RefOnly(arg.as_string() + "_in"); |
1 |
0 |
1 |
| return RefOnly(arg.as_string() + "_in"); |
1 |
0 |
1 |
| return RefOnly(arg.as_string() + "_in"); |
1 |
0 |
1 |
|
| 22 |
|
| } |
| 23 |
1 |
▶ | static Sv out (RefOnly& v, const Sv& = {}) { return Simple(v.s + "_out"); } |
Branch: 2 branches
| Branch | True | False | Total |
| static Sv out (RefOnly& v, const Sv& = {}) { return Simple(v.s + "_out"); } |
1 |
0 |
1 |
| static Sv out (RefOnly& v, const Sv& = {}) { return Simple(v.s + "_out"); } |
1 |
0 |
1 |
|
| 24 |
|
| }; |
| 25 |
|
| |
| 26 |
|
| template<> struct Typemap<RefAny> : TypemapBase<RefAny> { |
| 27 |
1 |
| static RefAny in (const Simple& arg) { |
| 28 |
1 |
▶ | return RefAny(arg.as_string() + "_inV"); |
Branch: 3 branches
| Branch | True | False | Total |
| return RefAny(arg.as_string() + "_inV"); |
1 |
0 |
1 |
| return RefAny(arg.as_string() + "_inV"); |
1 |
0 |
1 |
| return RefAny(arg.as_string() + "_inV"); |
1 |
0 |
1 |
|
| 29 |
|
| } |
| 30 |
1 |
▶ | static Sv out (const RefAny& v, const Sv& = {}) { return Simple(v.s + "_outV"); } |
Branch: 2 branches
| Branch | True | False | Total |
| static Sv out (const RefAny& v, const Sv& = {}) { return Simple(v.s + "_outV"); } |
1 |
0 |
1 |
| static Sv out (const RefAny& v, const Sv& = {}) { return Simple(v.s + "_outV"); } |
1 |
0 |
1 |
|
| 31 |
|
| }; |
| 32 |
|
| |
| 33 |
|
| template<> struct Typemap<RefAny&> : TypemapBase<RefAny&> { |
| 34 |
1 |
| static RefAny& in (const Simple& arg) { |
| 35 |
1 |
▶ | static RefAny r(""); |
Branch: 4 branches
| Branch | True | False | Total |
| static RefAny r(""); |
1 |
0 |
1 |
| static RefAny r(""); |
1 |
0 |
1 |
| static RefAny r(""); |
1 |
0 |
1 |
| static RefAny r(""); |
0 |
0 |
0 |
|
| 36 |
1 |
▶ | r.s = arg.as_string() + "_inR"; |
Branch: 3 branches
| Branch | True | False | Total |
| r.s = arg.as_string() + "_inR"; |
1 |
0 |
1 |
| r.s = arg.as_string() + "_inR"; |
1 |
0 |
1 |
| r.s = arg.as_string() + "_inR"; |
1 |
0 |
1 |
|
| 37 |
1 |
| return r; |
| 38 |
|
| } |
| 39 |
1 |
▶ | static Sv out (RefAny& v, const Sv& = {}) { return Simple(v.s + "_outR"); } |
Branch: 2 branches
| Branch | True | False | Total |
| static Sv out (RefAny& v, const Sv& = {}) { return Simple(v.s + "_outR"); } |
1 |
0 |
1 |
| static Sv out (RefAny& v, const Sv& = {}) { return Simple(v.s + "_outR"); } |
1 |
0 |
1 |
|
| 40 |
|
| }; |
| 41 |
|
| } |
| 42 |
|
| |
| 43 |
|
| using vv_fn = function<void()>; |
| 44 |
|
| using vi_fn = function<void(int)>; |
| 45 |
|
| using iid_fn = function<int(int, panda::string_view)>; |
| 46 |
|
| using iis_fn = function<int(int, panda::string_view)>; |
| 47 |
|
| |
| 48 |
|
| struct Data { |
| 49 |
|
| int i; |
| 50 |
4 |
| Data (int i) : i(i) {} |
| 51 |
|
| }; |
| 52 |
|
| |
| 53 |
7 |
| TEST_CASE("sub->function", "[function]") { |
| 54 |
7 |
▶ | eval("$MyTest::_marker = undef"); |
Branch: 1 branch
| Branch | True | False | Total |
| eval("$MyTest::_marker = undef"); |
7 |
0 |
7 |
|
| 55 |
7 |
▶ | auto marker = Stash("MyTest")["_marker"].scalar(); |
Branch: 3 branches
| Branch | True | False | Total |
| auto marker = Stash("MyTest")["_marker"].scalar(); |
7 |
0 |
7 |
| auto marker = Stash("MyTest")["_marker"].scalar(); |
7 |
0 |
7 |
| auto marker = Stash("MyTest")["_marker"].scalar(); |
7 |
0 |
7 |
|
| 56 |
|
| |
| 57 |
7 |
▶ | SECTION("void()") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("void()") { |
7 |
0 |
7 |
| SECTION("void()") { |
7 |
0 |
7 |
| SECTION("void()") { |
1 |
6 |
7 |
|
| 58 |
1 |
▶ | auto fn = xs::in<vv_fn>(Sub::create("$MyTest::_marker = 1")); |
Branch: 2 branches
| Branch | True | False | Total |
| auto fn = xs::in<vv_fn>(Sub::create("$MyTest::_marker = 1")); |
1 |
0 |
1 |
| auto fn = xs::in<vv_fn>(Sub::create("$MyTest::_marker = 1")); |
1 |
0 |
1 |
|
| 59 |
1 |
▶ | fn(); |
Branch: 1 branch
| Branch | True | False | Total |
| fn(); |
1 |
0 |
1 |
|
| 60 |
1 |
▶ | CHECK(marker.is_true()); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(marker.is_true()); |
1 |
0 |
1 |
| CHECK(marker.is_true()); |
1 |
0 |
1 |
| CHECK(marker.is_true()); |
1 |
0 |
1 |
| CHECK(marker.is_true()); |
1 |
0 |
1 |
| CHECK(marker.is_true()); |
1 |
0 |
1 |
| CHECK(marker.is_true()); |
0 |
0 |
0 |
| CHECK(marker.is_true()); |
0 |
0 |
0 |
|
| 61 |
8 |
| } |
| 62 |
7 |
▶ | SECTION("void(int)") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("void(int)") { |
7 |
0 |
7 |
| SECTION("void(int)") { |
7 |
0 |
7 |
| SECTION("void(int)") { |
1 |
6 |
7 |
|
| 63 |
1 |
▶ | auto fn = xs::in<vi_fn>(Sub::create("$MyTest::_marker = shift")); |
Branch: 2 branches
| Branch | True | False | Total |
| auto fn = xs::in<vi_fn>(Sub::create("$MyTest::_marker = shift")); |
1 |
0 |
1 |
| auto fn = xs::in<vi_fn>(Sub::create("$MyTest::_marker = shift")); |
1 |
0 |
1 |
|
| 64 |
1 |
▶ | fn(42); |
Branch: 1 branch
| Branch | True | False | Total |
| fn(42); |
1 |
0 |
1 |
|
| 65 |
1 |
▶ | CHECK(Simple(marker) == 42); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(marker) == 42); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 42); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 42); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 42); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 42); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 42); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 42); |
0 |
0 |
0 |
| CHECK(Simple(marker) == 42); |
0 |
0 |
0 |
|
| 66 |
8 |
| } |
| 67 |
7 |
▶ | SECTION("void(int) custom") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("void(int) custom") { |
7 |
0 |
7 |
| SECTION("void(int) custom") { |
7 |
0 |
7 |
| SECTION("void(int) custom") { |
1 |
6 |
7 |
|
| 68 |
1 |
▶ | auto sub = Sub::create("$MyTest::_marker = shift"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = Sub::create("$MyTest::_marker = shift"); |
1 |
0 |
1 |
|
| 69 |
2 |
▶ | auto fn = xs::sub2function<vi_fn>(sub, [](int val) { return Simple(val + 100); }); |
Branch: 1 branch
| Branch | True | False | Total |
| auto fn = xs::sub2function<vi_fn>(sub, [](int val) { return Simple(val + 100); }); |
1 |
0 |
1 |
|
| 70 |
1 |
▶ | fn(42); |
Branch: 1 branch
| Branch | True | False | Total |
| fn(42); |
1 |
0 |
1 |
|
| 71 |
1 |
▶ | CHECK(Simple(marker) == 142); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(marker) == 142); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 142); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 142); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 142); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 142); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 142); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 142); |
0 |
0 |
0 |
| CHECK(Simple(marker) == 142); |
0 |
0 |
0 |
|
| 72 |
8 |
| } |
| 73 |
7 |
▶ | SECTION("int(int,string_view)") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("int(int,string_view)") { |
7 |
0 |
7 |
| SECTION("int(int,string_view)") { |
7 |
0 |
7 |
| SECTION("int(int,string_view)") { |
1 |
6 |
7 |
|
| 74 |
1 |
▶ | auto sub = Sub::create("$MyTest::_marker = [@_]; return 10"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = Sub::create("$MyTest::_marker = [@_]; return 10"); |
1 |
0 |
1 |
|
| 75 |
1 |
▶ | auto fn = xs::in<iis_fn>(sub); |
Branch: 1 branch
| Branch | True | False | Total |
| auto fn = xs::in<iis_fn>(sub); |
1 |
0 |
1 |
|
| 76 |
1 |
▶ | auto res = fn(42, "the string"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto res = fn(42, "the string"); |
1 |
0 |
1 |
|
| 77 |
1 |
▶ | CHECK(res == 10); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(res == 10); |
1 |
0 |
1 |
| CHECK(res == 10); |
1 |
0 |
1 |
| CHECK(res == 10); |
1 |
0 |
1 |
| CHECK(res == 10); |
1 |
0 |
1 |
| CHECK(res == 10); |
1 |
0 |
1 |
| CHECK(res == 10); |
0 |
0 |
0 |
| CHECK(res == 10); |
0 |
0 |
0 |
|
| 78 |
1 |
▶ | CHECK(Simple(Array(marker)[0]) == 42); |
Branch: 10 branches
| Branch | True | False | Total |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 42); |
0 |
0 |
0 |
| CHECK(Simple(Array(marker)[0]) == 42); |
0 |
0 |
0 |
|
| 79 |
1 |
▶ | CHECK(Simple(Array(marker)[1]) == "the string"); |
Branch: 10 branches
| Branch | True | False | Total |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
0 |
0 |
0 |
| CHECK(Simple(Array(marker)[1]) == "the string"); |
0 |
0 |
0 |
|
| 80 |
8 |
| } |
| 81 |
7 |
▶ | SECTION("int(int,string_view) custom") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("int(int,string_view) custom") { |
7 |
0 |
7 |
| SECTION("int(int,string_view) custom") { |
7 |
0 |
7 |
| SECTION("int(int,string_view) custom") { |
1 |
6 |
7 |
|
| 82 |
1 |
▶ | auto sub = Sub::create("$MyTest::_marker = [@_]; return 10"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = Sub::create("$MyTest::_marker = [@_]; return 10"); |
1 |
0 |
1 |
|
| 83 |
|
| |
| 84 |
|
| auto fn = xs::sub2function<iis_fn>( |
| 85 |
|
| sub, |
| 86 |
1 |
| [=](const Sv& sv) { return SvIV(sv) + 10; }, |
| 87 |
1 |
| [](int val) { return Simple(val + 100); } |
| 88 |
1 |
▶ | ); |
Branch: 1 branch
| Branch | True | False | Total |
| ); |
1 |
0 |
1 |
|
| 89 |
|
| |
| 90 |
1 |
▶ | auto res = fn(42, "a string"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto res = fn(42, "a string"); |
1 |
0 |
1 |
|
| 91 |
1 |
▶ | CHECK(res == 20); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(res == 20); |
1 |
0 |
1 |
| CHECK(res == 20); |
1 |
0 |
1 |
| CHECK(res == 20); |
1 |
0 |
1 |
| CHECK(res == 20); |
1 |
0 |
1 |
| CHECK(res == 20); |
1 |
0 |
1 |
| CHECK(res == 20); |
0 |
0 |
0 |
| CHECK(res == 20); |
0 |
0 |
0 |
|
| 92 |
1 |
▶ | CHECK(Simple(Array(marker)[0]) == 142); |
Branch: 10 branches
| Branch | True | False | Total |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[0]) == 142); |
0 |
0 |
0 |
| CHECK(Simple(Array(marker)[0]) == 142); |
0 |
0 |
0 |
|
| 93 |
1 |
▶ | CHECK(Simple(Array(marker)[1]) == "a string"); |
Branch: 10 branches
| Branch | True | False | Total |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
1 |
0 |
1 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
0 |
0 |
0 |
| CHECK(Simple(Array(marker)[1]) == "a string"); |
0 |
0 |
0 |
|
| 94 |
8 |
| } |
| 95 |
7 |
▶ | SECTION("sub->function->sub") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("sub->function->sub") { |
7 |
0 |
7 |
| SECTION("sub->function->sub") { |
7 |
0 |
7 |
| SECTION("sub->function->sub") { |
1 |
6 |
7 |
|
| 96 |
1 |
▶ | auto src = Sub::create("$MyTest::_marker = shift"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto src = Sub::create("$MyTest::_marker = shift"); |
1 |
0 |
1 |
|
| 97 |
1 |
▶ | auto fn = xs::in<vi_fn>(src); |
Branch: 1 branch
| Branch | True | False | Total |
| auto fn = xs::in<vi_fn>(src); |
1 |
0 |
1 |
|
| 98 |
1 |
▶ | Sub sub = xs::out(fn); |
Branch: 2 branches
| Branch | True | False | Total |
| Sub sub = xs::out(fn); |
1 |
0 |
1 |
| Sub sub = xs::out(fn); |
1 |
0 |
1 |
|
| 99 |
1 |
▶ | CHECK(sub == src); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(sub == src); |
1 |
0 |
1 |
| CHECK(sub == src); |
1 |
0 |
1 |
| CHECK(sub == src); |
1 |
0 |
1 |
| CHECK(sub == src); |
1 |
0 |
1 |
| CHECK(sub == src); |
1 |
0 |
1 |
| CHECK(sub == src); |
0 |
0 |
0 |
| CHECK(sub == src); |
0 |
0 |
0 |
|
| 100 |
1 |
▶ | sub.call(Simple(43)); |
Branch: 2 branches
| Branch | True | False | Total |
| sub.call(Simple(43)); |
1 |
0 |
1 |
| sub.call(Simple(43)); |
1 |
0 |
1 |
|
| 101 |
1 |
▶ | CHECK(Simple(marker) == 43); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(marker) == 43); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 43); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 43); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 43); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 43); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 43); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 43); |
0 |
0 |
0 |
| CHECK(Simple(marker) == 43); |
0 |
0 |
0 |
|
| 102 |
8 |
| } |
| 103 |
7 |
▶ | SECTION("custom when no typemap") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("custom when no typemap") { |
7 |
0 |
7 |
| SECTION("custom when no typemap") { |
7 |
0 |
7 |
| SECTION("custom when no typemap") { |
1 |
6 |
7 |
|
| 104 |
1 |
▶ | auto sub = Sub::create("$MyTest::_marker = $_[0]; return $_[0] + 100"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = Sub::create("$MyTest::_marker = $_[0]; return $_[0] + 100"); |
1 |
0 |
1 |
|
| 105 |
|
| |
| 106 |
|
| auto fn = sub2function<function<Data(const Data&)>>( |
| 107 |
|
| sub, |
| 108 |
1 |
▶ | [=](const Sv& sv) { return Data((int)Simple(sv) + 1); }, |
Branch: 2 branches
| Branch | True | False | Total |
| [=](const Sv& sv) { return Data((int)Simple(sv) + 1); }, |
1 |
0 |
1 |
| [=](const Sv& sv) { return Data((int)Simple(sv) + 1); }, |
1 |
0 |
1 |
|
| 109 |
1 |
| [] (const Data& data) { return Simple(data.i + 2); } |
| 110 |
1 |
▶ | ); |
Branch: 1 branch
| Branch | True | False | Total |
| ); |
1 |
0 |
1 |
|
| 111 |
|
| |
| 112 |
1 |
▶ | auto ret = fn(Data(100)); |
Branch: 1 branch
| Branch | True | False | Total |
| auto ret = fn(Data(100)); |
1 |
0 |
1 |
|
| 113 |
1 |
▶ | CHECK(ret.i == 203); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(ret.i == 203); |
1 |
0 |
1 |
| CHECK(ret.i == 203); |
1 |
0 |
1 |
| CHECK(ret.i == 203); |
1 |
0 |
1 |
| CHECK(ret.i == 203); |
1 |
0 |
1 |
| CHECK(ret.i == 203); |
1 |
0 |
1 |
| CHECK(ret.i == 203); |
0 |
0 |
0 |
| CHECK(ret.i == 203); |
0 |
0 |
0 |
|
| 114 |
1 |
▶ | CHECK(Simple(marker) == 102); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(marker) == 102); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 102); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 102); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 102); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 102); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 102); |
1 |
0 |
1 |
| CHECK(Simple(marker) == 102); |
0 |
0 |
0 |
| CHECK(Simple(marker) == 102); |
0 |
0 |
0 |
|
| 115 |
8 |
| } |
| 116 |
|
| #ifdef USE_ITHREADS |
| 117 |
|
| SECTION("with threads") { |
| 118 |
|
| eval("require threads"); |
| 119 |
|
| Stash threads("threads"); |
| 120 |
|
| int tid = threads.call<Simple>("tid"); |
| 121 |
|
| auto sub = Sub::create("$MyTest::_marker = threads->tid(); return $_[0] + 10"); |
| 122 |
|
| auto fn = xs::in<function<int(int)>>(sub); |
| 123 |
|
| |
| 124 |
|
| auto res = fn(1); |
| 125 |
|
| CHECK(res == 11); |
| 126 |
|
| CHECK(Simple(marker) == tid); |
| 127 |
|
| |
| 128 |
|
| function<void()> thr_fn = [&] { res = fn(2); }; |
| 129 |
|
| |
| 130 |
|
| // fn() must call correct sub (from correct interpreter thread) |
| 131 |
|
| Stash("threads").call<Object>("create", xs::out(thr_fn)).call("join"); |
| 132 |
|
| CHECK(res == 12); |
| 133 |
|
| CHECK(Simple(marker) == tid); // marker in master thread should not be changed |
| 134 |
|
| |
| 135 |
|
| // check that fn() is not corrupted by svt_dup or svt_free |
| 136 |
|
| res = fn(3); |
| 137 |
|
| CHECK(res == 13); |
| 138 |
|
| CHECK(Simple(marker) == tid); |
| 139 |
|
| } |
| 140 |
|
| #endif |
| 141 |
7 |
| } |
| 142 |
|
| |
| 143 |
10 |
| TEST_CASE("function->sub", "[function]") { |
| 144 |
10 |
| int ecnt = 0; |
| 145 |
10 |
| int cnt = 0; |
| 146 |
10 |
▶ | SECTION("void()") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("void()") { |
10 |
0 |
10 |
| SECTION("void()") { |
10 |
0 |
10 |
| SECTION("void()") { |
1 |
9 |
10 |
|
| 147 |
1 |
| ecnt = 1; |
| 148 |
1 |
▶ | vv_fn fn = [&](){ cnt++; }; |
Branch: 1 branch
| Branch | True | False | Total |
| vv_fn fn = [&](){ cnt++; }; |
1 |
0 |
1 |
|
| 149 |
1 |
▶ | auto sub = function2sub(fn); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = function2sub(fn); |
1 |
0 |
1 |
|
| 150 |
1 |
▶ | sub.call<void>(); |
Branch: 1 branch
| Branch | True | False | Total |
| sub.call<void>(); |
1 |
0 |
1 |
|
| 151 |
11 |
| } |
| 152 |
10 |
▶ | SECTION("void(int)") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("void(int)") { |
10 |
0 |
10 |
| SECTION("void(int)") { |
10 |
0 |
10 |
| SECTION("void(int)") { |
1 |
9 |
10 |
|
| 153 |
1 |
| ecnt = 1; |
| 154 |
0 |
| vi_fn fn = [&](int val) { |
| 155 |
1 |
▶ | CHECK(val == 42); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
0 |
0 |
0 |
| CHECK(val == 42); |
0 |
0 |
0 |
|
| 156 |
1 |
| cnt++; |
| 157 |
2 |
▶ | }; |
Branch: 1 branch
| Branch | True | False | Total |
| }; |
1 |
0 |
1 |
|
| 158 |
1 |
▶ | auto sub = function2sub(fn); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = function2sub(fn); |
1 |
0 |
1 |
|
| 159 |
1 |
▶ | sub.call<void>(Simple(42)); |
Branch: 2 branches
| Branch | True | False | Total |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
|
| 160 |
11 |
| } |
| 161 |
10 |
▶ | SECTION("void(int) custom") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("void(int) custom") { |
10 |
0 |
10 |
| SECTION("void(int) custom") { |
10 |
0 |
10 |
| SECTION("void(int) custom") { |
1 |
9 |
10 |
|
| 162 |
1 |
| ecnt = 1; |
| 163 |
0 |
| vi_fn fn = [&](int val) { |
| 164 |
1 |
▶ | CHECK(val == 942); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(val == 942); |
1 |
0 |
1 |
| CHECK(val == 942); |
1 |
0 |
1 |
| CHECK(val == 942); |
1 |
0 |
1 |
| CHECK(val == 942); |
1 |
0 |
1 |
| CHECK(val == 942); |
1 |
0 |
1 |
| CHECK(val == 942); |
0 |
0 |
0 |
| CHECK(val == 942); |
0 |
0 |
0 |
|
| 165 |
1 |
| cnt++; |
| 166 |
2 |
▶ | }; |
Branch: 1 branch
| Branch | True | False | Total |
| }; |
1 |
0 |
1 |
|
| 167 |
2 |
▶ | auto sub = function2sub(fn, [](const Sv& sv){ return (int)Simple(sv) + 900; }); |
Branch: 3 branches
| Branch | True | False | Total |
| auto sub = function2sub(fn, [](const Sv& sv){ return (int)Simple(sv) + 900; }); |
1 |
0 |
1 |
| auto sub = function2sub(fn, [](const Sv& sv){ return (int)Simple(sv) + 900; }); |
1 |
0 |
1 |
| auto sub = function2sub(fn, [](const Sv& sv){ return (int)Simple(sv) + 900; }); |
1 |
0 |
1 |
|
| 168 |
1 |
▶ | sub.call<void>(Simple(42)); |
Branch: 2 branches
| Branch | True | False | Total |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
|
| 169 |
11 |
| } |
| 170 |
10 |
▶ | SECTION("int(int, double)") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("int(int, double)") { |
10 |
0 |
10 |
| SECTION("int(int, double)") { |
10 |
0 |
10 |
| SECTION("int(int, double)") { |
1 |
9 |
10 |
|
| 171 |
1 |
| ecnt = 1; |
| 172 |
0 |
| iid_fn fn = [&](int i, panda::string_view d) { |
| 173 |
1 |
▶ | CHECK(i == 42); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(i == 42); |
1 |
0 |
1 |
| CHECK(i == 42); |
1 |
0 |
1 |
| CHECK(i == 42); |
1 |
0 |
1 |
| CHECK(i == 42); |
1 |
0 |
1 |
| CHECK(i == 42); |
1 |
0 |
1 |
| CHECK(i == 42); |
0 |
0 |
0 |
| CHECK(i == 42); |
0 |
0 |
0 |
|
| 174 |
1 |
▶ | CHECK(d == "hello"); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(d == "hello"); |
1 |
0 |
1 |
| CHECK(d == "hello"); |
1 |
0 |
1 |
| CHECK(d == "hello"); |
1 |
0 |
1 |
| CHECK(d == "hello"); |
1 |
0 |
1 |
| CHECK(d == "hello"); |
1 |
0 |
1 |
| CHECK(d == "hello"); |
0 |
0 |
0 |
| CHECK(d == "hello"); |
0 |
0 |
0 |
|
| 175 |
1 |
| cnt++; |
| 176 |
1 |
| return 255; |
| 177 |
1 |
▶ | }; |
Branch: 1 branch
| Branch | True | False | Total |
| }; |
1 |
0 |
1 |
|
| 178 |
1 |
▶ | Sub sub = xs::out(fn); |
Branch: 2 branches
| Branch | True | False | Total |
| Sub sub = xs::out(fn); |
1 |
0 |
1 |
| Sub sub = xs::out(fn); |
1 |
0 |
1 |
|
| 179 |
1 |
▶ | Scalar ret = sub.call(Simple(42), Simple("hello")); |
Branch: 3 branches
| Branch | True | False | Total |
| Scalar ret = sub.call(Simple(42), Simple("hello")); |
1 |
0 |
1 |
| Scalar ret = sub.call(Simple(42), Simple("hello")); |
1 |
0 |
1 |
| Scalar ret = sub.call(Simple(42), Simple("hello")); |
1 |
0 |
1 |
|
| 180 |
1 |
▶ | CHECK(Simple(ret) == 255); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(ret) == 255); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 255); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 255); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 255); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 255); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 255); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 255); |
0 |
0 |
0 |
| CHECK(Simple(ret) == 255); |
0 |
0 |
0 |
|
| 181 |
11 |
| } |
| 182 |
10 |
▶ | SECTION("int(int, double) custom") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("int(int, double) custom") { |
10 |
0 |
10 |
| SECTION("int(int, double) custom") { |
10 |
0 |
10 |
| SECTION("int(int, double) custom") { |
1 |
9 |
10 |
|
| 183 |
1 |
| ecnt = 1; |
| 184 |
0 |
| iid_fn fn = [&](int i, panda::string_view d) { |
| 185 |
1 |
▶ | CHECK(i == 842); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(i == 842); |
1 |
0 |
1 |
| CHECK(i == 842); |
1 |
0 |
1 |
| CHECK(i == 842); |
1 |
0 |
1 |
| CHECK(i == 842); |
1 |
0 |
1 |
| CHECK(i == 842); |
1 |
0 |
1 |
| CHECK(i == 842); |
0 |
0 |
0 |
| CHECK(i == 842); |
0 |
0 |
0 |
|
| 186 |
1 |
▶ | CHECK(d == "hi"); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(d == "hi"); |
1 |
0 |
1 |
| CHECK(d == "hi"); |
1 |
0 |
1 |
| CHECK(d == "hi"); |
1 |
0 |
1 |
| CHECK(d == "hi"); |
1 |
0 |
1 |
| CHECK(d == "hi"); |
1 |
0 |
1 |
| CHECK(d == "hi"); |
0 |
0 |
0 |
| CHECK(d == "hi"); |
0 |
0 |
0 |
|
| 187 |
1 |
| cnt++; |
| 188 |
1 |
| return 255; |
| 189 |
1 |
▶ | }; |
Branch: 1 branch
| Branch | True | False | Total |
| }; |
1 |
0 |
1 |
|
| 190 |
|
| auto sub = function2sub(fn, |
| 191 |
1 |
| [](int r) { return Simple(r - 200); }, |
| 192 |
1 |
▶ | [](const Sv& sv) { return (int)Simple(sv) + 800; } |
Branch: 2 branches
| Branch | True | False | Total |
| [](const Sv& sv) { return (int)Simple(sv) + 800; } |
1 |
0 |
1 |
| [](const Sv& sv) { return (int)Simple(sv) + 800; } |
1 |
0 |
1 |
|
| 193 |
1 |
▶ | ); |
Branch: 1 branch
| Branch | True | False | Total |
| ); |
1 |
0 |
1 |
|
| 194 |
1 |
▶ | Scalar ret = sub.call(Simple(42), Simple("hi")); |
Branch: 3 branches
| Branch | True | False | Total |
| Scalar ret = sub.call(Simple(42), Simple("hi")); |
1 |
0 |
1 |
| Scalar ret = sub.call(Simple(42), Simple("hi")); |
1 |
0 |
1 |
| Scalar ret = sub.call(Simple(42), Simple("hi")); |
1 |
0 |
1 |
|
| 195 |
1 |
▶ | CHECK(Simple(ret) == 55); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(ret) == 55); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 55); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 55); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 55); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 55); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 55); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 55); |
0 |
0 |
0 |
| CHECK(Simple(ret) == 55); |
0 |
0 |
0 |
|
| 196 |
11 |
| } |
| 197 |
10 |
▶ | SECTION("function->sub->function") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("function->sub->function") { |
10 |
0 |
10 |
| SECTION("function->sub->function") { |
10 |
0 |
10 |
| SECTION("function->sub->function") { |
1 |
9 |
10 |
|
| 198 |
1 |
| ecnt = 2; |
| 199 |
0 |
| vi_fn fn = [&](int val) { |
| 200 |
2 |
▶ | CHECK(val == 42); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(val == 42); |
2 |
0 |
2 |
| CHECK(val == 42); |
2 |
0 |
2 |
| CHECK(val == 42); |
2 |
0 |
2 |
| CHECK(val == 42); |
2 |
0 |
2 |
| CHECK(val == 42); |
2 |
0 |
2 |
| CHECK(val == 42); |
0 |
0 |
0 |
| CHECK(val == 42); |
0 |
0 |
0 |
|
| 201 |
2 |
| cnt++; |
| 202 |
3 |
▶ | }; |
Branch: 1 branch
| Branch | True | False | Total |
| }; |
1 |
0 |
1 |
|
| 203 |
1 |
▶ | auto sub = function2sub(fn); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = function2sub(fn); |
1 |
0 |
1 |
|
| 204 |
1 |
▶ | sub.call<void>(Simple(42)); |
Branch: 2 branches
| Branch | True | False | Total |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
|
| 205 |
1 |
▶ | auto fn2 = xs::in<vi_fn>(sub); |
Branch: 1 branch
| Branch | True | False | Total |
| auto fn2 = xs::in<vi_fn>(sub); |
1 |
0 |
1 |
|
| 206 |
1 |
▶ | fn2(42); |
Branch: 1 branch
| Branch | True | False | Total |
| fn2(42); |
1 |
0 |
1 |
|
| 207 |
1 |
▶ | CHECK(fn == fn2); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(fn == fn2); |
1 |
0 |
1 |
| CHECK(fn == fn2); |
1 |
0 |
1 |
| CHECK(fn == fn2); |
1 |
0 |
1 |
| CHECK(fn == fn2); |
1 |
0 |
1 |
| CHECK(fn == fn2); |
1 |
0 |
1 |
| CHECK(fn == fn2); |
0 |
0 |
0 |
| CHECK(fn == fn2); |
0 |
0 |
0 |
|
| 208 |
11 |
| } |
| 209 |
10 |
▶ | SECTION("removing references") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("removing references") { |
10 |
0 |
10 |
| SECTION("removing references") { |
10 |
0 |
10 |
| SECTION("removing references") { |
1 |
9 |
10 |
|
| 210 |
1 |
| ecnt = 1; |
| 211 |
0 |
| function<void(int&)> fn = [&](int& val) { |
| 212 |
1 |
▶ | CHECK(val == 42); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
1 |
0 |
1 |
| CHECK(val == 42); |
0 |
0 |
0 |
| CHECK(val == 42); |
0 |
0 |
0 |
|
| 213 |
1 |
| cnt++; |
| 214 |
2 |
▶ | }; |
Branch: 1 branch
| Branch | True | False | Total |
| }; |
1 |
0 |
1 |
|
| 215 |
1 |
▶ | auto sub = function2sub(fn); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = function2sub(fn); |
1 |
0 |
1 |
|
| 216 |
1 |
▶ | sub.call<void>(Simple(42)); |
Branch: 2 branches
| Branch | True | False | Total |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
| sub.call<void>(Simple(42)); |
1 |
0 |
1 |
|
| 217 |
11 |
| } |
| 218 |
10 |
▶ | SECTION("custom when no typemap") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("custom when no typemap") { |
10 |
0 |
10 |
| SECTION("custom when no typemap") { |
10 |
0 |
10 |
| SECTION("custom when no typemap") { |
1 |
9 |
10 |
|
| 219 |
2 |
▶ | function<Data(const Data&)> fn = [&](const Data& data) { return data.i + 100; }; |
Branch: 1 branch
| Branch | True | False | Total |
| function<Data(const Data&)> fn = [&](const Data& data) { return data.i + 100; }; |
1 |
0 |
1 |
|
| 220 |
|
| auto sub = function2sub(fn, |
| 221 |
1 |
| [](const Data& data) { return Simple(data.i + 1000); }, |
| 222 |
1 |
▶ | [](const Sv& sv) { return Data((int)Simple(sv) + 10); } |
Branch: 2 branches
| Branch | True | False | Total |
| [](const Sv& sv) { return Data((int)Simple(sv) + 10); } |
1 |
0 |
1 |
| [](const Sv& sv) { return Data((int)Simple(sv) + 10); } |
1 |
0 |
1 |
|
| 223 |
1 |
▶ | ); |
Branch: 1 branch
| Branch | True | False | Total |
| ); |
1 |
0 |
1 |
|
| 224 |
1 |
▶ | Scalar ret = sub.call(Simple(1)); |
Branch: 2 branches
| Branch | True | False | Total |
| Scalar ret = sub.call(Simple(1)); |
1 |
0 |
1 |
| Scalar ret = sub.call(Simple(1)); |
1 |
0 |
1 |
|
| 225 |
1 |
▶ | CHECK(Simple(ret) == 1111); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(ret) == 1111); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 1111); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 1111); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 1111); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 1111); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 1111); |
1 |
0 |
1 |
| CHECK(Simple(ret) == 1111); |
0 |
0 |
0 |
| CHECK(Simple(ret) == 1111); |
0 |
0 |
0 |
|
| 226 |
11 |
| } |
| 227 |
10 |
▶ | SECTION("use ref typemap when it exists") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("use ref typemap when it exists") { |
10 |
0 |
10 |
| SECTION("use ref typemap when it exists") { |
10 |
0 |
10 |
| SECTION("use ref typemap when it exists") { |
2 |
8 |
10 |
|
| 228 |
2 |
▶ | SECTION("exists only ref typemap") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("exists only ref typemap") { |
2 |
0 |
2 |
| SECTION("exists only ref typemap") { |
2 |
0 |
2 |
| SECTION("exists only ref typemap") { |
1 |
1 |
2 |
|
| 229 |
|
| using ref_fn = function<RefOnly&(RefOnly&)>; |
| 230 |
2 |
▶ | ref_fn fn = [](RefOnly& v) -> RefOnly& { v.s += "_call"; return v; }; |
Branch: 1 branch
| Branch | True | False | Total |
| ref_fn fn = [](RefOnly& v) -> RefOnly& { v.s += "_call"; return v; }; |
1 |
0 |
1 |
|
| 231 |
1 |
▶ | auto sub = function2sub(fn); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = function2sub(fn); |
1 |
0 |
1 |
|
| 232 |
1 |
▶ | Scalar ret = sub.call(Simple("hello")); |
Branch: 2 branches
| Branch | True | False | Total |
| Scalar ret = sub.call(Simple("hello")); |
1 |
0 |
1 |
| Scalar ret = sub.call(Simple("hello")); |
1 |
0 |
1 |
|
| 233 |
1 |
▶ | CHECK(Simple(ret) == "hello_in_call_out"); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(ret) == "hello_in_call_out"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_in_call_out"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_in_call_out"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_in_call_out"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_in_call_out"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_in_call_out"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_in_call_out"); |
0 |
0 |
0 |
| CHECK(Simple(ret) == "hello_in_call_out"); |
0 |
0 |
0 |
|
| 234 |
3 |
| } |
| 235 |
2 |
▶ | SECTION("prefer ref when both exists") { |
Branch: 3 branches
| Branch | True | False | Total |
| SECTION("prefer ref when both exists") { |
2 |
0 |
2 |
| SECTION("prefer ref when both exists") { |
2 |
0 |
2 |
| SECTION("prefer ref when both exists") { |
1 |
1 |
2 |
|
| 236 |
|
| using val_fn = function<RefAny(RefAny)>; |
| 237 |
2 |
▶ | val_fn vfn = [](const RefAny& v) -> RefAny { return RefAny(v.s + "_call"); }; |
Branch: 3 branches
| Branch | True | False | Total |
| val_fn vfn = [](const RefAny& v) -> RefAny { return RefAny(v.s + "_call"); }; |
1 |
0 |
1 |
| val_fn vfn = [](const RefAny& v) -> RefAny { return RefAny(v.s + "_call"); }; |
1 |
0 |
1 |
| val_fn vfn = [](const RefAny& v) -> RefAny { return RefAny(v.s + "_call"); }; |
1 |
0 |
1 |
|
| 238 |
1 |
▶ | auto sub = function2sub(vfn); |
Branch: 1 branch
| Branch | True | False | Total |
| auto sub = function2sub(vfn); |
1 |
0 |
1 |
|
| 239 |
1 |
▶ | Scalar ret = sub.call(Simple("hello")); |
Branch: 2 branches
| Branch | True | False | Total |
| Scalar ret = sub.call(Simple("hello")); |
1 |
0 |
1 |
| Scalar ret = sub.call(Simple("hello")); |
1 |
0 |
1 |
|
| 240 |
1 |
▶ | CHECK(Simple(ret) == "hello_inV_call_outV"); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
0 |
0 |
0 |
| CHECK(Simple(ret) == "hello_inV_call_outV"); |
0 |
0 |
0 |
|
| 241 |
|
| |
| 242 |
|
| using ref_fn = function<RefAny&(RefAny&)>; |
| 243 |
2 |
▶ | ref_fn rfn = [](RefAny& v) -> RefAny& { v.s += "_call"; return v; }; |
Branch: 1 branch
| Branch | True | False | Total |
| ref_fn rfn = [](RefAny& v) -> RefAny& { v.s += "_call"; return v; }; |
1 |
0 |
1 |
|
| 244 |
1 |
▶ | sub = function2sub(rfn); |
Branch: 1 branch
| Branch | True | False | Total |
| sub = function2sub(rfn); |
1 |
0 |
1 |
|
| 245 |
1 |
▶ | ret = sub.call(Simple("hello")); |
Branch: 2 branches
| Branch | True | False | Total |
| ret = sub.call(Simple("hello")); |
1 |
0 |
1 |
| ret = sub.call(Simple("hello")); |
1 |
0 |
1 |
|
| 246 |
1 |
▶ | CHECK(Simple(ret) == "hello_inR_call_outR"); |
Branch: 8 branches
| Branch | True | False | Total |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
1 |
0 |
1 |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
0 |
0 |
0 |
| CHECK(Simple(ret) == "hello_inR_call_outR"); |
0 |
0 |
0 |
|
| 247 |
3 |
| } |
| 248 |
10 |
| } |
| 249 |
|
| #ifdef USE_ITHREADS |
| 250 |
|
| SECTION("with threads") { |
| 251 |
|
| std::thread::id id; |
| 252 |
|
| eval("require threads"); |
| 253 |
|
| function<int()> fn = [&]{ id = std::this_thread::get_id(); return 55; }; |
| 254 |
|
| Sub sub = xs::out(fn); |
| 255 |
|
| // sub must clone it's magic ptr on svt_dup |
| 256 |
|
| Object thr = Stash("threads").call("create", Ref::create(sub)); |
| 257 |
|
| Simple res = thr.call("join"); |
| 258 |
|
| CHECK(res == 55); |
| 259 |
|
| CHECK(id != std::this_thread::get_id()); |
| 260 |
|
| //check that sub isn't broken by svt_dup |
| 261 |
|
| res = sub.call(); |
| 262 |
|
| CHECK(res == 55); |
| 263 |
|
| CHECK(id == std::this_thread::get_id()); |
| 264 |
|
| } |
| 265 |
|
| #endif |
| 266 |
|
| |
| 267 |
10 |
▶ | CHECK(cnt == ecnt); |
Branch: 7 branches
| Branch | True | False | Total |
| CHECK(cnt == ecnt); |
10 |
0 |
10 |
| CHECK(cnt == ecnt); |
10 |
0 |
10 |
| CHECK(cnt == ecnt); |
10 |
0 |
10 |
| CHECK(cnt == ecnt); |
10 |
0 |
10 |
| CHECK(cnt == ecnt); |
10 |
0 |
10 |
| CHECK(cnt == ecnt); |
0 |
0 |
0 |
| CHECK(cnt == ecnt); |
0 |
0 |
0 |
|
| 268 |
10 |
| } |
| 269 |
|
| |
| 270 |
|
| //uint64_t bench_vv (Sub sub, int cnt) { |
| 271 |
|
| // RETVAL = 0; |
| 272 |
|
| // for (int i = 0; i < cnt; ++i) { |
| 273 |
|
| // RETVAL += (uint64_t)sub2function<vv_fn>(sub).func.get(); |
| 274 |
|
| // } |
| 275 |
|
| //} |
| 276 |
|
| // |
| 277 |
|
| //uint64_t bench_vi (Sub sub, int cnt) { |
| 278 |
|
| // RETVAL = 0; |
| 279 |
|
| // for (int i = 0; i < cnt; ++i) { |
| 280 |
|
| // RETVAL += (uint64_t)sub2function<vi_fn>(sub).func.get(); |
| 281 |
|
| // } |
| 282 |
|
| //} |
| 283 |
|
| // |
| 284 |
|
| //uint64_t bench_iis (Sub sub, int cnt) { |
| 285 |
|
| // RETVAL = 0; |
| 286 |
|
| // for (int i = 0; i < cnt; ++i) { |
| 287 |
|
| // RETVAL += (uint64_t)sub2function<iis_fn>(sub).func.get(); |
| 288 |
|
| // } |
| 289 |
|
| //} |
| 290 |
|
| // |
| 291 |
|
| //uint64_t bench_vvR (int cnt) { |
| 292 |
|
| // RETVAL = 0; |
| 293 |
|
| // vv_fn fn = [](){}; |
| 294 |
|
| // for (int i = 0; i < cnt; ++i) { |
| 295 |
|
| // RETVAL += (uint64_t)function2sub(fn).get(); |
| 296 |
|
| // } |
| 297 |
|
| //} |
| 298 |
|
| // |
| 299 |
|
| //uint64_t bench_viR (int cnt) { |
| 300 |
|
| // RETVAL = 0; |
| 301 |
|
| // vi_fn fn = [](int){}; |
| 302 |
|
| // for (int i = 0; i < cnt; ++i) { |
| 303 |
|
| // RETVAL += (uint64_t)function2sub(fn).get(); |
| 304 |
|
| // } |
| 305 |
|
| //} |
| 306 |
|
| // |
| 307 |
|
| //uint64_t bench_iisR (int cnt) { |
| 308 |
|
| // RETVAL = 0; |
| 309 |
|
| // iis_fn fn = [](int a, string_view d) -> int { return a + d.length(); }; |
| 310 |
|
| // for (int i = 0; i < cnt; ++i) { |
| 311 |
|
| // RETVAL += (uint64_t)function2sub(fn).get(); |
| 312 |
|
| // } |
| 313 |
|
| //} |