Browse Source

Add exception reflection to all exception usages

Patrick-Christopher Mattulat 1 year ago
parent
commit
5d36b2dfcd
23 changed files with 123 additions and 71 deletions
  1. 2 2
      include/ls-std/core/exception/Exception.hpp
  2. 1 1
      source/ls-std/core/exception/Exception.cpp
  3. 9 5
      test/cases/core/evaluator/EmptyStringArgumentEvaluatorTest.cpp
  4. 9 5
      test/cases/core/evaluator/IndexOutOfBoundsEvaluatorTest.cpp
  5. 9 5
      test/cases/core/evaluator/NullPointerArgumentEvaluatorTest.cpp
  6. 9 5
      test/cases/core/evaluator/NullPointerEvaluatorTest.cpp
  7. 8 4
      test/cases/core/exception/EventNotHandledExceptionTest.cpp
  8. 8 4
      test/cases/core/exception/EventNotSubscribedExceptionTest.cpp
  9. 8 4
      test/cases/core/exception/FileNotFoundExceptionTest.cpp
  10. 8 4
      test/cases/core/exception/FileOperationExceptionTest.cpp
  11. 8 4
      test/cases/core/exception/IllegalArgumentExceptionTest.cpp
  12. 8 4
      test/cases/core/exception/IllegalArithmeticOperationExceptionTest.cpp
  13. 8 4
      test/cases/core/exception/IncompleteJsonExceptionTest.cpp
  14. 8 4
      test/cases/core/exception/IndexOutOfBoundsExceptionTest.cpp
  15. 8 4
      test/cases/core/exception/NullPointerExceptionTest.cpp
  16. 2 2
      test/cases/io/evaluator/FileExistenceEvaluatorTest.cpp
  17. 2 2
      test/cases/io/section-pair/evaluator/SectionPairIdentifierArgumentEvaluatorTest.cpp
  18. 1 1
      test/cases/io/section-pair/evaluator/SectionPairRowArgumentEvaluatorTest.cpp
  19. 1 1
      test/cases/io/section-pair/evaluator/SectionPairRowListValueArgumentEvaluatorTest.cpp
  20. 1 1
      test/cases/io/section-pair/evaluator/SectionPairRowSingleValueArgumentEvaluatorTest.cpp
  21. 1 1
      test/cases/io/section-pair/evaluator/SectionPairSectionArgumentEvaluatorTest.cpp
  22. 2 2
      test/cases/io/section-pair/evaluator/SectionPairValueArgumentEvaluatorTest.cpp
  23. 2 2
      test/cases/io/section-pair/reader/SectionPairFileReaderTest.cpp

+ 2 - 2
include/ls-std/core/exception/Exception.hpp

@@ -22,8 +22,8 @@ namespace ls::std::core
 
       explicit Exception(::std::string _name);
       ~Exception() override;
-      
-      [[nodiscard]] ::std::string getName();
+
+      [[nodiscard]] ::std::string getName() const;
       [[nodiscard]] const char *what() const noexcept override;
 
     protected:

+ 1 - 1
source/ls-std/core/exception/Exception.cpp

@@ -14,7 +14,7 @@ ls::std::core::Exception::Exception(::std::string _name) : name(::std::move(_nam
 
 ls::std::core::Exception::~Exception() = default;
 
-::std::string ls::std::core::Exception::getName()
+::std::string ls::std::core::Exception::getName() const
 {
   return this->name;
 }

+ 9 - 5
test/cases/core/evaluator/EmptyStringArgumentEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-08
+* Changed:         2023-02-22
 *
 * */
 
@@ -40,8 +40,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("IllegalArgumentException thrown - passed argument is empty!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - passed argument is empty!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -58,8 +60,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("IllegalArgumentException thrown - this id is empty!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - this id is empty!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 9 - 5
test/cases/core/evaluator/IndexOutOfBoundsEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-10
-* Changed:         2023-02-10
+* Changed:         2023-02-22
 *
 * */
 
@@ -40,8 +40,10 @@ namespace
           }
           catch (const IndexOutOfBoundsException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("IndexOutOfBoundsException thrown - provided index is out of bounds!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - provided index is out of bounds!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -58,8 +60,10 @@ namespace
           }
           catch (const IndexOutOfBoundsException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("IndexOutOfBoundsException thrown - index 3 is not in range of the containers size, which is 2!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - index 3 is not in range of the containers size, which is 2!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 9 - 5
test/cases/core/evaluator/NullPointerArgumentEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-08
+* Changed:         2023-02-22
 *
 * */
 
@@ -40,8 +40,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("IllegalArgumentException thrown - passed argument is null!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - passed argument is null!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -58,8 +60,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("IllegalArgumentException thrown - this reference is null!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - this reference is null!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 9 - 5
test/cases/core/evaluator/NullPointerEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-08
-* Changed:         2023-02-08
+* Changed:         2023-02-22
 *
 * */
 
@@ -40,8 +40,10 @@ namespace
           }
           catch (const NullPointerException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("NullPointerException thrown - reference in use is null!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - reference in use is null!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -58,8 +60,10 @@ namespace
           }
           catch (const NullPointerException &_exception)
           {
-            string message = _exception.what();
-            ASSERT_STREQ("NullPointerException thrown - this reference is not set and causes this exception!", message.c_str());
+            string actual = _exception.what();
+            string expected = _exception.getName() + " thrown - this reference is not set and causes this exception!";
+
+            ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/EventNotHandledExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const EventNotHandledException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("EventNotHandledException thrown - event was not handled - nothing happened!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - event was not handled - nothing happened!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const EventNotHandledException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("EventNotHandledException thrown - id: OPEN_DOOR", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - id: OPEN_DOOR";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/EventNotSubscribedExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const EventNotSubscribedException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("EventNotSubscribedException thrown - event was not subscribed!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - event was not subscribed!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const EventNotSubscribedException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("EventNotSubscribedException thrown - id: OPEN_DOOR", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - id: OPEN_DOOR";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/FileNotFoundExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const FileNotFoundException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("FileNotFoundException thrown - file not found!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - file not found!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const FileNotFoundException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ(R"(FileNotFoundException thrown - "settings.txt" not found!)", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + R"( thrown - "settings.txt" not found!)";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/FileOperationExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const FileOperationException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("FileOperationException thrown - file operation failed!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - file operation failed!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const FileOperationException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ(R"(FileOperationException thrown - creating directory "tmp")", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + R"( thrown - creating directory "tmp")";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/IllegalArgumentExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IllegalArgumentException thrown - passed argument is not valid!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - passed argument is not valid!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IllegalArgumentException thrown - value is empty", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - value is empty";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/IllegalArithmeticOperationExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const IllegalArithmeticOperationException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IllegalArithmeticOperationException thrown - arithmetic operation is not allowed!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - arithmetic operation is not allowed!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const IllegalArithmeticOperationException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IllegalArithmeticOperationException thrown - division by zero", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - division by zero";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/IncompleteJsonExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const IncompleteJsonException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IncompleteJsonException thrown - this JSON string is incomplete.", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - this JSON string is incomplete.";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const IncompleteJsonException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IncompleteJsonException thrown - incomplete: {\"name\":\"}", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - incomplete: {\"name\":\"}";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/IndexOutOfBoundsExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const IndexOutOfBoundsException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IndexOutOfBoundsException thrown - provided index is out of bounds!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - provided index is out of bounds!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const IndexOutOfBoundsException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("IndexOutOfBoundsException thrown - index 3 is out of bounds!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - index 3 is out of bounds!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 8 - 4
test/cases/core/exception/NullPointerExceptionTest.cpp

@@ -39,8 +39,10 @@ namespace
           }
           catch (const NullPointerException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("NullPointerException thrown - reference is null!", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - reference is null!";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },
@@ -57,8 +59,10 @@ namespace
           }
           catch (const NullPointerException &_exception)
           {
-            ::std::string message = _exception.what();
-            EXPECT_STREQ("NullPointerException thrown - _value is null", message.c_str());
+            ::std::string actual = _exception.what();
+            ::std::string expected = _exception.getName() + " thrown - _value is null";
+
+            EXPECT_STREQ(expected.c_str(), actual.c_str());
             throw;
           }
         },

+ 2 - 2
test/cases/io/evaluator/FileExistenceEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-21
-* Changed:         2023-02-21
+* Changed:         2023-02-22
 *
 * */
 
@@ -43,7 +43,7 @@ namespace
           catch (const FileNotFoundException &_exception)
           {
             string actual = _exception.what();
-            string expected = "FileNotFoundException thrown - \"" + GetParam() + "\" does not exist!";
+            string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" does not exist!";
             ;
 
             ASSERT_STREQ(expected.c_str(), actual.c_str());

+ 2 - 2
test/cases/io/section-pair/evaluator/SectionPairIdentifierArgumentEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-09
-* Changed:         2023-02-20
+* Changed:         2023-02-22
 *
 * */
 
@@ -57,7 +57,7 @@ namespace
           catch (const IllegalArgumentException &_exception)
           {
             ::std::string actual = _exception.what();
-            ::std::string expected = "IllegalArgumentException thrown - \"" + GetParam() + "\" is not a valid identifier!";
+            ::std::string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" is not a valid identifier!";
 
             ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;

+ 1 - 1
test/cases/io/section-pair/evaluator/SectionPairRowArgumentEvaluatorTest.cpp

@@ -57,7 +57,7 @@ namespace
           catch (const IllegalArgumentException &_exception)
           {
             ::std::string actual = _exception.what();
-            ::std::string expected = "IllegalArgumentException thrown - \"" + GetParam() + "\" is not a valid section pair row!";
+            ::std::string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" is not a valid section pair row!";
 
             ASSERT_STREQ(SectionPairMessageFormatter::getFormattedMessage(expected).c_str(), actual.c_str());
             throw;

+ 1 - 1
test/cases/io/section-pair/evaluator/SectionPairRowListValueArgumentEvaluatorTest.cpp

@@ -57,7 +57,7 @@ namespace
           catch (const IllegalArgumentException &_exception)
           {
             ::std::string actual = _exception.what();
-            ::std::string expected = "IllegalArgumentException thrown - \"" + GetParam() + "\" is not a valid section pair list value row!";
+            ::std::string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" is not a valid section pair list value row!";
 
             ASSERT_STREQ(SectionPairMessageFormatter::getFormattedMessage(expected).c_str(), actual.c_str());
             throw;

+ 1 - 1
test/cases/io/section-pair/evaluator/SectionPairRowSingleValueArgumentEvaluatorTest.cpp

@@ -57,7 +57,7 @@ namespace
           catch (const IllegalArgumentException &_exception)
           {
             ::std::string actual = _exception.what();
-            ::std::string expected = "IllegalArgumentException thrown - \"" + GetParam() + "\" is not a valid section pair single value row!";
+            ::std::string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" is not a valid section pair single value row!";
 
             ASSERT_STREQ(SectionPairMessageFormatter::getFormattedMessage(expected).c_str(), actual.c_str());
             throw;

+ 1 - 1
test/cases/io/section-pair/evaluator/SectionPairSectionArgumentEvaluatorTest.cpp

@@ -57,7 +57,7 @@ namespace
           catch (const IllegalArgumentException &_exception)
           {
             ::std::string actual = _exception.what();
-            ::std::string expected = "IllegalArgumentException thrown - \"" + GetParam() + "\" is not a valid section!";
+            ::std::string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" is not a valid section!";
 
             ASSERT_STREQ(SectionPairMessageFormatter::getFormattedMessage(expected).c_str(), actual.c_str());
             throw;

+ 2 - 2
test/cases/io/section-pair/evaluator/SectionPairValueArgumentEvaluatorTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-10
-* Changed:         2023-02-20
+* Changed:         2023-02-22
 *
 * */
 
@@ -57,7 +57,7 @@ namespace
           catch (const IllegalArgumentException &_exception)
           {
             ::std::string actual = _exception.what();
-            ::std::string expected = "IllegalArgumentException thrown - \"" + GetParam() + "\" is not a valid value!";
+            ::std::string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" is not a valid value!";
 
             ASSERT_STREQ(expected.c_str(), actual.c_str());
             throw;

+ 2 - 2
test/cases/io/section-pair/reader/SectionPairFileReaderTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-21
-* Changed:         2023-02-21
+* Changed:         2023-02-22
 *
 * */
 
@@ -99,7 +99,7 @@ namespace
           catch (const IllegalArgumentException &_exception)
           {
             string message = _exception.what();
-            string expected = "IllegalArgumentException thrown - \"" + GetParam() + "\" does not have a valid section pair file extension (.txt or .sp)!";
+            string expected = _exception.getName() + " thrown - \"" + GetParam() + "\" does not have a valid section pair file extension (.txt or .sp)!";
 
             ASSERT_STREQ(expected.c_str(), message.c_str());
             throw;