Quellcode durchsuchen

Added XMLAttribute class

- added XMLAttribute class to represent an
attribute inside an XML document
- added tests for XMLAttribute class
Patrick-Laptop vor 4 Jahren
Ursprung
Commit
2955627215

+ 4 - 1
CMakeLists.txt

@@ -111,6 +111,8 @@ set(SOURCE_FILES
         ${CMAKE_CURRENT_SOURCE_DIR}/source/serialization/xml/logic/SerializableXMLStateConnection.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/serialization/xml/logic/SerializableXMLState.hpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/serialization/xml/logic/SerializableXMLState.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/io/xml/XMLAttribute.hpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/io/xml/XMLAttribute.cpp
         )
 
 set(LIBRARY_SOURCE_FILES
@@ -153,7 +155,8 @@ set(TEST_FILES
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/xml/RapidXMLTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/xml/TinyXMLTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/xml/logic/SerializableXMLStateConnectionTest.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/xml/logic/SerializableXMLStateTest.cpp)
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/xml/logic/SerializableXMLStateTest.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLAttributeTest.cpp)
 
 ##########################################################
 # Build

+ 38 - 0
source/io/xml/XMLAttribute.cpp

@@ -0,0 +1,38 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-09-23
+ * Changed:         2020-09-23
+ *
+ * */
+
+#include "XMLAttribute.hpp"
+
+ls_std::XMLAttribute::XMLAttribute() : Class("XMLAttribute")
+{}
+
+std::string ls_std::XMLAttribute::getName()
+{
+  return this->name;
+}
+
+std::string ls_std::XMLAttribute::getValue()
+{
+  return this->value;
+}
+
+void ls_std::XMLAttribute::setName(std::string _name)
+{
+  this->name = std::move(_name);
+}
+
+void ls_std::XMLAttribute::setValue(std::string _value)
+{
+  this->value = std::move(_value);
+}
+
+std::string ls_std::XMLAttribute::toXML()
+{
+  return this->name + "=\"" + this->value + "\"";
+}

+ 36 - 0
source/io/xml/XMLAttribute.hpp

@@ -0,0 +1,36 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-09-23
+ * Changed:         2020-09-23
+ *
+ * */
+
+#ifndef LS_STD_XML_ATTRIBUTE_HPP
+#define LS_STD_XML_ATTRIBUTE_HPP
+
+#include "../../base/Class.hpp"
+#include <string>
+
+namespace ls_std {
+  class XMLAttribute : public Class {
+    public:
+
+      XMLAttribute();
+      ~XMLAttribute() = default;
+
+      std::string getName();
+      std::string getValue();
+      void setName(std::string _name);
+      void setValue(std::string _value);
+      std::string toXML();
+
+    private:
+
+      std::string name {};
+      std::string value {};
+  };
+}
+
+#endif

+ 60 - 0
test/cases/io/xml/XMLAttributeTest.cpp

@@ -0,0 +1,60 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-09-23
+ * Changed:         2020-09-23
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include "../../../../source/io/xml/XMLAttribute.hpp"
+
+namespace {
+  class XMLAttributeTest : public ::testing::Test {
+    protected:
+
+      XMLAttributeTest() = default;
+      ~XMLAttributeTest() override = default;
+
+      void SetUp() override {}
+      void TearDown() override {}
+  };
+
+  TEST_F(XMLAttributeTest, getName)
+  {
+    ls_std::XMLAttribute attribute {};
+    ASSERT_TRUE(attribute.getName().empty());
+  }
+
+  TEST_F(XMLAttributeTest, getValue)
+  {
+    ls_std::XMLAttribute attribute {};
+    ASSERT_TRUE(attribute.getValue().empty());
+  }
+
+  TEST_F(XMLAttributeTest, setName)
+  {
+    ls_std::XMLAttribute attribute {};
+    attribute.setName("id");
+
+    ASSERT_STREQ("id", attribute.getName().c_str());
+  }
+
+  TEST_F(XMLAttributeTest, setValue)
+  {
+    ls_std::XMLAttribute attribute {};
+    attribute.setValue("some_content");
+
+    ASSERT_STREQ("some_content", attribute.getValue().c_str());
+  }
+
+  TEST_F(XMLAttributeTest, toXML)
+  {
+    ls_std::XMLAttribute attribute {};
+    attribute.setName("id");
+    attribute.setValue("some_content");
+
+    ASSERT_STREQ(R"(id="some_content")", attribute.toXML().c_str());
+  }
+}