XmlDeclarationTest.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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-23
  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. protected:
  20. XmlDeclarationTest() = default;
  21. ~XmlDeclarationTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. };
  27. TEST_F(XmlDeclarationTest, constructor_empty_version)
  28. {
  29. EXPECT_THROW(
  30. {
  31. try
  32. {
  33. XmlDeclaration declaration{""};
  34. }
  35. catch (const IllegalArgumentException &_exception)
  36. {
  37. throw;
  38. }
  39. },
  40. IllegalArgumentException);
  41. }
  42. TEST_F(XmlDeclarationTest, getEncoding)
  43. {
  44. XmlDeclaration declaration{"1.0"};
  45. ASSERT_TRUE(declaration.getEncoding().empty());
  46. }
  47. TEST_F(XmlDeclarationTest, getStandalone)
  48. {
  49. XmlDeclaration declaration{"1.0"};
  50. ASSERT_TRUE(declaration.getStandalone().empty());
  51. }
  52. TEST_F(XmlDeclarationTest, getVersion)
  53. {
  54. XmlDeclaration declaration{"1.0"};
  55. ASSERT_STREQ("1.0", declaration.getVersion().c_str());
  56. }
  57. TEST_F(XmlDeclarationTest, setEncoding)
  58. {
  59. XmlDeclaration declaration{"1.0"};
  60. ASSERT_TRUE(declaration.getEncoding().empty());
  61. declaration.setEncoding("iso-8859-1");
  62. ASSERT_STREQ("iso-8859-1", declaration.getEncoding().c_str());
  63. }
  64. TEST_F(XmlDeclarationTest, setEncoding_empty_encoding)
  65. {
  66. XmlDeclaration declaration{"1.0"};
  67. EXPECT_THROW(
  68. {
  69. try
  70. {
  71. declaration.setEncoding("");
  72. }
  73. catch (const IllegalArgumentException &_exception)
  74. {
  75. throw;
  76. }
  77. },
  78. IllegalArgumentException);
  79. }
  80. TEST_F(XmlDeclarationTest, setStandalone)
  81. {
  82. XmlDeclaration declaration{"1.0"};
  83. ASSERT_TRUE(declaration.getStandalone().empty());
  84. declaration.setStandalone("no");
  85. ASSERT_STREQ("no", declaration.getStandalone().c_str());
  86. }
  87. TEST_F(XmlDeclarationTest, setStandalone_empty_standalone)
  88. {
  89. XmlDeclaration declaration{"1.0"};
  90. EXPECT_THROW(
  91. {
  92. try
  93. {
  94. declaration.setStandalone("");
  95. }
  96. catch (const IllegalArgumentException &_exception)
  97. {
  98. throw;
  99. }
  100. },
  101. IllegalArgumentException);
  102. }
  103. TEST_F(XmlDeclarationTest, setVersion)
  104. {
  105. XmlDeclaration declaration{"1.0"};
  106. ASSERT_FALSE(declaration.getVersion().empty());
  107. ASSERT_STREQ("1.0", declaration.getVersion().c_str());
  108. declaration.setVersion("1.1");
  109. ASSERT_STREQ("1.1", declaration.getVersion().c_str());
  110. }
  111. TEST_F(XmlDeclarationTest, setVersion_empty_version)
  112. {
  113. XmlDeclaration declaration{"1.0"};
  114. EXPECT_THROW(
  115. {
  116. try
  117. {
  118. declaration.setVersion("");
  119. }
  120. catch (const IllegalArgumentException &_exception)
  121. {
  122. throw;
  123. }
  124. },
  125. IllegalArgumentException);
  126. }
  127. TEST_F(XmlDeclarationTest, toXml)
  128. {
  129. XmlDeclaration declaration{"1.0"};
  130. ASSERT_STREQ(R"(<?xml version="1.0" ?>)", declaration.toXml().c_str());
  131. declaration.setStandalone("yes");
  132. ASSERT_STREQ(R"(<?xml version="1.0" standalone="yes" ?>)", declaration.toXml().c_str());
  133. declaration.setEncoding("UTF-8");
  134. ASSERT_STREQ(R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>)", declaration.toXml().c_str());
  135. }
  136. }