diff --git a/glib/tests/sort.c b/glib/tests/sort.c index c2923b932..eb748c504 100644 --- a/glib/tests/sort.c +++ b/glib/tests/sort.c @@ -46,6 +46,30 @@ test_sort_basic (void) g_free (data); } +static void +test_sort_zero_elements (void) +{ + gint *data, *data_copy; + gsize i; + + data = g_malloc (100 * sizeof (int)); + data_copy = g_malloc (100 * sizeof (int)); + for (i = 0; i < 100; i++) + { + data[i] = g_random_int (); + data_copy[i] = data[i]; + } + + /* 0 elements is a valid case */ + g_qsort_with_data (data, 0, sizeof (int), int_compare_data, NULL); + + for (i = 0; i < 100; i++) + g_assert_cmpint (data[i], ==, data_copy[i]); + + g_free (data); + g_free (data_copy); +} + typedef struct { int val; int i; @@ -120,6 +144,7 @@ main (int argc, char *argv[]) g_test_init (&argc, &argv, NULL); g_test_add_func ("/sort/basic", test_sort_basic); + g_test_add_func ("/sort/zero-elements", test_sort_zero_elements); g_test_add_func ("/sort/stable", test_sort_stable); g_test_add_func ("/sort/big", test_sort_big); diff --git a/tests/meson.build b/tests/meson.build index 6741f8f52..1bb146afc 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -30,7 +30,6 @@ tests = { 'mapping-test' : {}, 'onceinit' : {}, 'asyncqueue-test' : {}, - 'qsort-test' : {}, 'relation-test' : {}, 'slice-concurrent' : {}, 'slice-threadinit' : { diff --git a/tests/qsort-test.c b/tests/qsort-test.c deleted file mode 100644 index 67abb23af..000000000 --- a/tests/qsort-test.c +++ /dev/null @@ -1,33 +0,0 @@ -#undef G_DISABLE_ASSERT -#undef G_LOG_DOMAIN - -#include - -#define SIZE 100000 - -guint32 array[SIZE]; - -static gint -sort (gconstpointer a, gconstpointer b, gpointer user_data) -{ - return *(guint32*)a < *(guint32*)b ? -1 : 1; -} - -int -main (int argc, char **argv) -{ - int i; - - for (i = 0; i < SIZE; i++) - array[i] = g_random_int (); - - g_qsort_with_data (array, SIZE, sizeof (guint32), sort, NULL); - - for (i = 0; i < SIZE - 1; i++) - g_assert (array[i] <= array[i+1]); - - /* 0 elements is a valid case */ - g_qsort_with_data (array, 0, sizeof (guint32), sort, NULL); - - return 0; -}