forked from Green-Sky/tomato
sdl (master post 3.1 preview) Merge commit 'e4f454091a943345938608570b104400f62fd625'
This commit is contained in:
22
external/sdl/SDL/test/testqsort.c
vendored
22
external/sdl/SDL/test/testqsort.c
vendored
@@ -14,6 +14,8 @@
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL_test.h>
|
||||
|
||||
static int a_global_var = 77;
|
||||
|
||||
static int SDLCALL
|
||||
num_compare(const void *_a, const void *_b)
|
||||
{
|
||||
@@ -22,20 +24,36 @@ num_compare(const void *_a, const void *_b)
|
||||
return (a < b) ? -1 : ((a > b) ? 1 : 0);
|
||||
}
|
||||
|
||||
static int SDLCALL
|
||||
num_compare_r(void *userdata, const void *a, const void *b)
|
||||
{
|
||||
if (userdata != &a_global_var) {
|
||||
SDL_Log("Uhoh, invalid userdata during qsort!");
|
||||
}
|
||||
return num_compare(a, b);
|
||||
}
|
||||
|
||||
static void
|
||||
test_sort(const char *desc, int *nums, const int arraylen)
|
||||
{
|
||||
static int nums_copy[1024 * 100];
|
||||
int i;
|
||||
int prev;
|
||||
|
||||
SDL_assert(SDL_arraysize(nums_copy) >= arraylen);
|
||||
|
||||
SDL_Log("test: %s arraylen=%d", desc, arraylen);
|
||||
|
||||
SDL_memcpy(nums_copy, nums, arraylen * sizeof (*nums));
|
||||
|
||||
SDL_qsort(nums, arraylen, sizeof(nums[0]), num_compare);
|
||||
SDL_qsort_r(nums_copy, arraylen, sizeof(nums[0]), num_compare_r, &a_global_var);
|
||||
|
||||
prev = nums[0];
|
||||
for (i = 1; i < arraylen; i++) {
|
||||
const int val = nums[i];
|
||||
if (val < prev) {
|
||||
const int val2 = nums_copy[i];
|
||||
if ((val < prev) || (val != val2)) {
|
||||
SDL_Log("sort is broken!");
|
||||
return;
|
||||
}
|
||||
@@ -53,6 +71,8 @@ int main(int argc, char *argv[])
|
||||
SDLTest_CommonState *state;
|
||||
int seed_seen = 0;
|
||||
|
||||
SDL_zero(rndctx);
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
if (!state) {
|
||||
|
||||
Reference in New Issue
Block a user