XmlAttributeTest.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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-23
  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 ls::std::core::IllegalArgumentException;
  13. using ls::std::io::XmlAttribute;
  14. using testing::Test;
  15. namespace
  16. {
  17. class XmlAttributeTest : public Test
  18. {
  19. protected:
  20. XmlAttributeTest() = default;
  21. ~XmlAttributeTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. };
  27. TEST_F(XmlAttributeTest, constructor_empty_name)
  28. {
  29. EXPECT_THROW(
  30. {
  31. try
  32. {
  33. XmlAttribute attribute{""};
  34. }
  35. catch (const IllegalArgumentException &_exception)
  36. {
  37. throw;
  38. }
  39. },
  40. IllegalArgumentException);
  41. }
  42. TEST_F(XmlAttributeTest, getName)
  43. {
  44. XmlAttribute attribute{"id"};
  45. ASSERT_STREQ("id", attribute.getName().c_str());
  46. }
  47. TEST_F(XmlAttributeTest, getValue)
  48. {
  49. XmlAttribute attribute{"id"};
  50. ASSERT_TRUE(attribute.getValue().empty());
  51. }
  52. TEST_F(XmlAttributeTest, setName)
  53. {
  54. XmlAttribute attribute{"id"};
  55. attribute.setName("id2");
  56. ASSERT_STREQ("id2", attribute.getName().c_str());
  57. }
  58. TEST_F(XmlAttributeTest, setName_empty_name)
  59. {
  60. EXPECT_THROW(
  61. {
  62. try
  63. {
  64. XmlAttribute attribute{"id"};
  65. attribute.setName("");
  66. }
  67. catch (const IllegalArgumentException &_exception)
  68. {
  69. throw;
  70. }
  71. },
  72. IllegalArgumentException);
  73. }
  74. TEST_F(XmlAttributeTest, setValue)
  75. {
  76. XmlAttribute attribute{"id"};
  77. attribute.setValue("some_content");
  78. ASSERT_STREQ("some_content", attribute.getValue().c_str());
  79. }
  80. TEST_F(XmlAttributeTest, setValue_empty_value)
  81. {
  82. EXPECT_THROW(
  83. {
  84. try
  85. {
  86. XmlAttribute attribute{"id"};
  87. attribute.setValue("");
  88. }
  89. catch (const IllegalArgumentException &_exception)
  90. {
  91. throw;
  92. }
  93. },
  94. IllegalArgumentException);
  95. }
  96. TEST_F(XmlAttributeTest, toXml)
  97. {
  98. XmlAttribute attribute{"id"};
  99. attribute.setValue("some_content");
  100. ASSERT_STREQ(R"(id="some_content")", attribute.toXml().c_str());
  101. }
  102. }