KvDocumentTest.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-25
  6. * Changed: 2021-07-15
  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.addPair(pair));
  28. ASSERT_EQ(1, document.getPairs().size());
  29. }
  30. TEST_F(KvDocumentTest, addPair_retry_to_add_pair)
  31. {
  32. ls_std::KvDocument document{};
  33. ls_std::KvPair pair{"port", "13088"};
  34. ASSERT_TRUE(document.addPair(pair));
  35. ASSERT_FALSE(document.addPair(pair));
  36. }
  37. TEST_F(KvDocumentTest, clear)
  38. {
  39. // preparation
  40. ls_std::KvDocument document{};
  41. ls_std::KvPair pair{"port", "13088"};
  42. document.addPair(pair);
  43. // check
  44. document.clear();
  45. ASSERT_TRUE(document.getPairs().empty());
  46. ASSERT_EQ(0, document.getPairs().size());
  47. }
  48. TEST_F(KvDocumentTest, getPairs)
  49. {
  50. ls_std::KvDocument document{};
  51. ASSERT_TRUE(document.getPairs().empty());
  52. }
  53. TEST_F(KvDocumentTest, hasPair)
  54. {
  55. ls_std::KvDocument document{};
  56. document.addPair(ls_std::KvPair{"port", "80"});
  57. ASSERT_TRUE(document.hasPair("port"));
  58. }
  59. TEST_F(KvDocumentTest, hasPair_no_pairs_available)
  60. {
  61. ls_std::KvDocument document{};
  62. ASSERT_FALSE(document.hasPair("port"));
  63. }
  64. TEST_F(KvDocumentTest, removePair)
  65. {
  66. // preparation
  67. ls_std::KvDocument document{};
  68. document.addPair(ls_std::KvPair{"port", "80"});
  69. document.addPair(ls_std::KvPair{"host", "localhost"});
  70. document.addPair(ls_std::KvPair{"protocol", "TCP"});
  71. // remove pair and check
  72. ASSERT_TRUE(document.removePair("protocol"));
  73. ASSERT_EQ(2, document.getPairs().size());
  74. ASSERT_TRUE(document.hasPair("port"));
  75. ASSERT_TRUE(document.hasPair("host"));
  76. }
  77. TEST_F(KvDocumentTest, removePair_no_pair_available)
  78. {
  79. ls_std::KvDocument document{};
  80. ASSERT_FALSE(document.removePair("port"));
  81. }
  82. }