NullPointerEvaluatorTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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-22
  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. protected:
  21. NullPointerArgumentTest() = default;
  22. ~NullPointerArgumentTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. TEST_F(NullPointerArgumentTest, evaluate)
  29. {
  30. EXPECT_THROW(
  31. {
  32. try
  33. {
  34. NullPointerEvaluator{nullptr}.evaluate();
  35. }
  36. catch (const NullPointerException &_exception)
  37. {
  38. string actual = _exception.what();
  39. string expected = _exception.getName() + " thrown - reference in use is null!";
  40. ASSERT_STREQ(expected.c_str(), actual.c_str());
  41. throw;
  42. }
  43. },
  44. NullPointerException);
  45. }
  46. TEST_F(NullPointerArgumentTest, evaluate_dedicated_message)
  47. {
  48. EXPECT_THROW(
  49. {
  50. try
  51. {
  52. NullPointerEvaluator(nullptr, "this reference is not set and causes this exception!").evaluate();
  53. }
  54. catch (const NullPointerException &_exception)
  55. {
  56. string actual = _exception.what();
  57. string expected = _exception.getName() + " thrown - this reference is not set and causes this exception!";
  58. ASSERT_STREQ(expected.c_str(), actual.c_str());
  59. throw;
  60. }
  61. },
  62. NullPointerException);
  63. }
  64. }