Blender V5.3
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_cpp_types.hh"
13#include "BKE_global.hh"
14#include "BKE_idtype.hh"
15#include "BKE_image.hh"
16#include "BKE_layer.hh"
17#include "BKE_lib_id.hh"
18#include "BKE_main.hh"
20#include "BKE_modifier.hh"
21#include "BKE_node.hh"
22#include "BKE_scene.hh"
23#include "BKE_vfont.hh"
24
25#include "BLF_api.hh"
26
27#include "BLI_listbase.hh"
28#include "BLI_path_utils.hh"
29#include "BLI_threads.hh"
30
31#include "BLO_readfile.hh"
32
33#include "DEG_depsgraph.hh"
35
36#include "DNA_genfile.h"
38
39#include "IMB_imbuf.hh"
40
41#include "ED_datafiles.h"
42
43#include "RNA_define.hh"
44
45#include "SEQ_modifier.hh"
46
47#include "WM_api.hh"
48#include "wm.hh"
49
50#include "CLG_log.h"
51
52namespace blender {
53
55{
56 testing::Test::SetUpTestCase();
57
58 /* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from
59 * main() in creator.c. */
60 CLG_init();
62
64
68 IMB_init();
72 RNA_init();
76 BLF_init();
77
79
80 G.background = true;
81 G.factory_startup = true;
82
83 /* Allocate a dummy window manager. The real window manager will try and load Python scripts from
84 * the release directory, which it won't be able to find. */
85 ASSERT_EQ(G.main->wm.first_, nullptr);
87 wm->runtime = MEM_new<bke::WindowManagerRuntime>(__func__);
88}
89
91{
92 /* Copied from WM_exit_ex() in wm_init_exit.cc, and cherry-picked those lines that match the
93 * allocation/initialization done in SetUpTestCase(). */
95 RNA_exit();
96
97 BLF_exit();
100
102
105 CLG_exit();
106
107 testing::Test::TearDownTestCase();
108}
109
111{
115
116 testing::Test::TearDown();
117}
118
120{
121 const std::string &test_assets_dir = tests::flags_test_asset_dir();
122 if (test_assets_dir.empty()) {
123 return false;
124 }
125
126 char abspath[FILE_MAX];
127 BLI_path_join(abspath, sizeof(abspath), test_assets_dir.c_str(), filepath);
128
129 BlendFileReadReport bf_reports = {};
130 bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, &bf_reports);
131 if (bfile == nullptr) {
132 ADD_FAILURE() << "Unable to load file '" << filepath << "' from test assets dir '"
133 << test_assets_dir << "'";
134 return false;
135 }
136
137 /* Make sure that all view_layers in the file are synced. Depsgraph can make a copy of the whole
138 * scene, which will fail when one view layer isn't synced. */
139 for (ViewLayer &view_layer : bfile->curscene->view_layers) {
141 }
142
143 return true;
144}
145
147{
148 if (bfile == nullptr) {
149 return;
150 }
151
153 bfile = nullptr;
154}
155
163
165{
166 if (depsgraph == nullptr) {
167 return;
168 }
170 depsgraph = nullptr;
171}
172
173} // namespace blender
Blender util stuff.
#define FILE_MAX
#define BLI_path_join(...)
external readfile function prototypes.
void CLG_exit()
Definition clog.cc:877
void CLG_init()
Definition clog.cc:870
blenloader genfile private function prototypes
const char datatoc_bfont_pfb[]
int datatoc_bfont_pfb_size
Read Blender memory allocation and freeing.
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
void node_system_init()
Definition node.cc:6178
BMesh Iterators.
void BKE_blender_free()
Definition blender.cc:64
void BKE_tempdir_session_purge()
Definition appdir.cc:1293
void DEG_free_node_types()
void DEG_graph_build_from_view_layer(Depsgraph *graph)
void BLI_threadapi_exit()
Definition threads.cc:121
void BKE_blender_globals_init()
Definition blender.cc:194
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:307
void BLO_blendfiledata_free(BlendFileData *bfd)
Main * BKE_main_new()
Definition main.cc:93
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:279
void BKE_appdir_init()
Definition appdir.cc:95
void RNA_init()
Definition rna_access.cc:88
void BLI_threadapi_init()
Definition threads.cc:116
Global G
Definition blender.cc:57
void BKE_idtype_init()
Definition idtype.cc:207
BlendFileData * BLO_read_from_file(const char *filepath, eBLOReadSkip skip_flags, BlendFileReadReport *reports)
void BKE_mball_cubeTable_free()
void RNA_exit()
void IMB_init()
Definition module.cc:26
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_blender_atexit()
Definition blender.cc:509
@ BLO_READ_SKIP_NONE
int BLF_init()
Definition blf.cc:63
void BKE_vfont_builtin_register(const void *mem, int size)
Definition vfont.cc:283
void DEG_register_node_types()
void BKE_appdir_exit()
Definition appdir.cc:103
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
void BKE_callback_global_init()
Definition callbacks.cc:115
void BKE_blender_globals_main_replace(Main *bmain)
Definition blender.cc:226
void BLF_exit()
Definition blf.cc:72
ListBaseT< ViewLayer > view_layers