SectionPairRowSingleValueArgumentEvaluatorTest.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-19
  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. #include <string>
  13. using ls::std::core::IllegalArgumentException;
  14. using ls::std::io::SectionPairMessageFormatter;
  15. using ls::std::io::SectionPairRowSingleValueArgumentEvaluator;
  16. using std::make_shared;
  17. using std::shared_ptr;
  18. using std::string;
  19. using testing::Test;
  20. using testing::TestWithParam;
  21. using testing::Values;
  22. namespace
  23. {
  24. class SectionPairRowSingleValueArgumentEvaluatorTest : public Test
  25. {
  26. public:
  27. SectionPairRowSingleValueArgumentEvaluatorTest() = default;
  28. ~SectionPairRowSingleValueArgumentEvaluatorTest() override = default;
  29. };
  30. class SectionPairRowSingleValueArgumentEvaluatorTest_InvalidArgumentTest : public TestWithParam<string>
  31. {
  32. public:
  33. SectionPairRowSingleValueArgumentEvaluatorTest_InvalidArgumentTest() = default;
  34. ~SectionPairRowSingleValueArgumentEvaluatorTest_InvalidArgumentTest() override = default;
  35. };
  36. TEST_F(SectionPairRowSingleValueArgumentEvaluatorTest, getClassName)
  37. {
  38. shared_ptr<SectionPairRowSingleValueArgumentEvaluator> evaluator = make_shared<SectionPairRowSingleValueArgumentEvaluator>("color=blue");
  39. ASSERT_STREQ("SectionPairRowSingleValueArgumentEvaluator", evaluator->getClassName().c_str());
  40. }
  41. TEST_P(SectionPairRowSingleValueArgumentEvaluatorTest_InvalidArgumentTest, evaluate)
  42. {
  43. EXPECT_THROW(
  44. {
  45. try
  46. {
  47. SectionPairRowSingleValueArgumentEvaluator(GetParam()).evaluate();
  48. }
  49. catch (const IllegalArgumentException &_exception)
  50. {
  51. string actual = _exception.what();
  52. string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" is not a valid section pair single value row!";
  53. ASSERT_STREQ(SectionPairMessageFormatter::getFormattedMessage(expected).c_str(), actual.c_str());
  54. throw;
  55. }
  56. },
  57. IllegalArgumentException);
  58. }
  59. INSTANTIATE_TEST_SUITE_P(InvalidArgumentTest, SectionPairRowSingleValueArgumentEvaluatorTest_InvalidArgumentTest, Values("favourite-color", "a value\n"));
  60. }