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