ST_engine  0.3-ALPHA
message_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 "../../include/message_bus.hpp"
12 
13 TEST(message_test, test_message_creation) {
14  auto test_subject = new message(1, make_data<bool>(true));
15  ASSERT_TRUE(test_subject);
16  delete test_subject;
17 }
18 
19 TEST(message_test, test_message_get_data) {
20  auto test_subject = new message(1, make_data<bool>(true));
21  ASSERT_TRUE(*static_cast<bool *>(test_subject->get_data()));
22  delete (test_subject);
23 }
24 
25 TEST(message_test, test_message_get_base_data) {
26  auto test_subject = new message(1, 30, nullptr);
27  test_subject->base_data1 = 100;
28  test_subject->base_data2 = 150;
29 
30  ASSERT_FALSE(static_cast<bool>(test_subject->get_data()));
31  ASSERT_EQ(30, test_subject->base_data0);
32  ASSERT_EQ(100, test_subject->base_data1);
33  ASSERT_EQ(150, test_subject->base_data2);
34  delete (test_subject);
35 }
36 
37 TEST(message_test, test_message_get_data_and_base_data) {
38  auto test_subject = new message(1, 30, make_data<bool>(true));
39  test_subject->base_data1 = 100;
40  test_subject->base_data2 = 150;
41 
42  ASSERT_TRUE(*static_cast<bool *>(test_subject->get_data()));
43  ASSERT_EQ(30, test_subject->base_data0);
44  ASSERT_EQ(100, test_subject->base_data1);
45  ASSERT_EQ(150, test_subject->base_data2);
46 
47  delete (test_subject);
48 }
49 
50 TEST(message_test, test_message_copy) {
51  auto test_subject = new message(1, 50, make_data<int>(12));
52  test_subject->base_data1 = 100;
53  test_subject->base_data2 = 150;
54 
55  auto copy = test_subject->make_copy();
56  ASSERT_TRUE(test_subject->get_data());
57  ASSERT_TRUE(copy->get_data());
58  ASSERT_EQ(test_subject->get_data(), copy->get_data());
59  ASSERT_EQ(test_subject->msg_name, copy->msg_name);
60  ASSERT_EQ(test_subject->base_data0, copy->base_data0);
61  ASSERT_EQ(test_subject->base_data1, copy->base_data1);
62  ASSERT_EQ(test_subject->base_data2, copy->base_data2);
63 
64  delete (test_subject);
65  delete (copy);
66 }
67 
68 int main(int argc, char **argv) {
69  ::testing::InitGoogleTest(&argc, argv);
70  return RUN_ALL_TESTS();
71 }
A message object passed around in the message bus. Holds anything created with make_data<>().
Definition: message.hpp:21