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-05-02
  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. }