MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / timer_addRemoveTimer

Function timer_addRemoveTimer

deps/SDL2/test/testautomation_timer.c:124–173  ·  view source on GitHub ↗

* @brief Call to SDL_AddTimer and SDL_RemoveTimer */

Source from the content-addressed store, hash-verified

122 * @brief Call to SDL_AddTimer and SDL_RemoveTimer
123 */
124int
125timer_addRemoveTimer(void *arg)
126{
127 SDL_TimerID id;
128 SDL_bool result;
129 int param;
130
131 /* Reset state */
132 _paramCheck = 0;
133 _timerCallbackCalled = 0;
134
135 /* Set timer with a long delay */
136 id = SDL_AddTimer(10000, _timerTestCallback, NULL);
137 SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
138 SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
139
140 /* Remove timer again and check that callback was not called */
141 result = SDL_RemoveTimer(id);
142 SDLTest_AssertPass("Call to SDL_RemoveTimer()");
143 SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
144 SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
145
146 /* Try to remove timer again (should be a NOOP) */
147 result = SDL_RemoveTimer(id);
148 SDLTest_AssertPass("Call to SDL_RemoveTimer()");
149 SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
150
151 /* Reset state */
152 param = SDLTest_RandomIntegerInRange(-1024, 1024);
153 _paramCheck = 1;
154 _paramValue = param;
155 _timerCallbackCalled = 0;
156
157 /* Set timer with a short delay */
158 id = SDL_AddTimer(10, _timerTestCallback, (void *)&param);
159 SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
160 SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
161
162 /* Wait to let timer trigger callback */
163 SDL_Delay(100);
164 SDLTest_AssertPass("Call to SDL_Delay(100)");
165
166 /* Remove timer again and check that callback was called */
167 result = SDL_RemoveTimer(id);
168 SDLTest_AssertPass("Call to SDL_RemoveTimer()");
169 SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
170 SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
171
172 return TEST_COMPLETED;
173}
174
175/* ================= Test References ================== */
176

Callers

nothing calls this directly

Calls 6

SDL_AddTimerFunction · 0.85
SDLTest_AssertPassFunction · 0.85
SDLTest_AssertCheckFunction · 0.85
SDL_RemoveTimerFunction · 0.85
SDL_DelayFunction · 0.50

Tested by

no test coverage detected