NullPointerEvaluatorTest.cpp 1.7 KB

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