NullPointerArgumentEvaluatorTest.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2023-02-08
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <gtest/gtest.h>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <memory>
  13. #include <string>
  14. using ls::standard::core::IllegalArgumentException;
  15. using ls::standard::core::NullPointerArgumentEvaluator;
  16. using std::shared_ptr;
  17. using std::string;
  18. using testing::Test;
  19. namespace
  20. {
  21. class NullPointerArgumentEvaluatorTest : public Test
  22. {
  23. public:
  24. NullPointerArgumentEvaluatorTest() = default;
  25. ~NullPointerArgumentEvaluatorTest() override = default;
  26. };
  27. TEST_F(NullPointerArgumentEvaluatorTest, evaluate_raw_pointer)
  28. {
  29. EXPECT_THROW(
  30. {
  31. try
  32. {
  33. NullPointerArgumentEvaluator{nullptr}.evaluate();
  34. }
  35. catch (const IllegalArgumentException &_exception)
  36. {
  37. string actual = _exception.what();
  38. string expected = _exception.getName() + " thrown - passed argument is null!";
  39. ASSERT_STREQ(expected.c_str(), actual.c_str());
  40. throw;
  41. }
  42. },
  43. IllegalArgumentException);
  44. }
  45. TEST_F(NullPointerArgumentEvaluatorTest, evaluate_raw_pointer_with_dedicated_message)
  46. {
  47. EXPECT_THROW(
  48. {
  49. try
  50. {
  51. NullPointerArgumentEvaluator(nullptr, "this reference is null!").evaluate();
  52. }
  53. catch (const IllegalArgumentException &_exception)
  54. {
  55. string actual = _exception.what();
  56. string expected = _exception.getName() + " thrown - this reference is null!";
  57. ASSERT_STREQ(expected.c_str(), actual.c_str());
  58. throw;
  59. }
  60. },
  61. IllegalArgumentException);
  62. }
  63. TEST_F(NullPointerArgumentEvaluatorTest, evaluate)
  64. {
  65. shared_ptr<void> value{};
  66. EXPECT_THROW(
  67. {
  68. try
  69. {
  70. NullPointerArgumentEvaluator{value}.evaluate();
  71. }
  72. catch (const IllegalArgumentException &_exception)
  73. {
  74. string actual = _exception.what();
  75. string expected = _exception.getName() + " thrown - passed argument is null!";
  76. ASSERT_STREQ(expected.c_str(), actual.c_str());
  77. throw;
  78. }
  79. },
  80. IllegalArgumentException);
  81. }
  82. TEST_F(NullPointerArgumentEvaluatorTest, evaluate_dedicated_message)
  83. {
  84. shared_ptr<void> value{};
  85. EXPECT_THROW(
  86. {
  87. try
  88. {
  89. NullPointerArgumentEvaluator(value, "this reference is null!").evaluate();
  90. }
  91. catch (const IllegalArgumentException &_exception)
  92. {
  93. const string actual = _exception.what();
  94. const string expected = _exception.getName() + " thrown - this reference is null!";
  95. ASSERT_STREQ(expected.c_str(), actual.c_str());
  96. throw;
  97. }
  98. },
  99. IllegalArgumentException);
  100. }
  101. }