IllegalArithmeticOperationExceptionTest.cpp 2.0 KB

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