NullPointerEvaluatorTest.cpp 1.6 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-02-08
  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. using namespace ::std;
  14. namespace
  15. {
  16. class NullPointerArgumentTest : public ::testing::Test
  17. {
  18. protected:
  19. NullPointerArgumentTest() = default;
  20. ~NullPointerArgumentTest() override = default;
  21. void SetUp() override
  22. {}
  23. void TearDown() override
  24. {}
  25. };
  26. TEST_F(NullPointerArgumentTest, evaluate)
  27. {
  28. EXPECT_THROW(
  29. {
  30. try
  31. {
  32. NullPointerEvaluator{nullptr}.evaluate();
  33. }
  34. catch (const NullPointerException &_exception)
  35. {
  36. string message = _exception.what();
  37. ASSERT_STREQ("NullPointerException thrown - reference in use is null!", message.c_str());
  38. throw;
  39. }
  40. },
  41. NullPointerException);
  42. }
  43. TEST_F(NullPointerArgumentTest, evaluate_dedicated_message)
  44. {
  45. EXPECT_THROW(
  46. {
  47. try
  48. {
  49. NullPointerEvaluator(nullptr, "this reference is not set and causes this exception!").evaluate();
  50. }
  51. catch (const NullPointerException &_exception)
  52. {
  53. string message = _exception.what();
  54. ASSERT_STREQ("NullPointerException thrown - this reference is not set and causes this exception!", message.c_str());
  55. throw;
  56. }
  57. },
  58. NullPointerException);
  59. }
  60. }