XmlAttributeTest.cpp 2.7 KB

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