XmlDeclarationTest.cpp 4.1 KB

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