Blender V5.3
depsgraph_query_iter_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_gtest_base.hh"
6#include "BKE_main.hh"
7#include "BKE_object.hh"
8#include "BKE_scene.hh"
9#include "BKE_viewer_path.hh"
10
11#include "DEG_depsgraph.hh"
14
15#include "BLI_listbase.hh"
16#include "BLI_memory_utils.hh"
17
18#include "DNA_object_types.h"
19#include "DNA_scene_types.h"
20
21#include "testing/testing.h"
22
23namespace blender::deg::tests {
24
26
27TEST_F(DepsgraphObjectIteratorTest, ObjectOnlyViewerPath)
28{
29 Main *bmain = BKE_main_new();
30 BLI_SCOPED_DEFER([&]() { BKE_main_free(bmain); });
31 Scene *scene = BKE_scene_add(bmain, "Scene");
32 ViewLayer *view_layer = scene->view_layers.first();
33 Object *object_a = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, "Object A");
34 Object *object_b = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, "Object B");
35
36 Depsgraph *depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT);
37 BLI_SCOPED_DEFER([&]() { DEG_graph_free(depsgraph); });
39 BKE_scene_graph_update_tagged(depsgraph, bmain);
40
41 ViewerPath viewer_path{};
42 BLI_SCOPED_DEFER([&]() { BKE_viewer_path_clear(&viewer_path); });
44 id_elem->id = &object_a->id;
45 BLI_addtail(&viewer_path.path, id_elem);
46
47 ASSERT_EQ(viewer_path.path.count(), 1);
48 ASSERT_EQ(id_elem->base.next, nullptr);
49
50 DEGObjectIterSettings settings{};
51 settings.depsgraph = depsgraph;
53 settings.viewer_path = &viewer_path;
54
55 int object_count = 0;
56 bool found_object_a = false;
57 bool found_object_b = false;
58 DEG_OBJECT_ITER_BEGIN (&settings, object) {
59 const Object *object_orig = DEG_get_original(object);
60 found_object_a |= object_orig == object_a;
61 found_object_b |= object_orig == object_b;
62 object_count++;
63 }
65
66 EXPECT_EQ(object_count, 2);
67 EXPECT_TRUE(found_object_a);
68 EXPECT_TRUE(found_object_b);
69}
70
71} // namespace blender::deg::tests
General operations, lookup, etc. for blender objects.
#define BLI_SCOPED_DEFER(function_to_defer)
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
Object is a sort of wrapper for general info.
#define EXPECT_TRUE(result)
TEST_F(DegBuilderRNATest, contains)
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name) ATTR_NONNULL(1
Definition object.cc:2296
void DEG_graph_build_from_view_layer(Depsgraph *graph)
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:307
IDViewerPathElem * BKE_viewer_path_elem_new_id()
Main * BKE_main_new()
Definition main.cc:93
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:279
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2867
Scene * BKE_scene_add(Main *bmain, const char *name)
Definition scene.cc:2200
@ DAG_EVAL_VIEWPORT
void BKE_main_free(Main *bmain)
Definition main.cc:202
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
T * DEG_get_original(T *id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BKE_viewer_path_clear(ViewerPath *viewer_path)
ListBaseT< ViewerPathElem > path