Kaynağa Gözat

Merge branch 'not-implemented-exception' of public/ls-standard-library into development

patrick-christopher.mattulat 1 yıl önce
ebeveyn
işleme
6442c4273a

+ 2 - 0
CMakeLists.txt

@@ -141,6 +141,7 @@ set(SOURCE_FILES_CORE
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/IllegalArithmeticOperationException.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/IncompleteJsonException.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/IndexOutOfBoundsException.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/NotImplementedException.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/exception/NullPointerException.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/interface/IBoxing.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/core/interface/IEncoding.cpp
@@ -251,6 +252,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/IllegalArithmeticOperationExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/IncompleteJsonExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/IndexOutOfBoundsExceptionTest.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/NotImplementedExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/NullPointerExceptionTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/ClassTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/ConditionalFunctionExecutorTest.cpp

+ 1 - 1
README.md

@@ -34,7 +34,7 @@ A __Date__ class comes with this submodule, which you can use to represent a dat
 
 #### Features ####
 
-- no comment
+- added NotImplementedException class, which can be thrown in case a method is provided, but not implemented
 
 #### Improvements ####
 

+ 31 - 0
include/ls-std/core/exception/NotImplementedException.hpp

@@ -0,0 +1,31 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-27
+* Changed:         2023-03-27
+*
+* */
+
+#ifndef LS_STD_NOT_IMPLEMENTED_EXCEPTION_HPP
+#define LS_STD_NOT_IMPLEMENTED_EXCEPTION_HPP
+
+#include "Exception.hpp"
+#include <ls-std/os/dynamic-goal.hpp>
+#include <string>
+
+namespace ls::std::core
+{
+  class LS_STD_DYNAMIC_GOAL NotImplementedException : public ls::std::core::Exception
+  {
+    public:
+
+      NotImplementedException();
+      explicit NotImplementedException(::std::string _message);
+      ~NotImplementedException() noexcept override;
+
+      [[nodiscard]] const char *what() const noexcept override;
+  };
+}
+
+#endif

+ 2 - 1
include/ls-std/ls-std-core.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-13
- * Changed:         2023-02-22
+ * Changed:         2023-03-27
  *
  * */
 
@@ -25,6 +25,7 @@
 #include <ls-std/core/exception/IllegalArithmeticOperationException.hpp>
 #include <ls-std/core/exception/IncompleteJsonException.hpp>
 #include <ls-std/core/exception/IndexOutOfBoundsException.hpp>
+#include <ls-std/core/exception/NotImplementedException.hpp>
 #include <ls-std/core/exception/NullPointerException.hpp>
 
 #include <ls-std/core/interface/IBoxing.hpp>

+ 44 - 0
source/ls-std/core/exception/NotImplementedException.cpp

@@ -0,0 +1,44 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-27
+* Changed:         2023-03-27
+*
+* */
+
+#include <ls-std/core/exception/ExceptionMessage.hpp>
+#include <ls-std/core/exception/NotImplementedException.hpp>
+#include <string>
+
+using ls::std::core::Exception;
+using ls::std::core::ExceptionMessage;
+using ls::std::core::NotImplementedException;
+using std::move;
+using std::string;
+
+NotImplementedException::NotImplementedException() : Exception("NotImplementedException")
+{}
+
+NotImplementedException::NotImplementedException(string _message) : NotImplementedException()
+{
+  this->message = ::move(_message);
+}
+
+NotImplementedException::~NotImplementedException() noexcept = default;
+
+const char *NotImplementedException::what() const noexcept
+{
+  string concatenatedMessage = this->name + " thrown - ";
+
+  if (this->message.empty())
+  {
+    concatenatedMessage = concatenatedMessage + "method is not implemented and should not be used!";
+  }
+  else
+  {
+    concatenatedMessage = concatenatedMessage + this->message;
+  }
+
+  return ExceptionMessage{concatenatedMessage}.toCharacterPointer();
+}

+ 72 - 0
test/cases/core/exception/NotImplementedExceptionTest.cpp

@@ -0,0 +1,72 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-27
+* Changed:         2023-03-27
+*
+* */
+
+#include <gtest/gtest.h>
+#include <ls-std/ls-std-core.hpp>
+#include <string>
+
+using ls::std::core::NotImplementedException;
+using std::string;
+using testing::Test;
+
+namespace
+{
+  class NotImplementedExceptionTest : public Test
+  {
+    public:
+
+      NotImplementedExceptionTest() = default;
+      ~NotImplementedExceptionTest() override = default;
+  };
+
+  TEST_F(NotImplementedExceptionTest, constructor)
+  {
+    EXPECT_THROW(
+        {
+          try
+          {
+            throw NotImplementedException{};
+          }
+          catch (const NotImplementedException &_exception)
+          {
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - method is not implemented and should not be used!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
+            throw;
+          }
+        },
+        NotImplementedException);
+  }
+
+  TEST_F(NotImplementedExceptionTest, constructor_dedicated_message)
+  {
+    EXPECT_THROW(
+        {
+          try
+          {
+            throw NotImplementedException{R"lit(method "marshal" is not implemented!)lit"};
+          }
+          catch (const NotImplementedException &_exception)
+          {
+            string actual = _exception.what();
+            string expected = _exception.getName() + R"lit( thrown - method "marshal" is not implemented!)lit";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
+            throw;
+          }
+        },
+        NotImplementedException);
+  }
+
+  TEST_F(NotImplementedExceptionTest, getName)
+  {
+    ASSERT_STREQ("NotImplementedException", NotImplementedException{}.getName().c_str());
+  }
+}