IncompleteJsonExceptionTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2021-05-01
  6. * Changed: 2023-03-25
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <string>
  12. using ls::std::core::IncompleteJsonException;
  13. using std::string;
  14. using testing::Test;
  15. namespace
  16. {
  17. class IncompleteJsonExceptionTest : public Test
  18. {
  19. public:
  20. IncompleteJsonExceptionTest() = default;
  21. ~IncompleteJsonExceptionTest() override = default;
  22. };
  23. TEST_F(IncompleteJsonExceptionTest, constructor)
  24. {
  25. EXPECT_THROW(
  26. {
  27. try
  28. {
  29. throw IncompleteJsonException{};
  30. }
  31. catch (const IncompleteJsonException &_exception)
  32. {
  33. string actual = _exception.what();
  34. string expected = _exception.getName() + " thrown - this JSON string is incomplete.";
  35. EXPECT_STREQ(expected.c_str(), actual.c_str());
  36. throw;
  37. }
  38. },
  39. IncompleteJsonException);
  40. }
  41. TEST_F(IncompleteJsonExceptionTest, constructor_dedicated_message)
  42. {
  43. EXPECT_THROW(
  44. {
  45. try
  46. {
  47. throw IncompleteJsonException{"incomplete: {\"name\":\"}"};
  48. }
  49. catch (const IncompleteJsonException &_exception)
  50. {
  51. string actual = _exception.what();
  52. string expected = _exception.getName() + " thrown - incomplete: {\"name\":\"}";
  53. EXPECT_STREQ(expected.c_str(), actual.c_str());
  54. throw;
  55. }
  56. },
  57. IncompleteJsonException);
  58. }
  59. TEST_F(IncompleteJsonExceptionTest, getName)
  60. {
  61. ASSERT_STREQ("IncompleteJsonException", IncompleteJsonException{}.getName().c_str());
  62. }
  63. }