ソースを参照

Add missing exception tests

- add tests for all exceptions
- improved message for IllegalArithmeticOperationException
Patrick-Christopher Mattulat 3 年 前
コミット
07b1321da1

+ 6 - 1
CMakeLists.txt

@@ -174,7 +174,12 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/boxing/SerializableJSONStringFactoryTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/event/SerializableJSONEventFactoryTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/factory/SerializableTestFactory.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/IncompleteJsonExceptionTest.cpp)
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/FileNotFoundExceptionTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/FileOperationExceptionTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/IllegalArgumentExceptionTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/IllegalArithmeticOperationExceptionTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/IncompleteJsonExceptionTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/NullPointerExceptionTest.cpp)
 endif ()
 
 ##########################################################

+ 2 - 2
include/ls_std/exception/IllegalArithmeticOperationException.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2021-04-23
+ * Changed:         2021-05-01
  *
  * */
 
@@ -22,7 +22,7 @@ namespace ls_std
 
       const char *what() const noexcept override
       {
-        return "IllegalArithmeticOperationException thrown - arithmetic operation is not valid!";
+        return "IllegalArithmeticOperationException thrown - arithmetic operation is not allowed!";
       }
   };
 }

+ 2 - 1
include/ls_std/ls_std.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-29
- * Changed:         2021-04-30
+ * Changed:         2021-05-01
  *
  * */
 
@@ -30,6 +30,7 @@
 #include "exception/FileOperationException.hpp"
 #include "exception/IllegalArgumentException.hpp"
 #include "exception/IllegalArithmeticOperationException.hpp"
+#include "exception/IncompleteJsonException.hpp"
 #include "exception/NullPointerException.hpp"
 
 #include "io/logging/LogLevel.hpp"

+ 43 - 0
test/cases/exception/FileNotFoundExceptionTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-05-01
+ * Changed:         2021-05-01
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std.hpp>
+
+namespace
+{
+  class FileNotFoundExceptionTest : public ::testing::Test
+  {
+    protected:
+
+      FileNotFoundExceptionTest() = default;
+      ~FileNotFoundExceptionTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(FileNotFoundExceptionTest, constructor)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     throw ls_std::FileNotFoundException{};
+                   }
+                   catch (const ls_std::FileNotFoundException &_exception)
+                   {
+                     EXPECT_STREQ("FileNotFoundException thrown - file not found!", _exception.what());
+                     throw;
+                   }
+                 }, ls_std::FileNotFoundException);
+  }
+}

+ 43 - 0
test/cases/exception/FileOperationExceptionTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-05-01
+ * Changed:         2021-05-01
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std.hpp>
+
+namespace
+{
+  class FileOperationExceptionTest : public ::testing::Test
+  {
+    protected:
+
+      FileOperationExceptionTest() = default;
+      ~FileOperationExceptionTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(FileOperationExceptionTest, constructor)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     throw ls_std::FileOperationException{};
+                   }
+                   catch (const ls_std::FileOperationException &_exception)
+                   {
+                     EXPECT_STREQ("FileOperationException thrown - file operation failed!", _exception.what());
+                     throw;
+                   }
+                 }, ls_std::FileOperationException);
+  }
+}

+ 43 - 0
test/cases/exception/IllegalArgumentExceptionTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-05-01
+ * Changed:         2021-05-01
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std.hpp>
+
+namespace
+{
+  class IllegalArgumentExceptionTest : public ::testing::Test
+  {
+    protected:
+
+      IllegalArgumentExceptionTest() = default;
+      ~IllegalArgumentExceptionTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(IllegalArgumentExceptionTest, constructor)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     throw ls_std::IllegalArgumentException{};
+                   }
+                   catch (const ls_std::IllegalArgumentException &_exception)
+                   {
+                     EXPECT_STREQ("IllegalArgumentException thrown - passed argument is not valid!", _exception.what());
+                     throw;
+                   }
+                 }, ls_std::IllegalArgumentException);
+  }
+}

+ 43 - 0
test/cases/exception/IllegalArithmeticOperationExceptionTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-05-01
+ * Changed:         2021-05-01
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std.hpp>
+
+namespace
+{
+  class IllegalArithmeticOperationExceptionTest : public ::testing::Test
+  {
+    protected:
+
+      IllegalArithmeticOperationExceptionTest() = default;
+      ~IllegalArithmeticOperationExceptionTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(IllegalArithmeticOperationExceptionTest, constructor)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     throw ls_std::IllegalArithmeticOperationException{};
+                   }
+                   catch (const ls_std::IllegalArithmeticOperationException &_exception)
+                   {
+                     EXPECT_STREQ("IllegalArithmeticOperationException thrown - arithmetic operation is not allowed!", _exception.what());
+                     throw;
+                   }
+                 }, ls_std::IllegalArithmeticOperationException);
+  }
+}

+ 0 - 1
test/cases/exception/IncompleteJsonExceptionTest.cpp

@@ -9,7 +9,6 @@
 
 #include <gtest/gtest.h>
 #include <ls_std/ls_std.hpp>
-#include <ls_std_test.hpp>
 
 namespace
 {

+ 43 - 0
test/cases/exception/NullPointerExceptionTest.cpp

@@ -0,0 +1,43 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-05-01
+ * Changed:         2021-05-01
+ *
+ * */
+
+#include <gtest/gtest.h>
+#include <ls_std/ls_std.hpp>
+
+namespace
+{
+  class NullPointerExceptionTest : public ::testing::Test
+  {
+    protected:
+
+      NullPointerExceptionTest() = default;
+      ~NullPointerExceptionTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(NullPointerExceptionTest, constructor)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     throw ls_std::NullPointerException{};
+                   }
+                   catch (const ls_std::NullPointerException &_exception)
+                   {
+                     EXPECT_STREQ("NullPointerException thrown - reference is null!", _exception.what());
+                     throw;
+                   }
+                 }, ls_std::NullPointerException);
+  }
+}