SectionPairRowSingleValueTest.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-02-11
  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::core::type;
  14. using namespace ls::std::io;
  15. using namespace ::std;
  16. namespace
  17. {
  18. class SectionPairRowSingleValueTest : public ::testing::Test
  19. {
  20. protected:
  21. SectionPairRowSingleValueTest() = default;
  22. ~SectionPairRowSingleValueTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. TEST_F(SectionPairRowSingleValueTest, getClassName)
  29. {
  30. ASSERT_STREQ("SectionPairRowSingleValue", SectionPairRowSingleValue{"blue"}.getClassName().c_str());
  31. }
  32. TEST_F(SectionPairRowSingleValueTest, constructor_empty_value)
  33. {
  34. EXPECT_THROW(
  35. {
  36. try
  37. {
  38. SectionPairRowSingleValue value{""};
  39. }
  40. catch (const IllegalArgumentException &_exception)
  41. {
  42. throw;
  43. }
  44. },
  45. IllegalArgumentException);
  46. }
  47. TEST_F(SectionPairRowSingleValueTest, constructor_invalid_value)
  48. {
  49. EXPECT_THROW(
  50. {
  51. try
  52. {
  53. SectionPairRowSingleValue value{"=33"};
  54. }
  55. catch (const IllegalArgumentException &_exception)
  56. {
  57. throw;
  58. }
  59. },
  60. IllegalArgumentException);
  61. }
  62. TEST_F(SectionPairRowSingleValueTest, get)
  63. {
  64. SectionPairRowSingleValue value{"blue"};
  65. ASSERT_STREQ("blue", value.get().c_str());
  66. }
  67. TEST_F(SectionPairRowSingleValueTest, getType)
  68. {
  69. SectionPairRowSingleValue value{"blue"};
  70. ASSERT_EQ(ls::std::io::SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
  71. }
  72. TEST_F(SectionPairRowSingleValueTest, marshal)
  73. {
  74. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  75. value->setSerializable(make_shared<SerializableSectionPairRowSingleValue>(value));
  76. ASSERT_STREQ("empty", value->marshal().c_str());
  77. }
  78. TEST_F(SectionPairRowSingleValueTest, marshal_no_serializable)
  79. {
  80. SectionPairRowSingleValue value{"blue"};
  81. EXPECT_THROW(
  82. {
  83. try
  84. {
  85. byte_field data = value.marshal();
  86. }
  87. catch (const NullPointerException &_exception)
  88. {
  89. throw;
  90. }
  91. },
  92. NullPointerException);
  93. }
  94. TEST_F(SectionPairRowSingleValueTest, set_empty_value)
  95. {
  96. SectionPairRowSingleValue value{"empty"};
  97. EXPECT_THROW(
  98. {
  99. try
  100. {
  101. value.set("");
  102. }
  103. catch (const IllegalArgumentException &_exception)
  104. {
  105. throw;
  106. }
  107. },
  108. IllegalArgumentException);
  109. }
  110. TEST_F(SectionPairRowSingleValueTest, set_invalid_value)
  111. {
  112. SectionPairRowSingleValue value{"empty"};
  113. EXPECT_THROW(
  114. {
  115. try
  116. {
  117. value.set("=33");
  118. }
  119. catch (const IllegalArgumentException &_exception)
  120. {
  121. throw;
  122. }
  123. },
  124. IllegalArgumentException);
  125. }
  126. TEST_F(SectionPairRowSingleValueTest, setSerializable_no_reference)
  127. {
  128. SectionPairRowSingleValue value{"empty"};
  129. EXPECT_THROW(
  130. {
  131. try
  132. {
  133. value.setSerializable(nullptr);
  134. }
  135. catch (const IllegalArgumentException &_exception)
  136. {
  137. throw;
  138. }
  139. },
  140. IllegalArgumentException);
  141. }
  142. TEST_F(SectionPairRowSingleValueTest, unmarshal)
  143. {
  144. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  145. value->setSerializable(make_shared<SerializableSectionPairRowSingleValue>(value));
  146. value->unmarshal("blue");
  147. ASSERT_STREQ("blue", value->get().c_str());
  148. }
  149. TEST_F(SectionPairRowSingleValueTest, unmarshal_no_serializable)
  150. {
  151. SectionPairRowSingleValue value{"blue"};
  152. EXPECT_THROW(
  153. {
  154. try
  155. {
  156. value.unmarshal("red");
  157. }
  158. catch (const NullPointerException &_exception)
  159. {
  160. throw;
  161. }
  162. },
  163. NullPointerException);
  164. }
  165. }