Blender V4.5
blendfile_loading_base_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
5
6#include "MEM_guardedalloc.h"
7
8#include "BKE_appdir.hh"
9#include "BKE_blender.hh"
10#include "BKE_callbacks.hh"
11#include "BKE_context.hh"
12#include "BKE_global.hh"
13#include "BKE_idtype.hh"
14#include "BKE_image.hh"
15#include "BKE_layer.hh"
16#include "BKE_lib_id.hh"
17#include "BKE_main.hh"
19#include "BKE_modifier.hh"
20#include "BKE_node.hh"
21#include "BKE_scene.hh"
22#include "BKE_vfont.hh"
23
24#include "BLF_api.hh"
25
26#include "BLI_listbase.h"
27#include "BLI_path_utils.hh"
28#include "BLI_threads.h"
29
30#include "BLO_readfile.hh"
31
32#include "DEG_depsgraph.hh"
34
35#include "DNA_genfile.h" /* for DNA_sdna_current_init() */
37
38#include "IMB_imbuf.hh"
39
40#include "ED_datafiles.h"
41
42#include "RNA_define.hh"
43
44#include "WM_api.hh"
45#include "wm.hh"
46
47#include "CLG_log.h"
48
50{
51 testing::Test::SetUpTestCase();
52
53 /* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from
54 * main() in creator.c. */
55 CLG_init();
57
60
63 IMB_init();
66 RNA_init();
70 BLF_init();
71
73
74 G.background = true;
75 G.factory_startup = true;
76
77 /* Allocate a dummy window manager. The real window manager will try and load Python scripts from
78 * the release directory, which it won't be able to find. */
79 ASSERT_EQ(G.main->wm.first, nullptr);
80 wmWindowManager *wm = BKE_id_new<wmWindowManager>(G.main, "WMdummy");
81 wm->runtime = MEM_new<blender::bke::WindowManagerRuntime>(__func__);
82}
83
85{
86 /* Copied from WM_exit_ex() in wm_init_exit.cc, and cherry-picked those lines that match the
87 * allocation/initialization done in SetUpTestCase(). */
89 RNA_exit();
90
91 BLF_exit();
95
97
100 CLG_exit();
101
102 testing::Test::TearDownTestCase();
103}
104
106{
110
111 testing::Test::TearDown();
112}
113
115{
116 const std::string &test_assets_dir = blender::tests::flags_test_asset_dir();
117 if (test_assets_dir.empty()) {
118 return false;
119 }
120
121 char abspath[FILE_MAX];
122 BLI_path_join(abspath, sizeof(abspath), test_assets_dir.c_str(), filepath);
123
124 BlendFileReadReport bf_reports = {};
125 bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, &bf_reports);
126 if (bfile == nullptr) {
127 ADD_FAILURE() << "Unable to load file '" << filepath << "' from test assets dir '"
128 << test_assets_dir << "'";
129 return false;
130 }
131
132 /* Make sure that all view_layers in the file are synced. Depsgraph can make a copy of the whole
133 * scene, which will fail when one view layer isn't synced. */
134 LISTBASE_FOREACH (ViewLayer *, view_layer, &bfile->curscene->view_layers) {
135 BKE_view_layer_synced_ensure(bfile->curscene, view_layer);
136 }
137
138 return true;
139}
140
142{
143 if (bfile == nullptr) {
144 return;
145 }
146
148 bfile = nullptr;
149}
150
152{
154 bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode);
157}
158
160{
161 if (depsgraph == nullptr) {
162 return;
163 }
165 depsgraph = nullptr;
166}
void BKE_appdir_init()
Definition appdir.cc:93
void BKE_appdir_exit()
Definition appdir.cc:101
void BKE_tempdir_session_purge()
Definition appdir.cc:1254
Blender util stuff.
void BKE_blender_globals_main_replace(Main *bmain)
Definition blender.cc:225
void BKE_blender_atexit()
Definition blender.cc:512
void BKE_blender_globals_init()
Definition blender.cc:190
void BKE_blender_free()
Definition blender.cc:60
void BKE_callback_global_init()
Definition callbacks.cc:102
void BKE_idtype_init()
Definition idtype.cc:122
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1495
Main * BKE_main_new()
Definition main.cc:48
void BKE_mball_cubeTable_free()
void BKE_modifier_init()
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2618
void BKE_vfont_builtin_register(const void *mem, int size)
Definition vfont.cc:278
void BLF_exit()
Definition blf.cc:70
int BLF_init()
Definition blf.cc:61
#define LISTBASE_FOREACH(type, var, list)
#define FILE_MAX
#define BLI_path_join(...)
void BLI_threadapi_init(void)
Definition threads.cc:114
void BLI_threadapi_exit(void)
Definition threads.cc:119
external readfile function prototypes.
@ BLO_READ_SKIP_NONE
BlendFileData * BLO_read_from_file(const char *filepath, eBLOReadSkip skip_flags, BlendFileReadReport *reports)
void BLO_blendfiledata_free(BlendFileData *bfd)
void CLG_exit(void)
Definition clog.c:704
void CLG_init(void)
Definition clog.c:697
void DEG_free_node_types()
eEvaluationMode
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:278
void DEG_register_node_types()
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:306
void DEG_graph_build_from_view_layer(Depsgraph *graph)
blenloader genfile private function prototypes
void DNA_sdna_current_free(void)
void DNA_sdna_current_init(void)
const char datatoc_bfont_pfb[]
int datatoc_bfont_pfb_size
void IMB_init()
Definition module.cc:16
Read Guarded memory(de)allocation.
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
#define G(x, y, z)
void node_system_init()
Definition node.cc:5615
void RNA_exit()
void RNA_init()
Definition rna_access.cc:80
WindowManagerRuntimeHandle * runtime