KVDocumentTest.cpp 2.5 KB

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