summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsniukalov <sniukaov@luxoft.com>2020-01-11 10:37:32 +0200
committersniukalov <sniukaov@luxoft.com>2020-01-11 10:37:59 +0200
commita61626cf8376d89f5d452f56431c17ce9c2de282 (patch)
treedf87ca0c641544fa9130a6cee39f7afa9a88e2fd
parent05fdb9006ef9c337c49474d0996789124e2401d7 (diff)
downloadsdl_core-fix/fix_crash_due_to_so_cleanup.tar.gz
Added test for double data cleanupfix/fix_crash_due_to_so_cleanup
-rw-r--r--src/components/smart_objects/test/CMakeLists.txt6
-rw-r--r--src/components/smart_objects/test/SmartObjectUnit_test.cc24
2 files changed, 30 insertions, 0 deletions
diff --git a/src/components/smart_objects/test/CMakeLists.txt b/src/components/smart_objects/test/CMakeLists.txt
index e0cc37e104..9c89079d94 100644
--- a/src/components/smart_objects/test/CMakeLists.txt
+++ b/src/components/smart_objects/test/CMakeLists.txt
@@ -53,5 +53,11 @@ set(EXCLUDE_PATHS
SmartObjectConvertionTime_test.cc
)
+# Enable detect Double-free, invalid free
+# AddressSanitizer is a fast memory error detector.
+# It consists of a compiler instrumentation module and a run-time library.
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
+set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
+
collect_sources(SOURCES "${CMAKE_CURRENT_SOURCE_DIR}" "${EXCLUDE_PATHS}")
create_test(smart_object_test "${SOURCES}" "${LIBRARIES}")
diff --git a/src/components/smart_objects/test/SmartObjectUnit_test.cc b/src/components/smart_objects/test/SmartObjectUnit_test.cc
index 2c03d8a329..72f96ef939 100644
--- a/src/components/smart_objects/test/SmartObjectUnit_test.cc
+++ b/src/components/smart_objects/test/SmartObjectUnit_test.cc
@@ -31,6 +31,7 @@
*/
#include "gmock/gmock.h"
+#define final // Disable error: cannot derive from ‘final’ base
#include "smart_objects/smart_object.h"
namespace test {
@@ -585,6 +586,29 @@ TEST(MapEraseTest, SmartObjectTest) {
}
// TODO: Add a test to check accessing an array at strange indexes.
+TEST(DoubleCleanupDataTest, SmartObjectTest) {
+ class DerivedSmartObject : public SmartObject {
+ public:
+ DerivedSmartObject(SmartType Type) : SmartObject(Type) {}
+ using SmartObject::operator=;
+ void cleanup_data() {
+ SmartObject::cleanup_data();
+ }
+ };
+
+ DerivedSmartObject obj(SmartType_String);
+ ASSERT_EQ(SmartType_String, obj.getType());
+
+ obj = "test string_value";
+ ASSERT_EQ(std::string("test string_value"), obj.asString());
+
+ obj.cleanup_data();
+ ASSERT_EQ(std::string(""), obj.asCharArray());
+
+ obj.cleanup_data();
+ ASSERT_EQ(std::string(""), obj.asCharArray());
+}
+
} // namespace smart_object_test
} // namespace components
} // namespace test