Blender V4.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_global.hh"
13#include "BKE_idtype.hh"
14#include "BKE_image.hh"
15#include "BKE_layer.hh"
16#include "BKE_main.hh"
18#include "BKE_modifier.hh"
19#include "BKE_node.hh"
20#include "BKE_scene.hh"
21#include "BKE_vfont.hh"
22
23#include "BLF_api.hh"
24
25#include "BLI_path_utils.hh"
26#include "BLI_threads.h"
27
28#include "BLO_readfile.hh"
29
30#include "DEG_depsgraph.hh"
32
33#include "DNA_genfile.h" /* for DNA_sdna_current_init() */
35
36#include "IMB_imbuf.hh"
37
38#include "ED_datafiles.h"
39
40#include "RNA_define.hh"
41
42#include "WM_api.hh"
43#include "wm.hh"
44
45#include "CLG_log.h"
46
48{
49 testing::Test::SetUpTestCase();
50
51 /* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from
52 * main() in creator.c. */
53 CLG_init();
55
58
61 IMB_init();
64 RNA_init();
68 BLF_init();
69
70 G.background = true;
71 G.factory_startup = true;
72
73 /* Allocate a dummy window manager. The real window manager will try and load Python scripts from
74 * the release directory, which it won't be able to find. */
75 ASSERT_EQ(G.main->wm.first, nullptr);
76 G.main->wm.first = MEM_callocN(sizeof(wmWindowManager), __func__);
77}
78
80{
81 if (G.main->wm.first != nullptr) {
82 MEM_freeN(G.main->wm.first);
83 G.main->wm.first = nullptr;
84 }
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. */
136 }
137
138 return true;
139}
140
142{
143 if (bfile == nullptr) {
144 return;
145 }
146
148 bfile = nullptr;
149}
150
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:1216
Blender util stuff.
void BKE_blender_atexit()
Definition blender.cc:491
void BKE_blender_globals_init()
Definition blender.cc:186
void BKE_blender_free()
Definition blender.cc:54
void BKE_callback_global_init()
Definition callbacks.cc:103
void BKE_idtype_init()
Definition idtype.cc:127
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
void BKE_mball_cubeTable_free()
void BKE_modifier_init()
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2568
void BKE_vfont_builtin_register(const void *mem, int size)
Definition vfont.cc:237
void BLF_exit()
Definition blf.cc:71
int BLF_init()
Definition blf.cc:62
#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:706
void CLG_init(void)
Definition clog.c:699
void DEG_free_node_types()
eEvaluationMode
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:273
void DEG_register_node_types()
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:301
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:18
Read Guarded memory(de)allocation.
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
bool blendfile_load(const char *filepath)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
#define G(x, y, z)
void node_system_init()
Definition node.cc:4649
void RNA_exit()
Definition rna_access.cc:98
void RNA_init()
Definition rna_access.cc:73
ViewLayer * cur_view_layer
ListBase view_layers