Explorar el Código

Merge remote-tracking branch 'origin/dev' into dev

Patrick-Christopher Mattulat hace 3 años
padre
commit
d4ce0fb42d

+ 5 - 3
include/ls_std/boxing/Boolean.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2021-05-01
+ * Changed:         2021-05-30
  *
  * */
 
@@ -70,8 +70,8 @@ namespace ls_std
       // additional functionality
 
       bool getValue() const;
-      void setSerializable(std::shared_ptr<ls_std::ISerializable> _serializable);
-      void setStorable(std::shared_ptr<ls_std::IStorable> _storable);
+      void setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
+      void setStorable(const std::shared_ptr<ls_std::IStorable>& _storable);
       static bool XOR(const ls_std::Boolean &_leftExpression, const ls_std::Boolean &_rightExpression);
       static bool XOR(const ls_std::Boolean &_leftExpression, bool _rightExpression);
       static bool XOR(bool _leftExpression, const ls_std::Boolean &_rightExpression);
@@ -86,6 +86,8 @@ namespace ls_std
       const std::string FALSE_STRING = "false";
       const std::string TRUE_STRING = "true";
 
+      void _assignSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
+      void _assignStorable(const std::shared_ptr<ls_std::IStorable>& _storable);
       std::string _toString() const;
   };
 }

+ 6 - 4
include/ls_std/logic/State.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2021-04-30
+ * Changed:         2021-05-28
  *
  * */
 
@@ -23,7 +23,7 @@ namespace ls_std
   {
     public:
 
-      explicit State(ls_std::StateId _id);
+      explicit State(const ls_std::StateId& _id);
       ~State() override = default;
 
       // implementation
@@ -39,8 +39,8 @@ namespace ls_std
       std::unordered_map<ls_std::StateConnectionId, std::shared_ptr<ls_std::StateConnection>> getConnectedStates();
       ls_std::StateId getId();
       bool hasConnection(const ls_std::StateConnectionId &_connectionId);
-      void setId(ls_std::StateId _id);
-      void setSerializable(std::shared_ptr<ls_std::ISerializable> _serializable);
+      void setId(const ls_std::StateId& _id);
+      void setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
 
     private:
 
@@ -48,6 +48,8 @@ namespace ls_std
       ls_std::StateId id{};
       std::shared_ptr<ISerializable> serializable{};
 
+      void _assignSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
+      void _assignStateId(const ls_std::StateId& _id);
       void _clearConnections();
       bool _hasConnection(const ls_std::StateConnectionId &_connectionId);
   };

+ 5 - 3
include/ls_std/logic/StateMachine.hpp

@@ -24,7 +24,7 @@ namespace ls_std
   {
     public:
 
-      explicit StateMachine(std::string _name);
+      explicit StateMachine(const std::string& _name);
       ~StateMachine() override = default;
 
       bool addState(const std::shared_ptr<ls_std::State> &_state);
@@ -34,8 +34,8 @@ namespace ls_std
       std::unordered_map<StateId, std::shared_ptr<ls_std::State>> getStates();
       bool hasState(const ls_std::StateId &_id);
       bool proceed();
-      void setMemory(std::vector<ls_std::StateId> _memory);
-      void setName(std::string _name);
+      void setMemory(const std::vector<ls_std::StateId>& _memory);
+      void setName(const std::string& _name);
       bool setStartState(const ls_std::StateId &_id);
 
     private:
@@ -45,6 +45,8 @@ namespace ls_std
       std::string name{};
       std::unordered_map<ls_std::StateId, std::shared_ptr<ls_std::State>> states{};
 
+      void _assignMemory(const std::vector<ls_std::StateId>& _memory);
+      void _assignName(const std::string& _name);
       std::vector<ls_std::StateId> _getNextValidStates();
       void _remember(const ls_std::StateId &_id);
       bool _hasState(const ls_std::StateId &_id);

+ 25 - 5
source/ls_std/boxing/Boolean.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2021-05-01
+ * Changed:         2021-05-30
  *
  * */
 
@@ -146,14 +146,14 @@ bool ls_std::Boolean::getValue() const
   return this->value;
 }
 
-void ls_std::Boolean::setSerializable(std::shared_ptr<ls_std::ISerializable> _serializable)
+void ls_std::Boolean::setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable)
 {
-  this->serializable = std::move(_serializable);
+  this->_assignSerializable(_serializable);
 }
 
-void ls_std::Boolean::setStorable(std::shared_ptr<ls_std::IStorable> _storable)
+void ls_std::Boolean::setStorable(const std::shared_ptr<ls_std::IStorable>& _storable)
 {
-  this->storable = std::move(_storable);
+  this->_assignStorable(_storable);
 }
 
 bool ls_std::Boolean::XOR(const ls_std::Boolean &_leftExpression, const ls_std::Boolean &_rightExpression)
@@ -176,6 +176,26 @@ bool ls_std::Boolean::XOR(bool _leftExpression, bool _rightExpression)
   return (_leftExpression && !_rightExpression) || (!_leftExpression && _rightExpression);
 }
 
+void ls_std::Boolean::_assignSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable)
+{
+  if (_serializable == nullptr)
+  {
+    throw ls_std::IllegalArgumentException{};
+  }
+
+  this->serializable = _serializable;
+}
+
+void ls_std::Boolean::_assignStorable(const std::shared_ptr<ls_std::IStorable> &_storable)
+{
+  if (_storable == nullptr)
+  {
+    throw ls_std::IllegalArgumentException{};
+  }
+
+  this->storable = _storable;
+}
+
 std::string ls_std::Boolean::_toString() const
 {
   std::string booleanString{};

+ 39 - 15
source/ls_std/logic/State.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2021-04-30
+ * Changed:         2021-05-28
  *
  * */
 
@@ -11,10 +11,10 @@
 #include <ls_std/exception/NullPointerException.hpp>
 #include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::State::State(ls_std::StateId _id)
-    : ls_std::Class("State"),
-      id(std::move(_id))
-{}
+ls_std::State::State(const ls_std::StateId& _id) : ls_std::Class("State")
+{
+  this->_assignStateId(_id);
+}
 
 ls_std::byte_field ls_std::State::marshal()
 {
@@ -49,11 +49,17 @@ bool ls_std::State::addStateConnection(const ls_std::StateConnectionId &_connect
   bool added{};
   std::shared_ptr<ls_std::StateConnection> connection{};
 
-  if (_connectedState != nullptr && !this->_hasConnection(_connectionId))
+  if (_connectionId.empty() || _connectedState == nullptr)
+  {
+    throw ls_std::IllegalArgumentException{};
+  }
+  else
   {
-    connection = std::make_shared<ls_std::StateConnection>(_connectionId, _connectedState->getId());
-    this->connectedStates.insert({_connectionId, connection});
-    added = true;
+    if (!this->_hasConnection(_connectionId))
+    {
+      connection = std::make_shared<ls_std::StateConnection>(_connectionId, _connectedState->getId());
+      added = this->connectedStates.insert({_connectionId, connection}).second;
+    }
   }
 
   return added;
@@ -65,8 +71,11 @@ bool ls_std::State::addStateConnection(const std::shared_ptr<ls_std::StateConnec
 
   if (_connection != nullptr)
   {
-    this->connectedStates.insert({_connection->getConnectionId(), _connection});
-    added = this->_hasConnection(_connection->getConnectionId());
+    added = this->connectedStates.insert({_connection->getConnectionId(), _connection}).second;
+  }
+  else
+  {
+    throw ls_std::IllegalArgumentException{};
   }
 
   return added;
@@ -92,19 +101,34 @@ bool ls_std::State::hasConnection(const ls_std::StateConnectionId &_connectionId
   return this->_hasConnection(_connectionId);
 }
 
-void ls_std::State::setId(ls_std::StateId _id)
+void ls_std::State::setId(const ls_std::StateId& _id)
 {
-  this->id = std::move(_id);
+  this->_assignStateId(_id);
 }
 
-void ls_std::State::setSerializable(std::shared_ptr<ls_std::ISerializable> _serializable)
+void ls_std::State::setSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable)
+{
+  this->_assignSerializable(_serializable);
+}
+
+void ls_std::State::_assignSerializable(const std::shared_ptr<ls_std::ISerializable> &_serializable)
 {
   if (_serializable == nullptr)
   {
     throw ls_std::IllegalArgumentException{};
   }
 
-  this->serializable = std::move(_serializable);
+  this->serializable = _serializable;
+}
+
+void ls_std::State::_assignStateId(const ls_std::StateId &_id)
+{
+  if (_id.empty())
+  {
+    throw ls_std::IllegalArgumentException{};
+  }
+
+  this->id = _id;
 }
 
 void ls_std::State::_clearConnections()

+ 56 - 21
source/ls_std/logic/StateMachine.cpp

@@ -8,23 +8,30 @@
  * */
 
 #include <ls_std/logic/StateMachine.hpp>
+#include <ls_std/exception/IllegalArgumentException.hpp>
 
-ls_std::StateMachine::StateMachine(std::string _name)
-    : ls_std::Class("StateMachine"),
-      name(std::move(_name))
-{}
+ls_std::StateMachine::StateMachine(const std::string& _name) : ls_std::Class("StateMachine")
+{
+  this->_assignName(_name);
+}
 
 bool ls_std::StateMachine::addState(const std::shared_ptr<ls_std::State> &_state)
 {
-  bool condition = !this->_hasState(_state->getId());
+  bool wasAdded{};
 
-  if (condition)
+  if (_state == nullptr)
+  {
+    throw ls_std::IllegalArgumentException{};
+  }
+  else
   {
-    this->states.insert({_state->getId(), _state});
-    condition = this->_hasState(_state->getId());
+    if (!this->_hasState(_state->getId()))
+    {
+      wasAdded = this->states.insert({_state->getId(), _state}).second;
+    }
   }
 
-  return condition;
+  return wasAdded;
 }
 
 std::shared_ptr<ls_std::State> ls_std::StateMachine::getCurrentState()
@@ -55,38 +62,66 @@ bool ls_std::StateMachine::hasState(const ls_std::StateId &_id)
 bool ls_std::StateMachine::proceed()
 {
   std::vector<ls_std::StateId> nextValidStates = this->_getNextValidStates();
-  bool condition = nextValidStates.size() == 1;
+  bool onlyOneWayToGo = nextValidStates.size() == 1;
 
-  if (condition)
+  if (onlyOneWayToGo)
   {
     this->currentState = this->states[nextValidStates.at(0)];
     this->_remember(nextValidStates.at(0));
   }
 
-  return condition;
+  return onlyOneWayToGo;
 }
 
-void ls_std::StateMachine::setMemory(std::vector<ls_std::StateId> _memory)
+void ls_std::StateMachine::setMemory(const std::vector<ls_std::StateId>& _memory)
 {
-  this->memory = std::move(_memory);
+  this->_assignMemory(_memory);
 }
 
-void ls_std::StateMachine::setName(std::string _name)
+void ls_std::StateMachine::setName(const std::string& _name)
 {
-  this->name = std::move(_name);
+  this->_assignName(_name);
 }
 
 bool ls_std::StateMachine::setStartState(const ls_std::StateId &_id)
 {
-  bool exists = this->_hasState(_id);
+  bool startStateSet{};
+
+  if (_id.empty())
+  {
+    throw ls_std::IllegalArgumentException{};
+  }
+  else
+  {
+    if (this->_hasState(_id))
+    {
+      this->currentState = this->states[_id];
+      this->_remember(_id);
+      startStateSet = true;
+    }
+  }
+
+  return startStateSet;
+}
+
+void ls_std::StateMachine::_assignMemory(const std::vector<ls_std::StateId> &_memory)
+{
+  if (_memory.empty())
+  {
+    throw ls_std::IllegalArgumentException{};
+  }
 
-  if (exists)
+  this->memory = _memory;
+}
+
+void ls_std::StateMachine::_assignName(const std::string &_name)
+{
+  if (_name.empty())
   {
-    this->currentState = this->states[_id];
-    this->_remember(_id);
+    throw ls_std::IllegalArgumentException{};
   }
 
-  return exists;
+  this->name = _name;
 }
 
 std::vector<ls_std::StateId> ls_std::StateMachine::_getNextValidStates()

+ 2 - 2
source/ls_std/serialization/json/logic/SerializableJsonStateMachine.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-17
- * Changed:         2021-05-02
+ * Changed:         2021-05-28
  *
  * */
 
@@ -64,7 +64,7 @@ void ls_std::SerializableJsonStateMachine::_unmarshalStates()
 {
   for (const auto &serializedState : this->jsonObject["states"])
   {
-    std::shared_ptr<ls_std::State> state = std::make_shared<ls_std::State>("");
+    std::shared_ptr<ls_std::State> state = std::make_shared<ls_std::State>("TMP_ID");
     ls_std::SerializableJsonState{state}.unmarshal(serializedState.dump());
     this->value->addState(state);
   }

+ 97 - 46
test/cases/boxing/BooleanTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2021-05-02
+ * Changed:         2021-05-30
  *
  * */
 
@@ -25,24 +25,47 @@ namespace
 
       void TearDown() override
       {}
+
+      static std::pair<std::shared_ptr<ls_std::File>, std::shared_ptr<ls_std::Boolean>> createTestExpression()
+      {
+        std::shared_ptr<ls_std::Boolean> expression = std::make_shared<ls_std::Boolean>();
+        std::string path = TestHelper::getResourcesFolderLocation() + "tmp_storable_bool.json";
+        std::shared_ptr<ls_std::File> file = std::make_shared<ls_std::File>(path);
+        file->createNewFile();
+        ls_std::FileWriter writer{*file};
+        writer.write(R"({"value":true})");
+
+        auto serializable = std::make_shared<ls_std::SerializableJsonBoolean>(expression);
+        expression->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
+
+        auto storable = std::make_shared<ls_std::StorableFile>(path);
+        expression->setStorable(std::dynamic_pointer_cast<ls_std::IStorable>(storable));
+
+        return std::pair<std::shared_ptr<ls_std::File>, std::shared_ptr<ls_std::Boolean>>(file, expression);
+      }
   };
 
   // assignment operators
 
-  TEST_F(BooleanTest, operatorAssignment)
+  TEST_F(BooleanTest, operator_assignment_boolean)
   {
     ls_std::Boolean expression{};
-
     expression = true;
+
     ASSERT_TRUE(expression);
+  }
 
+  TEST_F(BooleanTest, operator_assignment_integer)
+  {
+    ls_std::Boolean expression{};
     expression = 1;
+
     ASSERT_TRUE(expression);
   }
 
   // stream operators
 
-  TEST_F(BooleanTest, operatorOutputStream)
+  TEST_F(BooleanTest, operator_output_stream)
   {
     ls_std::Boolean expression{true};
     std::ostringstream _stream{};
@@ -53,19 +76,19 @@ namespace
 
   // logical operators
 
-  TEST_F(BooleanTest, operatorNot)
+  TEST_F(BooleanTest, operator_negation_negative_value)
   {
     ls_std::Boolean expression{};
     ASSERT_TRUE(!expression);
   }
 
-  TEST_F(BooleanTest, operatorNotNegative)
+  TEST_F(BooleanTest, operator_negation_positive_value)
   {
     ls_std::Boolean expression{true};
     ASSERT_FALSE(!expression);
   }
 
-  TEST_F(BooleanTest, operatorAnd)
+  TEST_F(BooleanTest, operator_and)
   {
     ls_std::Boolean expressionA{true};
     ls_std::Boolean expressionB{3 == 3};
@@ -77,7 +100,7 @@ namespace
     ASSERT_TRUE(1 && expressionB);
   }
 
-  TEST_F(BooleanTest, operatorAndNegative)
+  TEST_F(BooleanTest, operator_and_with_false_result)
   {
     ls_std::Boolean expressionA{true};
     ls_std::Boolean expressionB{3 == 4};
@@ -89,7 +112,7 @@ namespace
     ASSERT_FALSE(expressionB && false);
   }
 
-  TEST_F(BooleanTest, operatorOr)
+  TEST_F(BooleanTest, operator_or)
   {
     ls_std::Boolean expressionA{false};
     ls_std::Boolean expressionB{3 == 3};
@@ -101,7 +124,7 @@ namespace
     ASSERT_TRUE(1 || expressionA);
   }
 
-  TEST_F(BooleanTest, operatorOrNegative)
+  TEST_F(BooleanTest, operator_or_with_false_result)
   {
     ls_std::Boolean expressionA{false};
     ls_std::Boolean expressionB{3 == 4};
@@ -119,41 +142,37 @@ namespace
   {
     // preparation
 
-    std::shared_ptr<ls_std::Boolean> x = std::make_shared<ls_std::Boolean>();
-    std::string path = TestHelper::getResourcesFolderLocation() + "tmp_storable_bool.json";
-    ls_std::File file{path};
-    file.createNewFile();
-    ls_std::FileWriter writer{file};
-    writer.write(R"({"value":true})");
-
-    auto serializable = std::make_shared<ls_std::SerializableJsonBoolean>(x);
-    x->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-
-    auto storable = std::make_shared<ls_std::StorableFile>(path);
-    x->setStorable(std::dynamic_pointer_cast<ls_std::IStorable>(storable));
+    auto storableExpression = createTestExpression();
 
     // check
 
-    x->load();
-    ASSERT_TRUE(*x);
+    storableExpression.second->load();
+    ASSERT_TRUE(*storableExpression.second);
 
-    file.remove();
+    storableExpression.first->remove();
   }
 
-  TEST_F(BooleanTest, marshal)
+  TEST_F(BooleanTest, marshal_positive_value)
   {
-    std::shared_ptr<ls_std::Boolean> x = std::make_shared<ls_std::Boolean>(true);
+    std::shared_ptr<ls_std::Boolean> expression = std::make_shared<ls_std::Boolean>(true);
+
+    auto serializable = std::make_shared<ls_std::SerializableJsonBoolean>(expression);
+    expression->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
+
+    ASSERT_STREQ(R"({"value":true})", expression->marshal().c_str());
+  }
 
-    auto serializable = std::make_shared<ls_std::SerializableJsonBoolean>(x);
-    x->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
+  TEST_F(BooleanTest, marshal_negative_value)
+  {
+    std::shared_ptr<ls_std::Boolean> expression = std::make_shared<ls_std::Boolean>(false);
 
-    ASSERT_STREQ(R"({"value":true})", x->marshal().c_str());
+    auto serializable = std::make_shared<ls_std::SerializableJsonBoolean>(expression);
+    expression->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
 
-    *x = false;
-    ASSERT_STREQ(R"({"value":false})", x->marshal().c_str());
+    ASSERT_STREQ(R"({"value":false})", expression->marshal().c_str());
   }
 
-  TEST_F(BooleanTest, parse)
+  TEST_F(BooleanTest, parse_true_value)
   {
     ls_std::Boolean expression{};
 
@@ -167,7 +186,7 @@ namespace
     ASSERT_TRUE(expression);
   }
 
-  TEST_F(BooleanTest, parseNegative)
+  TEST_F(BooleanTest, parse_false_value)
   {
     ls_std::Boolean expression{};
 
@@ -181,26 +200,26 @@ namespace
     ASSERT_FALSE(expression);
   }
 
-  TEST_F(BooleanTest, toString)
+  TEST_F(BooleanTest, toString_true)
   {
     ls_std::Boolean expression{2 < 3};
     ASSERT_STREQ("true", expression.toString().c_str());
+  }
 
-    expression = 4 < 3;
+  TEST_F(BooleanTest, toString_false)
+  {
+    ls_std::Boolean expression{4 < 3};
     ASSERT_STREQ("false", expression.toString().c_str());
   }
 
   TEST_F(BooleanTest, unmarshal)
   {
-    std::shared_ptr<ls_std::Boolean> x = std::make_shared<ls_std::Boolean>(false);
-
-    ASSERT_FALSE(*x);
+    std::shared_ptr<ls_std::Boolean> expression = std::make_shared<ls_std::Boolean>(false);
+    auto serializable = std::make_shared<ls_std::SerializableJsonBoolean>(expression);
+    expression->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
+    expression->unmarshal(R"({"value":true})");
 
-    auto serializable = std::make_shared<ls_std::SerializableJsonBoolean>(x);
-    x->setSerializable(std::dynamic_pointer_cast<ls_std::ISerializable>(serializable));
-    x->unmarshal(R"({"value":true})");
-
-    ASSERT_TRUE(*x);
+    ASSERT_TRUE(*expression);
   }
 
   // additional functionality
@@ -211,7 +230,39 @@ namespace
     ASSERT_TRUE(x.getValue());
   }
 
-  TEST_F(BooleanTest, XOR)
+  TEST_F(BooleanTest, setSerialiable_no_reference)
+  {
+    ls_std::Boolean expression{};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     expression.setSerializable(nullptr);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
+  TEST_F(BooleanTest, setStorable_no_reference)
+  {
+    ls_std::Boolean expression{};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     expression.setStorable(nullptr);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
+  TEST_F(BooleanTest, XOR_with_positive_result)
   {
     ls_std::Boolean x{2 < 3};
     ls_std::Boolean y{4 < 3};
@@ -224,7 +275,7 @@ namespace
     ASSERT_TRUE(ls_std::Boolean::XOR(false, true));
   }
 
-  TEST_F(BooleanTest, XORNegative)
+  TEST_F(BooleanTest, XOR_with_negative_result)
   {
     ls_std::Boolean w{};
     ls_std::Boolean x{true};

+ 97 - 55
test/cases/logic/StateMachineTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-09
- * Changed:         2021-04-23
+ * Changed:         2021-05-28
  *
  * */
 
@@ -27,19 +27,54 @@ namespace
       {}
   };
 
-  TEST_F(StateMachineTest, addStateConnection)
+  TEST_F(StateMachineTest, getClassName)
+  {
+    ls_std::StateMachine stateMachine {"machine"};
+    ASSERT_STREQ("StateMachine", stateMachine.getClassName().c_str());
+  }
+
+  TEST_F(StateMachineTest, constructor_empty_name)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     ls_std::StateMachine stateMachine {""};
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
+  TEST_F(StateMachineTest, addState)
   {
     ls_std::StateMachine stateMachine{"test_machine"};
     ASSERT_TRUE(stateMachine.addState(std::make_shared<ls_std::State>("A")));
   }
 
-  TEST_F(StateMachineTest, addStateConnectionNegative)
+  TEST_F(StateMachineTest, addState_state_already_exists)
   {
     ls_std::StateMachine stateMachine{"test_machine"};
     ASSERT_TRUE(stateMachine.addState(std::make_shared<ls_std::State>("A")));
     ASSERT_FALSE(stateMachine.addState(std::make_shared<ls_std::State>("A")));
   }
 
+  TEST_F(StateMachineTest, addState_no_reference)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     ls_std::StateMachine stateMachine{"test_machine"};
+                     stateMachine.addState(nullptr);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
   TEST_F(StateMachineTest, getCurrentState)
   {
     ls_std::StateMachine stateMachine{"test_machine"};
@@ -50,38 +85,8 @@ namespace
 
   TEST_F(StateMachineTest, getMemory)
   {
-    ls_std::StateMachine stateMachine = ls_std_test::TestDataFactory::createStateMachine();
-    ASSERT_STREQ("test_machine", stateMachine.getName().c_str());
-    ASSERT_EQ(0, stateMachine.getMemory().size());
-
-    stateMachine.setStartState("A");
-    ASSERT_EQ(1, stateMachine.getMemory().size());
-    ASSERT_STREQ("A", stateMachine.getMemory().at(0).c_str());
-
-    ASSERT_FALSE(stateMachine.proceed());
-    ASSERT_EQ(1, stateMachine.getMemory().size());
-    ASSERT_STREQ("A", stateMachine.getMemory().at(0).c_str());
-
-    stateMachine.getCurrentState()->getConnectedStates().at("AB")->updatePassCondition(true);
-    ASSERT_TRUE(stateMachine.proceed());
-    ASSERT_EQ(2, stateMachine.getMemory().size());
-    ASSERT_STREQ("A", stateMachine.getMemory().at(0).c_str());
-    ASSERT_STREQ("B", stateMachine.getMemory().at(1).c_str());
-
-    stateMachine.getCurrentState()->getConnectedStates().at("BC")->updatePassCondition(true);
-    ASSERT_TRUE(stateMachine.proceed());
-    ASSERT_EQ(3, stateMachine.getMemory().size());
-    ASSERT_STREQ("A", stateMachine.getMemory().at(0).c_str());
-    ASSERT_STREQ("B", stateMachine.getMemory().at(1).c_str());
-    ASSERT_STREQ("C", stateMachine.getMemory().at(2).c_str());
-
-    stateMachine.getCurrentState()->getConnectedStates().at("CB")->updatePassCondition(true);
-    ASSERT_TRUE(stateMachine.proceed());
-    ASSERT_EQ(4, stateMachine.getMemory().size());
-    ASSERT_STREQ("A", stateMachine.getMemory().at(0).c_str());
-    ASSERT_STREQ("B", stateMachine.getMemory().at(1).c_str());
-    ASSERT_STREQ("C", stateMachine.getMemory().at(2).c_str());
-    ASSERT_STREQ("B", stateMachine.getMemory().at(3).c_str());
+    ls_std::StateMachine stateMachine {"machine"};
+    ASSERT_TRUE(stateMachine.getMemory().empty());
   }
 
   TEST_F(StateMachineTest, getName)
@@ -92,10 +97,8 @@ namespace
 
   TEST_F(StateMachineTest, getStates)
   {
-    ls_std::StateMachine stateMachine = ls_std_test::TestDataFactory::createStateMachine();
-
-    ASSERT_TRUE(!stateMachine.getStates().empty());
-    ASSERT_EQ(5, stateMachine.getStates().size());
+    ls_std::StateMachine stateMachine {"machine"};
+    ASSERT_TRUE(stateMachine.getStates().empty());
   }
 
   TEST_F(StateMachineTest, hasState)
@@ -109,9 +112,9 @@ namespace
     ASSERT_TRUE(stateMachine.hasState("E"));
   }
 
-  TEST_F(StateMachineTest, hasStateNegative)
+  TEST_F(StateMachineTest, hasState_no_state_available)
   {
-    ls_std::StateMachine stateMachine = ls_std_test::TestDataFactory::createStateMachine();
+    ls_std::StateMachine stateMachine {"machine"};
     ASSERT_FALSE(stateMachine.hasState("F"));
   }
 
@@ -166,19 +169,21 @@ namespace
     ASSERT_STREQ("E", stateMachine.getCurrentState()->getId().c_str());
   }
 
-  TEST_F(StateMachineTest, setMemory)
+  TEST_F(StateMachineTest, setMemory_no_memory)
   {
     ls_std::StateMachine stateMachine{"test_machine"};
-    ASSERT_TRUE(stateMachine.getMemory().empty());
-
-    std::vector<ls_std::StateId> memory{"A", "B", "C"};
-    stateMachine.setMemory(memory);
-
-    ASSERT_FALSE(stateMachine.getMemory().empty());
-    ASSERT_EQ(3, stateMachine.getMemory().size());
-    ASSERT_STREQ("A", stateMachine.getMemory().at(0).c_str());
-    ASSERT_STREQ("B", stateMachine.getMemory().at(1).c_str());
-    ASSERT_STREQ("C", stateMachine.getMemory().at(2).c_str());
+    std::vector<ls_std::StateId> memory{};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     stateMachine.setMemory(memory);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
   }
 
   TEST_F(StateMachineTest, setName)
@@ -190,13 +195,50 @@ namespace
     ASSERT_STREQ("bla", stateMachine.getName().c_str());
   }
 
+  TEST_F(StateMachineTest, setName_empty_name)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     ls_std::StateMachine stateMachine {"machine"};
+                     stateMachine.setName("");
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
   TEST_F(StateMachineTest, setStartState)
   {
     ls_std::StateMachine stateMachine{"test_machine"};
-    ASSERT_FALSE(stateMachine.getCurrentState() != nullptr);
+    ASSERT_TRUE(stateMachine.getCurrentState() == nullptr);
+    stateMachine.addState(std::make_shared<ls_std::State>("A"));
 
-    ASSERT_TRUE(stateMachine.addState(std::make_shared<ls_std::State>("A")));
     ASSERT_TRUE(stateMachine.setStartState("A"));
-    ASSERT_TRUE(stateMachine.getCurrentState() != nullptr);
+    ASSERT_FALSE(stateMachine.getCurrentState() == nullptr);
+  }
+
+  TEST_F(StateMachineTest, setStartState_state_does_not_exist)
+  {
+    ls_std::StateMachine stateMachine{"test_machine"};
+    ASSERT_FALSE(stateMachine.setStartState("A"));
+  }
+
+  TEST_F(StateMachineTest, setStartState_empty_id)
+  {
+    ls_std::StateMachine stateMachine{"test_machine"};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     stateMachine.setStartState("");
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
   }
 }

+ 90 - 28
test/cases/logic/StateTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-05
- * Changed:         2021-05-02
+ * Changed:         2021-05-28
  *
  * */
 
@@ -27,6 +27,26 @@ namespace
       {}
   };
 
+  TEST_F(StateTest, getClassName)
+  {
+    ls_std::State state{"A"};
+    ASSERT_STREQ("State", state.getClassName().c_str());
+  }
+
+  TEST_F(StateTest, constructor_empty_id)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     ls_std::State state = ls_std::State("");
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
   // implementation
 
   TEST_F(StateTest, marshal)
@@ -38,7 +58,7 @@ namespace
     ASSERT_FALSE(state->marshal().empty());
   }
 
-  TEST_F(StateTest, marshal_noSerializableReference)
+  TEST_F(StateTest, marshal_no_serializable_reference)
   {
     ls_std::State state{"A"};
 
@@ -65,7 +85,7 @@ namespace
     ASSERT_STREQ("A", state->getId().c_str());
   }
 
-  TEST_F(StateTest, unmarshal_noSerializableReference)
+  TEST_F(StateTest, unmarshal_no_serializable_reference)
   {
     std::shared_ptr<ls_std::State> state = std::make_shared<ls_std::State>("TMP_ID");
     std::string jsonString = R"({"id":"A","connectedStates":{"AB":{"condition":false,"connectionId":"AB","stateId":"B"}}})";
@@ -84,7 +104,7 @@ namespace
 
   // additional functionality
 
-  TEST_F(StateTest, addStateConnection)
+  TEST_F(StateTest, addStateConnection_v1)
   {
     ls_std::State stateA{"A"};
     ls_std::State stateB{"B"};
@@ -92,17 +112,48 @@ namespace
     ASSERT_TRUE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
   }
 
-  TEST_F(StateTest, addStateConnectionNegative)
+  TEST_F(StateTest, addStateConnection_v1_connection_already_exists)
   {
     ls_std::State stateA{"A"};
     ls_std::State stateB{"B"};
 
     ASSERT_TRUE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
     ASSERT_FALSE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
-    ASSERT_FALSE(stateA.addStateConnection("XX", nullptr));
   }
 
-  TEST_F(StateTest, addStateConnectionV2)
+  TEST_F(StateTest, addStateConnection_v1_empty_connection_id)
+  {
+    ls_std::State state{"A"};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     state.addStateConnection("", std::make_shared<ls_std::State>("B"));
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
+  TEST_F(StateTest, addStateConnection_v1_no_reference)
+  {
+    ls_std::State state{"A"};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     state.addStateConnection("AB", nullptr);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
+  TEST_F(StateTest, addStateConnection_v2)
   {
     ls_std::State stateA{"A"};
     ls_std::State stateB{"B"};
@@ -110,10 +161,20 @@ namespace
     ASSERT_TRUE(stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AB", stateB.getId())));
   }
 
-  TEST_F(StateTest, addStateConnectionV2Negative)
+  TEST_F(StateTest, addStateConnection_v2_no_reference)
   {
     ls_std::State stateA{"A"};
-    ASSERT_FALSE(stateA.addStateConnection(nullptr));
+
+    EXPECT_THROW({
+                   try
+                   {
+                     stateA.addStateConnection(nullptr);
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
   }
 
   TEST_F(StateTest, clearConnections)
@@ -122,28 +183,15 @@ namespace
     stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AB", "B"));
     stateA.addStateConnection(std::make_shared<ls_std::StateConnection>("AC", "C"));
 
-    ASSERT_EQ(2, stateA.getConnectedStates().size());
+    ASSERT_FALSE(stateA.getConnectedStates().empty());
     stateA.clearConnections();
-    ASSERT_EQ(0, stateA.getConnectedStates().size());
     ASSERT_TRUE(stateA.getConnectedStates().empty());
   }
 
   TEST_F(StateTest, getConnectedStates)
   {
     ls_std::State stateA{"A"};
-    ls_std::State stateB{"B"};
-
-    ASSERT_TRUE(stateA.addStateConnection("AB", std::make_shared<ls_std::State>(stateB)));
-    ASSERT_FALSE(stateA.getConnectedStates().empty());
-    ASSERT_EQ(1, stateA.getConnectedStates().size());
-  }
-
-  TEST_F(StateTest, getConnectedStatesNegative)
-  {
-    ls_std::State stateA{"A"};
-
     ASSERT_TRUE(stateA.getConnectedStates().empty());
-    ASSERT_EQ(0, stateA.getConnectedStates().size());
   }
 
   TEST_F(StateTest, getId)
@@ -161,6 +209,22 @@ namespace
     ASSERT_STREQ("B", stateA.getId().c_str());
   }
 
+  TEST_F(StateTest, setId_empty_id)
+  {
+    ls_std::State stateA{"A"};
+
+    EXPECT_THROW({
+                   try
+                   {
+                     stateA.setId("");
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+
   TEST_F(StateTest, hasConnection)
   {
     ls_std::State stateA{"A"};
@@ -173,22 +237,20 @@ namespace
     ASSERT_TRUE(stateA.hasConnection("AC"));
   }
 
-  TEST_F(StateTest, hasConnectionNegative)
+  TEST_F(StateTest, hasConnection_no_connections_available)
   {
     ls_std::State stateA{"A"};
     ASSERT_FALSE(stateA.hasConnection("AB"));
-    ASSERT_FALSE(stateA.hasConnection("AC"));
   }
 
-  TEST_F(StateTest, setSerializable_noSerializableReference)
+  TEST_F(StateTest, setSerializable_no_reference)
   {
     ls_std::State state{"A"};
-    std::shared_ptr<ls_std::ISerializable> serializable{};
 
     EXPECT_THROW({
                    try
                    {
-                     state.setSerializable(serializable);
+                     state.setSerializable(nullptr);
                    }
                    catch (const ls_std::IllegalArgumentException &_exception)
                    {

+ 18 - 18
test/cases/serialization/json/logic/SerializableJsonStateMachineTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-17
- * Changed:         2021-05-02
+ * Changed:         2021-05-28
  *
  * */
 
@@ -51,54 +51,54 @@ namespace
   {
     ls_std::File file{TestHelper::getResourcesFolderLocation() + "/state_machine_test.json"};
     ls_std::FileReader reader{file};
-    std::shared_ptr<ls_std::StateMachine> x = std::make_shared<ls_std::StateMachine>("bla");
-    ls_std::SerializableJsonStateMachine serializable{x};
+    std::shared_ptr<ls_std::StateMachine> machine = std::make_shared<ls_std::StateMachine>("bla");
+    ls_std::SerializableJsonStateMachine serializable{machine};
 
     serializable.unmarshal(reader.read());
 
-    ASSERT_STREQ("test_machine", x->getName().c_str());
+    ASSERT_STREQ("test_machine", machine->getName().c_str());
 
     // check memory
 
-    ASSERT_FALSE(x->getMemory().empty());
-    ASSERT_EQ(3, x->getMemory().size());
-    ASSERT_STREQ("A", x->getMemory().at(0).c_str());
-    ASSERT_STREQ("B", x->getMemory().at(1).c_str());
-    ASSERT_STREQ("C", x->getMemory().at(2).c_str());
+    ASSERT_FALSE(machine->getMemory().empty());
+    ASSERT_EQ(3, machine->getMemory().size());
+    ASSERT_STREQ("A", machine->getMemory().at(0).c_str());
+    ASSERT_STREQ("B", machine->getMemory().at(1).c_str());
+    ASSERT_STREQ("C", machine->getMemory().at(2).c_str());
 
     // check current state
 
-    ASSERT_TRUE(x->getCurrentState() != nullptr);
-    ASSERT_STREQ("A", x->getCurrentState()->getId().c_str());
+    ASSERT_TRUE(machine->getCurrentState() != nullptr);
+    ASSERT_STREQ("A", machine->getCurrentState()->getId().c_str());
 
     // check states
 
-    ASSERT_TRUE(!x->getStates().empty());
-    ASSERT_EQ(5, x->getStates().size());
+    ASSERT_TRUE(!machine->getStates().empty());
+    ASSERT_EQ(5, machine->getStates().size());
 
-    std::shared_ptr<ls_std::State> state = x->getStates().at("A");
+    std::shared_ptr<ls_std::State> state = machine->getStates().at("A");
     ASSERT_STREQ("A", state->getId().c_str());
     ASSERT_EQ(1, state->getConnectedStates().size());
     ASSERT_STREQ("AB", state->getConnectedStates().at("AB")->getConnectionId().c_str());
 
-    state = x->getStates().at("B");
+    state = machine->getStates().at("B");
     ASSERT_STREQ("B", state->getId().c_str());
     ASSERT_EQ(2, state->getConnectedStates().size());
     ASSERT_STREQ("BC", state->getConnectedStates().at("BC")->getConnectionId().c_str());
     ASSERT_STREQ("BD", state->getConnectedStates().at("BD")->getConnectionId().c_str());
 
-    state = x->getStates().at("C");
+    state = machine->getStates().at("C");
     ASSERT_STREQ("C", state->getId().c_str());
     ASSERT_EQ(2, state->getConnectedStates().size());
     ASSERT_STREQ("CB", state->getConnectedStates().at("CB")->getConnectionId().c_str());
     ASSERT_STREQ("CE", state->getConnectedStates().at("CE")->getConnectionId().c_str());
 
-    state = x->getStates().at("D");
+    state = machine->getStates().at("D");
     ASSERT_STREQ("D", state->getId().c_str());
     ASSERT_EQ(1, state->getConnectedStates().size());
     ASSERT_STREQ("DE", state->getConnectedStates().at("DE")->getConnectionId().c_str());
 
-    state = x->getStates().at("E");
+    state = machine->getStates().at("E");
     ASSERT_STREQ("E", state->getId().c_str());
     ASSERT_TRUE(state->getConnectedStates().empty());
   }