XmlAttributeTest.cpp 2.4 KB

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