7 EXPECT_EQ(demangle<const int>(),
"const int");
8 EXPECT_EQ(demangle<volatile int>(),
"volatile int");
9 EXPECT_EQ(demangle<const volatile int >(),
"const volatile int");
15 this->create_context();
42 this->create_context();
44 bool function_called =
false;
45 c->add_function(
"wants_by_value", [&](
bool b,
char c,
int i,
float f){
46 function_called =
true;
52 c->run(
"wants_by_value(true, 2, 3, 4.5)");
55 function_called =
false;
56 c->add_function(
"wants_by_value", [&](
bool const & b,
char const & c,
int const & i,
float const & f){
57 function_called =
true;
63 c->run(
"wants_by_value(false, 5, 6, 7.5)");
69 bool takes_float_called =
false;
70 bool takes_float_pointer_called =
false;
71 i->add_function(
"takes_float", [&](
float f){takes_float_called =
true;
EXPECT_EQ(f, 5.5);});
72 i->add_function(
"takes_float_pointer", [&](
float * pf){takes_float_pointer_called =
true;
EXPECT_EQ(*pf, 6.5);});
73 i->add_function(
"takes_const_float", [&](
float const f){takes_float_called =
true;
EXPECT_EQ(f, 7.5);});
74 i->add_function(
"takes_const_float_pointer", [&](
float const * pf){takes_float_pointer_called =
true;
EXPECT_EQ(*pf, 8.5);});
75 this->create_context();
78 c->run(
"takes_float(5.5);");
79 c->run(
"takes_float_pointer(6.5);");
80 c->run(
"takes_const_float(7.5);");
81 c->run(
"takes_const_float_pointer(8.5);");
89 this->create_context();
106 this->deleted =
true;
115 this->create_context();
119 auto upi = unique_ptr<std::string, FlaggedDeleter<std::string>>(
new std::string(
"test string"));
133 auto upi = unique_ptr<std::string, FlaggedDeleter<std::string>>(
new std::string(
"test string"));
150 auto upi = unique_ptr<std::string, FlaggedDeleter<std::string>>(
new std::string(
"test string"));
172 this->create_context();
176 std::vector<std::string> v{
"hello",
"there",
"this",
"is",
"a",
"vector"};
177 c->add_variable(
"v",
CastToJS<decltype(v)>()(*i, v));
178 c->run(
"assert_contents(v, ['hello', 'there', 'this', 'is', 'a', 'vector'])");
181 std::vector<std::string>
const cv{
"hello",
"there",
"this",
"is",
"a",
"vector"};
182 c->add_variable(
"cv",
CastToJS<decltype(cv)>()(*i, cv));
183 c->run(
"assert_contents(cv, ['hello', 'there', 'this', 'is', 'a', 'vector'])");
188 std::vector<std::string> v{
"hello",
"there",
"this",
"is",
"a",
"vector"};
190 c->run(
"assert_contents(v, ['hello', 'there', 'this', 'is', 'a', 'vector'])");
198 auto js_vector = c->run(
"[`a`, `b`, `c`]");
205 auto js_vector = c->run(
"[`a`, `b`, `c`]");
217 this->create_context();
223 std::set<int> v{1, 2, 3};
224 c->add_variable(
"v",
CastToJS<decltype(v)>()(*i, v));
225 auto sum = c->run(
"let sum = 0; for (let e of v) {sum += e} sum;");
231 std::set<std::string>
const v{
"d",
"e",
"f"};
232 c->add_variable(
"v",
CastToJS<decltype(v)>()(*i, v));
233 c->run(
"let o1 = {}; for (let e of v) {o1[e]=1;} EXPECT_EQJS(o1, {d: 1, e: 1, f: 1});");
241 std::set<std::string> v{
"g",
"h",
"i"};
243 c->run(
"let o2 = {}; for (let e of v) {o2[e]=1;} EXPECT_EQJS(o2, {g: 1, h: 1, i: 1});");
252 auto js_set = c->run(
"[`a`, `b`, `c`]");
261 auto js_set = c->run(
"[`a`, `b`, `c`]");
276 this->create_context();
281 std::map<std::string, int> m{{
"a", 1}, {
"b", 2},{
"c", 3}};
282 c->add_variable(
"m",
CastToJS<decltype(m)>()(*i, m));
283 c->run(
"assert_contents(m, {a: 1, b: 2, c: 3})");
287 std::map<std::string, int>
const cm{{
"a", 1}, {
"b", 2}, {
"c", 3}};
288 c->add_variable(
"cm",
CastToJS<decltype(cm)>()(*i, cm));
289 c->run(
"assert_contents(cm, {a: 1, b: 2, c: 3})");
293 std::map<std::string, int> m{{
"a", 1}, {
"b", 2},{
"c", 3}};
295 c->run(
"assert_contents(m, {a: 1, b: 2, c: 3})");
299 auto js_object = c->run(
"new Object({a: 1, b: 2, c: 3});");
307 auto js_object = c->run(
"new Object({a: 1, b: 2, c: 3});");
324 this->create_context();
328 std::list<float> l{1.5, 2.5, 3.5, 4.5};
329 c->add_variable(
"l",
CastToJS<decltype(l)>()(*i, l));
330 c->run(
"assert_contents(l, [1.5, 2.5, 3.5, 4.5]);");
332 std::map<std::string, int> m{{
"one", 1},{
"two", 2},{
"three", 3}};
333 c->add_variable(
"m",
CastToJS<decltype(m)>()(*i, m));
334 c->run(
"assert_contents(m, {'one': 1, 'two': 2, 'three': 3});");
336 std::map<std::string, int> m2{{
"four", 4},{
"five", 5},{
"six", 6}};
337 c->add_variable(
"m2",
CastToJS<decltype(m2)>()(*i, m2));
338 c->run(
"assert_contents(m2, {'four': 4, 'five': 5, 'six': 6});");
340 std::deque<long> d{7000000000, 8000000000, 9000000000};
341 c->add_variable(
"d",
CastToJS<decltype(d)>()(*i, d));
342 c->run(
"assert_contents(d, [7000000000, 8000000000, 9000000000]);");
344 std::multimap<string, int> mm{{
"a",1},{
"a",2},{
"a",3},{
"b",4},{
"c",5},{
"c",6}};
345 c->add_variable(
"mm",
CastToJS<decltype(mm)>()(*i, mm));
346 c->run(
"assert_contents(mm, {a: [1, 2, 3], b: [4], c: [5, 6]});");
347 auto js_mm = c->run(
"mm");
349 assert(reconstituted_mm.size() == 6);
350 assert(reconstituted_mm.count(
"a") == 3);
351 assert(reconstituted_mm.count(
"b") == 1);
352 assert(reconstituted_mm.count(
"c") == 2);
354 std::array<int, 3> a{{1,2,3}};
355 c->add_variable(
"a",
CastToJS<decltype(a)>()(*i, a));
356 c->run(
"assert_contents(a, [1, 2, 3]);");
358 std::map<std::string, std::vector<int>> composite = {{
"a",{1,2,3}},{
"b",{4,5,6}},{
"c",{7,8,9}}};
359 c->add_variable(
"composite",
CastToJS<decltype(composite)>()(*i, composite));
360 c->run(
"assert_contents(composite, {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]});");
364 auto tuple =
make_tuple(1, 2.2, tuple_string);
365 c->expose_variable(
"tuple", tuple);
366 c->run(
"assert_contents(tuple, [1, 2.2, 'Hello'])");
379 std::weak_ptr<v8toolkit::Isolate> weak_isolate_pointer;
380 std::weak_ptr<v8toolkit::Script> weak_script_pointer;
382 decltype(std::declval<ScriptPtr>()->run_async()) future;
388 auto i = Platform::create_isolate();
389 weak_isolate_pointer = i->weak_from_this();
396 weak_script_pointer = s->weak_from_this();
400 future = s->run_async();
417 this->create_context();
422 bool wants_function_was_called =
false;
423 c->add_function(
"wants_function", [&](std::function<
bool(
int * pi,
float & rf)>
function) {
427 wants_function_was_called =
true;
436 int javascript_function_call_count = 0;
437 c->expose_variable(
"javascript_function_call_count", javascript_function_call_count);
438 c->run(
"wants_function(function(i, j){javascript_function_call_count++; return i == j;});");
441 EXPECT_EQ(javascript_function_call_count, 2);
451 this->create_context();
#define EXPECT_NE(val1, val2)
#define EXPECT_STREQ(s1, s2)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_FALSE(condition)
const T & move(const T &t)
TEST_F(JavaScriptFixture, Helpers)