FileOperationExceptionTest.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 ls::std::core::FileOperationException;
  13. using std::string;
  14. using testing::Test;
  15. namespace
  16. {
  17. class FileOperationExceptionTest : public Test
  18. {
  19. protected:
  20. FileOperationExceptionTest() = default;
  21. ~FileOperationExceptionTest() override = default;
  22. void SetUp() override
  23. {}
  24. void TearDown() override
  25. {}
  26. };
  27. TEST_F(FileOperationExceptionTest, constructor)
  28. {
  29. EXPECT_THROW(
  30. {
  31. try
  32. {
  33. throw FileOperationException{};
  34. }
  35. catch (const FileOperationException &_exception)
  36. {
  37. string actual = _exception.what();
  38. string expected = _exception.getName() + " thrown - file operation failed!";
  39. EXPECT_STREQ(expected.c_str(), actual.c_str());
  40. throw;
  41. }
  42. },
  43. FileOperationException);
  44. }
  45. TEST_F(FileOperationExceptionTest, constructor_dedicated_message)
  46. {
  47. EXPECT_THROW(
  48. {
  49. try
  50. {
  51. throw FileOperationException{R"(creating directory "tmp")"};
  52. }
  53. catch (const FileOperationException &_exception)
  54. {
  55. string actual = _exception.what();
  56. string expected = _exception.getName() + R"( thrown - creating directory "tmp")";
  57. EXPECT_STREQ(expected.c_str(), actual.c_str());
  58. throw;
  59. }
  60. },
  61. FileOperationException);
  62. }
  63. TEST_F(FileOperationExceptionTest, getName)
  64. {
  65. ASSERT_STREQ("FileOperationException", FileOperationException{}.getName().c_str());
  66. }
  67. }