Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2020-08-11 09:19:50 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-08-11 09:19:50 +0300
commitd19a34296640c640d068e3f4a9274d2938aad79a (patch)
treecd16306b71b54f6f1b81828065c2dffa4cb37c3e /source/blender/blenloader
parentd8b4d81da0fb26f4f36f665cb9fcfaed091b31a3 (diff)
parent7f15120e9c30fd934dfff2a6771996e0724f988d (diff)
Merge branch 'master' into greasepencil-edit-curve
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/CMakeLists.txt14
-rw-r--r--source/blender/blenloader/intern/versioning_defaults.c8
-rw-r--r--source/blender/blenloader/tests/blendfile_load_test.cc31
-rw-r--r--source/blender/blenloader/tests/blendfile_loading_base_test.cc162
-rw-r--r--source/blender/blenloader/tests/blendfile_loading_base_test.h64
5 files changed, 279 insertions, 0 deletions
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 7eab0651d97..c56e0b5ad2e 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -98,3 +98,17 @@ blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
# needed so writefile.c can use dna_type_offsets.h
add_dependencies(bf_blenloader bf_dna)
+
+if(WITH_GTESTS)
+ set(TEST_SRC
+ tests/blendfile_loading_base_test.cc
+ tests/blendfile_load_test.cc
+ )
+ set(TEST_INC
+ )
+ set(TEST_LIB
+ bf_blenloader
+ )
+ include(GTestTesting)
+ blender_add_test_lib(bf_blenloader_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
+endif()
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index ae6d3a58091..631961e342d 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -698,6 +698,14 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
brush->sculpt_tool = SCULPT_TOOL_SMEAR;
}
+ brush_name = "Boundary";
+ brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
+ if (!brush) {
+ brush = BKE_brush_add(bmain, brush_name, OB_MODE_SCULPT);
+ id_us_min(&brush->id);
+ brush->sculpt_tool = SCULPT_TOOL_BOUNDARY;
+ }
+
brush_name = "Simplify";
brush = BLI_findstring(&bmain->brushes, brush_name, offsetof(ID, name) + 2);
if (!brush) {
diff --git a/source/blender/blenloader/tests/blendfile_load_test.cc b/source/blender/blenloader/tests/blendfile_load_test.cc
new file mode 100644
index 00000000000..2ba3e3fcd88
--- /dev/null
+++ b/source/blender/blenloader/tests/blendfile_load_test.cc
@@ -0,0 +1,31 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2019 by Blender Foundation.
+ */
+#include "blendfile_loading_base_test.h"
+
+class BlendfileLoadingTest : public BlendfileLoadingBaseTest {
+};
+
+TEST_F(BlendfileLoadingTest, CanaryTest)
+{
+ /* Load the smallest blend file we have in the SVN lib/tests directory. */
+ if (!blendfile_load("modifier_stack/array_test.blend")) {
+ return;
+ }
+ depsgraph_create(DAG_EVAL_RENDER);
+ EXPECT_NE(nullptr, this->depsgraph);
+}
diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.cc b/source/blender/blenloader/tests/blendfile_loading_base_test.cc
new file mode 100644
index 00000000000..d74bab4b31c
--- /dev/null
+++ b/source/blender/blenloader/tests/blendfile_loading_base_test.cc
@@ -0,0 +1,162 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2019 by Blender Foundation.
+ */
+#include "blendfile_loading_base_test.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BKE_appdir.h"
+#include "BKE_blender.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_idtype.h"
+#include "BKE_image.h"
+#include "BKE_main.h"
+#include "BKE_modifier.h"
+#include "BKE_node.h"
+#include "BKE_scene.h"
+
+#include "BLI_path_util.h"
+#include "BLI_threads.h"
+
+#include "BLO_readfile.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
+#include "DNA_genfile.h" /* for DNA_sdna_current_init() */
+#include "DNA_windowmanager_types.h"
+
+#include "IMB_imbuf.h"
+
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "wm.h"
+
+BlendfileLoadingBaseTest::~BlendfileLoadingBaseTest()
+{
+}
+
+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. */
+ BLI_threadapi_init();
+
+ DNA_sdna_current_init();
+ BKE_blender_globals_init();
+
+ BKE_idtype_init();
+ IMB_init();
+ BKE_images_init();
+ BKE_modifier_init();
+ DEG_register_node_types();
+ RNA_init();
+ init_nodesystem();
+
+ 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;
+ }
+
+ /* Copied from WM_exit_ex() in wm_init_exit.c, and cherry-picked those lines that match the
+ * allocation/initialization done in SetUpTestCase(). */
+ BKE_blender_free();
+ RNA_exit();
+
+ DEG_free_node_types();
+ DNA_sdna_current_free();
+ BLI_threadapi_exit();
+
+ BKE_blender_atexit();
+
+ BKE_tempdir_session_purge();
+
+ testing::Test::TearDownTestCase();
+}
+
+void BlendfileLoadingBaseTest::TearDown()
+{
+ depsgraph_free();
+ blendfile_free();
+
+ testing::Test::TearDown();
+}
+
+bool BlendfileLoadingBaseTest::blendfile_load(const char *filepath)
+{
+ const std::string &test_assets_dir = blender::tests::flags_test_asset_dir();
+ if (test_assets_dir.empty()) {
+ return false;
+ }
+
+ char abspath[FILENAME_MAX];
+ BLI_path_join(abspath, sizeof(abspath), test_assets_dir.c_str(), filepath, NULL);
+
+ bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, NULL /* reports */);
+ if (bfile == nullptr) {
+ ADD_FAILURE() << "Unable to load file '" << filepath << "' from test assets dir '"
+ << test_assets_dir << "'";
+ return false;
+ }
+ return true;
+}
+
+void BlendfileLoadingBaseTest::blendfile_free()
+{
+ if (bfile == nullptr) {
+ return;
+ }
+
+ wmWindowManager *wm = static_cast<wmWindowManager *>(bfile->main->wm.first);
+ if (wm != nullptr) {
+ wm_close_and_free(NULL, wm);
+ }
+ 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);
+ DEG_graph_build_from_view_layer(depsgraph, bfile->main, bfile->curscene, bfile->cur_view_layer);
+ BKE_scene_graph_update_tagged(depsgraph, bfile->main);
+}
+
+void BlendfileLoadingBaseTest::depsgraph_free()
+{
+ if (depsgraph == nullptr) {
+ return;
+ }
+ DEG_graph_free(depsgraph);
+ depsgraph = nullptr;
+}
diff --git a/source/blender/blenloader/tests/blendfile_loading_base_test.h b/source/blender/blenloader/tests/blendfile_loading_base_test.h
new file mode 100644
index 00000000000..a5e75ef6df8
--- /dev/null
+++ b/source/blender/blenloader/tests/blendfile_loading_base_test.h
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2019 by Blender Foundation.
+ */
+#ifndef __BLENDFILE_LOADING_BASE_TEST_H__
+#define __BLENDFILE_LOADING_BASE_TEST_H__
+
+#include "DEG_depsgraph.h"
+#include "testing/testing.h"
+
+struct BlendFileData;
+struct Depsgraph;
+
+class BlendfileLoadingBaseTest : public testing::Test {
+ protected:
+ struct BlendFileData *bfile = nullptr;
+ struct Depsgraph *depsgraph = nullptr;
+
+ public:
+ virtual ~BlendfileLoadingBaseTest();
+
+ /* Sets up Blender just enough to not crash on loading
+ * a blendfile and constructing a depsgraph. */
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+
+ protected:
+ /* Frees the depsgraph & blendfile. */
+ virtual void TearDown();
+
+ /* Loads a blend file from the lib/tests directory from SVN.
+ * Returns 'ok' flag (true=good, false=bad) and sets this->bfile.
+ * Fails the test if the file cannot be loaded (still returns though).
+ * Requires the CLI argument --test-asset-dir to point to ../../lib/tests.
+ *
+ * WARNING: only files saved with Blender 2.80+ can be loaded. Since Blender
+ * is only partially initialized (most importantly, without window manager),
+ * the space types are not registered, so any versioning code that handles
+ * those will SEGFAULT.
+ */
+ bool blendfile_load(const char *filepath);
+ /* Free bfile if it is not nullptr. */
+ void blendfile_free();
+
+ /* Create a depsgraph. Assumes a blend file has been loaded to this->bfile. */
+ void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode);
+ /* Free the depsgraph if it's not nullptr. */
+ void depsgraph_free();
+};
+
+#endif /* __BLENDFILE_LOADING_BASE_TEST_H__ */