XmlDeclarationTest.cpp 3.6 KB

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