XmlAttributeTest.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-23
  6. * Changed: 2022-11-09
  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. try
  30. {
  31. XmlAttribute attribute{""};
  32. }
  33. catch (const IllegalArgumentException &_exception)
  34. {
  35. throw;
  36. }
  37. }, IllegalArgumentException);
  38. }
  39. TEST_F(XmlAttributeTest, getName)
  40. {
  41. XmlAttribute attribute{"id"};
  42. ASSERT_STREQ("id", attribute.getName().c_str());
  43. }
  44. TEST_F(XmlAttributeTest, getValue)
  45. {
  46. 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. try
  59. {
  60. XmlAttribute attribute{"id"};
  61. attribute.setName("");
  62. }
  63. catch (const IllegalArgumentException &_exception)
  64. {
  65. throw;
  66. }
  67. }, IllegalArgumentException);
  68. }
  69. TEST_F(XmlAttributeTest, setValue)
  70. {
  71. XmlAttribute attribute{"id"};
  72. attribute.setValue("some_content");
  73. ASSERT_STREQ("some_content", attribute.getValue().c_str());
  74. }
  75. TEST_F(XmlAttributeTest, setValue_empty_value)
  76. {
  77. EXPECT_THROW({
  78. try
  79. {
  80. XmlAttribute attribute{"id"};
  81. attribute.setValue("");
  82. }
  83. catch (const IllegalArgumentException &_exception)
  84. {
  85. throw;
  86. }
  87. }, IllegalArgumentException);
  88. }
  89. TEST_F(XmlAttributeTest, toXml)
  90. {
  91. XmlAttribute attribute{"id"};
  92. attribute.setValue("some_content");
  93. ASSERT_STREQ(R"(id="some_content")", attribute.toXml().c_str());
  94. }
  95. }