ST_engine  0.3-ALPHA
subscriber_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_push_message_and_get_one_message) {
14  auto test_subject = new subscriber();
15  test_subject->push_message(new message(1, make_data(23)));
16  auto message = test_subject->get_next_message();
17  ASSERT_TRUE(message);
18  ASSERT_FALSE(test_subject->get_next_message());
19  ASSERT_EQ(23, *static_cast<int *>(message->get_data()));
20  delete (message);
21  delete (test_subject);
22 }
23 
24 TEST(message_test, test_push_message_and_get_100_messages) {
25  auto test_subject = new subscriber();
26  for (uint16_t i = 0; i < 100; i++) {
27  test_subject->push_message(new message(1, make_data(i)));
28  }
29  for (uint16_t i = 0; i < 100; i++) {
30  auto message = test_subject->get_next_message();
31  ASSERT_TRUE(message);
32  ASSERT_EQ(i, *static_cast<uint16_t *>(message->get_data()));
33  delete (message);
34  }
35  ASSERT_FALSE(test_subject->get_next_message());
36  delete (test_subject);
37 }
38 
39 int main(int argc, char **argv) {
40  ::testing::InitGoogleTest(&argc, argv);
41  return RUN_ALL_TESTS();
42 }
A message object passed around in the message bus. Holds anything created with make_data<>().
Definition: message.hpp:21
void * get_data() const
Definition: message.hpp:80
This class handles a small queue for messages.
Definition: subscriber.hpp:20