XmlDeclarationTest.cpp 3.6 KB

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