diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-10-18 16:45:02 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-10-18 16:48:06 +0300 |
commit | 3edae09eaaa6e4b7dca9bac4c98ad23edf9d08e5 (patch) | |
tree | 13fd73822fb5a141ac737ca9856f8953e3c14197 /source/blender/blenkernel/intern/asset_library_service_test.cc | |
parent | 729b2d026d1379de92908b16e7492a509721c796 (diff) |
Asset Library Service: fix failing unit test
On GCC in release mode (and maybe also debug mode without ASAN enabled),
allocating an `AssetLibraryService` will reuse the space that should
have just been freed. This made a test fail, as it was testing that new
memory was allocated and not some old instance reused.
To ensure that the calls that should allocate a new block of memory
return a unique pointer, I added some dummy allocation to the test.
No functional changes to Blender
Diffstat (limited to 'source/blender/blenkernel/intern/asset_library_service_test.cc')
-rw-r--r-- | source/blender/blenkernel/intern/asset_library_service_test.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/asset_library_service_test.cc b/source/blender/blenkernel/intern/asset_library_service_test.cc index 6acbe193eb7..e2d7a7680b6 100644 --- a/source/blender/blenkernel/intern/asset_library_service_test.cc +++ b/source/blender/blenkernel/intern/asset_library_service_test.cc @@ -60,12 +60,21 @@ TEST_F(AssetLibraryServiceTest, get_destroy) << "Calling twice without destroying in between should return the same instance."; AssetLibraryService::destroy(); + + /* On GCC in release mode (and maybe also debug mode without ASAN enabled), allocating an + * #AssetLibraryService will reuse the space that should have just been freed in the above + * destroy() call. To see that the get() call below really allocates a new object, allocate a + * dummy block of memory first. */ + AssetLibraryService *dummy_pointer = new AssetLibraryService(); + EXPECT_NE(service, AssetLibraryService::get()) << "Calling twice with destroying in between should return a new instance."; /* This should not crash. */ AssetLibraryService::destroy(); AssetLibraryService::destroy(); + + delete dummy_pointer; } TEST_F(AssetLibraryServiceTest, library_pointers) @@ -80,11 +89,20 @@ TEST_F(AssetLibraryServiceTest, library_pointers) << "Calling twice without destroying in between should return the same instance."; AssetLibraryService::destroy(); + + /* On GCC in release mode (and maybe also debug mode without ASAN enabled), allocating an + * #AssetLibraryService will reuse the space that should have just been freed in the above + * destroy() call. To see that the get() call below really allocates a new object, allocate a + * dummy block of memory first. */ + AssetLibrary *dummy_pointer = new AssetLibrary(); + service = AssetLibraryService::get(); EXPECT_NE(lib, service->get_asset_library_on_disk(asset_library_root_)) << "Calling twice with destroying in between should return a new instance."; EXPECT_NE(curfile_lib, service->get_asset_library_current_file()) << "Calling twice with destroying in between should return a new instance."; + + delete dummy_pointer; } TEST_F(AssetLibraryServiceTest, catalogs_loaded) |