Blender V5.3
action_legacy_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#include "ANIM_action.hh"
6
7#include "BKE_fcurve.hh"
8#include "BKE_gtest_base.hh"
9#include "BKE_idtype.hh"
10#include "BKE_lib_id.hh"
11#include "BKE_main.hh"
12#include "BKE_object.hh"
13
14#include "DNA_anim_types.h"
15
16#include "BLI_listbase.hh"
17
18#include "testing/testing.h"
19
22 public:
24
25 void SetUp() override
26 {
28 }
29
30 void TearDown() override
31 {
33 }
34
36 {
37 return BKE_id_new<bAction>(bmain, "ACAction");
38 }
39
40 FCurve *fcurve_add_legacy(bAction *action, const StringRefNull rna_path, const int array_index)
41 {
42 FCurve *fcurve = BKE_fcurve_create();
43 fcurve->rna_path_set(rna_path);
44 fcurve->array_index = array_index;
45 BLI_addtail(&action->curves, fcurve);
46 return fcurve;
47 }
48};
49
51{
52 { /* nil pointer. */
53 bAction *action = nullptr;
54 Vector<FCurve *> fcurves = legacy::fcurves_all(action);
55 EXPECT_TRUE(fcurves.is_empty());
56 }
57
58 { /* Empty Action. */
59 Vector<FCurve *> fcurves = legacy::fcurves_all(create_empty_action());
60 EXPECT_TRUE(fcurves.is_empty());
61 }
62 Action &action = create_empty_action()->wrap();
63 Slot &slot1 = action.slot_add();
64 Slot &slot2 = action.slot_add();
65
66 action.layer_keystrip_ensure();
67 StripKeyframeData &key_data = action.layer(0)->strip(0)->data<StripKeyframeData>(action);
68
69 FCurve &fcurve1 = key_data.channelbag_for_slot_ensure(slot1).fcurve_ensure(bmain,
70 {"location", 1});
71 FCurve &fcurve2 = key_data.channelbag_for_slot_ensure(slot2).fcurve_ensure(bmain, {"scale", 2});
72
73 Vector<FCurve *> fcurves_expect = {&fcurve1, &fcurve2};
74 EXPECT_EQ(fcurves_expect, legacy::fcurves_all(&action));
75}
76
77TEST_F(ActionLegacyTest, action_fcurves_remove)
78{
79 { /* Empty Action. */
80 bAction *action = create_empty_action();
82 }
83 /* Create an Action with two slots, to check that the 2nd slot is not affected
84 * by removal from the 1st. */
85 Action &action = create_empty_action()->wrap();
86 Slot &slot_1 = action.slot_add();
87 Slot &slot_2 = action.slot_add();
88
89 action.layer_keystrip_ensure();
90 StripKeyframeData *strip_data = action.strip_keyframe_data()[0];
91 Channelbag &bag_1 = strip_data->channelbag_for_slot_ensure(slot_1);
92 Channelbag &bag_2 = strip_data->channelbag_for_slot_ensure(slot_2);
93
94 /* Add some F-Curves to each channelbag. */
95 FCurve &fcurve_loc_x = bag_1.fcurve_ensure(nullptr, {"location", 0});
96 bag_1.fcurve_ensure(nullptr, {"rotation_euler", 2});
97 bag_1.fcurve_ensure(nullptr, {"rotation_mode", 0});
98 FCurve &fcurve_loc_y = bag_1.fcurve_ensure(nullptr, {"location", 1});
99
100 bag_2.fcurve_ensure(nullptr, {"location", 0});
101 bag_2.fcurve_ensure(nullptr, {"rotation_euler", 2});
102 bag_2.fcurve_ensure(nullptr, {"rotation_mode", 0});
103 bag_2.fcurve_ensure(nullptr, {"location", 1});
104
105 /* Check that removing from slot_1 works as expected. */
106 EXPECT_TRUE(legacy::action_fcurves_remove(action, slot_1.handle, "rotation"));
107
108 Vector<FCurve *> fcurves_bag_1_expect = {&fcurve_loc_x, &fcurve_loc_y};
109 EXPECT_EQ(fcurves_bag_1_expect.as_span(),
111
112 EXPECT_EQ(4, bag_2.fcurves().size())
113 << "Expected all F-Curves for slot 2 to be there after manipulating slot 1";
114}
115
116} // namespace blender::animrig::tests
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
General operations, lookup, etc. for blender objects.
bool is_empty() const
Span< T > as_span() const
const Layer * layer(int64_t index) const
Span< const StripKeyframeData * > strip_keyframe_data() const
Span< const FCurve * > fcurves() const
FCurve & fcurve_ensure(Main *bmain, const FCurveDescriptor &fcurve_descriptor)
const Strip * strip(int64_t index) const
static constexpr slot_handle_t unassigned
Channelbag & channelbag_for_slot_ensure(const Slot &slot)
const T & data(const Action &owning_action) const
FCurve * fcurve_add_legacy(bAction *action, const StringRefNull rna_path, const int array_index)
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
Vector< const FCurve * > fcurves_all(const bAction *action)
bool action_fcurves_remove(bAction &action, slot_handle_t slot_handle, StringRefNull rna_path_prefix)
TEST_F(ActionIteratorsTest, iterate_all_fcurves_of_slot)
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
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)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
FCurve * BKE_fcurve_create()
ListBaseT< FCurve > curves