Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2020-11-10 17:33:14 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-11-10 17:36:21 +0300
commitfeb71f1d714887715fd9319c91edfe71eddb4a56 (patch)
treeccd842a60aab63b5aa8c04ae86fd2b130c13318c
parent75a2db5d9742a46ec4662fe85765f27b6f5e0f95 (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.
-rw-r--r--intern/guardedalloc/tests/guardedalloc_overflow_test.cc5
-rw-r--r--source/blender/blenkernel/intern/fcurve.c2
-rw-r--r--source/blender/blenkernel/intern/fcurve_test.cc26
-rw-r--r--tests/gtests/testing/testing.h18
4 files changed, 43 insertions, 8 deletions
diff --git a/intern/guardedalloc/tests/guardedalloc_overflow_test.cc b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
index e5754bc95ea..efbfc171fff 100644
--- a/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
+++ b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
@@ -5,11 +5,6 @@
#include "MEM_guardedalloc.h"
/* We expect to abort on integer overflow, to prevent possible exploits. */
-#ifdef _WIN32
-# define ABORT_PREDICATE ::testing::ExitedWithCode(3)
-#else
-# define ABORT_PREDICATE ::testing::KilledBySignal(SIGABRT)
-#endif
#if defined(__GNUC__) && !defined(__clang__)
/* Disable since it's the purpose of this test. */
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);
}
diff --git a/tests/gtests/testing/testing.h b/tests/gtests/testing/testing.h
index 34928035b7d..8136a93314e 100644
--- a/tests/gtests/testing/testing.h
+++ b/tests/gtests/testing/testing.h
@@ -137,4 +137,22 @@ inline void EXPECT_EQ_ARRAY_ND(const T *expected, const T *actual, const size_t
}
}
+#ifdef _WIN32
+# define ABORT_PREDICATE ::testing::ExitedWithCode(3)
+#else
+# define ABORT_PREDICATE ::testing::KilledBySignal(SIGABRT)
+#endif
+
+/* Test macro for when BLI_assert() is expected to fail.
+ * Note that the EXPECT_BLI_ASSERT macro is a no-op, unless used in a debug build with
+ * WITH_ASSERT_ABORT=ON. */
+#if defined(WITH_ASSERT_ABORT) && !defined(NDEBUG)
+/* EXPECT_EXIT() is used as that's the only exit-expecting function in GTest that allows us to
+ * check for SIGABRT. */
+# define EXPECT_BLI_ASSERT(function_call, expect_message) \
+ EXPECT_EXIT(function_call, ABORT_PREDICATE, expect_message)
+#else
+# define EXPECT_BLI_ASSERT(function_call, expect_message) function_call
+#endif
+
#endif // __BLENDER_TESTING_H__