SectionPairSectionTest.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-13
  6. * Changed: 2023-02-14
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <ls-std/ls-std-io.hpp>
  12. using namespace ls::std::core;
  13. using namespace ls::std::io;
  14. using namespace ::std;
  15. namespace
  16. {
  17. class SectionPairSectionTest : public ::testing::Test
  18. {
  19. protected:
  20. SectionPairSectionTest() = default;
  21. ~SectionPairSectionTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. };
  27. TEST_F(SectionPairSectionTest, constructor_empty_id)
  28. {
  29. EXPECT_THROW(
  30. {
  31. try
  32. {
  33. SectionPairSection section{""};
  34. }
  35. catch (const IllegalArgumentException &_exception)
  36. {
  37. throw;
  38. }
  39. },
  40. IllegalArgumentException);
  41. }
  42. TEST_F(SectionPairSectionTest, constructor_invalid_id)
  43. {
  44. EXPECT_THROW(
  45. {
  46. try
  47. {
  48. SectionPairSection section = SectionPairSection{"SERVER"};
  49. }
  50. catch (const IllegalArgumentException &_exception)
  51. {
  52. throw;
  53. }
  54. },
  55. IllegalArgumentException);
  56. }
  57. TEST_F(SectionPairSectionTest, getClassName)
  58. {
  59. ASSERT_STREQ("SectionPairSection", SectionPairSection{"general"}.getClassName().c_str());
  60. }
  61. TEST_F(SectionPairSectionTest, add)
  62. {
  63. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  64. section->add(make_shared<SectionPairRow>("color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE));
  65. ASSERT_EQ(1, section->getRowAmount());
  66. }
  67. TEST_F(SectionPairSectionTest, add_row_already_exists)
  68. {
  69. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  70. section->add(make_shared<SectionPairRow>("color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE));
  71. EXPECT_THROW(
  72. {
  73. try
  74. {
  75. section->add(make_shared<SectionPairRow>("color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE));
  76. }
  77. catch (const IllegalArgumentException &_exception)
  78. {
  79. throw;
  80. }
  81. },
  82. IllegalArgumentException);
  83. }
  84. TEST_F(SectionPairSectionTest, get)
  85. {
  86. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  87. section->add(make_shared<SectionPairRow>("color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE));
  88. ASSERT_TRUE(section->get(0) != nullptr);
  89. }
  90. TEST_F(SectionPairSectionTest, get_out_of_bounds)
  91. {
  92. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  93. EXPECT_THROW(
  94. {
  95. try
  96. {
  97. section_pair_row_list_element element = section->get(1);
  98. }
  99. catch (const IndexOutOfBoundsException &_exception)
  100. {
  101. throw;
  102. }
  103. },
  104. IndexOutOfBoundsException);
  105. }
  106. TEST_F(SectionPairSectionTest, getAmount)
  107. {
  108. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  109. ASSERT_EQ(0, section->getRowAmount());
  110. }
  111. TEST_F(SectionPairSectionTest, getSectionId)
  112. {
  113. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  114. ASSERT_STREQ("general", section->getSectionId().c_str());
  115. }
  116. TEST_F(SectionPairSectionTest, setSectionId)
  117. {
  118. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  119. section->setSectionId("personal");
  120. ASSERT_STREQ("personal", section->getSectionId().c_str());
  121. }
  122. TEST_F(SectionPairSectionTest, setSectionId_empty_id)
  123. {
  124. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  125. EXPECT_THROW(
  126. {
  127. try
  128. {
  129. section->setSectionId("");
  130. }
  131. catch (const IllegalArgumentException &_exception)
  132. {
  133. throw;
  134. }
  135. },
  136. IllegalArgumentException);
  137. }
  138. TEST_F(SectionPairSectionTest, setSectionId_invalid_id)
  139. {
  140. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("general");
  141. EXPECT_THROW(
  142. {
  143. try
  144. {
  145. section->setSectionId("PERSONAL");
  146. }
  147. catch (const IllegalArgumentException &_exception)
  148. {
  149. throw;
  150. }
  151. },
  152. IllegalArgumentException);
  153. }
  154. }