KVReaderTest.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include <TestHelper.hpp>
  12. namespace {
  13. class KVReaderTest : public ::testing::Test {
  14. protected:
  15. KVReaderTest() = default;
  16. ~KVReaderTest() override = default;
  17. void SetUp() override {}
  18. void TearDown() override {}
  19. };
  20. TEST_F(KVReaderTest, getDocument)
  21. {
  22. std::string kvPath = TestHelper::getResourcesFolderLocation() + "server_settings.kv";
  23. ls_std::KVReader reader {std::make_shared<ls_std::KVDocument>(), kvPath};
  24. ASSERT_TRUE(reader.getDocument() != nullptr);
  25. }
  26. TEST_F(KVReaderTest, read)
  27. {
  28. std::string kvPath = TestHelper::getResourcesFolderLocation() + "server_settings.kv";
  29. std::shared_ptr<ls_std::KVDocument> document = std::make_shared<ls_std::KVDocument>();
  30. ls_std::KVReader reader {document, kvPath};
  31. reader.read();
  32. ASSERT_EQ(3, document->getPairs().size());
  33. ASSERT_TRUE(document->hasPair("port"));
  34. ASSERT_TRUE(document->hasPair("host"));
  35. ASSERT_TRUE(document->hasPair("service-name"));
  36. ASSERT_STREQ("8080", document->getPairs().at("port").getValue().c_str());
  37. ASSERT_STREQ("localhost", document->getPairs().at("host").getValue().c_str());
  38. ASSERT_STREQ("deamon", document->getPairs().at("service-name").getValue().c_str());
  39. }
  40. TEST_F(KVReaderTest, setDocument)
  41. {
  42. std::string kvPath = TestHelper::getResourcesFolderLocation() + "server_settings.kv";
  43. std::shared_ptr<ls_std::KVDocument> document1 = std::make_shared<ls_std::KVDocument>();
  44. std::shared_ptr<ls_std::KVDocument> document2 = std::make_shared<ls_std::KVDocument>();
  45. ls_std::KVReader reader {document1, kvPath};
  46. ASSERT_TRUE(reader.getDocument() == document1);
  47. reader.setDocument(document2);
  48. ASSERT_TRUE(reader.getDocument() == document2);
  49. }
  50. }