aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYauheni Kaliuta <yauheni.kaliuta@redhat.com>2016-11-08 22:57:26 +0200
committerLucas De Marchi <lucas.demarchi@intel.com>2016-11-08 22:21:13 -0200
commitd24270321142baead92285e2637f09da71992868 (patch)
tree50af88aa99553ba4589d65dd7539514daf195cdf
parentcb51a641d6d4c777ed38855b29131b8a1e941175 (diff)
downloadplatform_external_kmod-d24270321142baead92285e2637f09da71992868.tar.gz
platform_external_kmod-d24270321142baead92285e2637f09da71992868.tar.bz2
platform_external_kmod-d24270321142baead92285e2637f09da71992868.zip
testsuite: fix test_array_sort pointers inderection
The array elements in the tests are strings, what means "char *" in ะก. The comparation funtion takes pointers to the elements, so the arguments become "char **". It means, that strcmp() cannot be used directrly. The patch creates a wrapper on strcmp() which perfoms dereferencing of the "char **" to supply the actual strings to strcmp(), and uses the wrapper as a comparation function for the qsort() call. Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
-rw-r--r--testsuite/test-array.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/testsuite/test-array.c b/testsuite/test-array.c
index 3c72a8a..ef1e1e9 100644
--- a/testsuite/test-array.c
+++ b/testsuite/test-array.c
@@ -90,6 +90,13 @@ static int test_array_append_unique(const struct test *t)
DEFINE_TEST(test_array_append_unique,
.description = "test array append unique");
+static int strptrcmp(const void *pa, const void *pb) {
+ const char *a = *(const char **)pa;
+ const char *b = *(const char **)pb;
+
+ return strcmp(a, b);
+}
+
static int test_array_sort(const struct test *t)
{
struct array array;
@@ -104,7 +111,7 @@ static int test_array_sort(const struct test *t)
array_append(&array, c2);
array_append(&array, c3);
array_append(&array, c1);
- array_sort(&array, (int (*)(const void *a, const void *b)) strcmp);
+ array_sort(&array, strptrcmp);
assert_return(array.count == 6, EXIT_FAILURE);
assert_return(array.array[0] == c1, EXIT_FAILURE);
assert_return(array.array[1] == c1, EXIT_FAILURE);