@@ -88,9 +88,19 @@ int hints_getHint(void *arg)
88
88
return TEST_COMPLETED ;
89
89
}
90
90
91
+ typedef struct {
92
+ char * name ;
93
+ char * value ;
94
+ char * oldValue ;
95
+ } HintCallbackContext ;
96
+
91
97
static void SDLCALL hints_testHintChanged (void * userdata , const char * name , const char * oldValue , const char * hint )
92
98
{
93
- * (char * * )userdata = hint ? SDL_strdup (hint ) : NULL ;
99
+ HintCallbackContext * context = userdata ;
100
+
101
+ context -> name = name ? SDL_strdup (name ) : NULL ;
102
+ context -> value = hint ? SDL_strdup (hint ) : NULL ;
103
+ context -> oldValue = oldValue ? SDL_strdup (oldValue ) : NULL ;
94
104
}
95
105
96
106
/**
@@ -102,7 +112,7 @@ int hints_setHint(void *arg)
102
112
const char * originalValue ;
103
113
char * value ;
104
114
const char * testValue ;
105
- char * callbackValue ;
115
+ HintCallbackContext callback_data ;
106
116
SDL_bool result ;
107
117
int i , j ;
108
118
@@ -152,8 +162,10 @@ int hints_setHint(void *arg)
152
162
SDLTest_AssertPass ("Call to SDL_GetHint() after saving and restoring hint" );
153
163
originalValue = SDL_GetHint (testHint );
154
164
value = (originalValue == NULL ) ? NULL : SDL_strdup (originalValue );
155
- SDL_SetHint (testHint , "temp" );
156
- SDL_SetHint (testHint , value );
165
+ result = SDL_SetHint (testHint , "temp" );
166
+ SDLTest_AssertCheck (!result , "SDL_SetHint(\"%s\", \"temp\") should return false" , testHint );
167
+ result = SDL_SetHint (testHint , value );
168
+ SDLTest_AssertCheck (!result , "SDL_SetHint(\"%s\", \"%s\" should return false" , testHint , value );
157
169
SDL_free (value );
158
170
testValue = SDL_GetHint (testHint );
159
171
SDLTest_AssertCheck (
@@ -162,23 +174,35 @@ int hints_setHint(void *arg)
162
174
testValue );
163
175
164
176
SDLTest_AssertPass ("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)" );
165
- SDL_SetHintWithPriority (testHint , NULL , SDL_HINT_DEFAULT );
177
+ result = SDL_SetHintWithPriority (testHint , NULL , SDL_HINT_DEFAULT );
178
+ SDLTest_AssertCheck (!result , "SDL_SetHintWithPriority(\"%s\", NULL, SDL_HINT_DEFAULT) should return false" , testHint );
166
179
testValue = SDL_GetHint (testHint );
167
180
SDLTest_AssertCheck (
168
181
testValue && SDL_strcmp (testValue , "original" ) == 0 ,
169
182
"testValue = %s, expected \"original\"" ,
170
183
testValue );
171
184
185
+ SDLTest_AssertPass ("Call to SDL_SetHint(\"\", \"data\")" );
186
+ result = SDL_SetHint ("" , "data" );
187
+ SDLTest_AssertCheck (result , "SDL_SetHint(\"\", \"data\") should return true" );
188
+ testValue = SDL_GetHint ("" );
189
+ SDLTest_AssertCheck (
190
+ testValue && SDL_strcmp (testValue , "data" ) == 0 ,
191
+ "testValue = %s, expected \"data\"" ,
192
+ testValue );
193
+
172
194
SDLTest_AssertPass ("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)" );
173
- SDL_SetHintWithPriority (testHint , "temp" , SDL_HINT_OVERRIDE );
195
+ result = SDL_SetHintWithPriority (testHint , "temp" , SDL_HINT_OVERRIDE );
196
+ SDLTest_AssertCheck (result , "SDL_SetHintWithPriority(\"%s\", \"temp\", SDL_HINT_OVERRIDE) should return true" , testHint );
174
197
testValue = SDL_GetHint (testHint );
175
198
SDLTest_AssertCheck (
176
199
testValue && SDL_strcmp (testValue , "temp" ) == 0 ,
177
200
"testValue = %s, expected \"temp\"" ,
178
201
testValue );
179
202
180
203
SDLTest_AssertPass ("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)" );
181
- SDL_SetHintWithPriority (testHint , NULL , SDL_HINT_OVERRIDE );
204
+ result = SDL_SetHintWithPriority (testHint , NULL , SDL_HINT_OVERRIDE );
205
+ SDLTest_AssertCheck (result , "SDL_SetHintWithPriority(\"%s\", NULL, SDL_HINT_OVERRIDE) should return true" , testHint );
182
206
testValue = SDL_GetHint (testHint );
183
207
SDLTest_AssertCheck (
184
208
testValue == NULL ,
@@ -194,49 +218,75 @@ int hints_setHint(void *arg)
194
218
testValue );
195
219
196
220
/* Make sure callback functionality works past a reset */
221
+ SDL_zero (callback_data );
197
222
SDLTest_AssertPass ("Call to SDL_AddHintCallback()" );
198
- callbackValue = NULL ;
199
- SDL_AddHintCallback (testHint , hints_testHintChanged , & callbackValue );
223
+ SDL_AddHintCallback (testHint , hints_testHintChanged , & callback_data );
200
224
SDLTest_AssertCheck (
201
- callbackValue && SDL_strcmp (callbackValue , "original" ) == 0 ,
202
- "callbackValue = %s, expected \"original\"" ,
203
- callbackValue );
204
- SDL_free (callbackValue );
205
-
206
- SDLTest_AssertPass ("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback" );
207
- callbackValue = NULL ;
208
- SDL_SetHintWithPriority (testHint , "temp" , SDL_HINT_OVERRIDE );
225
+ callback_data .name && SDL_strcmp (callback_data .name , testHint ) == 0 ,
226
+ "callback_data.name = \"%s\", expected \"%s\"" ,
227
+ callback_data .name , testHint );
209
228
SDLTest_AssertCheck (
210
- callbackValue && SDL_strcmp (callbackValue , "temp" ) == 0 ,
211
- "callbackValue = %s, expected \"temp\"" ,
212
- callbackValue );
213
- SDL_free (callbackValue );
229
+ callback_data .value && SDL_strcmp (callback_data .value , "original" ) == 0 ,
230
+ "callback_data.value = \"%s\", expected \"%s\"" ,
231
+ callback_data .value , "original" );
232
+ SDL_free (callback_data .name );
233
+ SDL_free (callback_data .value );
234
+ SDL_free (callback_data .oldValue );
214
235
215
236
SDLTest_AssertPass ("Call to SDL_ResetHint(), using callback" );
216
- callbackValue = NULL ;
237
+ SDL_zero ( callback_data ) ;
217
238
SDL_ResetHint (testHint );
218
239
SDLTest_AssertCheck (
219
- callbackValue && SDL_strcmp (callbackValue , "original" ) == 0 ,
240
+ callback_data . value && SDL_strcmp (callback_data . value , "original" ) == 0 ,
220
241
"callbackValue = %s, expected \"original\"" ,
221
- callbackValue );
242
+ callback_data .value );
243
+ SDL_free (callback_data .name );
244
+ SDL_free (callback_data .value );
245
+ SDL_free (callback_data .oldValue );
222
246
223
247
SDLTest_AssertPass ("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset" );
224
- callbackValue = NULL ;
225
- SDL_SetHintWithPriority (testHint , "temp" , SDL_HINT_OVERRIDE );
248
+ SDL_zero (callback_data );
249
+ result = SDL_SetHintWithPriority (testHint , "temp" , SDL_HINT_OVERRIDE );
250
+ SDLTest_AssertCheck (result , "SDL_SetHintWithPriority(\"%s\", \"temp\", SDL_HINT_OVERRIDE) should return true" , testHint );
226
251
SDLTest_AssertCheck (
227
- callbackValue && SDL_strcmp (callbackValue , "temp" ) == 0 ,
252
+ callback_data . value && SDL_strcmp (callback_data . value , "temp" ) == 0 ,
228
253
"callbackValue = %s, expected \"temp\"" ,
229
- callbackValue );
230
- SDL_free (callbackValue );
254
+ callback_data .value );
255
+ SDL_free (callback_data .name );
256
+ SDL_free (callback_data .value );
257
+ SDL_free (callback_data .oldValue );
231
258
232
259
SDLTest_AssertPass ("Call to SDL_ResetHint(), after clearing callback" );
233
- callbackValue = NULL ;
234
- SDL_DelHintCallback (testHint , hints_testHintChanged , & callbackValue );
260
+ SDL_zero ( callback_data ) ;
261
+ SDL_DelHintCallback (testHint , hints_testHintChanged , & callback_data );
235
262
SDL_ResetHint (testHint );
236
263
SDLTest_AssertCheck (
237
- callbackValue == NULL ,
264
+ ! callback_data . value ,
238
265
"callbackValue = %s, expected \"(null)\"" ,
239
- callbackValue );
266
+ callback_data .value );
267
+ SDL_free (callback_data .name );
268
+ SDL_free (callback_data .value );
269
+ SDL_free (callback_data .oldValue );
270
+
271
+ /* Make sure callback functionality work with hint renamed in sdl3 */
272
+ SDLTest_AssertPass ("Call to SDL_AddHintCallback()" );
273
+ SDL_AddHintCallback (SDL_HINT_ALLOW_TOPMOST , hints_testHintChanged , & callback_data );
274
+ SDLTest_AssertPass ("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback" );
275
+ SDL_zero (callback_data );
276
+ result = SDL_SetHintWithPriority (SDL_HINT_ALLOW_TOPMOST , "temp" , SDL_HINT_OVERRIDE );
277
+ SDLTest_AssertCheck (result , "SDL_SetHintWithPriority(\"%s\", \"temp\", SDL_HINT_OVERRIDE) should return true" , testHint );
278
+ SDLTest_AssertCheck (
279
+ callback_data .name && SDL_strcmp (callback_data .name , SDL_HINT_ALLOW_TOPMOST ) == 0 ,
280
+ "callback_data.name = \"%s\", expected \"%s\"" ,
281
+ callback_data .name , SDL_HINT_ALLOW_TOPMOST );
282
+ SDLTest_AssertCheck (
283
+ callback_data .value && SDL_strcmp (callback_data .value , "temp" ) == 0 ,
284
+ "callback_data.value = \"%s\", expected \"%s\"" ,
285
+ callback_data .value , "temp" );
286
+ SDL_free (callback_data .name );
287
+ SDL_free (callback_data .value );
288
+ SDL_free (callback_data .oldValue );
289
+ SDL_ResetHint (testHint );
240
290
241
291
return TEST_COMPLETED ;
242
292
}
0 commit comments