XmlDeclarationTest.cpp 3.9 KB

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