XmlAttributeTest.cpp 2.6 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: 2021-07-16
  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::XmlAttribute attribute{""};
  29. }
  30. catch (const ls_std::IllegalArgumentException &_exception)
  31. {
  32. throw;
  33. }
  34. }, ls_std::IllegalArgumentException);
  35. }
  36. TEST_F(XmlAttributeTest, getName)
  37. {
  38. ls_std::XmlAttribute attribute{"id"};
  39. ASSERT_STREQ("id", attribute.getName().c_str());
  40. }
  41. TEST_F(XmlAttributeTest, getValue)
  42. {
  43. ls_std::XmlAttribute attribute{"id"};
  44. ASSERT_TRUE(attribute.getValue().empty());
  45. }
  46. TEST_F(XmlAttributeTest, setName)
  47. {
  48. ls_std::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::XmlAttribute attribute{"id"};
  58. attribute.setName("");
  59. }
  60. catch (const ls_std::IllegalArgumentException &_exception)
  61. {
  62. throw;
  63. }
  64. }, ls_std::IllegalArgumentException);
  65. }
  66. TEST_F(XmlAttributeTest, setValue)
  67. {
  68. ls_std::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::XmlAttribute attribute{"id"};
  78. attribute.setValue("");
  79. }
  80. catch (const ls_std::IllegalArgumentException &_exception)
  81. {
  82. throw;
  83. }
  84. }, ls_std::IllegalArgumentException);
  85. }
  86. TEST_F(XmlAttributeTest, toXml)
  87. {
  88. ls_std::XmlAttribute attribute{"id"};
  89. attribute.setValue("some_content");
  90. ASSERT_STREQ(R"(id="some_content")", attribute.toXml().c_str());
  91. }
  92. }