Browse Source

Fix memory leaks during test execution

Patrick-Christopher Mattulat 2 years ago
parent
commit
1b834e3849

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

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-27
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const EventNotHandledException &_exception)
           {
-            EXPECT_STREQ("EventNotHandledException thrown - event was not handled - nothing happened!", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("EventNotHandledException thrown - event was not handled - nothing happened!", message.c_str());
             throw;
           }
         },

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

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-27
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const EventNotSubscribedException &_exception)
           {
-            EXPECT_STREQ("EventNotSubscribedException thrown - event was not subscribed!", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("EventNotSubscribedException thrown - event was not subscribed!", message.c_str());
             throw;
           }
         },

+ 1 - 1
test/cases/core/exception/ExceptionMessageTest.cpp

@@ -36,7 +36,7 @@ namespace
     char *characterPointer = message.toCharacterPointer();
     ASSERT_STREQ(text.c_str(), characterPointer);
 
-    delete[] characterPointer;
+    delete characterPointer;
   }
 
   TEST_F(ExceptionMessageTest, toCharacterPointer_empty)

+ 5 - 2
test/cases/core/exception/FileNotFoundExceptionTest.cpp

@@ -9,6 +9,7 @@
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const FileNotFoundException &_exception)
           {
-            EXPECT_STREQ("FileNotFoundException thrown - file not found!", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("FileNotFoundException thrown - file not found!", message.c_str());
             throw;
           }
         },
@@ -55,7 +57,8 @@ namespace
           }
           catch (const FileNotFoundException &_exception)
           {
-            EXPECT_STREQ(R"(FileNotFoundException thrown - "settings.txt" not found!)", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ(R"(FileNotFoundException thrown - "settings.txt" not found!)", message.c_str());
             throw;
           }
         },

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

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-01
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const FileOperationException &_exception)
           {
-            EXPECT_STREQ("FileOperationException thrown - file operation failed!", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("FileOperationException thrown - file operation failed!", message.c_str());
             throw;
           }
         },

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

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-01
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const IllegalArgumentException &_exception)
           {
-            EXPECT_STREQ("IllegalArgumentException thrown - passed argument is not valid!", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("IllegalArgumentException thrown - passed argument is not valid!", message.c_str());
             throw;
           }
         },

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

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-01
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const IllegalArithmeticOperationException &_exception)
           {
-            EXPECT_STREQ("IllegalArithmeticOperationException thrown - arithmetic operation is not allowed!", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("IllegalArithmeticOperationException thrown - arithmetic operation is not allowed!", message.c_str());
             throw;
           }
         },

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

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-01
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const IncompleteJsonException &_exception)
           {
-            EXPECT_STREQ("IncompleteJsonException thrown - this JSON string is incomplete.", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("IncompleteJsonException thrown - this JSON string is incomplete.", message.c_str());
             throw;
           }
         },

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

@@ -3,12 +3,13 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2021-05-01
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <gtest/gtest.h>
 #include <ls-std/ls-std-core.hpp>
+#include <string>
 
 using namespace ls::std::core;
 
@@ -38,7 +39,8 @@ namespace
           }
           catch (const NullPointerException &_exception)
           {
-            EXPECT_STREQ("NullPointerException thrown - reference is null!", _exception.what());
+            ::std::string message = _exception.what();
+            EXPECT_STREQ("NullPointerException thrown - reference is null!", message.c_str());
             throw;
           }
         },