SectionPairRowSingleValueTest.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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-23
  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 ls::std::core::IllegalArgumentException;
  13. using ls::std::core::type::byte_field;
  14. using ls::std::io::NewLine;
  15. using ls::std::io::SectionPairRowEnumType;
  16. using ls::std::io::SectionPairRowSingleValue;
  17. using std::make_shared;
  18. using std::shared_ptr;
  19. using testing::Test;
  20. namespace
  21. {
  22. class SectionPairRowSingleValueTest : public Test
  23. {
  24. protected:
  25. SectionPairRowSingleValueTest() = default;
  26. ~SectionPairRowSingleValueTest() override = default;
  27. void SetUp() override
  28. {}
  29. void TearDown() override
  30. {}
  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, getClassName)
  68. {
  69. ASSERT_STREQ("SectionPairRowSingleValue", SectionPairRowSingleValue{"blue"}.getClassName().c_str());
  70. }
  71. TEST_F(SectionPairRowSingleValueTest, getType)
  72. {
  73. SectionPairRowSingleValue value{"blue"};
  74. ASSERT_EQ(SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
  75. }
  76. TEST_F(SectionPairRowSingleValueTest, marshal)
  77. {
  78. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  79. byte_field expected = "empty" + NewLine::get();
  80. byte_field actual = value->marshal();
  81. ASSERT_STREQ(expected.c_str(), actual.c_str());
  82. }
  83. TEST_F(SectionPairRowSingleValueTest, set_empty_value)
  84. {
  85. SectionPairRowSingleValue value{"empty"};
  86. EXPECT_THROW(
  87. {
  88. try
  89. {
  90. value.set("");
  91. }
  92. catch (const IllegalArgumentException &_exception)
  93. {
  94. throw;
  95. }
  96. },
  97. IllegalArgumentException);
  98. }
  99. TEST_F(SectionPairRowSingleValueTest, set_invalid_value)
  100. {
  101. SectionPairRowSingleValue value{"empty"};
  102. EXPECT_THROW(
  103. {
  104. try
  105. {
  106. value.set("=33");
  107. }
  108. catch (const IllegalArgumentException &_exception)
  109. {
  110. throw;
  111. }
  112. },
  113. IllegalArgumentException);
  114. }
  115. TEST_F(SectionPairRowSingleValueTest, unmarshal)
  116. {
  117. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  118. value->unmarshal("blue");
  119. ASSERT_STREQ("blue", value->get().c_str());
  120. }
  121. }