IO: Add test for iterating over invisible objects

Add a test that checks invisible objects are iterated over by the
`IO::AbstractHierarchyIterator` class, when a suitable depsgraph is given.

No functional changes.
This commit is contained in:
2020-08-17 16:55:31 +02:00
parent a95f863596
commit 271361e31f
2 changed files with 49 additions and 5 deletions

View File

@@ -56,9 +56,9 @@ class BlendfileLoadingBaseTest : public testing::Test {
void blendfile_free();
/* Create a depsgraph. Assumes a blend file has been loaded to this->bfile. */
void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode);
virtual void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode);
/* Free the depsgraph if it's not nullptr. */
void depsgraph_free();
virtual void depsgraph_free();
};
#endif /* __BLENDFILE_LOADING_BASE_TEST_H__ */

View File

@@ -20,8 +20,11 @@
#include "tests/blendfile_loading_base_test.h"
#include "BKE_scene.h"
#include "BLI_math.h"
#include "BLO_readfile.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DNA_object_types.h"
#include <map>
@@ -99,7 +102,7 @@ class TestingHierarchyIterator : public AbstractHierarchyIterator {
}
};
class USDHierarchyIteratorTest : public BlendfileLoadingBaseTest {
class AbstractHierarchyIteratorTest : public BlendfileLoadingBaseTest {
protected:
TestingHierarchyIterator *iterator;
@@ -131,7 +134,7 @@ class USDHierarchyIteratorTest : public BlendfileLoadingBaseTest {
}
};
TEST_F(USDHierarchyIteratorTest, ExportHierarchyTest)
TEST_F(AbstractHierarchyIteratorTest, ExportHierarchyTest)
{
/* Load the test blend file. */
if (!blendfile_load("usd/usd_hierarchy_export_test.blend")) {
@@ -206,7 +209,7 @@ TEST_F(USDHierarchyIteratorTest, ExportHierarchyTest)
EXPECT_EQ(expected_data, iterator->data_writers);
}
TEST_F(USDHierarchyIteratorTest, ExportSubsetTest)
TEST_F(AbstractHierarchyIteratorTest, ExportSubsetTest)
{
// The scene has no hair or particle systems, and this is already covered by ExportHierarchyTest,
// so not included here. Update this test when hair & particle systems are included.
@@ -317,4 +320,45 @@ TEST_F(USDHierarchyIteratorTest, ExportSubsetTest)
EXPECT_EQ(expected_transforms, iterator->transform_writers);
EXPECT_EQ(expected_data, iterator->data_writers);
}
/* Test class that constructs a depsgraph in such a way that it includes invisible objects. */
class AbstractHierarchyIteratorInvisibleTest : public AbstractHierarchyIteratorTest {
protected:
void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode) override
{
depsgraph = DEG_graph_new(
bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode);
DEG_graph_build_for_all_objects(
depsgraph, bfile->main, bfile->curscene, bfile->cur_view_layer);
BKE_scene_graph_update_tagged(depsgraph, bfile->main);
}
};
TEST_F(AbstractHierarchyIteratorInvisibleTest, ExportInvisibleTest)
{
if (!blendfile_load("alembic/visibility.blend")) {
return;
}
depsgraph_create(DAG_EVAL_RENDER);
iterator_create();
iterator->iterate_and_write();
// Mapping from object name to set of export paths.
used_writers expected_transforms = {{"OBInvisibleAnimatedCube", {"/InvisibleAnimatedCube"}},
{"OBInvisibleCube", {"/InvisibleCube"}},
{"OBVisibleCube", {"/VisibleCube"}}};
EXPECT_EQ(expected_transforms, iterator->transform_writers);
used_writers expected_data = {{"OBInvisibleAnimatedCube", {"/InvisibleAnimatedCube/Cube"}},
{"OBInvisibleCube", {"/InvisibleCube/Cube"}},
{"OBVisibleCube", {"/VisibleCube/Cube"}}};
EXPECT_EQ(expected_data, iterator->data_writers);
// The scene has no hair or particle systems.
EXPECT_EQ(0, iterator->hair_writers.size());
EXPECT_EQ(0, iterator->particle_writers.size());
}
} // namespace blender::io