KVParserTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-12-25
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std.hpp>
  11. namespace
  12. {
  13. class KVParserTest : public ::testing::Test
  14. {
  15. protected:
  16. KVParserTest() = default;
  17. ~KVParserTest() override = default;
  18. void SetUp() override
  19. {}
  20. void TearDown() override
  21. {}
  22. };
  23. TEST_F(KVParserTest, getDocument)
  24. {
  25. ls_std::KVParser parser{std::make_shared<ls_std::KVDocument>()};
  26. ASSERT_TRUE(parser.getDocument() != nullptr);
  27. }
  28. TEST_F(KVParserTest, parse)
  29. {
  30. std::shared_ptr<ls_std::KVDocument> document = std::make_shared<ls_std::KVDocument>();
  31. ls_std::KVParser parser{document};
  32. ls_std::byte_field data = "# starting comment\n\nport=8080; # some comment\nhost=localhost;\nservice-name=deamon;";
  33. parser.parse(data);
  34. ASSERT_EQ(3, document->getPairs().size());
  35. ASSERT_TRUE(document->hasPair("port"));
  36. ASSERT_TRUE(document->hasPair("host"));
  37. ASSERT_TRUE(document->hasPair("service-name"));
  38. ASSERT_STREQ("8080", document->getPairs().at("port").getValue().c_str());
  39. ASSERT_STREQ("localhost", document->getPairs().at("host").getValue().c_str());
  40. ASSERT_STREQ("deamon", document->getPairs().at("service-name").getValue().c_str());
  41. }
  42. TEST_F(KVParserTest, setDocument)
  43. {
  44. std::shared_ptr<ls_std::KVDocument> document1 = std::make_shared<ls_std::KVDocument>();
  45. std::shared_ptr<ls_std::KVDocument> document2 = std::make_shared<ls_std::KVDocument>();
  46. ls_std::KVParser parser{document1};
  47. ASSERT_TRUE(parser.getDocument() == document1);
  48. parser.setDocument(document2);
  49. ASSERT_TRUE(parser.getDocument() == document2);
  50. }
  51. }