[Bf-blender-cvs] [dbd3822329f] master: Cleanup: Extract asset test class into own header
Julian Eisel
noreply at git.blender.org
Mon Dec 12 17:10:23 CET 2022
Commit: dbd3822329f16b24d46ac1336a792cb4f6b8a92e
Author: Julian Eisel
Date: Mon Dec 12 16:06:23 2022 +0100
Branches: master
https://developer.blender.org/rBdbd3822329f16b24d46ac1336a792cb4f6b8a92e
Cleanup: Extract asset test class into own header
This manages setting up asset library directories for testing, which is
useful for testing multiple asset library related compontents. So move
it to a common header. No reason to squeeze everything into one file
then.
===================================================================
M source/blender/asset_system/CMakeLists.txt
M source/blender/asset_system/tests/asset_catalog_test.cc
A source/blender/asset_system/tests/asset_library_test_common.hh
===================================================================
diff --git a/source/blender/asset_system/CMakeLists.txt b/source/blender/asset_system/CMakeLists.txt
index de1f41667d5..6f4e058e78d 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -46,10 +46,12 @@ blender_add_lib(bf_asset_system "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
if(WITH_GTESTS)
set(TEST_SRC
- tests/asset_catalog_test.cc
tests/asset_catalog_path_test.cc
+ tests/asset_catalog_test.cc
tests/asset_library_service_test.cc
tests/asset_library_test.cc
+
+ tests/asset_library_test_common.hh
)
set(TEST_LIB
bf_asset_system
diff --git a/source/blender/asset_system/tests/asset_catalog_test.cc b/source/blender/asset_system/tests/asset_catalog_test.cc
index 0a051bfd51f..144912d62a1 100644
--- a/source/blender/asset_system/tests/asset_catalog_test.cc
+++ b/source/blender/asset_system/tests/asset_catalog_test.cc
@@ -17,6 +17,8 @@
#include "testing/testing.h"
+#include "asset_library_test_common.hh"
+
namespace blender::asset_system::tests {
/* UUIDs from lib/tests/asset_library/blender_assets.cats.txt */
@@ -76,59 +78,8 @@ class TestableAssetCatalogService : public AssetCatalogService {
}
};
-class AssetCatalogTest : public testing::Test {
+class AssetCatalogTest : public AssetLibraryTestBase {
protected:
- CatalogFilePath asset_library_root_;
- CatalogFilePath temp_library_path_;
-
- static void SetUpTestSuite()
- {
- testing::Test::SetUpTestSuite();
- CLG_init();
- }
-
- static void TearDownTestSuite()
- {
- CLG_exit();
- testing::Test::TearDownTestSuite();
- }
-
- void SetUp() override
- {
- const std::string test_files_dir = blender::tests::flags_test_asset_dir();
- if (test_files_dir.empty()) {
- FAIL();
- }
-
- asset_library_root_ = test_files_dir + SEP_STR + "asset_library";
- temp_library_path_ = "";
- }
-
- void TearDown() override
- {
- if (!temp_library_path_.empty()) {
- BLI_delete(temp_library_path_.c_str(), true, true);
- temp_library_path_ = "";
- }
- }
-
- /* Register a temporary path, which will be removed at the end of the test.
- * The returned path ends in a slash. */
- CatalogFilePath use_temp_path()
- {
- BKE_tempdir_init("");
- const CatalogFilePath tempdir = BKE_tempdir_session();
- temp_library_path_ = tempdir + "test-temporary-path" + SEP_STR;
- return temp_library_path_;
- }
-
- CatalogFilePath create_temp_path()
- {
- CatalogFilePath path = use_temp_path();
- BLI_dir_create_recursive(path.c_str());
- return path;
- }
-
void assert_expected_item(const AssetCatalogPath &expected_path,
const AssetCatalogTreeItem &actual_item)
{
diff --git a/source/blender/asset_system/tests/asset_library_test_common.hh b/source/blender/asset_system/tests/asset_library_test_common.hh
new file mode 100644
index 00000000000..d8a8966487f
--- /dev/null
+++ b/source/blender/asset_system/tests/asset_library_test_common.hh
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+
+#pragma once
+
+#include <string>
+
+#include "BKE_appdir.h"
+
+#include "BLI_fileops.h"
+#include "BLI_path_util.h"
+
+#include "CLG_log.h"
+
+#include "testing/testing.h"
+
+namespace blender::asset_system::tests {
+
+/**
+ * Functionality to setup and access directories on disk within which asset library related testing
+ * can be done.
+ */
+class AssetLibraryTestBase : public testing::Test {
+ protected:
+ std::string asset_library_root_;
+ std::string temp_library_path_;
+
+ static void SetUpTestSuite()
+ {
+ testing::Test::SetUpTestSuite();
+ CLG_init();
+ }
+
+ static void TearDownTestSuite()
+ {
+ CLG_exit();
+ testing::Test::TearDownTestSuite();
+ }
+
+ void SetUp() override
+ {
+ const std::string test_files_dir = blender::tests::flags_test_asset_dir();
+ if (test_files_dir.empty()) {
+ FAIL();
+ }
+
+ asset_library_root_ = test_files_dir + SEP_STR + "asset_library";
+ temp_library_path_ = "";
+ }
+
+ void TearDown() override
+ {
+ if (!temp_library_path_.empty()) {
+ BLI_delete(temp_library_path_.c_str(), true, true);
+ temp_library_path_ = "";
+ }
+ }
+
+ /* Register a temporary path, which will be removed at the end of the test.
+ * The returned path ends in a slash. */
+ std::string use_temp_path()
+ {
+ BKE_tempdir_init("");
+ const std::string tempdir = BKE_tempdir_session();
+ temp_library_path_ = tempdir + "test-temporary-path" + SEP_STR;
+ return temp_library_path_;
+ }
+
+ std::string create_temp_path()
+ {
+ std::string path = use_temp_path();
+ BLI_dir_create_recursive(path.c_str());
+ return path;
+ }
+};
+
+} // namespace blender::asset_system::tests
More information about the Bf-blender-cvs
mailing list