XmlAttributeTest.cpp 2.7 KB

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