Blender V5.0
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 "SEQ_modifier.hh"
45
46#include "WM_api.hh"
47#include "wm.hh"
48
49#include "CLG_log.h"
50
52{
53 testing::Test::SetUpTestCase();
54
55 /* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from
56 * main() in creator.c. */
57 CLG_init();
59
62
65 IMB_init();
69 RNA_init();
73 BLF_init();
74
76
77 G.background = true;
78 G.factory_startup = true;
79
80 /* Allocate a dummy window manager. The real window manager will try and load Python scripts from
81 * the release directory, which it won't be able to find. */
82 ASSERT_EQ(G.main->wm.first, nullptr);
83 wmWindowManager *wm = BKE_id_new<wmWindowManager>(G.main, "WMdummy");
84 wm->runtime = MEM_new<blender::bke::WindowManagerRuntime>(__func__);
85}
86
88{
89 /* Copied from WM_exit_ex() in wm_init_exit.cc, and cherry-picked those lines that match the
90 * allocation/initialization done in SetUpTestCase(). */
92 RNA_exit();
93
94 BLF_exit();
98
100
103 CLG_exit();
104
105 testing::Test::TearDownTestCase();
106}
107
109{
113
114 testing::Test::TearDown();
115}
116
118{
119 const std::string &test_assets_dir = blender::tests::flags_test_asset_dir();
120 if (test_assets_dir.empty()) {
121 return false;
122 }
123
124 char abspath[FILE_MAX];
125 BLI_path_join(abspath, sizeof(abspath), test_assets_dir.c_str(), filepath);
126
127 BlendFileReadReport bf_reports = {};
128 bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, &bf_reports);
129 if (bfile == nullptr) {
130 ADD_FAILURE() << "Unable to load file '" << filepath << "' from test assets dir '"
131 << test_assets_dir << "'";
132 return false;
133 }
134
135 /* Make sure that all view_layers in the file are synced. Depsgraph can make a copy of the whole
136 * scene, which will fail when one view layer isn't synced. */
137 LISTBASE_FOREACH (ViewLayer *, view_layer, &bfile->curscene->view_layers) {
138 BKE_view_layer_synced_ensure(bfile->curscene, view_layer);
139 }
140
141 return true;
142}
143
145{
146 if (bfile == nullptr) {
147 return;
148 }
149
151 bfile = nullptr;
152}
153
155{
157 bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode);
160}
161
163{
164 if (depsgraph == nullptr) {
165 return;
166 }
168 depsgraph = nullptr;
169}
void BKE_appdir_init()
Definition appdir.cc:93
void BKE_appdir_exit()
Definition appdir.cc:101
void BKE_tempdir_session_purge()
Definition appdir.cc:1248
Blender util stuff.
void BKE_blender_globals_main_replace(Main *bmain)
Definition blender.cc:228
void BKE_blender_atexit()
Definition blender.cc:515
void BKE_blender_globals_init()
Definition blender.cc:193
void BKE_blender_free()
Definition blender.cc:63
void BKE_callback_global_init()
Definition callbacks.cc:102
void BKE_idtype_init()
Definition idtype.cc:121
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:1514
Main * BKE_main_new()
Definition main.cc:89
void BKE_mball_cubeTable_free()
void BKE_modifier_init()
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2621
void BKE_vfont_builtin_register(const void *mem, int size)
Definition vfont.cc:282
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()
Definition clog.cc:880
void CLG_init()
Definition clog.cc:873
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:15
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:5426
void RNA_exit()
void RNA_init()
Definition rna_access.cc:88
WindowManagerRuntimeHandle * runtime