SectionPairDocumentTest.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-15
  6. * Changed: 2023-02-15
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <ls-std/ls-std-io.hpp>
  12. #include <memory>
  13. using namespace ls::std::core;
  14. using namespace ls::std::core::type;
  15. using namespace ls::std::io;
  16. using namespace ::std;
  17. namespace
  18. {
  19. class SectionPairDocumentTest : public ::testing::Test
  20. {
  21. protected:
  22. SectionPairDocumentTest() = default;
  23. ~SectionPairDocumentTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. TEST_F(SectionPairDocumentTest, add)
  30. {
  31. shared_ptr<SectionPairDocument> document = make_shared<SectionPairDocument>();
  32. ASSERT_TRUE(document->getSectionList().empty());
  33. document->add(make_shared<SectionPairSection>("general"));
  34. ASSERT_EQ(1, document->getAmountOfSections());
  35. }
  36. TEST_F(SectionPairDocumentTest, add_section_id_already_exists)
  37. {
  38. shared_ptr<SectionPairDocument> document = make_shared<SectionPairDocument>();
  39. document->add(make_shared<SectionPairSection>("general"));
  40. EXPECT_THROW(
  41. {
  42. try
  43. {
  44. document->add(make_shared<SectionPairSection>("general"));
  45. }
  46. catch (const IllegalArgumentException &_exception)
  47. {
  48. throw;
  49. }
  50. },
  51. IllegalArgumentException);
  52. }
  53. TEST_F(SectionPairDocumentTest, get)
  54. {
  55. shared_ptr<SectionPairDocument> document = make_shared<SectionPairDocument>();
  56. document->add(make_shared<SectionPairSection>("general"));
  57. ASSERT_TRUE(document->get(0) != nullptr);
  58. }
  59. TEST_F(SectionPairDocumentTest, get_out_of_bounds)
  60. {
  61. shared_ptr<SectionPairDocument> document = make_shared<SectionPairDocument>();
  62. EXPECT_THROW(
  63. {
  64. try
  65. {
  66. shared_ptr<SectionPairSection> section = document->get(0);
  67. }
  68. catch (const IndexOutOfBoundsException &_exception)
  69. {
  70. throw;
  71. }
  72. },
  73. IndexOutOfBoundsException);
  74. }
  75. TEST_F(SectionPairDocumentTest, getAmountOfSections)
  76. {
  77. shared_ptr<SectionPairDocument> document = make_shared<SectionPairDocument>();
  78. document->add(make_shared<SectionPairSection>("general"));
  79. ASSERT_EQ(1, document->getAmountOfSections());
  80. }
  81. TEST_F(SectionPairDocumentTest, getSectionList)
  82. {
  83. shared_ptr<SectionPairDocument> document = make_shared<SectionPairDocument>();
  84. ASSERT_TRUE(document->getSectionList().empty());
  85. }
  86. }