Files
blender/tests/gtests/blenloader/blendfile_loading_base_test.h
Sybren A. Stüvel f445f72eca Tests: Blendfile-loading test class
This new test class minimally sets up Blender so that it can load blend
files and construct a depsgraph without crashing.

Note that it hasn't been tested on very complex blend files, so it may
still crash when the loaded blend file references/requires uninitialised
data structures.

The test will certainly crash with Blend files created with Blender
older than 2.80, as the versioning code requires space types to be
registered. This is normally done by initialising the window manager,
which is not done in this test. The WM requires Python to run, which in
turn requires that Blender finds the release directory in the same
directory that contains the running executable, which is not the case
for GTest tests (they are written to `bin/tests/executablename`.

Reviewed By: sergey, mont29

Differential Revision: https://developer.blender.org/D6246
2019-11-28 17:41:32 +01:00

65 lines
2.3 KiB
C++

/*
* 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 "testing/testing.h"
#include "DEG_depsgraph.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 initialised (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__ */