ST_engine  0.3-ALPHA
lua_backend_tests.cpp
1 /* This file is part of the "ST" project.
2  * You may use, distribute or modify this code under the terms
3  * of the GNU General Public License version 2.
4  * See LICENCE.txt in the root directory of the project.
5  *
6  * Author: Maxim Atanasov
7  * E-mail: maxim.atanasov@protonmail.com
8  */
9 
10 #define TESTING_LUA_BACKEND
11 
12 #include <gtest/gtest.h>
13 #include <game_manager/lua_backend/lua_backend.cpp>
14 #include <main/timer.hpp>
15 
17 class lua_backend_test : public ::testing::Test {
18 
19 protected:
20  lua_backend test_subject{};
21 
22  std::string hash_file(const std::string &path) {
23  return test_subject.hash_file(path);
24  }
25 
26  std::string hash_string_lua(const std::string &string) {
27  return test_subject.hash_string(string);
28  }
29 
30  lua_State *get_lua_state() {
31  return test_subject.L;
32  }
33 
34  message_bus *msg_bus{};
35  game_manager *game_mngr{};
36 
37  void SetUp() override {
38  msg_bus = new message_bus();
39  game_mngr = new game_manager(msg_bus, nullptr);
40  test_subject.initialize(msg_bus, game_mngr);
41  }
42 
43  void TearDown() override {
44  test_subject.close();
45  delete game_mngr;
46  delete msg_bus;
47  }
48 };
49 
50 TEST_F(lua_backend_test, test_hash_file_playSound) {
51  std::string result = hash_file("lua_scripts/test_script_playSound.lua");
52  std::string resulting_integer = result.substr(10, std::string::npos);
53  resulting_integer.erase(resulting_integer.size() - 10);
54  try {
55  std::stoull(resulting_integer);
56  } catch (const std::invalid_argument &e) {
57  (void) e;
58  FAIL();
59  } catch (const std::out_of_range &e) {
60  (void) e;
61  FAIL();
62  }
63 }
64 
65 TEST_F(lua_backend_test, test_hash_file_playMusic) {
66  std::string result = hash_file("lua_scripts/test_script_playMusic.lua");
67  std::string resulting_integer = result.substr(10, std::string::npos);
68  resulting_integer.erase(resulting_integer.size() - 10);
69  try {
70  std::stoull(resulting_integer);
71  } catch (const std::invalid_argument &e) {
72  (void) e;
73  FAIL();
74  } catch (const std::out_of_range &e) {
75  (void) e;
76  FAIL();
77  }
78 }
79 
80 TEST_F(lua_backend_test, test_hash_file_keyHeld) {
81  std::string result = hash_file("lua_scripts/test_script_keyHeld.lua");
82  std::string resulting_integer = result.substr(8, std::string::npos);
83  resulting_integer.erase(resulting_integer.size() - 3);
84  try {
85  std::stoull(resulting_integer);
86  } catch (const std::invalid_argument &e) {
87  (void) e;
88  FAIL();
89  } catch (const std::out_of_range &e) {
90  (void) e;
91  FAIL();
92  }
93 }
94 
95 TEST_F(lua_backend_test, test_hash_file_keyPressed) {
96  std::string result = hash_file("lua_scripts/test_script_keyPressed.lua");
97  std::string resulting_integer = result.substr(11, std::string::npos);
98  resulting_integer.erase(resulting_integer.size() - 2);
99  try {
100  std::stoull(resulting_integer);
101  } catch (const std::invalid_argument &e) {
102  (void) e;
103  FAIL();
104  } catch (const std::out_of_range &e) {
105  (void) e;
106  FAIL();
107  }
108 }
109 
110 TEST_F(lua_backend_test, test_hash_file_keyReleased) {
111  std::string result = hash_file("lua_scripts/test_script_keyReleased.lua");
112  std::string resulting_integer = result.substr(12, std::string::npos);
113  resulting_integer.erase(resulting_integer.size() - 2);
114  try {
115  std::stoull(resulting_integer);
116  } catch (const std::invalid_argument &e) {
117  (void) e;
118  FAIL();
119  } catch (const std::out_of_range &e) {
120  (void) e;
121  FAIL();
122  }
123 }
124 
125 TEST_F(lua_backend_test, test_hash_file_setClickKey) {
126  std::string result = hash_file("lua_scripts/test_script_setClickKey.lua");
127  std::string resulting_integer = result.substr(12, std::string::npos);
128  resulting_integer.erase(resulting_integer.size() - 3);
129  try {
130  std::stoull(resulting_integer);
131  } catch (const std::invalid_argument &e) {
132  (void) e;
133  FAIL();
134  } catch (const std::out_of_range &e) {
135  (void) e;
136  FAIL();
137  }
138 }
139 
140 TEST_F(lua_backend_test, test_hash_file_keyAnnotation) {
141  std::string result = hash_file("lua_scripts/test_script_keyAnnotation.lua");
142  std::string resulting_integer = result.substr(10, std::string::npos);
143  try {
144  std::stoull(resulting_integer);
145  } catch (const std::invalid_argument &e) {
146  (void) e;
147  FAIL();
148  } catch (const std::out_of_range &e) {
149  (void) e;
150  FAIL();
151  }
152 }
153 
154 TEST_F(lua_backend_test, test_hash_string_playSound) {
155  std::string result = hash_string_lua("playSound(\"sound.wav\", 100, 1)");
156  std::string resulting_integer = result.substr(10, std::string::npos);
157  resulting_integer.erase(resulting_integer.size() - 9);
158  try {
159  std::stoull(resulting_integer);
160  } catch (const std::invalid_argument &e) {
161  (void) e;
162  FAIL();
163  } catch (const std::out_of_range &e) {
164  (void) e;
165  FAIL();
166  }
167 }
168 
169 TEST_F(lua_backend_test, test_hash_file_audioAnnotation) {
170  std::string result = hash_file("lua_scripts/test_script_audioAnnotation.lua");
171  std::string resulting_integer = result.substr(12, std::string::npos);
172  try {
173  std::stoull(resulting_integer);
174  } catch (const std::invalid_argument &e) {
175  (void) e;
176  FAIL();
177  } catch (const std::out_of_range &e) {
178  (void) e;
179  FAIL();
180  }
181 }
182 
183 TEST_F(lua_backend_test, test_hash_string_playMusic) {
184  std::string result = hash_string_lua("playMusic(\"music.mp3\", 100, 1)");
185  std::string resulting_integer = result.substr(10, std::string::npos);
186  resulting_integer.erase(resulting_integer.size() - 9);
187  try {
188  std::stoull(resulting_integer);
189  } catch (const std::invalid_argument &e) {
190  (void) e;
191  FAIL();
192  } catch (const std::out_of_range &e) {
193  (void) e;
194  FAIL();
195  }
196 }
197 
198 TEST_F(lua_backend_test, test_hash_string_keyHeld) {
199  std::string result = hash_string_lua("keyHeld(\"JUMP\")");
200  std::string resulting_integer = result.substr(8, std::string::npos);
201  resulting_integer.erase(resulting_integer.size() - 1);
202  try {
203  std::stoull(resulting_integer);
204  } catch (const std::invalid_argument &e) {
205  (void) e;
206  FAIL();
207  } catch (const std::out_of_range &e) {
208  (void) e;
209  FAIL();
210  }
211 }
212 
213 TEST_F(lua_backend_test, test_hash_string_keyPressed) {
214  std::string result = hash_string_lua("keyPressed(\"JUMP\")");
215  std::string resulting_integer = result.substr(11, std::string::npos);
216  resulting_integer.erase(resulting_integer.size() - 1);
217  try {
218  std::stoull(resulting_integer);
219  } catch (const std::invalid_argument &e) {
220  (void) e;
221  FAIL();
222  } catch (const std::out_of_range &e) {
223  (void) e;
224  FAIL();
225  }
226 }
227 
228 TEST_F(lua_backend_test, test_hash_string_keyReleased) {
229  std::string result = hash_string_lua("keyReleased(\"JUMP\")");
230  std::string resulting_integer = result.substr(12, std::string::npos);
231  resulting_integer.erase(resulting_integer.size() - 1);
232  try {
233  std::stoull(resulting_integer);
234  } catch (const std::invalid_argument &e) {
235  (void) e;
236  FAIL();
237  } catch (const std::out_of_range &e) {
238  (void) e;
239  FAIL();
240  }
241 }
242 
243 TEST_F(lua_backend_test, test_hash_string_setClickKey) {
244  std::string result = hash_string_lua("setClickKey(\"MOUSE1\")");
245  std::string resulting_integer = result.substr(12, std::string::npos);
246  resulting_integer.erase(resulting_integer.size() - 1);
247  try {
248  std::stoull(resulting_integer);
249  } catch (const std::invalid_argument &e) {
250  (void) e;
251  FAIL();
252  } catch (const std::out_of_range &e) {
253  (void) e;
254  FAIL();
255  }
256 }
257 
258 TEST_F(lua_backend_test, test_run_simple_script) {
259  ::testing::internal::CaptureStdout();
260  ASSERT_EQ(0, test_subject.run_file("lua_scripts/test_script_simple.lua"));
261  ASSERT_EQ("4\n", testing::internal::GetCapturedStdout());
262 }
263 
264 TEST_F(lua_backend_test, test_fail_on_broken_script) {
265  ::testing::FLAGS_gtest_death_test_style = "threadsafe";
266 #ifdef _MSC_VER
267  //Exit code 3 on WINDOWS
268  ASSERT_EXIT(test_subject.run_file("lua_scripts/test_script_broken.lua"), ::testing::ExitedWithCode(3), ".*");
269 #else
270  //SIGABRT on UNIX
271  ASSERT_EXIT(test_subject.run_file("lua_scripts/test_script_broken.lua"), ::testing::KilledBySignal(SIGABRT), ".*");
272 #endif
273 }
274 
275 TEST_F(lua_backend_test, test_call_function_setFullscreenLua) {
276  //Set up
277  subscriber subscriber1;
278  msg_bus->subscribe(SET_FULLSCREEN, &subscriber1);
279 
280  //Test
281  test_subject.run_script("setFullscreenLua(true)");
282 
283 
284  //Check result - expect to see a message with appropriate content
285  message *result = subscriber1.get_next_message();
286 
287  ASSERT_TRUE(result);
288  ASSERT_EQ(SET_FULLSCREEN, result->msg_name);
289  ASSERT_TRUE(static_cast<bool>(result->base_data0));
290 }
291 
292 TEST_F(lua_backend_test, test_call_function_hashString) {
293  //Set up
294  std::string test_string = "TEST_STRING";
295  size_t expected = ST::hash_string(test_string);
296 
297  //Test
298  test_subject.run_script("return hashString(\"" + test_string + "\")");
299  ASSERT_EQ(expected, lua_tointeger(get_lua_state(), -1));
300 }
301 
302 TEST_F(lua_backend_test, test_call_function_delay) {
303  //Set up
304  timer test_timer;
305  double runtime = 500;
306 
307  //Test
308  double start_time = test_timer.time_since_start();
309  test_subject.run_script("delay(" + std::to_string(runtime) + ")");
310  double end_time = test_timer.time_since_start();
311 
312  ASSERT_NEAR(runtime, static_cast<uint32_t>(end_time - start_time), 250);
313 }
314 
315 TEST_F(lua_backend_test, test_call_function_setVsyncLua) {
316  //Set up
317  subscriber subscriber1;
318  msg_bus->subscribe(SET_VSYNC, &subscriber1);
319 
320  //Test
321  test_subject.run_script("setVsyncLua(true)");
322 
323  //Check result - expect to see a message with appropriate content
324  message *result = subscriber1.get_next_message();
325 
326  ASSERT_TRUE(result);
327  ASSERT_EQ(SET_VSYNC, result->msg_name);
328  ASSERT_TRUE(static_cast<bool>(result->base_data0));
329 }
330 
331 
332 TEST_F(lua_backend_test, test_call_function_startLevelLua) {
333  //Set up
334  subscriber subscriber1;
335  msg_bus->subscribe(START_LEVEL, &subscriber1);
336  std::string level_name = "some_level";
337 
338  //Test
339  test_subject.run_script("startLevelLua(\"" + level_name + "\")");
340 
341  //Check result - expect to see a message with appropriate content
342  message *result = subscriber1.get_next_message();
343 
344  ASSERT_TRUE(result);
345  ASSERT_EQ(START_LEVEL, result->msg_name);
346  ASSERT_EQ(level_name, *static_cast<std::string *>(result->get_data()));
347 }
348 
349 TEST_F(lua_backend_test, test_call_function_loadLevel) {
350  //Set up
351  subscriber subscriber1;
352  msg_bus->subscribe(LOAD_LEVEL, &subscriber1);
353  std::string level_name = "some_level";
354 
355  //Test
356  test_subject.run_script("loadLevel(\"" + level_name + "\")");
357 
358  //Check result - expect to see a message with appropriate content
359  message *result = subscriber1.get_next_message();
360 
361  ASSERT_TRUE(result);
362  ASSERT_EQ(LOAD_LEVEL, result->msg_name);
363  ASSERT_EQ(level_name, *static_cast<std::string *>(result->get_data()));
364 }
365 
366 TEST_F(lua_backend_test, test_call_function_showMouseCursor) {
367  //Set up
368  subscriber subscriber1;
369  msg_bus->subscribe(SHOW_MOUSE, &subscriber1);
370 
371  //Test
372  test_subject.run_script("showMouseCursor()");
373 
374  //Check result - expect to see a message with appropriate content
375  message *result = subscriber1.get_next_message();
376 
377  ASSERT_TRUE(result);
378  ASSERT_EQ(SHOW_MOUSE, result->msg_name);
379  ASSERT_TRUE(static_cast<bool>(result->base_data0));
380 }
381 
382 TEST_F(lua_backend_test, test_call_function_hideMouseCursor) {
383  //Set up
384  subscriber subscriber1;
385  msg_bus->subscribe(SHOW_MOUSE, &subscriber1);
386 
387  //Test
388  test_subject.run_script("hideMouseCursor()");
389 
390  //Check result - expect to see a message with appropriate content
391  message *result = subscriber1.get_next_message();
392 
393  ASSERT_TRUE(result);
394  ASSERT_EQ(SHOW_MOUSE, result->msg_name);
395  ASSERT_FALSE(static_cast<bool>(result->base_data0));
396 }
397 
398 
399 TEST_F(lua_backend_test, test_call_function_showFps) {
400  //Set up
401  subscriber subscriber1;
402  msg_bus->subscribe(SHOW_FPS, &subscriber1);
403 
404  //Test
405  test_subject.run_script("showFps(true)");
406 
407  //Check result - expect to see a message with appropriate content
408  message *result = subscriber1.get_next_message();
409 
410  ASSERT_TRUE(result);
411  ASSERT_EQ(SHOW_FPS, result->msg_name);
412  ASSERT_TRUE(static_cast<bool>(result->base_data0));
413 }
414 
415 TEST_F(lua_backend_test, test_call_function_showMetrics) {
416  //Set up
417  subscriber subscriber1;
418  msg_bus->subscribe(SHOW_METRICS, &subscriber1);
419 
420  //Test
421  test_subject.run_script("showMetrics(true)");
422 
423  //Check result - expect to see a message with appropriate content
424  message *result = subscriber1.get_next_message();
425 
426  ASSERT_TRUE(result);
427  ASSERT_EQ(SHOW_METRICS, result->msg_name);
428  ASSERT_TRUE(static_cast<bool>(result->base_data0));
429 }
430 
431 
432 TEST_F(lua_backend_test, test_call_function_endGame) {
433  //Set up
434  subscriber subscriber1;
435  msg_bus->subscribe(END_GAME, &subscriber1);
436 
437  //Test
438  test_subject.run_script("endGame()");
439 
440  //Check result - expect to see a message with appropriate content
441  message *result = subscriber1.get_next_message();
442 
443  ASSERT_TRUE(result);
444  ASSERT_EQ(END_GAME, result->msg_name);
445  ASSERT_FALSE(result->get_data());
446 }
447 
448 TEST_F(lua_backend_test, test_call_function_setLevelFloor) {
449  //Set up
450  subscriber subscriber1;
451  msg_bus->subscribe(SET_FLOOR, &subscriber1);
452 
453  //Test
454  test_subject.run_script("setLevelFloor(500)");
455 
456  //Check result - expect to see a message with appropriate content
457  message *result = subscriber1.get_next_message();
458 
459  ASSERT_TRUE(result);
460  ASSERT_EQ(SET_FLOOR, result->msg_name);
461  ASSERT_EQ(500, static_cast<int32_t>(result->base_data0));
462 }
463 
464 TEST_F(lua_backend_test, test_call_function_unloadLevel) {
465  //Set up
466  subscriber subscriber1;
467  msg_bus->subscribe(UNLOAD_LEVEL, &subscriber1);
468  std::string level_name = "some_level";
469 
470  //Test
471  test_subject.run_script("unloadLevel(\"" + level_name + "\")");
472 
473  //Check result - expect to see a message with appropriate content
474  message *result = subscriber1.get_next_message();
475 
476  ASSERT_TRUE(result);
477  ASSERT_EQ(UNLOAD_LEVEL, result->msg_name);
478  ASSERT_EQ(level_name, *static_cast<std::string *>(result->get_data()));
479 }
480 
481 TEST_F(lua_backend_test, test_call_function_setGravity) {
482  //Set up
483  subscriber subscriber1;
484  msg_bus->subscribe(SET_GRAVITY, &subscriber1);
485 
486  //Test
487  test_subject.run_script("setGravity(12)");
488 
489  //Check result - expect to see a message with appropriate content
490  message *result = subscriber1.get_next_message();
491 
492  ASSERT_TRUE(result);
493  ASSERT_EQ(SET_GRAVITY, result->msg_name);
494  ASSERT_EQ(12, static_cast<uint8_t>(result->base_data0));
495 }
496 
497 TEST_F(lua_backend_test, test_call_function_getGravity) {
498  //Set up
499  gGame_managerLua->gravity = 11;
500 
501  //Test
502  test_subject.run_script("return getGravity()");
503 
504  gGame_managerLua->gravity = 0;
505 
506  //Check result
507  ASSERT_EQ(11, lua_tointeger(get_lua_state(), -1));
508 }
509 
510 
511 TEST_F(lua_backend_test, test_call_function_pausePhysics) {
512  //Set up
513  subscriber subscriber1;
514  msg_bus->subscribe(PAUSE_PHYSICS, &subscriber1);
515 
516  //Test
517  test_subject.run_script("pausePhysics()");
518 
519  //Check result - expect to see a message with appropriate content
520  message *result = subscriber1.get_next_message();
521 
522  ASSERT_TRUE(result);
523  ASSERT_EQ(PAUSE_PHYSICS, result->msg_name);
524  ASSERT_FALSE(result->get_data());
525 }
526 
527 TEST_F(lua_backend_test, test_call_function_unpausePhysics) {
528  //Set up
529  subscriber subscriber1;
530  msg_bus->subscribe(UNPAUSE_PHYSICS, &subscriber1);
531 
532  //Test
533  test_subject.run_script("unpausePhysics()");
534 
535  //Check result - expect to see a message with appropriate content
536  message *result = subscriber1.get_next_message();
537 
538  ASSERT_TRUE(result);
539  ASSERT_EQ(UNPAUSE_PHYSICS, result->msg_name);
540  ASSERT_FALSE(result->get_data());
541 }
542 
543 TEST_F(lua_backend_test, test_call_function_playSound) {
544  //Set up
545  subscriber subscriber1;
546  msg_bus->subscribe(PLAY_SOUND, &subscriber1);
547  std::string test_string = "some_sound.wav";
548  uint16_t expected = ST::hash_string(test_string);
549 
550  //Test
551  test_subject.run_script("playSound(\"" + test_string + "\", 100, 3)");
552 
553  //Check result - expect to see a message with appropriate content
554  message *result = subscriber1.get_next_message();
555  ASSERT_TRUE(result);
556  ASSERT_EQ(PLAY_SOUND, result->msg_name);
557 
558 
559  auto data = result->base_data0;
560 
561  ASSERT_EQ(expected, (data & 0x0000ffff));
562  ASSERT_EQ(100, (data >> 16) & 0x000000ff);
563  ASSERT_EQ(3, (data >> 24) & 0x000000ff);
564 }
565 
566 TEST_F(lua_backend_test, test_call_function_playMusic) {
567  //Set up
568  subscriber subscriber1;
569  msg_bus->subscribe(PLAY_MUSIC, &subscriber1);
570  std::string test_string = "some_music.mp3";
571  uint16_t expected = ST::hash_string(test_string);
572 
573  //Test
574  test_subject.run_script("playMusic(\"" + test_string + "\", 128, 2)");
575 
576  //Check result - expect to see a message with appropriate content
577  message *result = subscriber1.get_next_message();
578  ASSERT_TRUE(result);
579  ASSERT_EQ(PLAY_MUSIC, result->msg_name);
580 
581  auto data = result->base_data0;
582 
583  ASSERT_EQ(expected, (data & 0x0000ffff));
584  ASSERT_EQ(128, (data >> 16) & 0x000000ff);
585  ASSERT_EQ(2, (data >> 24) & 0x000000ff);
586 }
587 
588 TEST_F(lua_backend_test, test_call_function_stopMusic) {
589  //Set up
590  subscriber subscriber1;
591  msg_bus->subscribe(STOP_MUSIC, &subscriber1);
592 
593  //Test
594  test_subject.run_script("stopMusic()");
595 
596  //Check result - expect to see a message with appropriate content
597  message *result = subscriber1.get_next_message();
598 
599  ASSERT_TRUE(result);
600  ASSERT_EQ(STOP_MUSIC, result->msg_name);
601  ASSERT_FALSE(result->get_data());
602 }
603 
604 TEST_F(lua_backend_test, test_call_function_setAudioEnabledLua) {
605  //Set up
606  subscriber subscriber1;
607  msg_bus->subscribe(SET_AUDIO_ENABLED, &subscriber1);
608 
609  //Test
610  test_subject.run_script("setAudioEnabledLua(true)");
611 
612  //Check result - expect to see a message with appropriate content
613  message *result = subscriber1.get_next_message();
614 
615  ASSERT_TRUE(result);
616  ASSERT_EQ(SET_AUDIO_ENABLED, result->msg_name);
617  ASSERT_TRUE(static_cast<bool>(result->base_data0));
618 }
619 
620 TEST_F(lua_backend_test, test_call_function_stopAllSounds) {
621  //Set up
622  subscriber subscriber1;
623  msg_bus->subscribe(STOP_ALL_SOUNDS, &subscriber1);
624 
625  //Test
626  test_subject.run_script("stopAllSounds()");
627 
628  //Check result - expect to see a message with appropriate content
629  message *result = subscriber1.get_next_message();
630 
631  ASSERT_TRUE(result);
632  ASSERT_EQ(STOP_ALL_SOUNDS, result->msg_name);
633  ASSERT_FALSE(result->get_data());
634 }
635 
636 TEST_F(lua_backend_test, test_call_function_setMusicVolume) {
637  //Set up
638  subscriber subscriber1;
639  msg_bus->subscribe(SET_MUSIC_VOLUME, &subscriber1);
640 
641  //Test
642  test_subject.run_script("setMusicVolume(50)");
643 
644  //Check result - expect to see a message with appropriate content
645  message *result = subscriber1.get_next_message();
646 
647  ASSERT_TRUE(result);
648  ASSERT_EQ(SET_MUSIC_VOLUME, result->msg_name);
649  ASSERT_EQ(50, static_cast<uint8_t>(result->base_data0));
650 }
651 
652 TEST_F(lua_backend_test, test_call_function_setSoundsVolume) {
653  //Set up
654  subscriber subscriber1;
655  msg_bus->subscribe(SET_SOUNDS_VOLUME, &subscriber1);
656 
657  //Test
658  test_subject.run_script("setSoundsVolume(50)");
659 
660  //Check result - expect to see a message with appropriate content
661  message *result = subscriber1.get_next_message();
662 
663  ASSERT_TRUE(result);
664  ASSERT_EQ(SET_SOUNDS_VOLUME, result->msg_name);
665  ASSERT_EQ(50, static_cast<uint8_t>(result->base_data0));
666 }
667 
668 TEST_F(lua_backend_test, test_call_function_loadAsset) {
669  //Set up
670  subscriber subscriber1;
671  msg_bus->subscribe(LOAD_ASSET, &subscriber1);
672 
673  //Test
674  test_subject.run_script("loadAsset(\"path/to/asset.webp\")");
675 
676  //Check result - expect to see a message with appropriate content
677  message *result = subscriber1.get_next_message();
678 
679  ASSERT_TRUE(result);
680  ASSERT_EQ(LOAD_ASSET, result->msg_name);
681  ASSERT_EQ("path/to/asset.webp", *static_cast<std::string *>(result->get_data()));
682 }
683 
684 TEST_F(lua_backend_test, test_call_function_unloadAsset) {
685  //Set up
686  subscriber subscriber1;
687  msg_bus->subscribe(UNLOAD_ASSET, &subscriber1);
688 
689  //Test
690  test_subject.run_script("unloadAsset(\"path/to/asset.webp\")");
691 
692  //Check result - expect to see a message with appropriate content
693  message *result = subscriber1.get_next_message();
694 
695  ASSERT_TRUE(result);
696  ASSERT_EQ(UNLOAD_ASSET, result->msg_name);
697  ASSERT_EQ("path/to/asset.webp", *static_cast<std::string *>(result->get_data()));
698 }
699 
700 TEST_F(lua_backend_test, test_call_function_setDarkness) {
701  //Set up
702  subscriber subscriber1;
703  msg_bus->subscribe(SET_DARKNESS, &subscriber1);
704 
705  //Test
706  test_subject.run_script("setDarkness(250)");
707 
708  //Check result - expect to see a message with appropriate content
709  message *result = subscriber1.get_next_message();
710 
711  ASSERT_TRUE(result);
712  ASSERT_EQ(SET_DARKNESS, result->msg_name);
713  ASSERT_EQ(250, static_cast<uint8_t>(result->base_data0));
714 }
715 
716 TEST_F(lua_backend_test, test_call_function_enableLighting) {
717  //Set up
718  subscriber subscriber1;
719  msg_bus->subscribe(ENABLE_LIGHTING, &subscriber1);
720 
721  //Test
722  test_subject.run_script("enableLighting(false)");
723 
724  //Check result - expect to see a message with appropriate content
725  message *result = subscriber1.get_next_message();
726 
727  ASSERT_TRUE(result);
728  ASSERT_EQ(ENABLE_LIGHTING, result->msg_name);
729  ASSERT_FALSE(static_cast<bool>(result->base_data0));
730 }
731 
732 TEST_F(lua_backend_test, test_call_function_getFullscreenStatus) {
733  game_mngr->fullscreen_status = false;
734  test_subject.run_script("return getFullscreenStatus()");
735 
736  //Check result
737  ASSERT_FALSE(lua_toboolean(get_lua_state(), -1));
738 }
739 
740 TEST_F(lua_backend_test, test_call_function_use) {
741  //Set up
742  ::testing::internal::CaptureStdout();
743 
744  //Test
745  test_subject.run_script("use(\"test_script_simple.lua\")");
746  ASSERT_EQ("4\n", testing::internal::GetCapturedStdout());
747 }
748 
749 TEST_F(lua_backend_test, test_call_function_setBackground) {
750  test_subject.run_script("setBackground(\"some_bg.webp\")");
751  ASSERT_EQ(2, game_mngr->get_level_calls);
752 }
753 
754 TEST_F(lua_backend_test, test_call_function_setBackgroundColor) {
755  test_subject.run_script("setBackgroundColor(255, 255, 255, 255)");
756  ASSERT_EQ(1, game_mngr->get_level_calls);
757 }
758 
759 TEST_F(lua_backend_test, test_call_function_getVsyncState) {
760  game_mngr->vsync_flag = true;
761  test_subject.run_script("return getVsyncState()");
762 
763  //Check result
764  ASSERT_TRUE(lua_toboolean(get_lua_state(), -1));
765 }
766 
767 
768 TEST_F(lua_backend_test, test_call_function_setBrightness) {
769  //Set up
770  subscriber subscriber1;
771  msg_bus->subscribe(SET_WINDOW_BRIGHTNESS, &subscriber1);
772 
773  //Test
774  test_subject.run_script("setBrightness(250)");
775 
776  //Check result - expect to see a message with appropriate content
777  message *result = subscriber1.get_next_message();
778 
779  ASSERT_TRUE(result);
780  ASSERT_EQ(SET_WINDOW_BRIGHTNESS, result->msg_name);
781  ASSERT_EQ(250, *static_cast<float *>(result->get_data()));
782 }
783 
784 TEST_F(lua_backend_test, test_call_function_setOverlay) {
785  test_subject.run_script("setOverlay(\"some_bg.webp\", 3)");
786  ASSERT_EQ(2, game_mngr->get_level_calls);
787  ASSERT_EQ(3, game_mngr->get_level()->overlay_sprite_num);
788  ASSERT_EQ(ST::hash_string("some_bg.webp"), game_mngr->get_level()->overlay);
789 }
790 
791 TEST_F(lua_backend_test, test_call_function_getMusicVolume) {
792  game_mngr->music_volume_level = 123;
793  test_subject.run_script("return getMusicVolume()");
794 
795  //Check result
796  ASSERT_EQ(123, lua_tointeger(get_lua_state(), -1));
797 }
798 
799 TEST_F(lua_backend_test, test_call_function_getSoundsVolume) {
800  game_mngr->sounds_volume_level = 123;
801  test_subject.run_script("return getSoundsVolume()");
802 
803  //Check result
804  ASSERT_EQ(123, lua_tointeger(get_lua_state(), -1));
805 }
806 
807 TEST_F(lua_backend_test, test_call_function_isAudioEnabled) {
808  test_subject.run_script("return isAudioEnabled()");
809 
810  //Check result
811  ASSERT_TRUE(lua_toboolean(get_lua_state(), -1));
812 }
813 
814 TEST_F(lua_backend_test, test_call_function_centerCamera) {
815  test_subject.run_script("centerCamera(5)"); //Test US spelling
816  test_subject.run_script("centreCamera(2)"); //Test UK spelling
817 
818  //Check result
819  ASSERT_EQ(2, game_mngr->center_camera_on_entity_calls);
820 }
821 
822 TEST_F(lua_backend_test, test_call_function_setLevelSize) {
823  test_subject.run_script("setLevelSize(5000, 5000)");
824 
825  //Check result
826  ASSERT_EQ(2, game_mngr->get_level_calls);
827  ASSERT_EQ(5000, game_mngr->get_level()->camera.limitX2);
828  ASSERT_EQ(5000, game_mngr->get_level()->camera.limitY2);
829 }
830 
831 TEST_F(lua_backend_test, test_call_function_getMouseX) {
832  test_subject.run_script("return getMouseX()");
833 
834  //Check result
835  ASSERT_EQ(100, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
836 }
837 
838 
839 TEST_F(lua_backend_test, test_call_function_getMouseY) {
840  test_subject.run_script("return getMouseY()");
841 
842  //Check result
843  ASSERT_EQ(200, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
844 }
845 
846 TEST_F(lua_backend_test, test_call_function_leftTrigger) {
847  test_subject.run_script("return leftTrigger()");
848 
849  //Check result
850  ASSERT_EQ(100, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
851 }
852 
853 TEST_F(lua_backend_test, test_call_function_rightTrigger) {
854  test_subject.run_script("return rightTrigger()");
855 
856  //Check result
857  ASSERT_EQ(200, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
858 }
859 
860 TEST_F(lua_backend_test, test_call_function_rightStickHorizontal) {
861  test_subject.run_script("return rightStickHorizontal()");
862 
863  //Check result
864  ASSERT_EQ(400, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
865 }
866 
867 TEST_F(lua_backend_test, test_call_function_leftStickHorizontal) {
868  test_subject.run_script("return leftStickHorizontal()");
869 
870  //Check result
871  ASSERT_EQ(100, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
872 }
873 
874 TEST_F(lua_backend_test, test_call_function_leftStickVertical) {
875  test_subject.run_script("return leftStickVertical()");
876 
877  //Check result
878  ASSERT_EQ(200, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
879 }
880 
881 TEST_F(lua_backend_test, test_call_function_rightStickVertical) {
882  test_subject.run_script("return rightStickVertical()");
883 
884  //Check result
885  ASSERT_EQ(300, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
886 }
887 
888 TEST_F(lua_backend_test, test_call_function_controllerRumble) {
889  subscriber subscriber1;
890  msg_bus->subscribe(CONTROLLER_RUMBLE, &subscriber1);
891  test_subject.run_script("return controllerRumble(0.7, 1000)");
892 
893  //Check result - expect to see a message with appropriate content
894  message *result = subscriber1.get_next_message();
895 
896  ASSERT_TRUE(result);
897  ASSERT_EQ(CONTROLLER_RUMBLE, result->msg_name);
898  ASSERT_FALSE(result->get_data());
899 
900  float strength = *reinterpret_cast<float *>(&result->base_data0);
901  uint16_t duration = result->base_data1;
902 
903  ASSERT_EQ(0.7f, strength);
904  ASSERT_EQ(1000, duration);
905 }
906 
907 
908 TEST_F(lua_backend_test, test_call_function_setLeftStickHorizontalThreshold) {
909  subscriber subscriber1;
910  msg_bus->subscribe(SET_LEFT_JOYSTICK_HORIZONTAL_THRESHOLD, &subscriber1);
911  test_subject.run_script("setLeftStickHorizontalThreshold(1000)");
912 
913  //Check result - expect to see a message with appropriate content
914  message *result = subscriber1.get_next_message();
915 
916  ASSERT_TRUE(result);
917  ASSERT_EQ(SET_LEFT_JOYSTICK_HORIZONTAL_THRESHOLD, result->msg_name);
918  ASSERT_FALSE(result->get_data());
919 
920  uint16_t threshold = static_cast<int16_t>(result->base_data0);
921 
922  ASSERT_EQ(1000, threshold);
923 }
924 
925 TEST_F(lua_backend_test, test_call_function_setLeftStickVerticalThreshold) {
926  subscriber subscriber1;
927  msg_bus->subscribe(SET_LEFT_JOYSTICK_VERTICAL_THRESHOLD, &subscriber1);
928  test_subject.run_script("setLeftStickVerticalThreshold(1000)");
929 
930  //Check result - expect to see a message with appropriate content
931  message *result = subscriber1.get_next_message();
932 
933  ASSERT_TRUE(result);
934  ASSERT_EQ(SET_LEFT_JOYSTICK_VERTICAL_THRESHOLD, result->msg_name);
935  ASSERT_FALSE(result->get_data());
936 
937  uint16_t threshold = static_cast<int16_t>(result->base_data0);
938 
939  ASSERT_EQ(1000, threshold);
940 }
941 
942 TEST_F(lua_backend_test, test_call_function_setRightStickHorizontalThreshold) {
943  subscriber subscriber1;
944  msg_bus->subscribe(SET_RIGHT_JOYSTICK_HORIZONTAL_THRESHOLD, &subscriber1);
945  test_subject.run_script("setRightStickHorizontalThreshold(1000)");
946 
947  //Check result - expect to see a message with appropriate content
948  message *result = subscriber1.get_next_message();
949 
950  ASSERT_TRUE(result);
951  ASSERT_EQ(SET_RIGHT_JOYSTICK_HORIZONTAL_THRESHOLD, result->msg_name);
952  ASSERT_FALSE(result->get_data());
953 
954  uint16_t threshold = static_cast<int16_t>(result->base_data0);
955 
956  ASSERT_EQ(1000, threshold);
957 }
958 
959 TEST_F(lua_backend_test, test_call_function_setRightStickVerticalThreshold) {
960  subscriber subscriber1;
961  msg_bus->subscribe(SET_RIGHT_JOYSTICK_VERTICAL_THRESHOLD, &subscriber1);
962  test_subject.run_script("setRightStickVerticalThreshold(1000)");
963 
964  //Check result - expect to see a message with appropriate content
965  message *result = subscriber1.get_next_message();
966 
967  ASSERT_TRUE(result);
968  ASSERT_EQ(SET_RIGHT_JOYSTICK_VERTICAL_THRESHOLD, result->msg_name);
969  ASSERT_FALSE(result->get_data());
970 
971  uint16_t threshold = static_cast<int16_t>(result->base_data0);
972 
973  ASSERT_EQ(1000, threshold);
974 }
975 
976 TEST_F(lua_backend_test, test_call_function_setLeftTriggerThreshold) {
977  subscriber subscriber1;
978  msg_bus->subscribe(SET_LEFT_TRIGGER_THRESHOLD, &subscriber1);
979  test_subject.run_script("setLeftTriggerThreshold(1000)");
980 
981  //Check result - expect to see a message with appropriate content
982  message *result = subscriber1.get_next_message();
983 
984  ASSERT_TRUE(result);
985  ASSERT_EQ(SET_LEFT_TRIGGER_THRESHOLD, result->msg_name);
986  ASSERT_FALSE(result->get_data());
987 
988  uint16_t threshold = static_cast<int16_t>(result->base_data0);
989 
990  ASSERT_EQ(1000, threshold);
991 }
992 
993 TEST_F(lua_backend_test, test_call_function_setRightTriggerThreshold) {
994  subscriber subscriber1;
995  msg_bus->subscribe(SET_RIGHT_TRIGGER_THRESHOLD, &subscriber1);
996  test_subject.run_script("setRightTriggerThreshold(1000)");
997 
998  //Check result - expect to see a message with appropriate content
999  message *result = subscriber1.get_next_message();
1000 
1001  ASSERT_TRUE(result);
1002  ASSERT_EQ(SET_RIGHT_TRIGGER_THRESHOLD, result->msg_name);
1003  ASSERT_FALSE(result->get_data());
1004 
1005  uint16_t threshold = static_cast<int16_t>(result->base_data0);
1006 
1007  ASSERT_EQ(1000, threshold);
1008 }
1009 
1010 TEST_F(lua_backend_test, test_call_function_keyHeld) {
1011  test_subject.run_script("return keyHeld(\"SOME_KEY\")");
1012 
1013  //Check result
1014  ASSERT_TRUE(lua_toboolean(get_lua_state(), lua_gettop(get_lua_state())));
1015 }
1016 
1017 TEST_F(lua_backend_test, test_call_function_keyPressed) {
1018  test_subject.run_script("return keyPressed(\"SOME_KEY\")");
1019 
1020  //Check result
1021  ASSERT_TRUE(lua_toboolean(get_lua_state(), lua_gettop(get_lua_state())));
1022 }
1023 
1024 TEST_F(lua_backend_test, test_call_function_keyReleased) {
1025  test_subject.run_script("return keyReleased(\"SOME_KEY\")");
1026 
1027  //Check result
1028  ASSERT_TRUE(lua_toboolean(get_lua_state(), lua_gettop(get_lua_state())));
1029 }
1030 
1031 
1032 TEST_F(lua_backend_test, test_call_function_createLight) {
1033  test_subject.run_script("createLight(500, 600, 100, 50, 400)");
1034 
1035  //Check results
1036  ASSERT_EQ(1, game_mngr->get_level_calls);
1037  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1038  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1039  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1040  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1041  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1042  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1043 }
1044 
1045 TEST_F(lua_backend_test, test_call_function_setLightOriginX) {
1046  //Set up
1047  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1048 
1049  //Test
1050  test_subject.run_script("setLightOriginX(0, 1000)");
1051 
1052  //Check results
1053  ASSERT_EQ(2, game_mngr->get_level_calls);
1054  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1055  ASSERT_EQ(1000, game_mngr->get_level()->lights.at(0).origin_x);
1056  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1057  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1058  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1059  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1060 }
1061 
1062 TEST_F(lua_backend_test, test_call_function_setLightOriginY) {
1063  //Set up
1064  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1065 
1066  //Test
1067  test_subject.run_script("setLightOriginY(0, 1000)");
1068 
1069  //Check results
1070  ASSERT_EQ(2, game_mngr->get_level_calls);
1071  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1072  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1073  ASSERT_EQ(1000, game_mngr->get_level()->lights.at(0).origin_y);
1074  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1075  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1076  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1077 }
1078 
1079 TEST_F(lua_backend_test, test_call_function_getLightOriginX) {
1080  //Set up
1081  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1082 
1083  //Test
1084  test_subject.run_script("return getLightOriginX(0)");
1085 
1086  //Check results
1087  ASSERT_EQ(500, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1088 
1089  //Make sure nothing has changed in the light object
1090  ASSERT_EQ(2, game_mngr->get_level_calls);
1091  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1092  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1093  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1094  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1095  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1096  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1097 }
1098 
1099 TEST_F(lua_backend_test, test_call_function_getLightOriginY) {
1100  //Set up
1101  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1102 
1103  //Test
1104  test_subject.run_script("return getLightOriginY(0)");
1105 
1106  //Check results
1107  ASSERT_EQ(600, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1108 
1109  //Make sure nothing has changed in the light object
1110  ASSERT_EQ(2, game_mngr->get_level_calls);
1111  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1112  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1113  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1114  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1115  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1116  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1117 }
1118 
1119 TEST_F(lua_backend_test, test_call_function_setLightIntensity) {
1120  //Set up
1121  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1122 
1123  //Test
1124  test_subject.run_script("setLightIntensity(0, 1000)");
1125 
1126  //Check results
1127  ASSERT_EQ(2, game_mngr->get_level_calls);
1128  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1129  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1130  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1131  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1132  ASSERT_EQ(1000, game_mngr->get_level()->lights.at(0).intensity);
1133  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1134 }
1135 
1136 TEST_F(lua_backend_test, test_call_function_getLightIntensity) {
1137  //Set up
1138  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1139 
1140  //Test
1141  test_subject.run_script("return getLightIntensity(0)");
1142 
1143  //Check results
1144  ASSERT_EQ(50, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1145 
1146  //Make sure nothing has changed in the light object
1147  ASSERT_EQ(2, game_mngr->get_level_calls);
1148  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1149  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1150  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1151  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1152  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1153  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1154 }
1155 
1156 TEST_F(lua_backend_test, test_call_function_getLightRadius) {
1157  //Set up
1158  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1159 
1160  //Test
1161  test_subject.run_script("return getLightRadius(0)");
1162 
1163  //Check results
1164  ASSERT_EQ(100, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1165 
1166  //Make sure nothing has changed in the light object
1167  ASSERT_EQ(2, game_mngr->get_level_calls);
1168  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1169  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1170  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1171  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1172  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1173  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1174 }
1175 
1176 TEST_F(lua_backend_test, test_call_function_setLightRadius) {
1177  //Set up
1178  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1179 
1180  //Test
1181  test_subject.run_script("return setLightRadius(0, 300)");
1182 
1183  //Check results
1184  ASSERT_EQ(2, game_mngr->get_level_calls);
1185  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1186  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1187  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1188  ASSERT_EQ(300, game_mngr->get_level()->lights.at(0).radius);
1189  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1190  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1191 }
1192 
1193 TEST_F(lua_backend_test, test_call_function_getLightBrightness) {
1194  //Set up
1195  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1196 
1197  //Test
1198  test_subject.run_script("return getLightBrightness(0)");
1199 
1200  //Check results
1201  ASSERT_EQ(400, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1202 
1203  //Make sure nothing has changed in the light object
1204  ASSERT_EQ(2, game_mngr->get_level_calls);
1205  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1206  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1207  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1208  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1209  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1210  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1211 }
1212 
1213 TEST_F(lua_backend_test, test_call_function_setLightBrightness) {
1214  //Set up
1215  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1216 
1217  //Test
1218  test_subject.run_script("return setLightBrightness(0, 300)");
1219 
1220  //Check results
1221  ASSERT_EQ(2, game_mngr->get_level_calls);
1222  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1223  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1224  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1225  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1226  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1227  ASSERT_EQ(300, game_mngr->get_level()->lights.at(0).brightness);
1228 }
1229 
1230 TEST_F(lua_backend_test, test_call_function_isLightStatic) {
1231  //Set up
1232  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1233 
1234  //Test
1235  test_subject.run_script("return isLightStatic(0)");
1236 
1237  //Check results
1238  ASSERT_FALSE(lua_toboolean(get_lua_state(), lua_gettop(get_lua_state())));
1239 
1240  //Make sure nothing has changed in the light object
1241  ASSERT_EQ(2, game_mngr->get_level_calls);
1242  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1243  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1244  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1245  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1246  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1247  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1248 }
1249 
1250 TEST_F(lua_backend_test, test_call_function_setLightStatic) {
1251  //Set up
1252  game_mngr->get_level()->lights.emplace_back(500, 600, 100, 50, 400);
1253 
1254  //Test
1255  test_subject.run_script("return setLightStatic(0, true)");
1256 
1257  //Check results
1258  ASSERT_EQ(2, game_mngr->get_level_calls);
1259  ASSERT_EQ(1, game_mngr->get_level()->lights.size());
1260  ASSERT_EQ(500, game_mngr->get_level()->lights.at(0).origin_x);
1261  ASSERT_EQ(600, game_mngr->get_level()->lights.at(0).origin_y);
1262  ASSERT_EQ(100, game_mngr->get_level()->lights.at(0).radius);
1263  ASSERT_EQ(50, game_mngr->get_level()->lights.at(0).intensity);
1264  ASSERT_EQ(400, game_mngr->get_level()->lights.at(0).brightness);
1265  ASSERT_TRUE(game_mngr->get_level()->lights.at(0).is_static);
1266 }
1267 
1268 TEST_F(lua_backend_test, test_call_function_createTextObject) {
1269  test_subject.run_script(R"(createTextObject(500, 600, "SOME_TEXT", "SOME_FONT.ttf", 40))");
1270  //Check results
1271  ASSERT_EQ(1, game_mngr->get_level_calls);
1272  ASSERT_EQ(1, game_mngr->get_level()->text_objects.size());
1273  ASSERT_EQ(500, game_mngr->get_level()->text_objects.at(0).x);
1274  ASSERT_EQ(600, game_mngr->get_level()->text_objects.at(0).y);
1275  ASSERT_EQ("SOME_TEXT", game_mngr->get_level()->text_objects.at(0).text_string);
1276  ASSERT_EQ(ST::hash_string("SOME_FONT.ttf 40"), game_mngr->get_level()->text_objects.at(0).font);
1277  ASSERT_TRUE(game_mngr->get_level()->text_objects.at(0).is_visible);
1278 
1279  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.r);
1280  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.g);
1281  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.b);
1282  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.a);
1283 }
1284 
1285 
1286 TEST_F(lua_backend_test, test_call_function_setTextObjectColor) {
1287  //Set up
1288  game_mngr->get_level()->text_objects.emplace_back(ST::text(500, 600, {255, 255, 255, 255},
1289  "SOME_TEXT", ST::hash_string("SOME_FONT.ttf 40")));
1290 
1291  //Test
1292  test_subject.run_script("setTextObjectColor(0, 100, 110, 120, 130)");
1293 
1294  //Check results
1295  ASSERT_EQ(2, game_mngr->get_level_calls);
1296  ASSERT_EQ(1, game_mngr->get_level()->text_objects.size());
1297  ASSERT_EQ(500, game_mngr->get_level()->text_objects.at(0).x);
1298  ASSERT_EQ(600, game_mngr->get_level()->text_objects.at(0).y);
1299  ASSERT_EQ("SOME_TEXT", game_mngr->get_level()->text_objects.at(0).text_string);
1300  ASSERT_EQ(ST::hash_string("SOME_FONT.ttf 40"), game_mngr->get_level()->text_objects.at(0).font);
1301  ASSERT_TRUE(game_mngr->get_level()->text_objects.at(0).is_visible);
1302 
1303  ASSERT_EQ(100, game_mngr->get_level()->text_objects.at(0).color.r);
1304  ASSERT_EQ(110, game_mngr->get_level()->text_objects.at(0).color.g);
1305  ASSERT_EQ(120, game_mngr->get_level()->text_objects.at(0).color.b);
1306  ASSERT_EQ(130, game_mngr->get_level()->text_objects.at(0).color.a);
1307 }
1308 
1309 TEST_F(lua_backend_test, test_call_function_setTextObjectText) {
1310  //Set up
1311  game_mngr->get_level()->text_objects.emplace_back(ST::text(500, 600, {255, 255, 255, 255},
1312  "SOME_TEXT", ST::hash_string("SOME_FONT.ttf 40")));
1313  //Test
1314  test_subject.run_script("setTextObjectText(0, \"NEW_TEXT\")");
1315 
1316  //Check results
1317  ASSERT_EQ(2, game_mngr->get_level_calls);
1318  ASSERT_EQ(1, game_mngr->get_level()->text_objects.size());
1319  ASSERT_EQ(500, game_mngr->get_level()->text_objects.at(0).x);
1320  ASSERT_EQ(600, game_mngr->get_level()->text_objects.at(0).y);
1321  ASSERT_EQ("NEW_TEXT", game_mngr->get_level()->text_objects.at(0).text_string);
1322  ASSERT_EQ(ST::hash_string("SOME_FONT.ttf 40"), game_mngr->get_level()->text_objects.at(0).font);
1323  ASSERT_TRUE(game_mngr->get_level()->text_objects.at(0).is_visible);
1324 
1325  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.r);
1326  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.g);
1327  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.b);
1328  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.a);
1329 }
1330 
1331 TEST_F(lua_backend_test, test_call_function_setTextObjectFont) {
1332  //Set up
1333  game_mngr->get_level()->text_objects.emplace_back(ST::text(500, 600, {255, 255, 255, 255},
1334  "SOME_TEXT", ST::hash_string("SOME_FONT.ttf 40")));
1335  //Test
1336  test_subject.run_script("setTextObjectFont(0, \"NEW_FONT.ttf 40\")");
1337 
1338  //Check results
1339  ASSERT_EQ(2, game_mngr->get_level_calls);
1340  ASSERT_EQ(1, game_mngr->get_level()->text_objects.size());
1341  ASSERT_EQ(500, game_mngr->get_level()->text_objects.at(0).x);
1342  ASSERT_EQ(600, game_mngr->get_level()->text_objects.at(0).y);
1343  ASSERT_EQ("SOME_TEXT", game_mngr->get_level()->text_objects.at(0).text_string);
1344  ASSERT_EQ(ST::hash_string("NEW_FONT.ttf 40"), game_mngr->get_level()->text_objects.at(0).font);
1345  ASSERT_TRUE(game_mngr->get_level()->text_objects.at(0).is_visible);
1346 
1347  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.r);
1348  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.g);
1349  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.b);
1350  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.a);
1351 }
1352 
1353 TEST_F(lua_backend_test, test_call_function_setTextObjectX) {
1354  //Set up
1355  game_mngr->get_level()->text_objects.emplace_back(
1356  ST::text(500, 600, {255, 255, 255, 255}, "SOME_TEXT", ST::hash_string("SOME_FONT.ttf 40")));
1357  //Test
1358  test_subject.run_script("setTextObjectX(0, 123)");
1359 
1360  //Check results
1361  ASSERT_EQ(2, game_mngr->get_level_calls);
1362  ASSERT_EQ(1, game_mngr->get_level()->text_objects.size());
1363  ASSERT_EQ(123, game_mngr->get_level()->text_objects.at(0).x);
1364  ASSERT_EQ(600, game_mngr->get_level()->text_objects.at(0).y);
1365  ASSERT_EQ("SOME_TEXT", game_mngr->get_level()->text_objects.at(0).text_string);
1366  ASSERT_EQ(ST::hash_string("SOME_FONT.ttf 40"), game_mngr->get_level()->text_objects.at(0).font);
1367  ASSERT_TRUE(game_mngr->get_level()->text_objects.at(0).is_visible);
1368 
1369  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.r);
1370  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.g);
1371  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.b);
1372  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.a);
1373 }
1374 
1375 TEST_F(lua_backend_test, test_call_function_setTextObjectY) {
1376  //Set up
1377  game_mngr->get_level()->text_objects.emplace_back(ST::text(500, 600, {255, 255, 255, 255},
1378  "SOME_TEXT", ST::hash_string("SOME_FONT.ttf 40")));
1379  //Test
1380  test_subject.run_script("setTextObjectY(0, 123)");
1381 
1382  //Check results
1383  ASSERT_EQ(2, game_mngr->get_level_calls);
1384  ASSERT_EQ(1, game_mngr->get_level()->text_objects.size());
1385  ASSERT_EQ(500, game_mngr->get_level()->text_objects.at(0).x);
1386  ASSERT_EQ(123, game_mngr->get_level()->text_objects.at(0).y);
1387  ASSERT_EQ("SOME_TEXT", game_mngr->get_level()->text_objects.at(0).text_string);
1388  ASSERT_EQ(ST::hash_string("SOME_FONT.ttf 40"), game_mngr->get_level()->text_objects.at(0).font);
1389  ASSERT_TRUE(game_mngr->get_level()->text_objects.at(0).is_visible);
1390 
1391  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.r);
1392  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.g);
1393  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.b);
1394  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.a);
1395 }
1396 
1397 TEST_F(lua_backend_test, test_call_function_setTextObjectVisible) {
1398  //Set up
1399  game_mngr->get_level()->text_objects.emplace_back(ST::text(500, 600, {255, 255, 255, 255},
1400  "SOME_TEXT", ST::hash_string("SOME_FONT.ttf 40")));
1401  //Test
1402  test_subject.run_script("setTextObjectVisible(0, false)");
1403 
1404  //Check results
1405  ASSERT_EQ(2, game_mngr->get_level_calls);
1406  ASSERT_EQ(1, game_mngr->get_level()->text_objects.size());
1407  ASSERT_EQ(500, game_mngr->get_level()->text_objects.at(0).x);
1408  ASSERT_EQ(600, game_mngr->get_level()->text_objects.at(0).y);
1409  ASSERT_EQ("SOME_TEXT", game_mngr->get_level()->text_objects.at(0).text_string);
1410  ASSERT_EQ(ST::hash_string("SOME_FONT.ttf 40"), game_mngr->get_level()->text_objects.at(0).font);
1411  ASSERT_FALSE(game_mngr->get_level()->text_objects.at(0).is_visible);
1412 
1413  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.r);
1414  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.g);
1415  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.b);
1416  ASSERT_EQ(255, game_mngr->get_level()->text_objects.at(0).color.a);
1417 }
1418 
1419 TEST_F(lua_backend_test, test_call_function_createEntity) {
1420  test_subject.run_script("createEntity(0)");
1421 
1422  //Check results
1423  ASSERT_EQ(1, game_mngr->get_level_calls);
1424  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1425  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1426  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1427  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1428  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1429  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1430  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1431  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1432  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1433  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1434  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1435  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1436  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1437  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1438  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1439  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1440  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1441  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1442  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1443  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1444  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1445 }
1446 
1447 TEST_F(lua_backend_test, test_call_function_setEntityActive) {
1448  //Set up
1449  game_mngr->get_level()->entities.emplace_back();
1450 
1451  //Test
1452  test_subject.run_script("setEntityActive(0, false)");
1453 
1454  //Check results
1455  ASSERT_EQ(2, game_mngr->get_level_calls);
1456  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1457  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1458  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1459  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1460  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1461  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1462  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1463  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1464  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1465  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1466  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1467  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1468  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1469  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1470  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1471  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1472  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1473  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1474  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1475  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1476  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_active());
1477 }
1478 
1479 TEST_F(lua_backend_test, test_call_function_setEntityX) {
1480  //Set up
1481  game_mngr->get_level()->entities.emplace_back();
1482 
1483  //Test
1484  test_subject.run_script("setEntityX(0, 500)");
1485 
1486  //Check results
1487  ASSERT_EQ(2, game_mngr->get_level_calls);
1488  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1489  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).x);
1490  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1491  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1492  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1493  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1494  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1495  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1496  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1497  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1498  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1499  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1500  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1501  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1502  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1503  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1504  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1505  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1506  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1507  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1508  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1509 }
1510 
1511 TEST_F(lua_backend_test, test_call_function_setEntityY) {
1512  //Set up
1513  game_mngr->get_level()->entities.emplace_back();
1514 
1515  //Test
1516  test_subject.run_script("setEntityY(0, 500)");
1517 
1518  //Check results
1519  ASSERT_EQ(2, game_mngr->get_level_calls);
1520  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1521  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1522  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).y);
1523  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1524  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1525  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1526  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1527  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1528  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1529  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1530  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1531  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1532  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1533  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1534  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1535  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1536  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1537  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1538  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1539  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1540  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1541 }
1542 
1543 TEST_F(lua_backend_test, test_call_function_getEntityX) {
1544  //Set up
1545  game_mngr->get_level()->entities.emplace_back();
1546  game_mngr->get_level()->entities.at(0).x = 500;
1547 
1548  //Test
1549  test_subject.run_script("return getEntityX(0)");
1550 
1551  //Check result
1552  ASSERT_EQ(500, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1553 
1554  //Check that nothing has changed in the entity
1555  ASSERT_EQ(3, game_mngr->get_level_calls);
1556  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1557  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).x);
1558  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1559  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1560  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1561  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1562  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1563  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1564  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1565  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1566  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1567  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1568  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1569  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1570  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1571  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1572  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1573  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1574  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1575  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1576  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1577 }
1578 
1579 TEST_F(lua_backend_test, test_call_function_getEntityY) {
1580  //Set up
1581  game_mngr->get_level()->entities.emplace_back();
1582  game_mngr->get_level()->entities.at(0).y = 500;
1583 
1584  //Test
1585  test_subject.run_script("return getEntityY(0)");
1586 
1587  //Check result
1588  ASSERT_EQ(500, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1589 
1590  //Check that nothing has changed in the entity
1591  ASSERT_EQ(3, game_mngr->get_level_calls);
1592  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1593  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1594  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).y);
1595  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1596  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1597  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1598  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1599  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1600  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1601  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1602  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1603  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1604  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1605  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1606  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1607  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1608  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1609  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1610  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1611  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1612  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1613 }
1614 
1615 TEST_F(lua_backend_test, test_call_function_setEntityStatic) {
1616  //Set up
1617  game_mngr->get_level()->entities.emplace_back();
1618 
1619  //Test
1620  test_subject.run_script("setEntityStatic(0, true)");
1621 
1622  //Check results
1623  ASSERT_EQ(2, game_mngr->get_level_calls);
1624  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1625  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1626  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1627  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1628  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_static());
1629  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1630  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1631  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1632  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1633  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1634  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1635  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1636  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1637  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1638  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1639  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1640  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1641  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1642  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1643  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1644  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1645 }
1646 
1647 TEST_F(lua_backend_test, test_call_function_setEntityVelocityX) {
1648  //Set up
1649  game_mngr->get_level()->entities.emplace_back();
1650 
1651  //Test
1652  test_subject.run_script("setEntityVelocityX(0, 120)");
1653 
1654  //Check results
1655  ASSERT_EQ(2, game_mngr->get_level_calls);
1656  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1657  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1658  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1659  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1660  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1661  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1662  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1663  ASSERT_EQ(120, game_mngr->get_level()->entities.at(0).velocity_x);
1664  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1665  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1666  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1667  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1668  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1669  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1670  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1671  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1672  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1673  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1674  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1675  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1676  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1677 }
1678 
1679 TEST_F(lua_backend_test, test_call_function_setEntityVelocityY) {
1680  //Set up
1681  game_mngr->get_level()->entities.emplace_back();
1682 
1683  //Test
1684  test_subject.run_script("setEntityVelocityY(0, 120)");
1685 
1686  //Check results
1687  ASSERT_EQ(2, game_mngr->get_level_calls);
1688  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1689  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1690  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1691  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1692  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1693  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1694  ASSERT_EQ(120, game_mngr->get_level()->entities.at(0).velocity_y);
1695  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1696  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1697  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1698  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1699  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1700  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1701  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1702  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1703  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1704  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1705  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1706  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1707  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1708  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1709 }
1710 
1711 TEST_F(lua_backend_test, test_call_function_getEntityVelocityX) {
1712  //Set up
1713  game_mngr->get_level()->entities.emplace_back();
1714  game_mngr->get_level()->entities.at(0).velocity_x = 120;
1715 
1716  //Test
1717  test_subject.run_script("return getEntityVelocityX(0)");
1718 
1719  //Check result
1720  ASSERT_EQ(120, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1721 
1722  //Check that nothing has changed in the entity
1723  ASSERT_EQ(3, game_mngr->get_level_calls);
1724  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1725  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1726  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1727  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1728  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1729  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1730  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1731  ASSERT_EQ(120, game_mngr->get_level()->entities.at(0).velocity_x);
1732  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1733  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1734  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1735  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1736  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1737  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1738  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1739  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1740  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1741  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1742  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1743  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1744  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1745 }
1746 
1747 TEST_F(lua_backend_test, test_call_function_getEntityVelocityY) {
1748  //Set up
1749  game_mngr->get_level()->entities.emplace_back();
1750  game_mngr->get_level()->entities.at(0).velocity_y = 120;
1751 
1752  //Test
1753  test_subject.run_script("return getEntityVelocityY(0)");
1754 
1755  //Check result
1756  ASSERT_EQ(120, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1757 
1758  //Check that nothing has changed in the entity
1759  ASSERT_EQ(3, game_mngr->get_level_calls);
1760  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1761  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1762  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1763  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1764  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1765  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1766  ASSERT_EQ(120, game_mngr->get_level()->entities.at(0).velocity_y);
1767  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1768  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1769  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1770  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1771  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1772  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1773  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1774  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1775  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1776  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1777  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1778  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1779  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1780  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1781 }
1782 
1783 TEST_F(lua_backend_test, test_call_function_setEntityTextureScale) {
1784  //Set up
1785  game_mngr->get_level()->entities.emplace_back();
1786 
1787  //Test
1788  test_subject.run_script("setEntityTextureScale(0, 2, 2)");
1789 
1790  //Check results
1791  ASSERT_EQ(2, game_mngr->get_level_calls);
1792  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1793  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1794  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1795  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1796  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1797  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1798  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1799  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1800  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1801  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1802  ASSERT_EQ(2, game_mngr->get_level()->entities.at(0).tex_scale_x);
1803  ASSERT_EQ(2, game_mngr->get_level()->entities.at(0).tex_scale_y);
1804  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1805  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1806  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1807  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1808  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1809  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1810  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1811  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1812  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1813 }
1814 
1815 TEST_F(lua_backend_test, test_call_function_setEntityTexture) {
1816  //Set up
1817  game_mngr->get_level()->entities.emplace_back();
1818 
1819  //Test
1820  test_subject.run_script("setEntityTexture(0, \"new_texture.webp\")");
1821 
1822  //Check results
1823  ASSERT_EQ(2, game_mngr->get_level_calls);
1824  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1825  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1826  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1827  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1828  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1829  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1830  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1831  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1832  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1833  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1834  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1835  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1836  ASSERT_EQ(ST::hash_string("new_texture.webp"), game_mngr->get_level()->entities.at(0).texture);
1837  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1838  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1839  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1840  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1841  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1842  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1843  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1844  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1845 }
1846 
1847 TEST_F(lua_backend_test, test_call_function_setEntityTexW) {
1848  //Set up
1849  game_mngr->get_level()->entities.emplace_back();
1850 
1851  //Test
1852  test_subject.run_script("setEntityTexW(0, 500)");
1853 
1854  //Check results
1855  ASSERT_EQ(2, game_mngr->get_level_calls);
1856  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1857  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1858  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1859  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1860  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1861  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1862  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1863  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1864  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1865  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).tex_w);
1866  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1867  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1868  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1869  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1870  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1871  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1872  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1873  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1874  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1875  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1876  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1877 }
1878 
1879 TEST_F(lua_backend_test, test_call_function_setEntityTexH) {
1880  //Set up
1881  game_mngr->get_level()->entities.emplace_back();
1882 
1883  //Test
1884  test_subject.run_script("setEntityTexH(0, 500)");
1885 
1886  //Check results
1887  ASSERT_EQ(2, game_mngr->get_level_calls);
1888  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1889  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1890  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1891  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1892  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1893  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1894  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1895  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1896  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).tex_h);
1897  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1898  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1899  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1900  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1901  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1902  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1903  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1904  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1905  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1906  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1907  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1908  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1909 }
1910 
1911 TEST_F(lua_backend_test, test_call_function_getEntityTexW) {
1912  //Set up
1913  game_mngr->get_level()->entities.emplace_back();
1914  game_mngr->get_level()->entities.at(0).tex_w = 500;
1915 
1916  //Test
1917  test_subject.run_script("return getEntityTexW(0)");
1918 
1919  //Check result
1920  ASSERT_EQ(500, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1921 
1922  //Check that nothing has changed in the entity
1923  ASSERT_EQ(3, game_mngr->get_level_calls);
1924  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1925  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1926  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1927  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1928  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1929  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1930  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1931  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1932  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
1933  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).tex_w);
1934  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1935  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1936  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1937  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1938  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1939  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1940  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1941  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1942  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1943  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1944  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1945 }
1946 
1947 TEST_F(lua_backend_test, test_call_function_getEntityTexH) {
1948  //Set up
1949  game_mngr->get_level()->entities.emplace_back();
1950  game_mngr->get_level()->entities.at(0).tex_h = 500;
1951 
1952  //Test
1953  test_subject.run_script("return getEntityTexH(0)");
1954 
1955  //Check result
1956  ASSERT_EQ(500, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
1957 
1958  //Check that nothing has changed in the entity
1959  ASSERT_EQ(3, game_mngr->get_level_calls);
1960  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1961  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1962  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1963  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
1964  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1965  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1966  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1967  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
1968  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).tex_h);
1969  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
1970  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
1971  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
1972  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
1973  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
1974  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
1975  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
1976  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
1977  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
1978  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
1979  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
1980  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
1981 }
1982 
1983 TEST_F(lua_backend_test, test_call_function_setEntityVisible) {
1984  //Set up
1985  game_mngr->get_level()->entities.emplace_back();
1986 
1987  //Test
1988  test_subject.run_script("setEntityVisible(0, false)");
1989 
1990  //Check results
1991  ASSERT_EQ(2, game_mngr->get_level_calls);
1992  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
1993  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
1994  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
1995  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_visible());
1996  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
1997  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
1998  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
1999  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2000  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2001  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2002  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2003  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2004  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2005  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2006  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2007  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2008  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
2009  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
2010  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2011  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2012  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2013 }
2014 
2015 TEST_F(lua_backend_test, test_call_function_setEntityCollisionBox) {
2016  //Set up
2017  game_mngr->get_level()->entities.emplace_back();
2018 
2019  //Test
2020  test_subject.run_script("setEntityCollisionBox(0, 0, 0, 500, 500)");
2021 
2022  //Check results
2023  ASSERT_EQ(2, game_mngr->get_level_calls);
2024  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2025  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2026  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2027  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2028  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2029  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2030  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2031  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2032  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2033  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2034  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2035  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2036  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2037  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2038  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2039  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2040  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).get_col_x());
2041  ASSERT_EQ(-500, game_mngr->get_level()->entities.at(0).get_col_y());
2042  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2043  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2044  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2045 }
2046 
2047 TEST_F(lua_backend_test, test_call_function_entityCollides) {
2048  //Set up
2049  game_mngr->get_level()->entities.emplace_back();
2050  game_mngr->get_level()->entities.emplace_back();
2051  game_mngr->get_level()->entities.at(0).x = 500;
2052  game_mngr->get_level()->entities.at(0).y = 500;
2053  game_mngr->get_level()->entities.at(1).x = 500;
2054  game_mngr->get_level()->entities.at(1).y = 500;
2055  game_mngr->get_level()->entities.at(0).set_collision_box(0, 0, 500, 500);
2056  game_mngr->get_level()->entities.at(1).set_collision_box(0, 0, 500, 500);
2057 
2058  //Test
2059  test_subject.run_script("return entityCollides(0, 1)");
2060 
2061  //Check that they are colliding
2062  ASSERT_TRUE(lua_toboolean(get_lua_state(), lua_gettop(get_lua_state())));
2063 
2064  ASSERT_EQ(2, game_mngr->get_level()->entities.size());
2065 
2066  //Check nothing has been modified in entity 1
2067  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).x);
2068  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).y);
2069  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2070  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2071  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2072  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2073  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2074  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2075  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2076  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2077  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2078  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2079  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2080  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2081  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2082  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).get_col_x());
2083  ASSERT_EQ(-500, game_mngr->get_level()->entities.at(0).get_col_y());
2084  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2085  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2086  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2087 
2088  //Check nothing has been modified in entity 2
2089  ASSERT_EQ(500, game_mngr->get_level()->entities.at(1).x);
2090  ASSERT_EQ(500, game_mngr->get_level()->entities.at(1).y);
2091  ASSERT_TRUE(game_mngr->get_level()->entities.at(1).is_visible());
2092  ASSERT_FALSE(game_mngr->get_level()->entities.at(1).is_static());
2093  ASSERT_FALSE(game_mngr->get_level()->entities.at(1).is_affected_by_physics());
2094  ASSERT_EQ(0, game_mngr->get_level()->entities.at(1).velocity_y);
2095  ASSERT_EQ(0, game_mngr->get_level()->entities.at(1).velocity_x);
2096  ASSERT_EQ(0, game_mngr->get_level()->entities.at(1).tex_h);
2097  ASSERT_EQ(0, game_mngr->get_level()->entities.at(1).tex_w);
2098  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2099  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2100  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(1).texture);
2101  ASSERT_EQ(1, game_mngr->get_level()->entities.at(1).sprite_num);
2102  ASSERT_EQ(1, game_mngr->get_level()->entities.at(1).animation_num);
2103  ASSERT_EQ(1, game_mngr->get_level()->entities.at(1).animation);
2104  ASSERT_EQ(500, game_mngr->get_level()->entities.at(1).get_col_x());
2105  ASSERT_EQ(-500, game_mngr->get_level()->entities.at(1).get_col_y());
2106  ASSERT_EQ(0, game_mngr->get_level()->entities.at(1).get_col_x_offset());
2107  ASSERT_EQ(0, game_mngr->get_level()->entities.at(1).get_col_y_offset());
2108  ASSERT_TRUE(game_mngr->get_level()->entities.at(1).is_active());
2109 }
2110 
2111 TEST_F(lua_backend_test, test_call_function_setEntityAffectedByPhysics) {
2112  //Set up
2113  game_mngr->get_level()->entities.emplace_back();
2114 
2115  //Test
2116  test_subject.run_script("setEntityAffectedByPhysics(0, true)");
2117 
2118  //Check results
2119  ASSERT_EQ(4, game_mngr->get_level_calls);
2120  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2121  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2122  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2123  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2124  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2125  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2126  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2127  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2128  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2129  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2130  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2131  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2132  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2133  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2134  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2135  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2136  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
2137  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
2138  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2139  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2140  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2141 }
2142 
2143 TEST_F(lua_backend_test, test_call_function_getEntityColX) {
2144  //Set up
2145  game_mngr->get_level()->entities.emplace_back();
2146  game_mngr->get_level()->entities.at(0).set_collision_box(0, 0, 500, 500);
2147 
2148  //Test
2149  test_subject.run_script("return getEntityColX(0)");
2150 
2151  //Check result
2152  ASSERT_EQ(500, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
2153 
2154  //Check that nothing has changed in the entity
2155  ASSERT_EQ(3, game_mngr->get_level_calls);
2156  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2157  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2158  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2159  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2160  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2161  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2162  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2163  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2164  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2165  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2166  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2167  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2168  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2169  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2170  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2171  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2172  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).get_col_x());
2173  ASSERT_EQ(-500, game_mngr->get_level()->entities.at(0).get_col_y());
2174  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2175  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2176  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2177 }
2178 
2179 TEST_F(lua_backend_test, test_call_function_getEntityColY) {
2180  //Set up
2181  game_mngr->get_level()->entities.emplace_back();
2182  game_mngr->get_level()->entities.at(0).set_collision_box(0, 0, 500, 500);
2183 
2184  //Test
2185  test_subject.run_script("return getEntityColY(0)");
2186 
2187  //Check result
2188  ASSERT_EQ(-500, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
2189 
2190  //Check that nothing has changed in the entity
2191  ASSERT_EQ(3, game_mngr->get_level_calls);
2192  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2193  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2194  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2195  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2196  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2197  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2198  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2199  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2200  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2201  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2202  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2203  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2204  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2205  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2206  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2207  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2208  ASSERT_EQ(500, game_mngr->get_level()->entities.at(0).get_col_x());
2209  ASSERT_EQ(-500, game_mngr->get_level()->entities.at(0).get_col_y());
2210  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2211  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2212  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2213 }
2214 
2215 TEST_F(lua_backend_test, test_call_function_getEntityColXOffset) {
2216  //Set up
2217  game_mngr->get_level()->entities.emplace_back();
2218  game_mngr->get_level()->entities.at(0).set_collision_box(6, 0, 0, 0);
2219 
2220  //Test
2221  test_subject.run_script("return getEntityColXOffset(0)");
2222 
2223  //Check result
2224  ASSERT_EQ(6, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
2225 
2226  //Check that nothing has changed in the entity
2227  ASSERT_EQ(3, game_mngr->get_level_calls);
2228  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2229  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2230  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2231  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2232  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2233  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2234  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2235  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2236  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2237  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2238  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2239  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2240  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2241  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2242  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2243  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2244  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
2245  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
2246  ASSERT_EQ(6, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2247  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2248  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2249 }
2250 
2251 TEST_F(lua_backend_test, test_call_function_getEntityColYOffset) {
2252  //Set up
2253  game_mngr->get_level()->entities.emplace_back();
2254  game_mngr->get_level()->entities.at(0).set_collision_box(0, 6, 0, 0);
2255 
2256  //Test
2257  test_subject.run_script("return getEntityColYOffset(0)");
2258 
2259  //Check result
2260  ASSERT_EQ(6, lua_tointeger(get_lua_state(), lua_gettop(get_lua_state())));
2261 
2262  //Check that nothing has changed in the entity
2263  ASSERT_EQ(3, game_mngr->get_level_calls);
2264  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2265  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2266  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2267  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2268  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2269  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2270  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2271  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2272  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2273  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2274  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2275  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2276  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2277  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2278  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2279  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2280  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
2281  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
2282  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2283  ASSERT_EQ(6, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2284  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2285 }
2286 
2287 TEST_F(lua_backend_test, test_call_function_setEntityAnimation) {
2288  //Set up
2289  game_mngr->get_level()->entities.emplace_back();
2290 
2291  //Test
2292  test_subject.run_script("setEntityAnimation(0, 3)");
2293 
2294  //Check results
2295  ASSERT_EQ(2, game_mngr->get_level_calls);
2296  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2297  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2298  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2299  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2300  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2301  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2302  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2303  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2304  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2305  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2306  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2307  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2308  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2309  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2310  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2311  ASSERT_EQ(3, game_mngr->get_level()->entities.at(0).animation);
2312  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
2313  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
2314  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2315  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2316  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2317 }
2318 
2319 TEST_F(lua_backend_test, test_call_function_setEntityAnimationNum) {
2320  //Set up
2321  game_mngr->get_level()->entities.emplace_back();
2322 
2323  //Test
2324  test_subject.run_script("setEntityAnimationNum(0, 3)");
2325 
2326  //Check results
2327  ASSERT_EQ(2, game_mngr->get_level_calls);
2328  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2329  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2330  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2331  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2332  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2333  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2334  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2335  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2336  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2337  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2338  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2339  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2340  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2341  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).sprite_num);
2342  ASSERT_EQ(3, game_mngr->get_level()->entities.at(0).animation_num);
2343  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2344  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
2345  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
2346  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2347  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2348  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2349 }
2350 
2351 TEST_F(lua_backend_test, test_call_function_setEntitySpriteNum) {
2352  //Set up
2353  game_mngr->get_level()->entities.emplace_back();
2354 
2355  //Test
2356  test_subject.run_script("setEntitySpriteNum(0, 3)");
2357 
2358  //Check results
2359  ASSERT_EQ(2, game_mngr->get_level_calls);
2360  ASSERT_EQ(1, game_mngr->get_level()->entities.size());
2361  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).x);
2362  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).y);
2363  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_visible());
2364  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_static());
2365  ASSERT_FALSE(game_mngr->get_level()->entities.at(0).is_affected_by_physics());
2366  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_y);
2367  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).velocity_x);
2368  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_h);
2369  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).tex_w);
2370  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_x);
2371  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).tex_scale_y);
2372  ASSERT_EQ(65535, game_mngr->get_level()->entities.at(0).texture);
2373  ASSERT_EQ(3, game_mngr->get_level()->entities.at(0).sprite_num);
2374  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation_num);
2375  ASSERT_EQ(1, game_mngr->get_level()->entities.at(0).animation);
2376  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x());
2377  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y());
2378  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_x_offset());
2379  ASSERT_EQ(0, game_mngr->get_level()->entities.at(0).get_col_y_offset());
2380  ASSERT_TRUE(game_mngr->get_level()->entities.at(0).is_active());
2381 }
2382 
2383 TEST_F(lua_backend_test, test_call_function_setInternalResolutionLua) {
2384  //Set up
2385  subscriber subscriber1;
2386  msg_bus->subscribe(SET_INTERNAL_RESOLUTION, &subscriber1);
2387 
2388  //Test
2389  test_subject.run_script("setInternalResolution(3840, 2160)");
2390 
2391 
2392  //Check result - expect to see a message with appropriate content
2393  message *result = subscriber1.get_next_message();
2394 
2395  ASSERT_TRUE(result);
2396  ASSERT_EQ(SET_INTERNAL_RESOLUTION, result->msg_name);
2397  ASSERT_TRUE(static_cast<bool>(result->base_data0));
2398  auto data = result->base_data0;
2399  ASSERT_EQ(data & 0x0000ffffU, 3840);
2400  ASSERT_EQ((data >> 16U) & 0x0000ffffU, 2160);
2401 }
2402 
2403 TEST_F(lua_backend_test, test_call_function_setWindowResolutionLua) {
2404  //Set up
2405  subscriber subscriber1;
2406  msg_bus->subscribe(SET_WINDOW_RESOLUTION, &subscriber1);
2407 
2408  //Test
2409  test_subject.run_script("setWindowResolution(3840, 2160)");
2410 
2411 
2412  //Check result - expect to see a message with appropriate content
2413  message *result = subscriber1.get_next_message();
2414 
2415  ASSERT_TRUE(result);
2416  ASSERT_EQ(SET_WINDOW_RESOLUTION, result->msg_name);
2417  ASSERT_TRUE(static_cast<bool>(result->base_data0));
2418  auto data = result->base_data0;
2419  ASSERT_EQ(data & 0x0000ffffU, 3840);
2420  ASSERT_EQ((data >> 16U) & 0x0000ffffU, 2160);
2421 }
2422 
2423 TEST_F(lua_backend_test, test_call_function_getInternalResolutionLua) {
2424  //Test
2425  test_subject.run_script("return getInternalResolution()");
2426 
2427  //Check result
2428  ASSERT_EQ(1080, lua_tointeger(get_lua_state(), -1));
2429  ASSERT_EQ(1920, lua_tointeger(get_lua_state(), -2));
2430 }
2431 
2432 TEST_F(lua_backend_test, test_call_function_getWindowResolutionLua) {
2433  //Test
2434  test_subject.run_script("return getWindowResolution()");
2435 
2436  //Check result
2437  ASSERT_EQ(1440, lua_tointeger(get_lua_state(), -1));
2438  ASSERT_EQ(2560, lua_tointeger(get_lua_state(), -2));
2439 }
2440 
2441 int main(int argc, char **argv) {
2442  ::testing::InitGoogleTest(&argc, argv);
2443  return RUN_ALL_TESTS();
2444 }
This class is responsible for managing all levels and the lua backend, it is the heart of the engine.
Tests fixture for the lua_backend.
This class handles all interaction with lua.
Definition: lua_backend.hpp:31
int initialize(message_bus *msg_bus, game_manager *game_mngr)
Definition: lua_backend.cpp:41
The central messaging system of the engine. All subsystem make extensive use of it.
Definition: message_bus.hpp:29
A message object passed around in the message bus. Holds anything created with make_data<>().
Definition: message.hpp:21
void * get_data() const
Definition: message.hpp:80
This class handles a small queue for messages.
Definition: subscriber.hpp:20
message * get_next_message()
Definition: subscriber.hpp:39
A timer used for keeping track of time in the main loop.
Definition: timer.hpp:19
double time_since_start() const
Definition: timer.cpp:22
This struct represents text objects in the game.
Definition: text.hpp:23