KvDocumentTest.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-25
  6. * Changed: 2021-05-02
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace
  12. {
  13. class KvDocumentTest : public ::testing::Test
  14. {
  15. protected:
  16. KvDocumentTest() = default;
  17. ~KvDocumentTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. TEST_F(KvDocumentTest, addPair)
  24. {
  25. ls_std::KvDocument document{};
  26. ls_std::KvPair pair{"port", "13088"};
  27. ASSERT_TRUE(document.getPairs().empty());
  28. ASSERT_TRUE(document.addPair(pair));
  29. ASSERT_EQ(1, document.getPairs().size());
  30. }
  31. TEST_F(KvDocumentTest, addPairNegative)
  32. {
  33. ls_std::KvDocument document{};
  34. ls_std::KvPair pair{"port", "13088"};
  35. ASSERT_TRUE(document.getPairs().empty());
  36. ASSERT_TRUE(document.addPair(pair));
  37. ASSERT_EQ(1, document.getPairs().size());
  38. ASSERT_FALSE(document.addPair(pair));
  39. }
  40. TEST_F(KvDocumentTest, clear)
  41. {
  42. ls_std::KvDocument document{};
  43. ls_std::KvPair pair{"port", "13088"};
  44. ASSERT_TRUE(document.getPairs().empty());
  45. ASSERT_TRUE(document.addPair(pair));
  46. ASSERT_FALSE(document.getPairs().empty());
  47. ASSERT_EQ(1, document.getPairs().size());
  48. document.clear();
  49. ASSERT_TRUE(document.getPairs().empty());
  50. ASSERT_EQ(0, document.getPairs().size());
  51. }
  52. TEST_F(KvDocumentTest, getPairs)
  53. {
  54. ls_std::KvDocument document{};
  55. ASSERT_TRUE(document.getPairs().empty());
  56. }
  57. TEST_F(KvDocumentTest, hasPair)
  58. {
  59. ls_std::KvDocument document{};
  60. ASSERT_TRUE(document.getPairs().empty());
  61. ASSERT_TRUE(document.addPair(ls_std::KvPair{"port", "80"}));
  62. ASSERT_TRUE(document.hasPair("port"));
  63. }
  64. TEST_F(KvDocumentTest, hasPairNegative)
  65. {
  66. ls_std::KvDocument document{};
  67. ASSERT_TRUE(document.getPairs().empty());
  68. ASSERT_FALSE(document.hasPair("port"));
  69. }
  70. TEST_F(KvDocumentTest, removePair)
  71. {
  72. ls_std::KvDocument document{};
  73. ASSERT_TRUE(document.addPair(ls_std::KvPair{"port", "80"}));
  74. ASSERT_TRUE(document.addPair(ls_std::KvPair{"host", "localhost"}));
  75. ASSERT_TRUE(document.addPair(ls_std::KvPair{"protocol", "TCP"}));
  76. ASSERT_EQ(3, document.getPairs().size());
  77. document.removePair("protocol");
  78. ASSERT_EQ(2, document.getPairs().size());
  79. ASSERT_TRUE(document.hasPair("port"));
  80. ASSERT_TRUE(document.hasPair("host"));
  81. }
  82. }