IllegalArithmeticOperationExceptionTest.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2021-05-01
  6. * Changed: 2024-05-31
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <string>
  12. using ls::std::core::IllegalArithmeticOperationException;
  13. using std::string;
  14. using testing::Test;
  15. namespace
  16. {
  17. class IllegalArithmeticOperationExceptionTest : public Test
  18. {
  19. public:
  20. IllegalArithmeticOperationExceptionTest() = default;
  21. ~IllegalArithmeticOperationExceptionTest() override = default;
  22. };
  23. TEST_F(IllegalArithmeticOperationExceptionTest, constructor)
  24. {
  25. EXPECT_THROW(
  26. {
  27. try
  28. {
  29. throw IllegalArithmeticOperationException{};
  30. }
  31. catch (const IllegalArithmeticOperationException &_exception)
  32. {
  33. const string actual = _exception.what();
  34. const string expected = _exception.getName() + " thrown - arithmetic operation is not allowed!";
  35. EXPECT_STREQ(expected.c_str(), actual.c_str());
  36. throw;
  37. }
  38. },
  39. IllegalArithmeticOperationException);
  40. }
  41. TEST_F(IllegalArithmeticOperationExceptionTest, constructor_dedicated_message)
  42. {
  43. EXPECT_THROW(
  44. {
  45. try
  46. {
  47. throw IllegalArithmeticOperationException{"division by zero"};
  48. }
  49. catch (const IllegalArithmeticOperationException &_exception)
  50. {
  51. const string actual = _exception.what();
  52. const string expected = _exception.getName() + " thrown - division by zero";
  53. EXPECT_STREQ(expected.c_str(), actual.c_str());
  54. throw;
  55. }
  56. },
  57. IllegalArithmeticOperationException);
  58. }
  59. TEST_F(IllegalArithmeticOperationExceptionTest, getName)
  60. {
  61. ASSERT_STREQ("IllegalArithmeticOperationException", IllegalArithmeticOperationException{}.getName().c_str());
  62. }
  63. }