XmlDeclarationTest.cpp 3.6 KB

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