Blender V5.3
node_structure_type_inferencing_tests.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 "testing/testing.h"
6
7#include "BKE_global.hh"
8#include "BKE_gtest_base.hh"
9#include "BKE_main.hh"
10#include "BKE_node.hh"
11#include "BKE_node_runtime.hh"
13
14#include "DNA_node_types.h"
15
16namespace blender::nodes::tests {
17
18namespace {
19class StructureTypeInferenceTest : public bke::BlenderGTestBase {};
20
21class TestData {
22 public:
23 Main *bmain = nullptr;
24
25 TestData()
26 {
27 bmain = BKE_main_new();
28 G.main = bmain;
29 }
30
31 ~TestData()
32 {
33 BKE_main_free(bmain);
34 G.main = nullptr;
35 }
36};
37} // namespace
38
40{
41 return *bke::node_add_node(nullptr, tree, "GeometryNodeInputNamedAttribute"_ustr);
42}
43
44static bNode &add_switch_node(Main &bmain, bNodeTree &tree, const eNodeSocketDatatype socket_type)
45{
46 bNode &node = *bke::node_add_node(nullptr, tree, "GeometryNodeSwitch"_ustr);
47 NodeSwitch &storage = *static_cast<NodeSwitch *>(node.storage);
48 storage.input_type = socket_type;
50 return node;
51}
52
54 const eNodeSocketDatatype socket_type)
55{
56 TestData data;
57 bNodeTree &tree = *bke::node_tree_add_tree(data.bmain, "Test", "GeometryNodeTree");
58 bNode &field_node = add_field_boolean_node(tree);
59 bNode &switch_node = add_switch_node(*data.bmain, tree, socket_type);
60
62 field_node,
63 *field_node.output_by_identifier("Exists"_ustr),
64 switch_node,
65 *switch_node.input_by_identifier("Switch"_ustr));
67
68 return switch_node.output_by_identifier("Output"_ustr)->runtime->inferred_structure_type;
69}
70
71TEST_F(StructureTypeInferenceTest, GeometryOutputDoesNotBecomeField)
72{
74 StructureType::Single);
75}
76
77TEST_F(StructureTypeInferenceTest, ValueOutputCanBecomeField)
78{
80}
81
82} // namespace blender::nodes::tests
#define storage(slot, qualifiers)
bNode * node_add_node(const bContext *C, bNodeTree &ntree, UString idname, std::optional< int > unique_identifier=std::nullopt)
Definition node.cc:4260
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
Definition node.cc:4638
bNodeTree * node_tree_add_tree(Main *bmain, StringRef name, StringRef idname)
Definition node.cc:4992
static bNode & add_switch_node(Main &bmain, bNodeTree &tree, const eNodeSocketDatatype socket_type)
static StructureType infer_switch_output_structure_with_field_condition(const eNodeSocketDatatype socket_type)
TEST_F(BundleTest, DefaultBundle)
static bNode & add_field_boolean_node(bNodeTree &tree)
Main * BKE_main_new()
Definition main.cc:93
Global G
Definition blender.cc:57
BMesh const char void * data
void BKE_ntree_update_after_single_tree_change(Main &bmain, bNodeTree &modified_tree, const NodeTreeUpdateExtraParams &params={})
void BKE_main_free(Main *bmain)
Definition main.cc:202
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
bke::bNodeRuntime * runtime