Skip to content

Commit

Permalink
animation: test how many times callbacks get called
Browse files Browse the repository at this point in the history
  • Loading branch information
PaideiaDilemma committed Jan 11, 2025
1 parent f020e5d commit 1b165be
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions tests/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,31 +260,27 @@ int main(int argc, char** argv, char** envp) {
//
// Test callbacks
//
bool beginCallbackRan = false;
bool updateCallbackRan = false;
bool endCallbackRan = false;
s.m_iA->setCallbackOnBegin([&beginCallbackRan](WP<CBaseAnimatedVariable> pav) { beginCallbackRan = true; });
s.m_iA->setUpdateCallback([&updateCallbackRan](WP<CBaseAnimatedVariable> pav) { updateCallbackRan = true; });
s.m_iA->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> pav) { endCallbackRan = true; }, false);
int beginCallbackRan = false;
int updateCallbackRan = false;
int endCallbackRan = false;
s.m_iA->setCallbackOnBegin([&beginCallbackRan](WP<CBaseAnimatedVariable> pav) { beginCallbackRan++; });
s.m_iA->setUpdateCallback([&updateCallbackRan](WP<CBaseAnimatedVariable> pav) { updateCallbackRan++; });
s.m_iA->setCallbackOnEnd([&endCallbackRan](WP<CBaseAnimatedVariable> pav) { endCallbackRan++; }, false);

s.m_iA->setValueAndWarp(42);

EXPECT(beginCallbackRan, false);
EXPECT(updateCallbackRan, true);
EXPECT(endCallbackRan, true);

beginCallbackRan = false;
updateCallbackRan = false;
endCallbackRan = false;
EXPECT(beginCallbackRan, 0);
EXPECT(updateCallbackRan, 1);
EXPECT(endCallbackRan, 2); // first called when setting the callback, then when warping.

*s.m_iA = 1337;
while (gAnimationManager.shouldTickForNext()) {
gAnimationManager.tick();
}

EXPECT(beginCallbackRan, true);
EXPECT(updateCallbackRan, true);
EXPECT(endCallbackRan, true);
EXPECT(beginCallbackRan, 1);
EXPECT(updateCallbackRan > 2, true);
EXPECT(endCallbackRan, 3);

std::vector<PANIMVAR<int>> vars;
for (int i = 0; i < 10; i++) {
Expand Down Expand Up @@ -316,17 +312,14 @@ int main(int argc, char** argv, char** envp) {
EXPECT(std::find_if(vars.begin(), vars.end(), [](const auto& v) { return v->value() != 1337; }) == vars.end(), true);

// test one-time callbacks
endCallbackRan = false;
s.m_iA->resetAllCallbacks();
s.m_iA->setCallbackOnEnd([&endCallbackRan](auto) { endCallbackRan = true; }, true);

EXPECT(endCallbackRan, true);
s.m_iA->setCallbackOnEnd([&endCallbackRan](auto) { endCallbackRan++; }, true);

endCallbackRan = false;
EXPECT(endCallbackRan, 4);

s.m_iA->setValueAndWarp(10);

EXPECT(endCallbackRan, false);
EXPECT(endCallbackRan, 4);
EXPECT(s.m_iA->value(), 10);

return ret;
Expand Down

0 comments on commit 1b165be

Please sign in to comment.