[glib: 1/2] gqsort: Move test to glib/tests/




commit 279a610018c89ca2ef163a933d13660fbf76a1be
Author: Nishal Kulkarni <nishalkulkarni gmail com>
Date:   Sat Nov 27 02:16:22 2021 +0530

    gqsort: Move test to glib/tests/
    
    Previously tests existed in two places,
    `$top_srcdir/tests/qsort-test.c` contained a similar test
    to the one in `$top_srcdir/glib/tests/sort.c` called `test_sort_basic()`
    
    The test for checking with zero elements was additional added to
    `$top_srcdir/glib/tests/sort.c` and `$top_srcdir/tests/qsort-test.c`
    was deleted.
    
    Related to: #1434

 glib/tests/sort.c  | 25 +++++++++++++++++++++++++
 tests/meson.build  |  1 -
 tests/qsort-test.c | 33 ---------------------------------
 3 files changed, 25 insertions(+), 34 deletions(-)
---
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' : {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]