5#include "testing/testing.h"
28using namespace blender::animrig;
35struct fcurve_deleter {
44using FCurvePtr = std::unique_ptr<FCurve, fcurve_deleter>;
50FCurvePtr fake_fcurve(
const char *
rna_path,
const int array_index)
59 return FCurvePtr(fcurve);
69FCurvePtr fake_fcurve_in_buffer(
const char *
rna_path,
70 const int array_index,
73 ID *owner_id =
nullptr)
75 FCurvePtr fcurve_ptr = fake_fcurve(
rna_path, array_index);
113 <<
"unflippable name should remain unchanged";
115 <<
"flippable name should be flipped";
117 EXPECT_EQ(
"pose.bones[\"Arm_L\"].rotation_euler",
118 flip_names(
"pose.bones[\"Arm_R\"].rotation_euler"))
119 <<
"flippable name should be flipped";
128 FCurvePtr fcurve_target = fake_fcurve(
nullptr, 0);
129 FCurvePtr fcurve_in_buffer = fake_fcurve_in_buffer(
nullptr, 0,
false);
133 auto call = [&](
const bool from_single,
const bool to_single,
const bool flip) {
135 nullptr, *fcurve_target, *fcurve_in_buffer, unassigned, from_single, to_single, flip);
151 FCurvePtr fcurve = fake_fcurve(
"location", 0);
155 *fake_fcurve_in_buffer(
"location", 0,
false),
162 *fake_fcurve_in_buffer(
"location", 1,
false),
167 <<
"array index mismatch";
170 *fake_fcurve_in_buffer(
"rotation_euler", 0,
false),
175 <<
"rna path mismatch";
181 const bool from_single =
false;
182 const bool to_single =
false;
183 const bool flip =
true;
185 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
190 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
195 <<
"original path match, is bone";
199 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
204 <<
"flipped path match, is bone";
209 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
false),
214 <<
"flipped path match, is NOT bone";
218 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
false),
223 <<
"original path match, is NOT bone";
227 *fake_fcurve_in_buffer(
"location", 0,
false),
232 <<
"rna path mismatch";
237 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
242 <<
"flipped path match, but array index mismatch";
249 const bool from_single =
false;
250 const bool to_single =
true;
251 const bool flip =
true;
253 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
258 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
263 <<
"original path match, is bone";
267 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
272 <<
"flipped path match, is bone";
276 *fake_fcurve_in_buffer(
"location", 0,
false),
281 <<
"rna path mismatch, ACI is NOT bone";
286 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
291 <<
"rna path mismatch, ACI is bone";
296 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
301 <<
"original path match, but array index mismatch";
306 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
311 <<
"flipped path match, but array index mismatch";
316 const bool from_single =
true;
317 const bool to_single =
false;
318 const bool flip =
true;
320 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
325 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
330 <<
"original path match, is bone";
334 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
339 <<
"flipped path match, is bone";
343 *fake_fcurve_in_buffer(
"location", 0,
false),
348 <<
"rna path mismatch, ACI is NOT bone";
353 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
358 <<
"rna path mismatch, ACI is bone";
363 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
368 <<
"original path match, but array index mismatch";
373 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
378 <<
"flipped path match, but array index mismatch";
384 const bool from_single =
true;
385 const bool to_single =
false;
386 const bool flip =
false;
388 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
393 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
398 <<
"original path match, is bone";
402 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
407 <<
"flipped path match, is bone";
411 *fake_fcurve_in_buffer(
"location", 0,
false),
416 <<
"rna path mismatch, ACI is NOT bone";
421 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
426 <<
"rna path mismatch, ACI is bone";
431 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
436 <<
"original path match, but array index mismatch";
441 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
446 <<
"flipped path match, but array index mismatch";
452 const bool from_single =
true;
453 const bool to_single =
true;
454 const bool flip =
true;
456 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
461 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
466 <<
"original path match, is bone";
470 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
475 <<
"flipped path match, is bone";
479 *fake_fcurve_in_buffer(
"location", 0,
false),
484 <<
"rna path mismatch, ACI is NOT bone";
489 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
494 <<
"rna path mismatch, ACI is bone";
499 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
504 <<
"flipped path match, but array index mismatch";
509 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
514 <<
"original path match, but array index mismatch";
527 for (
const auto &bone_name : {
"hand.L",
"hand.R",
"middle"}) {
528 Bone *bone = MEM_new<Bone>(__func__);
534 armature_object->
data = id_cast<ID *>(armature);
537 arm_ob_id = &armature_object->
id;
541 const auto fake_armob_fcurve =
542 [&](
const char *
rna_path,
const int array_index,
const bool is_bone) {
543 return fake_fcurve_in_buffer(
rna_path, array_index, is_bone, unassigned, arm_ob_id);
548 const bool from_single =
true;
549 const bool to_single =
false;
550 const bool flip =
false;
552 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
557 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
562 <<
"original path match, is bone";
567 *fake_armob_fcurve(
"pose.bones[\"hand.R\"].location", 0,
true),
572 <<
"flipped path match, is bone";
577 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 2,
true),
582 <<
"original path match, other array index";
587 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].rotation_euler", 0,
true),
592 <<
"same bone, other property";
597 *fake_armob_fcurve(
"pose.bones[\"hand.", 0,
true),
602 <<
"malformed rna path";
607 *fake_armob_fcurve(
"location", 0,
false),
612 <<
"other struct, same property name";
616 *fake_armob_fcurve(
"location", 0,
false),
621 <<
"other struct, same property name";
626 *fake_armob_fcurve(
"pose.bones[\"missing\"].location", 0,
true),
631 <<
"nonexistent bone, but same property name";
635 FCurvePtr fcurve_with_long_rna_path = fake_fcurve(
636 "pose.bones[\"hand.L\"].weirdly_long_location", 0);
640 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
645 <<
"property name suffix-match";
650 const bool from_single =
false;
651 const bool to_single =
false;
652 const bool flip =
false;
654 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
659 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
664 <<
"original path match, is bone";
669 *fake_armob_fcurve(
"pose.bones[\"hand.R\"].location", 0,
true),
674 <<
"flipped path match, is bone";
679 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 2,
true),
684 <<
"original path match, other array index";
689 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].rotation_euler", 0,
true),
694 <<
"same bone, other property";
699 *fake_armob_fcurve(
"location", 0,
false),
704 <<
"other struct, same property name";
708 *fake_armob_fcurve(
"location", 0,
false),
713 <<
"other struct, same property name";
718 *fake_armob_fcurve(
"pose.bones[\"missing\"].location", 0,
true),
723 <<
"nonexistent bone, but same property name";
727 FCurvePtr fcurve_with_long_rna_path = fake_fcurve(
728 "pose.bones[\"hand.L\"].weirdly_long_location", 0);
731 *fcurve_with_long_rna_path,
732 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
737 <<
"property name suffix-match";
742 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
748 *fake_fcurve_in_buffer(
749 "pose.bones[\"hand.L\"].location", 0,
true, unassigned, &object_not_in_main->
id),
754 <<
"copying from deleted ID";
766 FCurvePtr fcurve = fake_fcurve(
"some_prop", 1);
770 *fake_fcurve_in_buffer(
"location", 1,
false),
777 *fake_fcurve_in_buffer(
"location", 2,
false),
General operations, lookup, etc. for blender objects.
#define STRNCPY_UTF8(dst, src)
Object is a sort of wrapper for general info.
static constexpr slot_handle_t unassigned
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
decltype(blender::ActionSlot::handle) slot_handle_t
TEST_F(keyframes_paste, flip_names)
std::optional< std::string > flip_names(const StringRefNull rna_path)
KeyframeCopyBuffer * keyframe_copy_buffer
bool pastebuf_match_index_only(Main *, const FCurve &fcurve_to_match, const FCurve &fcurve_in_copy_buffer, animrig::slot_handle_t, const bool from_single, const bool, const bool)
bool pastebuf_match_path_property_and_component_length(Main *bmain, const FCurve &fcurve_to_match, const FCurve &fcurve_in_copy_buffer, const animrig::slot_handle_t slot_handle_in_copy_buffer, const bool from_single, const bool to_single, const bool flip)
bool pastebuf_match_path_property(Main *, const FCurve &fcurve_to_match, const FCurve &fcurve_in_copy_buffer, 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, animrig::slot_handle_t, const bool from_single, const bool to_single, const bool flip)
void ANIM_fcurves_copybuf_reset()
bArmature * BKE_armature_add(Main *bmain, const char *name)
void ANIM_fcurves_copybuf_free()
void BKE_pose_ensure(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
void BKE_id_free(Main *bmain, void *idv)
void BKE_main_free(Main *bmain)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void BKE_fcurve_free(FCurve *fcu)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
FCurve * BKE_fcurve_create()
ListBaseT< Bone > bonebase
Set< const FCurve * > bone_fcurves
Map< blender::animrig::slot_handle_t, ID * > slot_animated_ids
static void SetUpTestSuite()
static void TearDownTestSuite()