瀏覽代碼

Add IncompleteJsonException class

This exception can be used to raise the concern that a JSON string might not be complete.
Patrick-Christopher Mattulat 3 年之前
父節點
當前提交
ce3881a95a

+ 2 - 1
CMakeLists.txt

@@ -173,7 +173,8 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/factory/serialization/boxing/SerializableJSONLongFactoryTest.cpp
             ${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/classes/factory/SerializableTestFactory.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/exception/IncompleteJsonExceptionTest.cpp)
 endif ()
 
 ##########################################################

+ 30 - 0
include/ls_std/exception/IncompleteJsonException.hpp

@@ -0,0 +1,30 @@
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2021-04-30
+ * Changed:         2021-05-01
+ *
+ * */
+
+#ifndef LS_STD_INCOMPLETE_JSON_EXCEPTION_HPP
+#define LS_STD_INCOMPLETE_JSON_EXCEPTION_HPP
+
+#include <exception>
+
+namespace ls_std
+{
+  class IncompleteJsonException : public std::exception
+  {
+    public:
+
+      explicit IncompleteJsonException() = default;
+
+      const char *what() const noexcept override
+      {
+        return "IncompleteJsonException thrown - this JSON string is incomplete.";
+      }
+  };
+}
+
+#endif

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

@@ -0,0 +1,44 @@
+/*
+ * 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>
+#include <ls_std_test.hpp>
+
+namespace
+{
+  class IncompleteJsonExceptionTest : public ::testing::Test
+  {
+    protected:
+
+      IncompleteJsonExceptionTest() = default;
+      ~IncompleteJsonExceptionTest() override = default;
+
+      void SetUp() override
+      {}
+
+      void TearDown() override
+      {}
+  };
+
+  TEST_F(IncompleteJsonExceptionTest, constructor)
+  {
+    EXPECT_THROW({
+                   try
+                   {
+                     throw ls_std::IncompleteJsonException{};
+                   }
+                   catch (const ls_std::IncompleteJsonException &_exception)
+                   {
+                     EXPECT_STREQ("IncompleteJsonException thrown - this JSON string is incomplete.", _exception.what());
+                     throw;
+                   }
+                 }, ls_std::IncompleteJsonException);
+  }
+}