10 #include <gtest/gtest.h>
11 #include "../../../ST_message_bus/include/message_bus.hpp"
12 #include <console.hpp>
20 uint8_t get_log_level() {
21 return test_cnsl->log_level;
24 void write(ST::log_type type,
const std::string &text) {
25 test_cnsl->write(text, type);
30 void SetUp()
override {
32 test_cnsl =
new console(*msg_bus);
35 void TearDown()
override {
42 test_cnsl->set_log_level(ST::log_type::ERROR);
43 EXPECT_EQ(
static_cast<uint8_t
>(ST::log_type::ERROR), get_log_level());
45 test_cnsl->set_log_level(ST::log_type::INFO);
46 EXPECT_EQ(
static_cast<uint8_t
>(ST::log_type::INFO), get_log_level());
48 test_cnsl->set_log_level(ST::log_type::SUCCESS);
49 EXPECT_EQ(
static_cast<uint8_t
>(ST::log_type::SUCCESS), get_log_level());
51 test_cnsl->set_log_level(ST::log_type::SUCCESS | ST::log_type::ERROR);
52 EXPECT_EQ(
static_cast<uint8_t
>(ST::log_type::SUCCESS | ST::log_type::ERROR), get_log_level());
54 test_cnsl->set_log_level(ST::log_type::INFO | ST::log_type::ERROR);
55 EXPECT_EQ(
static_cast<uint8_t
>(ST::log_type::INFO | ST::log_type::ERROR), get_log_level());
57 test_cnsl->set_log_level(ST::log_type::INFO | ST::log_type::SUCCESS);
58 EXPECT_EQ(
static_cast<uint8_t
>(ST::log_type::INFO | ST::log_type::SUCCESS), get_log_level());
60 test_cnsl->set_log_level(ST::log_type::INFO | ST::log_type::SUCCESS | ST::log_type::ERROR);
61 EXPECT_EQ(
static_cast<uint8_t
>(ST::log_type::INFO | ST::log_type::SUCCESS | ST::log_type::ERROR), get_log_level());
65 ::testing::internal::CaptureStderr();
66 ::testing::internal::CaptureStdout();
67 test_cnsl->set_log_level(ST::log_type::ERROR);
68 msg_bus->send_msg(
new message(LOG_ERROR, make_data<std::string>(
"TEST_STRING")));
69 msg_bus->send_msg(
new message(LOG_INFO, make_data<std::string>(
"TEST_STRING2")));
70 msg_bus->send_msg(
new message(LOG_SUCCESS, make_data<std::string>(
"TEST_STRING3")));
72 ASSERT_EQ(
"TEST_STRING\n", testing::internal::GetCapturedStderr());
73 ASSERT_EQ(
"", testing::internal::GetCapturedStdout());
77 ::testing::internal::CaptureStdout();
78 ::testing::internal::CaptureStderr();
79 test_cnsl->set_log_level(ST::log_type::INFO);
80 msg_bus->send_msg(
new message(LOG_ERROR, make_data<std::string>(
"TEST_STRING")));
81 msg_bus->send_msg(
new message(LOG_INFO, make_data<std::string>(
"TEST_STRING2")));
82 msg_bus->send_msg(
new message(LOG_SUCCESS, make_data<std::string>(
"TEST_STRING3")));
84 ASSERT_EQ(
"TEST_STRING2\n", testing::internal::GetCapturedStdout());
85 ASSERT_EQ(
"", testing::internal::GetCapturedStderr());
89 ::testing::internal::CaptureStdout();
90 ::testing::internal::CaptureStderr();
91 test_cnsl->set_log_level(ST::log_type::SUCCESS);
92 msg_bus->send_msg(
new message(LOG_ERROR, make_data<std::string>(
"TEST_STRING")));
93 msg_bus->send_msg(
new message(LOG_INFO, make_data<std::string>(
"TEST_STRING2")));
94 msg_bus->send_msg(
new message(LOG_SUCCESS, make_data<std::string>(
"TEST_STRING3")));
96 ASSERT_EQ(
"TEST_STRING3\n", testing::internal::GetCapturedStdout());
97 ASSERT_EQ(
"", testing::internal::GetCapturedStderr());
101 ::testing::internal::CaptureStdout();
102 ::testing::internal::CaptureStderr();
103 test_cnsl->set_log_level(ST::log_type::ERROR | ST::log_type::INFO);
104 msg_bus->send_msg(
new message(LOG_ERROR, make_data<std::string>(
"TEST_STRING")));
105 msg_bus->send_msg(
new message(LOG_INFO, make_data<std::string>(
"TEST_STRING2")));
106 msg_bus->send_msg(
new message(LOG_SUCCESS, make_data<std::string>(
"TEST_STRING3")));
108 ASSERT_EQ(
"TEST_STRING2\n", testing::internal::GetCapturedStdout());
109 ASSERT_EQ(
"TEST_STRING\n", testing::internal::GetCapturedStderr());
113 ::testing::internal::CaptureStdout();
114 ::testing::internal::CaptureStderr();
115 test_cnsl->set_log_level(ST::log_type::ERROR | ST::log_type::SUCCESS);
116 msg_bus->send_msg(
new message(LOG_ERROR, make_data<std::string>(
"TEST_STRING")));
117 msg_bus->send_msg(
new message(LOG_INFO, make_data<std::string>(
"TEST_STRING2")));
118 msg_bus->send_msg(
new message(LOG_SUCCESS, make_data<std::string>(
"TEST_STRING3")));
120 ASSERT_EQ(
"TEST_STRING3\n", testing::internal::GetCapturedStdout());
121 ASSERT_EQ(
"TEST_STRING\n", testing::internal::GetCapturedStderr());
125 ::testing::internal::CaptureStdout();
126 ::testing::internal::CaptureStderr();
127 test_cnsl->set_log_level(ST::log_type::INFO | ST::log_type::SUCCESS);
128 msg_bus->send_msg(
new message(LOG_ERROR, make_data<std::string>(
"TEST_STRING")));
129 msg_bus->send_msg(
new message(LOG_INFO, make_data<std::string>(
"TEST_STRING2")));
130 msg_bus->send_msg(
new message(LOG_SUCCESS, make_data<std::string>(
"TEST_STRING3")));
132 ASSERT_EQ(
"TEST_STRING2\nTEST_STRING3\n", testing::internal::GetCapturedStdout());
133 ASSERT_EQ(
"", testing::internal::GetCapturedStderr());
137 ::testing::internal::CaptureStdout();
138 ::testing::internal::CaptureStderr();
140 test_cnsl->set_log_level(ST::log_type::SUCCESS | ST::log_type::INFO | ST::log_type::ERROR);
142 write(ST::log_type::INFO,
"TEST_STRING");
143 write(ST::log_type::ERROR,
"TEST_STRING2");
144 write(ST::log_type::SUCCESS,
"TEST_STRING3");
146 ASSERT_EQ(
"TEST_STRING\nTEST_STRING3\n", testing::internal::GetCapturedStdout());
147 ASSERT_EQ(
"TEST_STRING2\n", testing::internal::GetCapturedStderr());
151 int main(
int argc,
char **argv) {
152 ::testing::InitGoogleTest(&argc, argv);
153 return RUN_ALL_TESTS();
Tests fixture for the console.
This object represents the console window.
The central messaging system of the engine. All subsystem make extensive use of it.
A message object passed around in the message bus. Holds anything created with make_data<>().