SectionPairRowTest.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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-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::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. }