Browse Source

Reduce polymorphism of Event class

- remove ISerializable extension
- adjust tests for Event class
Patrick-Christopher Mattulat 3 years ago
parent
commit
294491cb3e
3 changed files with 4 additions and 103 deletions
  1. 2 10
      include/ls_std/event/Event.hpp
  2. 1 36
      source/ls_std/event/Event.cpp
  3. 1 57
      test/cases/event/EventTest.cpp

+ 2 - 10
include/ls_std/event/Event.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2021-05-24
+ * Changed:         2021-07-14
  *
  * */
 
@@ -17,18 +17,13 @@
 
 namespace ls_std
 {
-  class Event : public ls_std::Class, public ls_std::ISerializable
+  class Event : public ls_std::Class
   {
     public:
 
       explicit Event(const ls_std::event_id &_id);
       ~Event() override = default;
 
-      // implementation
-
-      ls_std::byte_field marshal() override;
-      void unmarshal(const ls_std::byte_field &_data) override;
-
       // additional functionality
 
       bool addParameter(const ls_std::event_parameter &_eventParameter);
@@ -37,16 +32,13 @@ namespace ls_std
       ls_std::event_parameter_list getParameterList();
       bool removeParameter(const ls_std::event_parameter_id &_id);
       void setId(const ls_std::event_id &_id);
-      void setSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable);
 
     private:
 
       ls_std::event_id id{};
       ls_std::event_parameter_list parameterList{};
-      std::shared_ptr<ls_std::ISerializable> serializable{};
 
       void _assignId(const ls_std::event_id &_id);
-      void _assignSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable);
       bool _hasParameter(const ls_std::event_id &_id);
   };
 }

+ 1 - 36
source/ls_std/event/Event.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2021-05-24
+ * Changed:         2021-07-14
  *
  * */
 
@@ -15,26 +15,6 @@ ls_std::Event::Event(const ls_std::event_id &_id) : ls_std::Class("Event")
   this->_assignId(_id);
 }
 
-ls_std::byte_field ls_std::Event::marshal()
-{
-  ls_std::byte_field data{};
-
-  if (this->serializable != nullptr)
-  {
-    data = this->serializable->marshal();
-  }
-
-  return data;
-}
-
-void ls_std::Event::unmarshal(const ls_std::byte_field &_data)
-{
-  if (this->serializable != nullptr)
-  {
-    this->serializable->unmarshal(_data);
-  }
-}
-
 bool ls_std::Event::addParameter(const ls_std::event_parameter &_eventParameter)
 {
   bool wasAdded{};
@@ -72,11 +52,6 @@ void ls_std::Event::setId(const ls_std::event_id &_id)
   this->_assignId(_id);
 }
 
-void ls_std::Event::setSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable)
-{
-  this->_assignSerializable(_serializable);
-}
-
 void ls_std::Event::_assignId(const ls_std::event_id &_id)
 {
   if (_id.empty())
@@ -87,16 +62,6 @@ void ls_std::Event::_assignId(const ls_std::event_id &_id)
   this->id = _id;
 }
 
-void ls_std::Event::_assignSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable)
-{
-  if (_serializable == nullptr)
-  {
-    throw ls_std::IllegalArgumentException{};
-  }
-
-  this->serializable = _serializable;
-}
-
 bool ls_std::Event::_hasParameter(const ls_std::event_id &_id)
 {
   return this->parameterList.find(_id) != this->parameterList.end();

+ 1 - 57
test/cases/event/EventTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2021-05-24
+ * Changed:         2021-07-14
  *
  * */
 
@@ -24,49 +24,8 @@ namespace
 
       void TearDown() override
       {}
-
-      static ls_std::Event createSerializableTestEvent()
-      {
-        ls_std::Event event{"OPEN_DOOR_EVENT"};
-        event.addParameter(ls_std::event_parameter{"key_available", "true"});
-        event.addParameter(ls_std::event_parameter{"door_id", "16675"});
-
-        std::shared_ptr<ls_std::SerializableJsonEvent> serializable = std::make_shared<ls_std::SerializableJsonEvent>(std::make_shared<ls_std::Event>(event));
-        event.setSerializable(serializable);
-
-        return event;
-      }
   };
 
-  // implementation
-
-  TEST_F(EventTest, marshal)
-  {
-    ls_std::Event event = createSerializableTestEvent();
-
-    ls_std::byte_field data = event.marshal();
-    ASSERT_FALSE(data.empty());
-    std::string expectedString = R"({"id":"OPEN_DOOR_EVENT","parameterList":{"door_id":["door_id","16675"],"key_available":["key_available","true"]}})";
-    ASSERT_STREQ(expectedString.c_str(), data.c_str());
-  }
-
-  TEST_F(EventTest, unmarshal)
-  {
-    std::shared_ptr<ls_std::Event> event = std::make_shared<ls_std::Event>("TMP_EVENT");
-    std::shared_ptr<ls_std::SerializableJsonEvent> serializable = std::make_shared<ls_std::SerializableJsonEvent>(event);
-    event->setSerializable(serializable);
-
-    std::string jsonString = R"({"id":"OPEN_DOOR_EVENT","parameterList":{"door_id":["door_id","16675"],"key_available":["key_available","true"]}})";
-    event->unmarshal(jsonString);
-    ASSERT_STREQ("OPEN_DOOR_EVENT", event->getId().c_str());
-    ls_std::event_parameter_list parameterList = event->getParameterList();
-
-    ASSERT_FALSE(parameterList.empty());
-    ASSERT_EQ(2, parameterList.size());
-    ASSERT_STREQ("16675", parameterList.at("door_id").c_str());
-    ASSERT_STREQ("true", parameterList.at("key_available").c_str());
-  }
-
   // additional functionality
 
   TEST_F(EventTest, getClassName)
@@ -174,19 +133,4 @@ namespace
                    }
                  }, ls_std::IllegalArgumentException);
   }
-
-  TEST_F(EventTest, setSerializable_no_reference)
-  {
-    EXPECT_THROW({
-                   try
-                   {
-                     ls_std::Event event{"TMP_ID"};
-                     event.setSerializable(nullptr);
-                   }
-                   catch (const ls_std::IllegalArgumentException &_exception)
-                   {
-                     throw;
-                   }
-                 }, ls_std::IllegalArgumentException);
-  }
 }