XmlAttributeTest.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-23
  6. * Changed: 2023-03-25
  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. public:
  20. XmlAttributeTest() = default;
  21. ~XmlAttributeTest() override = default;
  22. };
  23. TEST_F(XmlAttributeTest, constructor_empty_name)
  24. {
  25. EXPECT_THROW(
  26. {
  27. try
  28. {
  29. XmlAttribute attribute{""};
  30. }
  31. catch (const IllegalArgumentException &_exception)
  32. {
  33. throw;
  34. }
  35. },
  36. IllegalArgumentException);
  37. }
  38. TEST_F(XmlAttributeTest, getName)
  39. {
  40. XmlAttribute attribute{"id"};
  41. ASSERT_STREQ("id", attribute.getName().c_str());
  42. }
  43. TEST_F(XmlAttributeTest, getValue)
  44. {
  45. XmlAttribute attribute{"id"};
  46. ASSERT_TRUE(attribute.getValue().empty());
  47. }
  48. TEST_F(XmlAttributeTest, setName)
  49. {
  50. XmlAttribute attribute{"id"};
  51. attribute.setName("id2");
  52. ASSERT_STREQ("id2", attribute.getName().c_str());
  53. }
  54. TEST_F(XmlAttributeTest, setName_empty_name)
  55. {
  56. EXPECT_THROW(
  57. {
  58. try
  59. {
  60. XmlAttribute attribute{"id"};
  61. attribute.setName("");
  62. }
  63. catch (const IllegalArgumentException &_exception)
  64. {
  65. throw;
  66. }
  67. },
  68. IllegalArgumentException);
  69. }
  70. TEST_F(XmlAttributeTest, setValue)
  71. {
  72. XmlAttribute attribute{"id"};
  73. attribute.setValue("some_content");
  74. ASSERT_STREQ("some_content", attribute.getValue().c_str());
  75. }
  76. TEST_F(XmlAttributeTest, setValue_empty_value)
  77. {
  78. EXPECT_THROW(
  79. {
  80. try
  81. {
  82. XmlAttribute attribute{"id"};
  83. attribute.setValue("");
  84. }
  85. catch (const IllegalArgumentException &_exception)
  86. {
  87. throw;
  88. }
  89. },
  90. IllegalArgumentException);
  91. }
  92. TEST_F(XmlAttributeTest, toXml)
  93. {
  94. XmlAttribute attribute{"id"};
  95. attribute.setValue("some_content");
  96. ASSERT_STREQ(R"(id="some_content")", attribute.toXml().c_str());
  97. }
  98. }