Blender V5.3
anim_data_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_action.hh"
6#include "BKE_gtest_base.hh"
7#include "BKE_idtype.hh"
8#include "BKE_lib_id.hh"
9#include "BKE_main.hh"
10#include "BKE_object.hh"
11
12#include "ANIM_action.hh"
13
14#include "DNA_action_types.h"
15#include "DNA_anim_types.h"
16
17#include "BLI_vector.hh"
18
19#include "CLG_log.h"
20
21#include "testing/testing.h"
22
24
26
27TEST_F(AnimDataTest, BKE_fcurves_id_cb_test)
28{
29 Main *bmain = BKE_main_new();
30 bAction *action = BKE_id_new<bAction>(bmain, "ACÄnimåtië");
31 Object *cube = BKE_object_add_only_object(bmain, OB_EMPTY, "Küüübus");
32 Object *suzanne = BKE_object_add_only_object(bmain, OB_EMPTY, "OBSuzanne");
33
34 /* Create F-Curves for Cube. */
35 ASSERT_TRUE(animrig::assign_action(action, cube->id));
36 FCurve &fcurve_cube_loc1 = animrig::action_fcurve_ensure(
37 bmain, *action, cube->id, {"location", 1});
38 FCurve &fcurve_cube_scale2 = animrig::action_fcurve_ensure(
39 bmain, *action, cube->id, {"scale", 2});
40
41 /* Create F-Curves for Suzanne. */
42 ASSERT_TRUE(animrig::assign_action(action, suzanne->id));
43 FCurve &fcurve_suzanne_loc0 = animrig::action_fcurve_ensure(
44 bmain, *action, suzanne->id, {"location", 0});
45 FCurve &fcurve_suzanne_scale1 = animrig::action_fcurve_ensure(
46 bmain, *action, suzanne->id, {"scale", 1});
47
48 /* Test that BKE_fcurves_id_cb only reports F-Curves that are meant for that ID. */
49 Set<ID *> reported_ids;
50 Vector<FCurve *> reported_fcurves;
51 const auto callback = [&](ID *id, FCurve *fcurve) {
52 reported_ids.add(id);
53 reported_fcurves.append(fcurve);
54 };
55
56 BKE_fcurves_id_cb(&cube->id, callback);
57 EXPECT_EQ(1, reported_ids.size());
58 EXPECT_EQ(2, reported_fcurves.size());
59 EXPECT_EQ(&cube->id, *reported_ids.begin());
60 EXPECT_EQ(&fcurve_cube_loc1, reported_fcurves[0]);
61 EXPECT_EQ(&fcurve_cube_scale2, reported_fcurves[1]);
62
63 /* Also test for Suzanne, as that's a different slot. The first slot could
64 * have been covered by legacy-compatible code. */
65 reported_ids.clear();
66 reported_fcurves.clear();
67
68 BKE_fcurves_id_cb(&suzanne->id, callback);
69 EXPECT_EQ(1, reported_ids.size());
70 EXPECT_EQ(2, reported_fcurves.size());
71 EXPECT_EQ(&suzanne->id, *reported_ids.begin());
72 EXPECT_EQ(&fcurve_suzanne_loc0, reported_fcurves[0]);
73 EXPECT_EQ(&fcurve_suzanne_scale1, reported_fcurves[1]);
74
75 BKE_main_free(bmain);
76}
77
78} // namespace blender::bke::tests
Functions and classes to work with Actions.
Blender kernel action and pose functionality.
General operations, lookup, etc. for blender objects.
Iterator begin() const
Definition BLI_set.hh:499
int64_t size() const
Definition BLI_set.hh:606
bool add(const Key &key)
Definition BLI_set.hh:248
void clear()
Definition BLI_set.hh:570
int64_t size() const
void append(const T &value)
bool assign_action(bAction *action, ID &animated_id)
FCurve & action_fcurve_ensure(Main *bmain, bAction &action, ID &animated_id, const FCurveDescriptor &fcurve_descriptor)
TEST_F(AnimDataTest, BKE_fcurves_id_cb_test)
void BKE_fcurves_id_cb(struct ID *id, FunctionRef< void(ID *, FCurve *)> func)
Main * BKE_main_new()
Definition main.cc:93
void BKE_main_free(Main *bmain)
Definition main.cc:202
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
Definition object.cc:2265
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612