XMLDeclarationTest.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-29
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace
  12. {
  13. class XMLDeclarationTest : public ::testing::Test
  14. {
  15. protected:
  16. XMLDeclarationTest() = default;
  17. ~XMLDeclarationTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. TEST_F(XMLDeclarationTest, getEncoding)
  24. {
  25. ls_std::XMLDeclaration declaration{"1.0"};
  26. ASSERT_TRUE(declaration.getEncoding().empty());
  27. }
  28. TEST_F(XMLDeclarationTest, getStandalone)
  29. {
  30. ls_std::XMLDeclaration declaration{"1.0"};
  31. ASSERT_TRUE(declaration.getStandalone().empty());
  32. }
  33. TEST_F(XMLDeclarationTest, getVersion)
  34. {
  35. ls_std::XMLDeclaration declaration{"1.0"};
  36. ASSERT_FALSE(declaration.getVersion().empty());
  37. ASSERT_STREQ("1.0", declaration.getVersion().c_str());
  38. }
  39. TEST_F(XMLDeclarationTest, setEncoding)
  40. {
  41. ls_std::XMLDeclaration declaration{"1.0"};
  42. ASSERT_TRUE(declaration.getEncoding().empty());
  43. declaration.setEncoding("iso-8859-1");
  44. ASSERT_STREQ("iso-8859-1", declaration.getEncoding().c_str());
  45. }
  46. TEST_F(XMLDeclarationTest, setStandalone)
  47. {
  48. ls_std::XMLDeclaration declaration{"1.0"};
  49. ASSERT_TRUE(declaration.getStandalone().empty());
  50. declaration.setStandalone("no");
  51. ASSERT_STREQ("no", declaration.getStandalone().c_str());
  52. }
  53. TEST_F(XMLDeclarationTest, setVersion)
  54. {
  55. ls_std::XMLDeclaration declaration{"1.0"};
  56. ASSERT_FALSE(declaration.getVersion().empty());
  57. ASSERT_STREQ("1.0", declaration.getVersion().c_str());
  58. declaration.setVersion("1.1");
  59. ASSERT_STREQ("1.1", declaration.getVersion().c_str());
  60. }
  61. TEST_F(XMLDeclarationTest, toXML)
  62. {
  63. ls_std::XMLDeclaration declaration{"1.0"};
  64. ASSERT_STREQ(R"(<?xml version="1.0" ?>)", declaration.toXML().c_str());
  65. declaration.setStandalone("yes");
  66. ASSERT_STREQ(R"(<?xml version="1.0" standalone="yes" ?>)", declaration.toXML().c_str());
  67. declaration.setEncoding("UTF-8");
  68. ASSERT_STREQ(R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>)", declaration.toXML().c_str());
  69. }
  70. }