]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: int_array unit tests
authorJouni Malinen <j@w1.fi>
Sun, 25 May 2014 19:30:46 +0000 (22:30 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 26 May 2014 14:21:44 +0000 (17:21 +0300)
Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/utils_module_tests.c

index 206bc9d6cf1062c82f109c6f324734e3e2b5ac15..d514c546ebc78eebdeeffd561a2cb5d5f6d4f059 100644 (file)
@@ -157,15 +157,46 @@ static int bitfield_tests(void)
 }
 
 
+static int int_array_tests(void)
+{
+       int test1[] = { 1, 2, 3, 4, 5, 6, 0 };
+       int test2[] = { 1, -1, 0 };
+       int test3[] = { 1, 1, 1, -1, 2, 3, 4, 1, 2, 0 };
+       int test3_res[] = { -1, 1, 2, 3, 4, 0 };
+       int errors = 0;
+       int len;
+
+       wpa_printf(MSG_INFO, "int_array tests");
+
+       if (int_array_len(test1) != 6 ||
+           int_array_len(test2) != 2)
+               errors++;
+
+       int_array_sort_unique(test3);
+       len = int_array_len(test3_res);
+       if (int_array_len(test3) != len)
+               errors++;
+       else if (os_memcmp(test3, test3_res, len * sizeof(int)) != 0)
+               errors++;
+
+       if (errors) {
+               wpa_printf(MSG_ERROR, "%d int_array test(s) failed", errors);
+               return -1;
+       }
+
+       return 0;
+}
+
+
 int utils_module_tests(void)
 {
        int ret = 0;
 
        wpa_printf(MSG_INFO, "utils module tests");
 
-       if (printf_encode_decode_tests() < 0)
-               ret = -1;
-       if (bitfield_tests() < 0)
+       if (printf_encode_decode_tests() < 0 ||
+           bitfield_tests() < 0 ||
+           int_array_tests() < 0)
                ret = -1;
 
        return ret;