diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-11-10 17:33:14 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-11-10 17:36:21 +0300 |
commit | feb71f1d714887715fd9319c91edfe71eddb4a56 (patch) | |
tree | ccd842a60aab63b5aa8c04ae86fd2b130c13318c /source/blender | |
parent | 75a2db5d9742a46ec4662fe85765f27b6f5e0f95 (diff) |
Animation: Expand unit tests for `BKE_fcurve_active_keyframe_index()`
Expand unit test for `BKE_fcurve_active_keyframe_index()` to test edge
cases better.
This also introduces a new test macro `EXPECT_BLI_ASSERT()`, which can be
used to test that an assertion fails successfully.
No functional changes to actual Blender code.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fcurve_test.cc | 26 |
2 files changed, 25 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 8bfc626379f..e6d3696b198 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -855,7 +855,7 @@ void BKE_fcurve_active_keyframe_set(FCurve *fcu, const BezTriple *active_bezt) } /* The active keyframe should always be selected. */ - BLI_assert(BEZT_ISSEL_ANY(active_bezt)); + BLI_assert(BEZT_ISSEL_ANY(active_bezt) || !"active keyframe must be selected"); fcu->active_keyframe_index = (int)offset; } diff --git a/source/blender/blenkernel/intern/fcurve_test.cc b/source/blender/blenkernel/intern/fcurve_test.cc index 97dd541e2b9..fb6ce02d146 100644 --- a/source/blender/blenkernel/intern/fcurve_test.cc +++ b/source/blender/blenkernel/intern/fcurve_test.cc @@ -22,6 +22,7 @@ #include "BKE_fcurve.h" #include "ED_keyframing.h" +#include "ED_types.h" /* For SELECT. */ #include "DNA_anim_types.h" @@ -295,17 +296,38 @@ TEST(fcurve_active_keyframe, ActiveKeyframe) EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), FCURVE_ACTIVE_KEYFRAME_NONE); /* Check a "normal" action. */ + fcu->bezt[2].f2 |= SELECT; BKE_fcurve_active_keyframe_set(fcu, &fcu->bezt[2]); EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), 2); - /* Check out of bounds. */ + /* Check setting an unselected keyframe as active. */ + fcu->bezt[2].f1 = fcu->bezt[2].f2 = fcu->bezt[2].f3 = 0; + EXPECT_BLI_ASSERT(BKE_fcurve_active_keyframe_set(fcu, &fcu->bezt[2]), + "active keyframe must be selected"); + EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), FCURVE_ACTIVE_KEYFRAME_NONE); + + /* Check out of bounds (lower). */ BKE_fcurve_active_keyframe_set(fcu, fcu->bezt - 20); + EXPECT_EQ(fcu->active_keyframe_index, FCURVE_ACTIVE_KEYFRAME_NONE) + << "Setting out-of-bounds value via the API should result in valid active_keyframe_index"; EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), FCURVE_ACTIVE_KEYFRAME_NONE); - /* Check out of bounds again. */ + fcu->active_keyframe_index = -20; + EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), FCURVE_ACTIVE_KEYFRAME_NONE) + << "Even with active_keyframe_index out of bounds, getting it via the API should produce a " + "valid value"; + + /* Check out of bounds (higher). */ BKE_fcurve_active_keyframe_set(fcu, fcu->bezt + 4); + EXPECT_EQ(fcu->active_keyframe_index, FCURVE_ACTIVE_KEYFRAME_NONE) + << "Setting out-of-bounds value via the API should result in valid active_keyframe_index"; EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), FCURVE_ACTIVE_KEYFRAME_NONE); + fcu->active_keyframe_index = fcu->totvert; + EXPECT_EQ(BKE_fcurve_active_keyframe_index(fcu), FCURVE_ACTIVE_KEYFRAME_NONE) + << "Even with active_keyframe_index out of bounds, getting it via the API should produce a " + "valid value"; + BKE_fcurve_free(fcu); } |