Browse Source

Add "ls_std_event" header

This header file replaces the generic header file to remove unnecessary dependencies from "event" module tests.
Patrick-Christopher Mattulat 2 năm trước cách đây
mục cha
commit
f6d76c7297

+ 29 - 5
CMakeLists.txt

@@ -138,11 +138,14 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventManagerTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/NarratorTest.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/NewsAgency.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/Colour.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/DailyNewsAgency.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/GossipNewsAgency.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/GossipNewsEvent.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/SeriousNewsEvent.cpp)
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/NewsAgency.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/SeriousNewsEvent.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/TestDataCar.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/TestDataMercedesCar.cpp)
 
     set(TEST_FILES_IO
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvDocumentTest.cpp
@@ -172,9 +175,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateConnectionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateMachineTest.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateTest.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/observer/TestDataCar.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/observer/TestDataMercedesCar.cpp)
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateTest.cpp)
 
     set(TEST_FILES_SERIALIZATION
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/JsonTest.cpp)
@@ -206,6 +207,15 @@ if (${LS_STD_BUILD_WITH_TESTS})
     add_executable(${MODULE_NAME_CORE}_test ${TEST_FILES_CORE})
 endif ()
 
+##########################################################
+# Build Tests (event)
+##########################################################
+
+if (${LS_STD_BUILD_WITH_TESTS})
+    message("${MODULE_NAME_EVENT}: Building tests...")
+    add_executable(${MODULE_NAME_EVENT}_test ${TEST_FILES_EVENT})
+endif ()
+
 ##########################################################
 # Build Tests
 ##########################################################
@@ -326,6 +336,20 @@ if (${LS_STD_BUILD_WITH_TESTS})
             "${MODULE_NAME_CORE}")
 endif ()
 
+##########################################################
+# Linking (event)
+##########################################################
+
+if (${LS_STD_BUILD_WITH_TESTS})
+    message("${MODULE_NAME_EVENT}: Linking libraries for test application...")
+    target_link_libraries(${MODULE_NAME_EVENT}_test
+            gtest
+            gmock
+            gtest_main
+            "${MODULE_NAME_EVENT}"
+            "${MODULE_NAME_CORE}")
+endif ()
+
 ##########################################################
 # Linking
 ##########################################################

+ 19 - 0
include/ls_std/ls_std_event.hpp

@@ -0,0 +1,19 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-05-14
+ * Changed:         2022-05-14
+ *
+ * */
+
+#ifndef LS_STD_LS_STD_EVENT_HPP
+#define LS_STD_LS_STD_EVENT_HPP
+
+#include <ls_std/event/serialization/SerializableJsonEvent.hpp>
+#include <ls_std/event/Event.hpp>
+#include <ls_std/event/EventHandler.hpp>
+#include <ls_std/event/EventManager.hpp>
+#include <ls_std/event/Narrator.hpp>
+
+#endif

+ 3 - 2
test/cases/event/EventHandlerTest.cpp

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-09
+ * Changed:         2022-05-14
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
+#include <ls_std/ls_std_core.hpp>
+#include <ls_std/ls_std_event.hpp>
 
 namespace
 {

+ 3 - 3
test/cases/event/EventManagerTest.cpp

@@ -3,13 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-12
+ * Changed:         2022-05-14
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
-#include <ls_std_test.hpp>
+#include <ls_std/ls_std_event.hpp>
+#include <ls_std_event_test.hpp>
 
 namespace
 {

+ 3 - 2
test/cases/event/EventTest.cpp

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2022-05-12
+ * Changed:         2022-05-14
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
+#include <ls_std/ls_std_core.hpp>
+#include <ls_std/ls_std_event.hpp>
 
 namespace
 {

+ 5 - 4
test/cases/event/NarratorTest.cpp

@@ -3,13 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2022-05-12
+ * Changed:         2022-05-14
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
-#include <classes/observer/TestDataMercedesCar.hpp>
+#include <ls_std/ls_std_core.hpp>
+#include <ls_std/ls_std_event.hpp>
+#include <ls_std_event_test.hpp>
 
 namespace
 {
@@ -142,7 +143,7 @@ namespace
     ASSERT_STREQ("blue", this->mercedes2->getColor().c_str());
     ASSERT_STREQ("red", this->mercedes3->getColor().c_str());
 
-    ls::std::boxing::String newColor{"black"};
+    ls_std_event_test::Colour newColor{"black"};
     paintingMachine.tell(static_cast<const ls::std::core::Class &>(newColor));
 
     ASSERT_STREQ("black", this->mercedes1->getColor().c_str());

+ 3 - 2
test/cases/event/serialization/SerializableJsonEventTest.cpp

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-20
- * Changed:         2022-05-12
+ * Changed:         2022-05-14
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls_std/ls_std.hpp>
+#include <ls_std/ls_std_core.hpp>
+#include <ls_std/ls_std_event.hpp>
 
 namespace
 {

+ 2 - 2
test/classes/base/ClassWrapper.hpp

@@ -12,8 +12,8 @@
 
 #include <ls_std/ls_std.hpp>
 #include <gmock/gmock.h>
-
-namespace ls_std_test
+// TODO: check if this class is being used with correct include
+namespace ls_std_test // TODO: change namespace to core specific namespace
 {
   class ClassWrapper : public ls::std::core::Class
   {

+ 20 - 0
test/classes/event/Colour.cpp

@@ -0,0 +1,20 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-05-14
+ * Changed:         2022-05-14
+ *
+ * */
+
+#include "Colour.hpp"
+
+ls_std_event_test::Colour::Colour(const ::std::string &_value) : ls::std::core::Class("Colour")
+{
+  this->value = _value;
+}
+
+::std::string ls_std_event_test::Colour::getValue() const
+{
+  return this->value;
+}

+ 32 - 0
test/classes/event/Colour.hpp

@@ -0,0 +1,32 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-05-14
+ * Changed:         2022-05-14
+ *
+ * */
+
+#ifndef LS_STD_COLOUR_HPP
+#define LS_STD_COLOUR_HPP
+
+#include <ls_std/ls_std_core.hpp>
+
+namespace ls_std_event_test
+{
+  class Colour : public ls::std::core::Class
+  {
+    public:
+
+      explicit Colour(const ::std::string &_value);
+      ~Colour() override = default;
+
+      ::std::string getValue() const;
+
+    private:
+
+      ::std::string value{};
+  };
+}
+
+#endif

+ 2 - 1
test/classes/event/DailyNewsAgency.cpp

@@ -3,11 +3,12 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-09
+ * Changed:         2022-05-14
  *
  * */
 
 #include "DailyNewsAgency.hpp"
+#include <ls_std/ls_std_event.hpp>
 
 ls_std_test::DailyNewsAgency::DailyNewsAgency() : ls_std_test::NewsAgency("DailyNewsAgency")
 {}

+ 3 - 3
test/classes/event/DailyNewsAgency.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-11
+ * Changed:         2022-05-14
  *
  * */
 
@@ -13,10 +13,10 @@
 #include <string>
 #include <memory>
 #include <map>
-#include <ls_std/ls_std.hpp>
+#include <ls_std/ls_std_core.hpp>
 #include "NewsAgency.hpp"
 
-namespace ls_std_test
+namespace ls_std_test // TODO: change namespace to event specific namespace
 {
   class DailyNewsAgency : public ls_std_test::NewsAgency, public ls::std::core::IListener
   {

+ 2 - 1
test/classes/event/GossipNewsAgency.cpp

@@ -3,11 +3,12 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-09
+ * Changed:         2022-05-14
  *
  * */
 
 #include "GossipNewsAgency.hpp"
+#include <ls_std/ls_std_event.hpp>
 
 ls_std_test::GossipNewsAgency::GossipNewsAgency() : ls_std_test::NewsAgency("GossipNewsAgency")
 {}

+ 2 - 2
test/classes/event/GossipNewsAgency.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-11
+ * Changed:         2022-05-14
  *
  * */
 
@@ -13,7 +13,7 @@
 #include <string>
 #include <memory>
 #include <map>
-#include <ls_std/ls_std.hpp>
+#include <ls_std/ls_std_core.hpp>
 #include "NewsAgency.hpp"
 
 namespace ls_std_test

+ 2 - 2
test/classes/event/GossipNewsEvent.hpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-08
+ * Changed:         2022-05-14
  *
  * */
 
 #ifndef LS_STD_GOSSIP_NEWS_EVENT_HPP
 #define LS_STD_GOSSIP_NEWS_EVENT_HPP
 
-#include <ls_std/ls_std.hpp>
+#include <ls_std/ls_std_event.hpp>
 #include <string>
 
 namespace ls_std_test

+ 2 - 2
test/classes/event/NewsAgency.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2021-04-23
+ * Changed:         2022-05-14
  *
  * */
 
@@ -18,7 +18,7 @@ namespace ls_std_test
   {
     public:
 
-      explicit NewsAgency(std::string _agencyName);
+      explicit NewsAgency(std::string _agencyName); // TODO: use ::std:: instead of std:: library wide
       ~NewsAgency() = default;
 
       std::string getName();

+ 2 - 2
test/classes/event/SeriousNewsEvent.hpp

@@ -3,14 +3,14 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2022-05-08
+ * Changed:         2022-05-14
  *
  * */
 
 #ifndef LS_STD_SERIOUS_NEWS_EVENT_HPP
 #define LS_STD_SERIOUS_NEWS_EVENT_HPP
 
-#include <ls_std/ls_std.hpp>
+#include <ls_std/ls_std_event.hpp>
 #include <string>
 
 namespace ls_std_test

+ 1 - 1
test/classes/observer/TestDataCar.cpp → test/classes/event/TestDataCar.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2021-04-23
+ * Changed:         2022-05-14
  *
  * */
 

+ 1 - 1
test/classes/observer/TestDataCar.hpp → test/classes/event/TestDataCar.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2021-04-23
+ * Changed:         2022-05-14
  *
  * */
 

+ 3 - 3
test/classes/observer/TestDataMercedesCar.cpp → test/classes/event/TestDataMercedesCar.cpp

@@ -3,11 +3,11 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2022-05-09
+ * Changed:         2022-05-14
  *
  * */
 
-#include <ls_std/boxing/String.hpp>
+#include "Colour.hpp"
 #include "TestDataMercedesCar.hpp"
 
 ls_std_test::TestDataMercedesCar::TestDataMercedesCar() : TestDataCar()
@@ -17,5 +17,5 @@ ls_std_test::TestDataMercedesCar::TestDataMercedesCar() : TestDataCar()
 
 void ls_std_test::TestDataMercedesCar::listen(const ls::std::core::Class &_info)
 {
-  this->setColor(dynamic_cast<const ls::std::boxing::String &>(_info));
+  this->setColor(dynamic_cast<const ls_std_event_test::Colour &>(_info).getValue());
 }

+ 2 - 2
test/classes/observer/TestDataMercedesCar.hpp → test/classes/event/TestDataMercedesCar.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2022-05-11
+ * Changed:         2022-05-14
  *
  * */
 
@@ -12,7 +12,7 @@
 
 #include "TestDataCar.hpp"
 #include "ls_std/core/interface/IListener.hpp"
-#include <ls_std/core/Class.hpp>
+#include "ls_std/core/Class.hpp"
 
 namespace ls_std_test
 {

+ 22 - 0
test/ls_std_event_test.hpp

@@ -0,0 +1,22 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2022-05-14
+ * Changed:         2022-05-14
+ *
+ * */
+
+#ifndef LS_STD_LS_STD_EVENT_TEST_HPP
+#define LS_STD_LS_STD_EVENT_TEST_HPP
+
+#include <classes/event/Colour.hpp>
+#include <classes/event/NewsAgency.hpp>
+#include <classes/event/DailyNewsAgency.hpp>
+#include <classes/event/GossipNewsAgency.hpp>
+#include <classes/event/GossipNewsEvent.hpp>
+#include <classes/event/SeriousNewsEvent.hpp>
+#include <classes/event/TestDataCar.hpp>
+#include <classes/event/TestDataMercedesCar.hpp>
+
+#endif