5#include "testing/testing.h"
31struct fcurve_deleter {
40using FCurvePtr = std::unique_ptr<FCurve, fcurve_deleter>;
46FCurvePtr fake_fcurve(
const char *rna_path,
const int array_index)
55 return FCurvePtr(fcurve);
65FCurvePtr fake_fcurve_in_buffer(
const char *rna_path,
66 const int array_index,
69 ID *owner_id =
nullptr)
71 FCurvePtr fcurve_ptr = fake_fcurve(rna_path, array_index);
107 <<
"unflippable name should remain unchanged";
109 <<
"flippable name should be flipped";
111 EXPECT_EQ(
"pose.bones[\"Arm_L\"].rotation_euler",
112 flip_names(
"pose.bones[\"Arm_R\"].rotation_euler"))
113 <<
"flippable name should be flipped";
122 FCurvePtr fcurve_target = fake_fcurve(
nullptr, 0);
123 FCurvePtr fcurve_in_buffer = fake_fcurve_in_buffer(
nullptr, 0,
false);
127 auto call = [&](
const bool from_single,
const bool to_single,
const bool flip) {
129 nullptr, *fcurve_target, *fcurve_in_buffer, unassigned, from_single, to_single, flip);
133 EXPECT_FALSE(call(
false,
false,
false));
134 EXPECT_FALSE(call(
false,
false,
true));
135 EXPECT_TRUE(call(
false,
true,
false));
136 EXPECT_TRUE(call(
false,
true,
true));
137 EXPECT_FALSE(call(
true,
false,
false));
138 EXPECT_FALSE(call(
true,
false,
true));
139 EXPECT_TRUE(call(
true,
true,
false));
140 EXPECT_TRUE(call(
true,
true,
true));
145 FCurvePtr fcurve = fake_fcurve(
"location", 0);
149 *fake_fcurve_in_buffer(
"location", 0,
false),
156 *fake_fcurve_in_buffer(
"location", 1,
false),
161 <<
"array index mismatch";
164 *fake_fcurve_in_buffer(
"rotation_euler", 0,
false),
169 <<
"rna path mismatch";
175 const bool from_single =
false;
176 const bool to_single =
false;
177 const bool flip =
true;
179 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
184 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
189 <<
"original path match, is bone";
193 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
198 <<
"flipped path match, is bone";
203 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
false),
208 <<
"flipped path match, is NOT bone";
212 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
false),
217 <<
"original path match, is NOT bone";
221 *fake_fcurve_in_buffer(
"location", 0,
false),
226 <<
"rna path mismatch";
231 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
236 <<
"flipped path match, but array index mismatch";
243 const bool from_single =
false;
244 const bool to_single =
true;
245 const bool flip =
true;
247 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
252 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
257 <<
"original path match, is bone";
261 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
266 <<
"flipped path match, is bone";
270 *fake_fcurve_in_buffer(
"location", 0,
false),
275 <<
"rna path mismatch, ACI is NOT bone";
280 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
285 <<
"rna path mismatch, ACI is bone";
290 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
295 <<
"original path match, but array index mismatch";
300 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
305 <<
"flipped path match, but array index mismatch";
310 const bool from_single =
true;
311 const bool to_single =
false;
312 const bool flip =
true;
314 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
319 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
324 <<
"original path match, is bone";
328 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
333 <<
"flipped path match, is bone";
337 *fake_fcurve_in_buffer(
"location", 0,
false),
342 <<
"rna path mismatch, ACI is NOT bone";
347 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
352 <<
"rna path mismatch, ACI is bone";
357 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
362 <<
"original path match, but array index mismatch";
367 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
372 <<
"flipped path match, but array index mismatch";
378 const bool from_single =
true;
379 const bool to_single =
false;
380 const bool flip =
false;
382 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
387 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
392 <<
"original path match, is bone";
396 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
401 <<
"flipped path match, is bone";
405 *fake_fcurve_in_buffer(
"location", 0,
false),
410 <<
"rna path mismatch, ACI is NOT bone";
415 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
420 <<
"rna path mismatch, ACI is bone";
425 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
430 <<
"original path match, but array index mismatch";
435 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
440 <<
"flipped path match, but array index mismatch";
446 const bool from_single =
true;
447 const bool to_single =
true;
448 const bool flip =
true;
450 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
455 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
460 <<
"original path match, is bone";
464 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
469 <<
"flipped path match, is bone";
473 *fake_fcurve_in_buffer(
"location", 0,
false),
478 <<
"rna path mismatch, ACI is NOT bone";
483 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
488 <<
"rna path mismatch, ACI is bone";
493 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
498 <<
"flipped path match, but array index mismatch";
503 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
508 <<
"original path match, but array index mismatch";
523 for (
const auto &bone_name : {
"hand.L",
"hand.R",
"middle"}) {
530 armature_object->
data = armature;
533 arm_ob_id = &armature_object->
id;
537 const auto fake_armob_fcurve =
538 [&](
const char *rna_path,
const int array_index,
const bool is_bone) {
539 return fake_fcurve_in_buffer(rna_path, array_index, is_bone, unassigned, arm_ob_id);
544 const bool from_single =
true;
545 const bool to_single =
false;
546 const bool flip =
false;
548 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
553 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
558 <<
"original path match, is bone";
563 *fake_armob_fcurve(
"pose.bones[\"hand.R\"].location", 0,
true),
568 <<
"flipped path match, is bone";
573 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 2,
true),
578 <<
"original path match, other array index";
583 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].rotation_euler", 0,
true),
588 <<
"same bone, other property";
592 *fake_armob_fcurve(
"rotation_euler", 0,
false),
597 <<
"other struct, same property name";
602 *fake_armob_fcurve(
"pose.bones[\"missing\"].location", 0,
true),
607 <<
"nonexistent bone, but same property name";
611 FCurvePtr fcurve_with_long_rna_path = fake_fcurve(
612 "pose.bones[\"hand.L\"].weirdly_long_location", 0);
616 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
621 <<
"property name suffix-match";
626 const bool from_single =
false;
627 const bool to_single =
false;
628 const bool flip =
false;
630 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
635 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
640 <<
"original path match, is bone";
645 *fake_armob_fcurve(
"pose.bones[\"hand.R\"].location", 0,
true),
650 <<
"flipped path match, is bone";
655 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 2,
true),
660 <<
"original path match, other array index";
665 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].rotation_euler", 0,
true),
670 <<
"same bone, other property";
674 *fake_armob_fcurve(
"rotation_euler", 0,
false),
679 <<
"other struct, same property name";
684 *fake_armob_fcurve(
"pose.bones[\"missing\"].location", 0,
true),
689 <<
"nonexistent bone, but same property name";
693 FCurvePtr fcurve_with_long_rna_path = fake_fcurve(
694 "pose.bones[\"hand.L\"].weirdly_long_location", 0);
698 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
703 <<
"property name suffix-match";
708 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
714 *fake_fcurve_in_buffer(
715 "pose.bones[\"hand.L\"].location", 0,
true, unassigned, &object_not_in_main->
id),
720 <<
"copying from deleted ID";
732 FCurvePtr fcurve = fake_fcurve(
"some_prop", 1);
736 *fake_fcurve_in_buffer(
"location", 1,
false),
743 *fake_fcurve_in_buffer(
"location", 2,
false),
void BKE_pose_ensure(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
bArmature * BKE_armature_add(Main *bmain, const char *name)
FCurve * BKE_fcurve_create()
void BKE_fcurve_free(FCurve *fcu)
void BKE_id_free(Main *bmain, void *idv)
void BKE_main_free(Main *bmain)
General operations, lookup, etc. for blender objects.
Object * BKE_object_add_only_object(Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
char * STRNCPY(char(&dst)[N], const char *src)
Object is a sort of wrapper for general info.
static constexpr slot_handle_t unassigned
void ANIM_fcurves_copybuf_reset()
void ANIM_fcurves_copybuf_free()
void * MEM_callocN(size_t len, const char *str)
TEST_F(ActionIteratorsTest, iterate_all_fcurves_of_slot)
decltype(::ActionSlot::handle) slot_handle_t
KeyframeCopyBuffer * keyframe_copy_buffer
bool pastebuf_match_index_only(Main *, const FCurve &fcurve_to_match, const FCurve &fcurve_in_copy_buffer, blender::animrig::slot_handle_t, const bool from_single, const bool, const bool)
bool pastebuf_match_path_full(Main *, const FCurve &fcurve_to_match, const FCurve &fcurve_in_copy_buffer, blender::animrig::slot_handle_t, const bool from_single, const bool to_single, const bool flip)
bool pastebuf_match_path_property(Main *bmain, const FCurve &fcurve_to_match, const FCurve &fcurve_in_copy_buffer, blender::animrig::slot_handle_t slot_handle_in_copy_buffer, const bool from_single, const bool, const bool)
std::optional< std::string > flip_names(const blender::StringRefNull rna_path)
static void SetUpTestSuite()
static void TearDownTestSuite()