ST_engine  0.3-ALPHA
entity_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 
11 #include <gtest/gtest.h>
12 #include <game_manager/level/entity.hpp>
13 
14 TEST(entity_tests, test_set_collisions_box) {
15  //Set up
16  ST::entity test_subject;
17 
18  //Test
19  test_subject.set_collision_box(0, 0, 0, 0);
20 
21  ASSERT_FALSE(test_subject.is_affected_by_physics());
22  ASSERT_EQ(0, test_subject.get_col_x());
23  ASSERT_EQ(0, test_subject.get_col_y());
24 }
25 
26 TEST(entity_tests, test_entities_collision) {
27  //Set up
28  ST::entity test_subject1;
29  ST::entity test_subject2;
30 
31  test_subject1.x = 0;
32  test_subject1.y = 0;
33  test_subject1.set_collision_box(0, 0, 100, 100);
34 
35  test_subject2.x = 0;
36  test_subject2.y = 0;
37  test_subject2.set_collision_box(0, 0, 100, 100);
38 
39  //Test
40  ASSERT_TRUE(test_subject1.collides(test_subject2));
41 }
42 
43 TEST(entity_tests, test_entities_colliding_on_edge) {
44  //Set up
45  ST::entity test_subject1;
46  ST::entity test_subject2;
47 
48  test_subject1.x = 0;
49  test_subject1.y = 0;
50  test_subject1.set_collision_box(0, 0, 100, 100);
51 
52  test_subject2.x = 99;
53  test_subject2.y = 99;
54  test_subject2.set_collision_box(0, 0, 100, 100);
55 
56  //Test
57  ASSERT_TRUE(test_subject1.collides(test_subject2));
58 }
59 
60 TEST(entity_tests, test_entities_colliding_one_pixel_from_edge) {
61  //Set up
62  ST::entity test_subject1;
63  ST::entity test_subject2;
64 
65  test_subject1.x = 0;
66  test_subject1.y = 0;
67  test_subject1.set_collision_box(0, 0, 100, 100);
68 
69  test_subject2.x = 98;
70  test_subject2.y = 98;
71  test_subject2.set_collision_box(0, 0, 100, 100);
72 
73  //Test
74  ASSERT_TRUE(test_subject1.collides(test_subject2));
75 }
76 
77 
78 TEST(entity_tests, test_set_get_is_active) {
79  //Set up
80  ST::entity test_subject;
81 
82  //Test
83  test_subject.set_active(true);
84  ASSERT_TRUE(test_subject.is_active());
85  test_subject.set_active(false);
86  ASSERT_FALSE(test_subject.is_active());
87 }
88 
89 TEST(entity_tests, test_set_get_is_static) {
90  //Set up
91  ST::entity test_subject;
92 
93  //Test
94  test_subject.set_static(true);
95  ASSERT_TRUE(test_subject.is_static());
96  test_subject.set_static(false);
97  ASSERT_FALSE(test_subject.is_static());
98 }
99 
100 TEST(entity_tests, test_set_get_is_visible) {
101  //Set up
102  ST::entity test_subject;
103 
104  //Test
105  test_subject.set_visible(true);
106  ASSERT_TRUE(test_subject.is_visible());
107  test_subject.set_visible(false);
108  ASSERT_FALSE(test_subject.is_visible());
109 }
110 
111 
112 TEST(entity_tests, test_set_get_is_affected_by_physics) {
113  //Set up
114  ST::entity test_subject;
115 
116  //Test
117  test_subject.set_affected_by_physics(true);
118  ASSERT_TRUE(test_subject.is_affected_by_physics());
119  test_subject.set_affected_by_physics(false);
120  ASSERT_FALSE(test_subject.is_affected_by_physics());
121 }
122 
123 int main(int argc, char **argv) {
124  ::testing::InitGoogleTest(&argc, argv);
125  return RUN_ALL_TESTS();
126 }
This class represents all static or dynamic objects in the game (excluding text, see ST::text)
Definition: entity.hpp:24
int32_t get_col_y() const
Definition: entity.hpp:170
void set_collision_box(int16_t, int16_t, int16_t, int16_t)
Definition: entity.hpp:197
bool collides(const entity &) const
Definition: entity.hpp:210
int32_t get_col_x() const
Definition: entity.hpp:162