XmlDeclarationTest.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-29
  6. * Changed: 2021-07-16
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace
  12. {
  13. class XmlDeclarationTest : public ::testing::Test
  14. {
  15. protected:
  16. XmlDeclarationTest() = default;
  17. ~XmlDeclarationTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. TEST_F(XmlDeclarationTest, constructor_empty_version)
  24. {
  25. EXPECT_THROW({
  26. try
  27. {
  28. ls_std::XmlDeclaration declaration{""};
  29. }
  30. catch (const ls_std::IllegalArgumentException &_exception)
  31. {
  32. throw;
  33. }
  34. }, ls_std::IllegalArgumentException);
  35. }
  36. TEST_F(XmlDeclarationTest, getEncoding)
  37. {
  38. ls_std::XmlDeclaration declaration{"1.0"};
  39. ASSERT_TRUE(declaration.getEncoding().empty());
  40. }
  41. TEST_F(XmlDeclarationTest, getStandalone)
  42. {
  43. ls_std::XmlDeclaration declaration{"1.0"};
  44. ASSERT_TRUE(declaration.getStandalone().empty());
  45. }
  46. TEST_F(XmlDeclarationTest, getVersion)
  47. {
  48. ls_std::XmlDeclaration declaration{"1.0"};
  49. ASSERT_STREQ("1.0", declaration.getVersion().c_str());
  50. }
  51. TEST_F(XmlDeclarationTest, setEncoding)
  52. {
  53. ls_std::XmlDeclaration declaration{"1.0"};
  54. ASSERT_TRUE(declaration.getEncoding().empty());
  55. declaration.setEncoding("iso-8859-1");
  56. ASSERT_STREQ("iso-8859-1", declaration.getEncoding().c_str());
  57. }
  58. TEST_F(XmlDeclarationTest, setEncoding_empty_encoding)
  59. {
  60. ls_std::XmlDeclaration declaration{"1.0"};
  61. EXPECT_THROW({
  62. try
  63. {
  64. declaration.setEncoding("");
  65. }
  66. catch (const ls_std::IllegalArgumentException &_exception)
  67. {
  68. throw;
  69. }
  70. }, ls_std::IllegalArgumentException);
  71. }
  72. TEST_F(XmlDeclarationTest, setStandalone)
  73. {
  74. ls_std::XmlDeclaration declaration{"1.0"};
  75. ASSERT_TRUE(declaration.getStandalone().empty());
  76. declaration.setStandalone("no");
  77. ASSERT_STREQ("no", declaration.getStandalone().c_str());
  78. }
  79. TEST_F(XmlDeclarationTest, setStandalone_empty_standalone)
  80. {
  81. ls_std::XmlDeclaration declaration{"1.0"};
  82. EXPECT_THROW({
  83. try
  84. {
  85. declaration.setStandalone("");
  86. }
  87. catch (const ls_std::IllegalArgumentException &_exception)
  88. {
  89. throw;
  90. }
  91. }, ls_std::IllegalArgumentException);
  92. }
  93. TEST_F(XmlDeclarationTest, setVersion)
  94. {
  95. ls_std::XmlDeclaration declaration{"1.0"};
  96. ASSERT_FALSE(declaration.getVersion().empty());
  97. ASSERT_STREQ("1.0", declaration.getVersion().c_str());
  98. declaration.setVersion("1.1");
  99. ASSERT_STREQ("1.1", declaration.getVersion().c_str());
  100. }
  101. TEST_F(XmlDeclarationTest, setVersion_empty_version)
  102. {
  103. ls_std::XmlDeclaration declaration{"1.0"};
  104. EXPECT_THROW({
  105. try
  106. {
  107. declaration.setVersion("");
  108. }
  109. catch (const ls_std::IllegalArgumentException &_exception)
  110. {
  111. throw;
  112. }
  113. }, ls_std::IllegalArgumentException);
  114. }
  115. TEST_F(XmlDeclarationTest, toXml)
  116. {
  117. ls_std::XmlDeclaration declaration{"1.0"};
  118. ASSERT_STREQ(R"(<?xml version="1.0" ?>)", declaration.toXml().c_str());
  119. declaration.setStandalone("yes");
  120. ASSERT_STREQ(R"(<?xml version="1.0" standalone="yes" ?>)", declaration.toXml().c_str());
  121. declaration.setEncoding("UTF-8");
  122. ASSERT_STREQ(R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>)", declaration.toXml().c_str());
  123. }
  124. }