KVReaderTest.cpp 2.0 KB

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