IncompleteJsonExceptionTest.cpp 1.6 KB

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