Anim: add keyframing unit tests #122553

Merged
Nathan Vegdahl merged 17 commits from nathanvegdahl/blender:keyframing_unit_tests into main 2024-06-04 16:04:04 +02:00
Member

Add unit tests for the two main keyframing API functions: insert_key_rna() and insert_keyframe().

This is (partly) in preparation for landing #121661 and #122053, to help catch unintended changes to existing behavior.

The tests are not exhaustive of every possible permutation of parameters, but the tests do try to hit each of the behaviors in at least one permutation. In the future tests should also be added for the lower-level keying functions and behaviors as well, but I'm leaving that as future work since we aren't changing/refactoring those functions right now.

Note to reviewers: the test for the NLA quaternions special case is only implemented for insert_keyframe() and not insert_key_rna() because the latter doesn't implement that special case and thus wouldn't pass. I suspect this is because insert_key_rna() is used for viewport keyframing where in theory you can't key individual components of the quaternion anyway. In any case, the two functions will be merged and this will become moot when we land #122053.

Add unit tests for the two main keyframing API functions: `insert_key_rna()` and `insert_keyframe()`. This is (partly) in preparation for landing #121661 and #122053, to help catch unintended changes to existing behavior. The tests are not exhaustive of every possible permutation of parameters, but the tests do try to hit each of the behaviors in at least one permutation. In the future tests should also be added for the lower-level keying functions and behaviors as well, but I'm leaving that as future work since we aren't changing/refactoring those functions right now. **Note to reviewers:** the test for the NLA quaternions special case is only implemented for `insert_keyframe()` and not `insert_key_rna()` because the latter doesn't implement that special case and thus wouldn't pass. I suspect this is because `insert_key_rna()` is used for viewport keyframing where in theory you can't key individual components of the quaternion anyway. In any case, the two functions will be merged and this will become moot when we land #122053.
Nathan Vegdahl added the
Module
Animation & Rigging
label 2024-05-31 16:10:51 +02:00
Nathan Vegdahl added 1 commit 2024-05-31 16:11:01 +02:00
So far it's just testing a trikcy special case of the NLA system.
Nathan Vegdahl added 1 commit 2024-06-03 12:15:49 +02:00
Nathan Vegdahl added 1 commit 2024-06-03 15:58:40 +02:00
Nathan Vegdahl added 1 commit 2024-06-03 16:27:55 +02:00
Nathan Vegdahl added 1 commit 2024-06-03 16:33:00 +02:00
Nathan Vegdahl added 1 commit 2024-06-03 17:56:31 +02:00
Nathan Vegdahl added 1 commit 2024-06-03 18:18:27 +02:00
Nathan Vegdahl changed title from WIP: Anim: add keyframing unit tests to Anim: add keyframing unit tests 2024-06-03 18:19:21 +02:00
Nathan Vegdahl requested review from Sybren A. Stüvel 2024-06-03 18:19:30 +02:00
Nathan Vegdahl requested review from Christoph Lendenfeld 2024-06-03 18:19:41 +02:00
Nathan Vegdahl added 1 commit 2024-06-04 10:25:24 +02:00
Sybren A. Stüvel requested changes 2024-06-04 11:40:10 +02:00
Dismissed
Sybren A. Stüvel left a comment
Member

The tests don't seem to check whether a key was actually inserted, and with which value/frame (they just check that an FCurve was created). I think that's kinda important for a key insertion function.

I feel that at least one of the various tests for each specific function (so once for insert_key_rna, once for insert_keyframe, etc) there should be a test that checks that key insertion also works correctly when there is actually already an F-Curve there, and a key is inserted at a different frame. Even though insert_keyframe__only_available is testing with pre-existing FCurves, the anim_eval_context doesn't change, and so the 2nd key is overwriting the 1st key, still resulting in a 1-key FCurve.

The expects that are there to prevent nullptr dereference should actual be asserts:

  ASSERT_NE(nullptr, object->adt);
  ASSERT_NE(nullptr, object->adt->action);

as this will immediately stop the test, instead of reporting failure but continuing.

Having the NLA keying tests in there is nice, and much needed ;-)

The tests don't seem to check whether a key was actually inserted, and with which value/frame (they just check that an FCurve was created). I think that's kinda important for a key insertion function. I feel that at least one of the various tests for each specific function (so once for `insert_key_rna`, once for `insert_keyframe`, etc) there should be a test that checks that key insertion also works correctly when there is actually already an F-Curve there, and a key is inserted at a different frame. Even though `insert_keyframe__only_available` is testing with pre-existing FCurves, the `anim_eval_context` doesn't change, and so the 2nd key is overwriting the 1st key, still resulting in a 1-key FCurve. The expects that are there to prevent `nullptr` dereference should actual be asserts: ```cpp ASSERT_NE(nullptr, object->adt); ASSERT_NE(nullptr, object->adt->action); ``` as this will immediately stop the test, instead of reporting failure but continuing. Having the NLA keying tests in there is nice, and much needed ;-)
@ -0,0 +268,4 @@
anim_eval_context);
EXPECT_EQ(0, result_1.get_count(SingleKeyingResult::SUCCESS));
EXPECT_NE(nullptr, object->adt);

Why should the adt not be nullptr, if the key insertion failed? Might be worth adding a message.

  EXPECT_NE(nullptr, object->adt) << "blabla message here";
Why should the `adt` not be `nullptr`, if the key insertion failed? Might be worth adding a message. ```cpp EXPECT_NE(nullptr, object->adt) << "blabla message here"; ```
Author
Member

Same as below: I don't know why this should be the case, but it is how it behaves currently, so I'm testing it to ensure no unintentional changes.

Same as below: I don't know why this should be the case, but it is how it behaves currently, so I'm testing it to ensure no *unintentional* changes.
nathanvegdahl marked this conversation as resolved
@ -0,0 +269,4 @@
EXPECT_EQ(0, result_1.get_count(SingleKeyingResult::SUCCESS));
EXPECT_NE(nullptr, object->adt);
EXPECT_NE(nullptr, object->adt->action);

I didn't expect this (so 👍 for getting it tested). Deleting the last FCurve from an Action deletes the Action, but apparently failing to insert a key will create an empty Action. Might also be worth a message that explains why/how, or maybe even that if this specific EXPECT fails, it's kind of a good thing?

I didn't expect this (so :+1: for getting it tested). Deleting the last FCurve from an Action deletes the Action, but apparently failing to insert a key will create an empty Action. Might also be worth a message that explains why/how, or maybe even that if this specific `EXPECT` fails, it's kind of a good thing?
Author
Member

Yeah, good point.

I added the checks for completeness to ensure the behavior doesn't change unintentionally, but to be honest the current behavior seems kind of arbitrary, and it's not clear to me why it was chosen or if it's even desireable. So perhaps something along the lines of:

Not sure why this behavior was chosen, but testing it to ensure no unintentional changes. In the future we may want to change this.

Yeah, good point. I added the checks for completeness to ensure the behavior doesn't change *unintentionally*, but to be honest the current behavior seems kind of arbitrary, and it's not clear to me why it was chosen or if it's even desireable. So perhaps something along the lines of: > Not sure why this behavior was chosen, but testing it to ensure no unintentional changes. In the future we may want to change this.

Yeah, perfect. It makes a nice distinction between "noticing behavioural changes" and "saying it should work this way".

Yeah, perfect. It makes a nice distinction between "noticing behavioural changes" and "saying it should work this way".
nathanvegdahl marked this conversation as resolved
Nathan Vegdahl added 1 commit 2024-06-04 13:52:05 +02:00
Nathan Vegdahl added 3 commits 2024-06-04 14:22:49 +02:00
Nathan Vegdahl added 1 commit 2024-06-04 14:59:45 +02:00
This covers one test each for `insert_key_rna()` and
`insert_keyframe()`.
Nathan Vegdahl added 1 commit 2024-06-04 15:37:59 +02:00
Nathan Vegdahl added 1 commit 2024-06-04 15:39:14 +02:00
Nathan Vegdahl added 1 commit 2024-06-04 15:44:34 +02:00
Nathan Vegdahl added 1 commit 2024-06-04 15:45:44 +02:00
Author
Member

@dr.sybren I believe I've addressed all of your comments now.

@dr.sybren I believe I've addressed all of your comments now.
Nathan Vegdahl requested review from Sybren A. Stüvel 2024-06-04 15:47:17 +02:00
Sybren A. Stüvel approved these changes 2024-06-04 16:00:58 +02:00
Sybren A. Stüvel left a comment
Member

LGTM!

LGTM!
Nathan Vegdahl merged commit b9c7e5e766 into main 2024-06-04 16:04:04 +02:00
Nathan Vegdahl deleted branch keyframing_unit_tests 2024-06-04 16:04:06 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#122553
No description provided.