XMLDeclarationTest.cpp 2.2 KB

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