Blender V5.0
anim_draw_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
6
7#include "ED_anim_api.hh"
8
9#include "DNA_anim_types.h"
10
11#include "BKE_fcurve.hh"
12#include "BKE_idtype.hh"
13#include "BKE_lib_id.hh"
14#include "BKE_main.hh"
15
16#include "CLG_log.h"
17#include "testing/testing.h"
18
20
21class AnimDrawTest : public testing::Test {
22 public:
25
26 static void SetUpTestSuite()
27 {
28 CLG_init();
30 }
31
32 static void TearDownTestSuite()
33 {
34 CLG_exit();
35 }
36
37 void SetUp() override
38 {
39 this->bmain = BKE_main_new();
40 this->object = BKE_id_new<Object>(this->bmain, "OBTestObject");
41 }
42
43 void TearDown() override
44 {
45 BKE_main_free(this->bmain);
46 }
47};
48
49TEST_F(AnimDrawTest, anim_unit_mapping_get_factor_not_normalizing)
50{
51 FCurve *fcurve = MEM_callocN<FCurve>(__func__);
52 fcurve->array_index = 0;
53
54 /* Avoid creating a Scene via BKE_id_new<Scene>(this->bmain, "SCTestScene"); as that requires
55 * much more setup (appdirs, imbuf for color management, and maybe more). This test doesn't
56 * actually need a full Scene, it just needs its `units` field. */
57 Scene scene;
58 memset(&scene.unit, 0, sizeof(scene.unit));
59 scene.unit.scale_length = 1.0f;
60
61 { /* Rotation: Degrees. */
62 scene.unit.system_rotation = 0;
63 BKE_fcurve_rnapath_set(*fcurve, "rotation_euler");
64
65 EXPECT_FLOAT_EQ(RAD2DEGF(1.0f),
66 ANIM_unit_mapping_get_factor(&scene, &this->object->id, fcurve, 0, nullptr));
67 EXPECT_FLOAT_EQ(1.0f / RAD2DEGF(1.0f),
69 &scene, &this->object->id, fcurve, ANIM_UNITCONV_RESTORE, nullptr));
70 }
71
72 { /* Rotation: Radians. */
74 BKE_fcurve_rnapath_set(*fcurve, "rotation_euler");
75
76 EXPECT_FLOAT_EQ(1.0f,
77 ANIM_unit_mapping_get_factor(&scene, &this->object->id, fcurve, 0, nullptr));
78 EXPECT_FLOAT_EQ(1.0f,
80 &scene, &this->object->id, fcurve, ANIM_UNITCONV_RESTORE, nullptr));
81 }
82
83 BKE_fcurve_free(fcurve);
84}
85
86} // namespace blender::animrig::tests
void BKE_fcurve_rnapath_set(FCurve &fcu, blender::StringRef rna_path)
void BKE_fcurve_free(FCurve *fcu)
void BKE_idtype_init()
Definition idtype.cc:121
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1514
Main * BKE_main_new()
Definition main.cc:89
void BKE_main_free(Main *bmain)
Definition main.cc:192
#define RAD2DEGF(_rad)
void CLG_exit()
Definition clog.cc:880
void CLG_init()
Definition clog.cc:873
@ USER_UNIT_ROT_RADIANS
@ ANIM_UNITCONV_RESTORE
float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset)
Definition anim_draw.cc:624
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
TEST_F(ActionIteratorsTest, iterate_all_fcurves_of_slot)
int array_index
struct UnitSettings unit