NullPointerEvaluatorTest.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 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 actual = _exception.what();
  37. string expected = _exception.getName() + " thrown - reference in use is null!";
  38. ASSERT_STREQ(expected.c_str(), actual.c_str());
  39. throw;
  40. }
  41. },
  42. NullPointerException);
  43. }
  44. TEST_F(NullPointerArgumentTest, evaluate_dedicated_message)
  45. {
  46. EXPECT_THROW(
  47. {
  48. try
  49. {
  50. NullPointerEvaluator(nullptr, "this reference is not set and causes this exception!").evaluate();
  51. }
  52. catch (const NullPointerException &_exception)
  53. {
  54. string actual = _exception.what();
  55. string expected = _exception.getName() + " thrown - this reference is not set and causes this exception!";
  56. ASSERT_STREQ(expected.c_str(), actual.c_str());
  57. throw;
  58. }
  59. },
  60. NullPointerException);
  61. }
  62. }