KvDocumentTest.cpp 2.2 KB

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