XmlAttributeTest.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-23
  6. * Changed: 2023-02-04
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <ls-std/ls-std-io.hpp>
  12. using namespace ls::std::core;
  13. using namespace ls::std::io;
  14. namespace
  15. {
  16. class XmlAttributeTest : public ::testing::Test
  17. {
  18. protected:
  19. XmlAttributeTest() = default;
  20. ~XmlAttributeTest() override = default;
  21. void SetUp() override
  22. {}
  23. void TearDown() override
  24. {}
  25. };
  26. TEST_F(XmlAttributeTest, constructor_empty_name)
  27. {
  28. EXPECT_THROW(
  29. {
  30. try
  31. {
  32. XmlAttribute attribute{""};
  33. }
  34. catch (const IllegalArgumentException &_exception)
  35. {
  36. throw;
  37. }
  38. },
  39. IllegalArgumentException);
  40. }
  41. TEST_F(XmlAttributeTest, getName)
  42. {
  43. XmlAttribute attribute{"id"};
  44. ASSERT_STREQ("id", attribute.getName().c_str());
  45. }
  46. TEST_F(XmlAttributeTest, getValue)
  47. {
  48. XmlAttribute attribute{"id"};
  49. ASSERT_TRUE(attribute.getValue().empty());
  50. }
  51. TEST_F(XmlAttributeTest, setName)
  52. {
  53. XmlAttribute attribute{"id"};
  54. attribute.setName("id2");
  55. ASSERT_STREQ("id2", attribute.getName().c_str());
  56. }
  57. TEST_F(XmlAttributeTest, setName_empty_name)
  58. {
  59. EXPECT_THROW(
  60. {
  61. try
  62. {
  63. XmlAttribute attribute{"id"};
  64. attribute.setName("");
  65. }
  66. catch (const IllegalArgumentException &_exception)
  67. {
  68. throw;
  69. }
  70. },
  71. IllegalArgumentException);
  72. }
  73. TEST_F(XmlAttributeTest, setValue)
  74. {
  75. XmlAttribute attribute{"id"};
  76. attribute.setValue("some_content");
  77. ASSERT_STREQ("some_content", attribute.getValue().c_str());
  78. }
  79. TEST_F(XmlAttributeTest, setValue_empty_value)
  80. {
  81. EXPECT_THROW(
  82. {
  83. try
  84. {
  85. XmlAttribute attribute{"id"};
  86. attribute.setValue("");
  87. }
  88. catch (const IllegalArgumentException &_exception)
  89. {
  90. throw;
  91. }
  92. },
  93. IllegalArgumentException);
  94. }
  95. TEST_F(XmlAttributeTest, toXml)
  96. {
  97. XmlAttribute attribute{"id"};
  98. attribute.setValue("some_content");
  99. ASSERT_STREQ(R"(id="some_content")", attribute.toXml().c_str());
  100. }
  101. }