SectionPairRowTest.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-08
  6. * Changed: 2023-02-12
  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 SectionPairRowTest : public ::testing::Test
  18. {
  19. protected:
  20. SectionPairRowTest() = default;
  21. ~SectionPairRowTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. };
  27. TEST_F(SectionPairRowTest, getClassName)
  28. {
  29. ASSERT_STREQ("SectionPairRow", SectionPairRow("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE).getClassName().c_str());
  30. }
  31. TEST_F(SectionPairRowTest, constructor_empty_key)
  32. {
  33. EXPECT_THROW(
  34. {
  35. try
  36. {
  37. SectionPairRow row("", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  38. }
  39. catch (const IllegalArgumentException &_exception)
  40. {
  41. throw;
  42. }
  43. },
  44. IllegalArgumentException);
  45. }
  46. TEST_F(SectionPairRowTest, constructor_invalid_key)
  47. {
  48. EXPECT_THROW(
  49. {
  50. try
  51. {
  52. SectionPairRow row("-tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  53. }
  54. catch (const IllegalArgumentException &_exception)
  55. {
  56. throw;
  57. }
  58. },
  59. IllegalArgumentException);
  60. }
  61. TEST_F(SectionPairRowTest, getKey)
  62. {
  63. ls::std::io::section_pair_identifier key = "tmp-key";
  64. SectionPairRow row(key, SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
  65. ASSERT_STREQ(key.c_str(), row.getKey().c_str());
  66. }
  67. TEST_F(SectionPairRowTest, getValue)
  68. {
  69. SectionPairRow row("hobbies", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
  70. shared_ptr<SectionPairRowValue> value = row.getValue();
  71. ASSERT_TRUE(value != nullptr);
  72. ASSERT_EQ(SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE, value->getType());
  73. }
  74. TEST_F(SectionPairRowTest, isSingleValue)
  75. {
  76. ASSERT_TRUE(SectionPairRow("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE).isSingleValue());
  77. }
  78. TEST_F(SectionPairRowTest, isList)
  79. {
  80. ASSERT_FALSE(SectionPairRow("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE).isList());
  81. }
  82. TEST_F(SectionPairRowTest, setKey)
  83. {
  84. SectionPairRow row("hobbies", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
  85. row.setKey("colors");
  86. ASSERT_STREQ("colors", row.getKey().c_str());
  87. }
  88. }