Debian Codegraph @

CorsixTH/CppTest/test_th_lua_map.cpp

raw
1 #include <catch2/catch_test_macros.hpp>
2
3 #include "../Src/lua.hpp"
4 #include "../Src/th_lua.h"
5 #include "../Src/th_map.h"
6
7 TEST_CASE("test l_map_setcellflags", "[l_map_setcellflags]") {
8 // Prepare lua bindings
9 const lua_state_unique_ptr L(luaL_newstate());
10 luaL_openlibs(L.get());
11 preload_lua_package(L.get(), "TH", luaopen_th);
12 luaT_execute(L.get(), "return require \"TH\"");
13 lua_settop(L.get(), 1);
14
15 // Create a map
16 lua_getfield(L.get(), -1, "map");
17 lua_call(L.get(), 0, 1);
18 auto* map = static_cast<level_map*>(lua_touserdata(L.get(), -1));
19
20 // Default map is 0,0, increase size so we can set flags
21 map->set_size(128, 128);
22
23 lua_getfield(L.get(), -1, "setCellFlags");
24
25 lua_pushvalue(L.get(), -2); // Copy the map to the top of the stack
26
27 lua_pushinteger(L.get(), 5); // X
28 lua_pushinteger(L.get(), 10); // Y
29
30 // flags
31 lua_newtable(L.get());
32 lua_pushstring(L.get(), "buildable");
33 lua_pushboolean(L.get(), true);
34 lua_settable(L.get(), -3);
35
36 lua_pushstring(L.get(), "doorNorth");
37 lua_pushboolean(L.get(), true);
38 lua_settable(L.get(), -3);
39
40 lua_pushstring(L.get(), "parcelId");
41 lua_pushnumber(L.get(), 3);
42 lua_settable(L.get(), -3);
43
44 lua_call(L.get(), 4, 0);
45
46 const map_tile* tile = map->get_tile(4, 9);
47
48 REQUIRE(tile->flags.buildable == true);
49 REQUIRE(tile->flags.do_not_idle == false);
50 REQUIRE(tile->flags.door_north == true);
51 REQUIRE(tile->iParcelId == 3);
52 }