ST_engine  0.3-ALPHA
level_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 #include <gtest/gtest.h>
11 #include <game_manager/level/level.hpp>
12 #include <ST_util/test_util.hpp>
13 #include <ST_util/string_util.hpp>
14 
16 class level_tests : public ::testing::Test {
17 
18 protected:
19 
20  int8_t load_input_conf(ST::level *lvl) {
21  return lvl->load_input_conf();
22  }
23 
24  void SetUp() override {
25  initialize_SDL();
26  }
27 
28  void TearDown() override {
29  close_SDL();
30  }
31 };
32 
33 TEST_F(level_tests, test_load_input_configuration) {
34 
35  //Set up
36  ST::level level("test_level", new message_bus());
37 
38  std::string key1 = "INVENTORY";
39  uint16_t key1_hash = ST::hash_string(key1);
40 
41  std::string key2 = "GO";
42  uint16_t key2_hash = ST::hash_string(key2);
43 
44  std::string key3 = "JUMP";
45  uint16_t key3_hash = ST::hash_string(key3);
46 
47  //Test
48  ASSERT_EQ(0, load_input_conf(&level));
49  ska::bytell_hash_map<uint16_t, std::vector<ST::key>> actions_buttons = level.actions_buttons;
50 
51  ST::key check_key1 = actions_buttons.at(key1_hash).at(0);
52  ASSERT_EQ(ST::key::I, check_key1);
53 
54  ST::key check_key2 = actions_buttons.at(key1_hash).at(1);
55  ASSERT_EQ(ST::key::CONTROLLER_BUTTON_B, check_key2);
56 
57  ST::key check_key3 = actions_buttons.at(key2_hash).at(0);
58  ASSERT_EQ(ST::key::ENTER, check_key3);
59 
60  ST::key check_key4 = actions_buttons.at(key3_hash).at(0);
61  ASSERT_EQ(ST::key::SPACEBAR, check_key4);
62 
63  ST::key check_key5 = actions_buttons.at(key3_hash).at(1);
64  ASSERT_EQ(ST::key::CONTROLLER_BUTTON_A, check_key5);
65 }
66 
67 
68 int main(int argc, char **argv) {
69  ::testing::InitGoogleTest(&argc, argv);
70  return RUN_ALL_TESTS();
71 }
This object contains all the data for a level and provides functions for loading and unloading a leve...
Definition: level.hpp:29
int8_t load_input_conf()
Definition: level.cpp:132
Tests fixture for the level object.
Definition: level_tests.cpp:16
The central messaging system of the engine. All subsystem make extensive use of it.
Definition: message_bus.hpp:29