NullPointerEvaluatorTest.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-08
  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::NullPointerEvaluator;
  13. using ls::std::core::NullPointerException;
  14. using std::string;
  15. using testing::Test;
  16. namespace
  17. {
  18. class NullPointerArgumentTest : public Test
  19. {
  20. public:
  21. NullPointerArgumentTest() = default;
  22. ~NullPointerArgumentTest() override = default;
  23. };
  24. TEST_F(NullPointerArgumentTest, evaluate)
  25. {
  26. EXPECT_THROW(
  27. {
  28. try
  29. {
  30. NullPointerEvaluator{nullptr}.evaluate();
  31. }
  32. catch (const NullPointerException &_exception)
  33. {
  34. string actual = _exception.what();
  35. string expected = _exception.getName() + " thrown - reference in use is null!";
  36. ASSERT_STREQ(expected.c_str(), actual.c_str());
  37. throw;
  38. }
  39. },
  40. NullPointerException);
  41. }
  42. TEST_F(NullPointerArgumentTest, evaluate_dedicated_message)
  43. {
  44. EXPECT_THROW(
  45. {
  46. try
  47. {
  48. NullPointerEvaluator(nullptr, "this reference is not set and causes this exception!").evaluate();
  49. }
  50. catch (const NullPointerException &_exception)
  51. {
  52. string actual = _exception.what();
  53. string expected = _exception.getName() + " thrown - this reference is not set and causes this exception!";
  54. ASSERT_STREQ(expected.c_str(), actual.c_str());
  55. throw;
  56. }
  57. },
  58. NullPointerException);
  59. }
  60. }