SectionPairRowSingleValueTest.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-03-25
  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. public:
  25. SectionPairRowSingleValueTest() = default;
  26. ~SectionPairRowSingleValueTest() override = default;
  27. };
  28. TEST_F(SectionPairRowSingleValueTest, constructor_empty_value)
  29. {
  30. EXPECT_THROW(
  31. {
  32. try
  33. {
  34. SectionPairRowSingleValue value{""};
  35. }
  36. catch (const IllegalArgumentException &_exception)
  37. {
  38. throw;
  39. }
  40. },
  41. IllegalArgumentException);
  42. }
  43. TEST_F(SectionPairRowSingleValueTest, constructor_invalid_value)
  44. {
  45. EXPECT_THROW(
  46. {
  47. try
  48. {
  49. SectionPairRowSingleValue value{"=33"};
  50. }
  51. catch (const IllegalArgumentException &_exception)
  52. {
  53. throw;
  54. }
  55. },
  56. IllegalArgumentException);
  57. }
  58. TEST_F(SectionPairRowSingleValueTest, get)
  59. {
  60. SectionPairRowSingleValue value{"blue"};
  61. ASSERT_STREQ("blue", value.get().c_str());
  62. }
  63. TEST_F(SectionPairRowSingleValueTest, getClassName)
  64. {
  65. ASSERT_STREQ("SectionPairRowSingleValue", SectionPairRowSingleValue{"blue"}.getClassName().c_str());
  66. }
  67. TEST_F(SectionPairRowSingleValueTest, getType)
  68. {
  69. SectionPairRowSingleValue value{"blue"};
  70. ASSERT_EQ(SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
  71. }
  72. TEST_F(SectionPairRowSingleValueTest, marshal)
  73. {
  74. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  75. byte_field expected = "empty" + NewLine::get();
  76. byte_field actual = value->marshal();
  77. ASSERT_STREQ(expected.c_str(), actual.c_str());
  78. }
  79. TEST_F(SectionPairRowSingleValueTest, set_empty_value)
  80. {
  81. SectionPairRowSingleValue value{"empty"};
  82. EXPECT_THROW(
  83. {
  84. try
  85. {
  86. value.set("");
  87. }
  88. catch (const IllegalArgumentException &_exception)
  89. {
  90. throw;
  91. }
  92. },
  93. IllegalArgumentException);
  94. }
  95. TEST_F(SectionPairRowSingleValueTest, set_invalid_value)
  96. {
  97. SectionPairRowSingleValue value{"empty"};
  98. EXPECT_THROW(
  99. {
  100. try
  101. {
  102. value.set("=33");
  103. }
  104. catch (const IllegalArgumentException &_exception)
  105. {
  106. throw;
  107. }
  108. },
  109. IllegalArgumentException);
  110. }
  111. TEST_F(SectionPairRowSingleValueTest, unmarshal)
  112. {
  113. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  114. value->unmarshal("blue");
  115. ASSERT_STREQ("blue", value->get().c_str());
  116. }
  117. }