* @brief Call to SDL_AddTimer and SDL_RemoveTimer */
| 122 | * @brief Call to SDL_AddTimer and SDL_RemoveTimer |
| 123 | */ |
| 124 | int |
| 125 | timer_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 *)¶m); |
| 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 |
nothing calls this directly
no test coverage detected