diff options
author | Serhii Niukalov (GitHub) <36993782+SNiukalov@users.noreply.github.com> | 2020-01-13 16:57:23 +0200 |
---|---|---|
committer | Collin <iCollin@users.noreply.github.com> | 2020-01-13 09:57:23 -0500 |
commit | 8752616b531c96f985c41870e9bd0f05737831ca (patch) | |
tree | df87ca0c641544fa9130a6cee39f7afa9a88e2fd | |
parent | 05fdb9006ef9c337c49474d0996789124e2401d7 (diff) | |
download | sdl_core-8752616b531c96f985c41870e9bd0f05737831ca.tar.gz |
Added test for double data cleanup (#3146)
-rw-r--r-- | src/components/smart_objects/test/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/components/smart_objects/test/SmartObjectUnit_test.cc | 24 |
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 |