5#include "testing/testing.h"
32struct fcurve_deleter {
41using FCurvePtr = std::unique_ptr<FCurve, fcurve_deleter>;
47FCurvePtr fake_fcurve(
const char *rna_path,
const int array_index)
56 return FCurvePtr(fcurve);
66FCurvePtr fake_fcurve_in_buffer(
const char *rna_path,
67 const int array_index,
70 ID *owner_id =
nullptr)
72 FCurvePtr fcurve_ptr = fake_fcurve(rna_path, array_index);
108 <<
"unflippable name should remain unchanged";
110 <<
"flippable name should be flipped";
112 EXPECT_EQ(
"pose.bones[\"Arm_L\"].rotation_euler",
113 flip_names(
"pose.bones[\"Arm_R\"].rotation_euler"))
114 <<
"flippable name should be flipped";
123 FCurvePtr fcurve_target = fake_fcurve(
nullptr, 0);
124 FCurvePtr fcurve_in_buffer = fake_fcurve_in_buffer(
nullptr, 0,
false);
128 auto call = [&](
const bool from_single,
const bool to_single,
const bool flip) {
130 nullptr, *fcurve_target, *fcurve_in_buffer, unassigned, from_single, to_single, flip);
134 EXPECT_FALSE(call(
false,
false,
false));
135 EXPECT_FALSE(call(
false,
false,
true));
136 EXPECT_TRUE(call(
false,
true,
false));
137 EXPECT_TRUE(call(
false,
true,
true));
138 EXPECT_FALSE(call(
true,
false,
false));
139 EXPECT_FALSE(call(
true,
false,
true));
140 EXPECT_TRUE(call(
true,
true,
false));
141 EXPECT_TRUE(call(
true,
true,
true));
146 FCurvePtr fcurve = fake_fcurve(
"location", 0);
150 *fake_fcurve_in_buffer(
"location", 0,
false),
157 *fake_fcurve_in_buffer(
"location", 1,
false),
162 <<
"array index mismatch";
165 *fake_fcurve_in_buffer(
"rotation_euler", 0,
false),
170 <<
"rna path mismatch";
176 const bool from_single =
false;
177 const bool to_single =
false;
178 const bool flip =
true;
180 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
185 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
190 <<
"original path match, is bone";
194 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
199 <<
"flipped path match, is bone";
204 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
false),
209 <<
"flipped path match, is NOT bone";
213 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
false),
218 <<
"original path match, is NOT bone";
222 *fake_fcurve_in_buffer(
"location", 0,
false),
227 <<
"rna path mismatch";
232 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
237 <<
"flipped path match, but array index mismatch";
244 const bool from_single =
false;
245 const bool to_single =
true;
246 const bool flip =
true;
248 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
253 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
258 <<
"original path match, is bone";
262 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
267 <<
"flipped path match, is bone";
271 *fake_fcurve_in_buffer(
"location", 0,
false),
276 <<
"rna path mismatch, ACI is NOT bone";
281 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
286 <<
"rna path mismatch, ACI is bone";
291 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
296 <<
"original path match, but array index mismatch";
301 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
306 <<
"flipped path match, but array index mismatch";
311 const bool from_single =
true;
312 const bool to_single =
false;
313 const bool flip =
true;
315 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
320 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
325 <<
"original path match, is bone";
329 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
334 <<
"flipped path match, is bone";
338 *fake_fcurve_in_buffer(
"location", 0,
false),
343 <<
"rna path mismatch, ACI is NOT bone";
348 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
353 <<
"rna path mismatch, ACI is bone";
358 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
363 <<
"original path match, but array index mismatch";
368 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
373 <<
"flipped path match, but array index mismatch";
379 const bool from_single =
true;
380 const bool to_single =
false;
381 const bool flip =
false;
383 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
388 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
393 <<
"original path match, is bone";
397 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
402 <<
"flipped path match, is bone";
406 *fake_fcurve_in_buffer(
"location", 0,
false),
411 <<
"rna path mismatch, ACI is NOT bone";
416 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
421 <<
"rna path mismatch, ACI is bone";
426 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
431 <<
"original path match, but array index mismatch";
436 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
441 <<
"flipped path match, but array index mismatch";
447 const bool from_single =
true;
448 const bool to_single =
true;
449 const bool flip =
true;
451 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
456 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 0,
true),
461 <<
"original path match, is bone";
465 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 0,
true),
470 <<
"flipped path match, is bone";
474 *fake_fcurve_in_buffer(
"location", 0,
false),
479 <<
"rna path mismatch, ACI is NOT bone";
484 *fake_fcurve_in_buffer(
"pose.bones[\"nose\"].rotation_euler", 0,
true),
489 <<
"rna path mismatch, ACI is bone";
494 *fake_fcurve_in_buffer(
"pose.bones[\"hand.R\"].location", 1,
true),
499 <<
"flipped path match, but array index mismatch";
504 *fake_fcurve_in_buffer(
"pose.bones[\"hand.L\"].location", 1,
true),
509 <<
"original path match, but array index mismatch";
524 for (
const auto &bone_name : {
"hand.L",
"hand.R",
"middle"}) {
531 armature_object->
data = armature;
534 arm_ob_id = &armature_object->
id;
538 const auto fake_armob_fcurve =
539 [&](
const char *rna_path,
const int array_index,
const bool is_bone) {
540 return fake_fcurve_in_buffer(rna_path, array_index, is_bone, unassigned, arm_ob_id);
545 const bool from_single =
true;
546 const bool to_single =
false;
547 const bool flip =
false;
549 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
554 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
559 <<
"original path match, is bone";
564 *fake_armob_fcurve(
"pose.bones[\"hand.R\"].location", 0,
true),
569 <<
"flipped path match, is bone";
574 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 2,
true),
579 <<
"original path match, other array index";
584 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].rotation_euler", 0,
true),
589 <<
"same bone, other property";
593 *fake_armob_fcurve(
"rotation_euler", 0,
false),
598 <<
"other struct, same property name";
603 *fake_armob_fcurve(
"pose.bones[\"missing\"].location", 0,
true),
608 <<
"nonexistent bone, but same property name";
612 FCurvePtr fcurve_with_long_rna_path = fake_fcurve(
613 "pose.bones[\"hand.L\"].weirdly_long_location", 0);
617 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
622 <<
"property name suffix-match";
627 const bool from_single =
false;
628 const bool to_single =
false;
629 const bool flip =
false;
631 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
636 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
641 <<
"original path match, is bone";
646 *fake_armob_fcurve(
"pose.bones[\"hand.R\"].location", 0,
true),
651 <<
"flipped path match, is bone";
656 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 2,
true),
661 <<
"original path match, other array index";
666 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].rotation_euler", 0,
true),
671 <<
"same bone, other property";
675 *fake_armob_fcurve(
"rotation_euler", 0,
false),
680 <<
"other struct, same property name";
685 *fake_armob_fcurve(
"pose.bones[\"missing\"].location", 0,
true),
690 <<
"nonexistent bone, but same property name";
694 FCurvePtr fcurve_with_long_rna_path = fake_fcurve(
695 "pose.bones[\"hand.L\"].weirdly_long_location", 0);
699 *fake_armob_fcurve(
"pose.bones[\"hand.L\"].location", 0,
true),
704 <<
"property name suffix-match";
709 FCurvePtr fcurve = fake_fcurve(
"pose.bones[\"hand.L\"].location", 0);
715 *fake_fcurve_in_buffer(
716 "pose.bones[\"hand.L\"].location", 0,
true, unassigned, &object_not_in_main->
id),
721 <<
"copying from deleted ID";
733 FCurvePtr fcurve = fake_fcurve(
"some_prop", 1);
737 *fake_fcurve_in_buffer(
"location", 1,
false),
744 *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
#define STRNCPY_UTF8(dst, 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()