2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2019 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-11-28 17:37:27 +01:00
|
|
|
#include "blendfile_loading_base_test.h"
|
|
|
|
|
|
2020-01-26 16:38:18 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2024-01-21 19:42:13 +01:00
|
|
|
#include "BKE_appdir.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
#include "BKE_blender.h"
|
2021-12-21 11:12:47 +01:00
|
|
|
#include "BKE_callbacks.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
#include "BKE_global.h"
|
2024-01-20 19:17:36 +01:00
|
|
|
#include "BKE_idtype.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
#include "BKE_image.h"
|
2024-01-23 15:18:09 -05:00
|
|
|
#include "BKE_layer.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2024-01-24 11:33:47 -05:00
|
|
|
#include "BKE_mball_tessellate.hh"
|
2023-11-14 09:30:40 +01:00
|
|
|
#include "BKE_modifier.hh"
|
2023-05-15 15:14:22 +02:00
|
|
|
#include "BKE_node.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
#include "BKE_scene.h"
|
2023-11-28 16:05:12 -05:00
|
|
|
#include "BKE_vfont.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
|
2024-01-31 14:04:56 -05:00
|
|
|
#include "BLF_api.hh"
|
2023-11-23 21:49:28 +01:00
|
|
|
|
2019-11-28 17:37:27 +01:00
|
|
|
#include "BLI_path_util.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_threads.h"
|
2019-11-28 17:37:27 +01:00
|
|
|
|
|
|
|
|
#include "BLO_readfile.h"
|
|
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
|
|
|
|
#include "DEG_depsgraph_build.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
|
|
|
|
|
#include "DNA_genfile.h" /* for DNA_sdna_current_init() */
|
|
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
|
2022-01-03 14:49:31 -05:00
|
|
|
#include "ED_datafiles.h"
|
|
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_define.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
2023-08-04 17:55:14 -04:00
|
|
|
#include "wm.hh"
|
2019-11-28 17:37:27 +01:00
|
|
|
|
2023-04-06 07:40:07 +10:00
|
|
|
#include "GHOST_Path-api.hh"
|
2021-11-16 12:47:14 +01:00
|
|
|
|
2020-10-05 14:24:07 +02:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
|
2019-11-28 17:37:27 +01:00
|
|
|
void BlendfileLoadingBaseTest::SetUpTestCase()
|
|
|
|
|
{
|
|
|
|
|
testing::Test::SetUpTestCase();
|
|
|
|
|
|
|
|
|
|
/* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from
|
|
|
|
|
* main() in creator.c. */
|
2020-10-05 14:24:07 +02:00
|
|
|
CLG_init();
|
2019-11-28 17:37:27 +01:00
|
|
|
BLI_threadapi_init();
|
|
|
|
|
|
|
|
|
|
DNA_sdna_current_init();
|
|
|
|
|
BKE_blender_globals_init();
|
2020-03-05 10:54:00 +01:00
|
|
|
|
|
|
|
|
BKE_idtype_init();
|
2020-10-05 14:24:07 +02:00
|
|
|
BKE_appdir_init();
|
2019-11-28 17:37:27 +01:00
|
|
|
IMB_init();
|
|
|
|
|
BKE_modifier_init();
|
|
|
|
|
DEG_register_node_types();
|
|
|
|
|
RNA_init();
|
2020-11-06 16:43:09 +11:00
|
|
|
BKE_node_system_init();
|
2021-12-21 11:12:47 +01:00
|
|
|
BKE_callback_global_init();
|
2022-01-03 14:49:31 -05:00
|
|
|
BKE_vfont_builtin_register(datatoc_bfont_pfb, datatoc_bfont_pfb_size);
|
2023-11-23 21:49:28 +01:00
|
|
|
BLF_init();
|
2019-11-28 17:37:27 +01:00
|
|
|
|
|
|
|
|
G.background = true;
|
|
|
|
|
G.factory_startup = true;
|
|
|
|
|
|
|
|
|
|
/* Allocate a dummy window manager. The real window manager will try and load Python scripts from
|
|
|
|
|
* the release directory, which it won't be able to find. */
|
|
|
|
|
ASSERT_EQ(G.main->wm.first, nullptr);
|
|
|
|
|
G.main->wm.first = MEM_callocN(sizeof(wmWindowManager), __func__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlendfileLoadingBaseTest::TearDownTestCase()
|
|
|
|
|
{
|
|
|
|
|
if (G.main->wm.first != nullptr) {
|
|
|
|
|
MEM_freeN(G.main->wm.first);
|
|
|
|
|
G.main->wm.first = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 00:32:39 +01:00
|
|
|
/* Copied from WM_exit_ex() in wm_init_exit.cc, and cherry-picked those lines that match the
|
2019-12-17 16:28:28 +11:00
|
|
|
* allocation/initialization done in SetUpTestCase(). */
|
2019-11-28 17:37:27 +01:00
|
|
|
BKE_blender_free();
|
|
|
|
|
RNA_exit();
|
|
|
|
|
|
2023-11-23 21:49:28 +01:00
|
|
|
BLF_exit();
|
2019-11-28 17:37:27 +01:00
|
|
|
DEG_free_node_types();
|
2021-11-16 12:47:14 +01:00
|
|
|
GHOST_DisposeSystemPaths();
|
2019-11-28 17:37:27 +01:00
|
|
|
DNA_sdna_current_free();
|
|
|
|
|
BLI_threadapi_exit();
|
|
|
|
|
|
|
|
|
|
BKE_blender_atexit();
|
|
|
|
|
|
|
|
|
|
BKE_tempdir_session_purge();
|
2020-12-04 08:13:54 +01:00
|
|
|
BKE_appdir_exit();
|
2020-10-05 14:24:07 +02:00
|
|
|
CLG_exit();
|
|
|
|
|
|
2019-11-28 17:37:27 +01:00
|
|
|
testing::Test::TearDownTestCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlendfileLoadingBaseTest::TearDown()
|
|
|
|
|
{
|
2022-01-03 14:49:31 -05:00
|
|
|
BKE_mball_cubeTable_free();
|
2019-11-28 17:37:27 +01:00
|
|
|
blendfile_free();
|
2023-01-25 14:51:39 -05:00
|
|
|
depsgraph_free();
|
2019-11-28 17:37:27 +01:00
|
|
|
|
|
|
|
|
testing::Test::TearDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BlendfileLoadingBaseTest::blendfile_load(const char *filepath)
|
|
|
|
|
{
|
Tests: move tests from USD test directory into `io/common` and `io/usd`
This commit is a followup of {D7649}, and ports the USD tests to the new
testing approach. It moves test code from `tests/gtests/usd` into
`source/blender/io/common` and `source/blender/io/usd`, and adjusts the
use of namespaces to be consistent with the other tests.
I decided to put one test into `io/usd/tests`, instead of
`io/usd/intern`. The reason is that this test does not correspond with a
single file in that directory; instead, it tests Blender's integration
with the USD library itself.
There are two new CLI arguments for the Big Test Runner:
- `--test-assets-dir`, which points to the `lib/tests` directory in the
SVN repository. This allows unit tests to find test assets.
- `--test-release-dir`, which points to `bin/{BLENDER_VERSION}` in the
build directory. At the moment this is only used by the USD test.
The CLI arguments are automatically passed to the Big Test Runner when
using `ctest`. When manually running the tests, the arguments are only
required when there is a test run that needs them.
For more info about splitting some code into 'common', see
rB084c5d6c7e2cf8.
No functional changes to the tests themselves, only to the way they are
built & run.
Differential Revision: https://developer.blender.org/D8314
Reviewed by: brecht, mont29
2020-07-16 16:10:53 +02:00
|
|
|
const std::string &test_assets_dir = blender::tests::flags_test_asset_dir();
|
|
|
|
|
if (test_assets_dir.empty()) {
|
2019-11-28 17:37:27 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-13 17:38:50 +10:00
|
|
|
char abspath[FILE_MAX];
|
2022-10-17 11:16:41 +11:00
|
|
|
BLI_path_join(abspath, sizeof(abspath), test_assets_dir.c_str(), filepath);
|
2019-11-28 17:37:27 +01:00
|
|
|
|
2023-10-13 11:29:59 +02:00
|
|
|
BlendFileReadReport bf_reports = {};
|
2021-06-23 09:51:11 +02:00
|
|
|
bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, &bf_reports);
|
2019-11-28 17:37:27 +01:00
|
|
|
if (bfile == nullptr) {
|
|
|
|
|
ADD_FAILURE() << "Unable to load file '" << filepath << "' from test assets dir '"
|
Tests: move tests from USD test directory into `io/common` and `io/usd`
This commit is a followup of {D7649}, and ports the USD tests to the new
testing approach. It moves test code from `tests/gtests/usd` into
`source/blender/io/common` and `source/blender/io/usd`, and adjusts the
use of namespaces to be consistent with the other tests.
I decided to put one test into `io/usd/tests`, instead of
`io/usd/intern`. The reason is that this test does not correspond with a
single file in that directory; instead, it tests Blender's integration
with the USD library itself.
There are two new CLI arguments for the Big Test Runner:
- `--test-assets-dir`, which points to the `lib/tests` directory in the
SVN repository. This allows unit tests to find test assets.
- `--test-release-dir`, which points to `bin/{BLENDER_VERSION}` in the
build directory. At the moment this is only used by the USD test.
The CLI arguments are automatically passed to the Big Test Runner when
using `ctest`. When manually running the tests, the arguments are only
required when there is a test run that needs them.
For more info about splitting some code into 'common', see
rB084c5d6c7e2cf8.
No functional changes to the tests themselves, only to the way they are
built & run.
Differential Revision: https://developer.blender.org/D8314
Reviewed by: brecht, mont29
2020-07-16 16:10:53 +02:00
|
|
|
<< test_assets_dir << "'";
|
2019-11-28 17:37:27 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2022-09-14 21:33:51 +02:00
|
|
|
|
|
|
|
|
/* Make sure that all view_layers in the file are synced. Depsgraph can make a copy of the whole
|
|
|
|
|
* scene, which will fail when one view layer isn't synced. */
|
|
|
|
|
LISTBASE_FOREACH (ViewLayer *, view_layer, &bfile->curscene->view_layers) {
|
|
|
|
|
BKE_view_layer_synced_ensure(bfile->curscene, view_layer);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-28 17:37:27 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlendfileLoadingBaseTest::blendfile_free()
|
|
|
|
|
{
|
|
|
|
|
if (bfile == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLO_blendfiledata_free(bfile);
|
|
|
|
|
bfile = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlendfileLoadingBaseTest::depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
|
|
|
|
|
{
|
|
|
|
|
depsgraph = DEG_graph_new(
|
|
|
|
|
bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode);
|
2020-08-18 15:51:32 +02:00
|
|
|
DEG_graph_build_from_view_layer(depsgraph);
|
2019-11-28 17:37:27 +01:00
|
|
|
BKE_scene_graph_update_tagged(depsgraph, bfile->main);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlendfileLoadingBaseTest::depsgraph_free()
|
|
|
|
|
{
|
|
|
|
|
if (depsgraph == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DEG_graph_free(depsgraph);
|
|
|
|
|
depsgraph = nullptr;
|
|
|
|
|
}
|