Line data Source code
1 : /* 2 : * Unix SMB/CIFS implementation. 3 : * 4 : * Copyright (C) 2018 Andreas Schneider <asn@samba.org> 5 : * 6 : * This program is free software; you can redistribute it and/or modify 7 : * it under the terms of the GNU General Public License as published by 8 : * the Free Software Foundation; either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * This program is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU General Public License 17 : * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 : */ 19 : 20 : #include <stdarg.h> 21 : #include <stddef.h> 22 : #include <stdint.h> 23 : #include <setjmp.h> 24 : #include <cmocka.h> 25 : 26 : #include <ldb.h> 27 : 28 18 : static int cmp_integer(int *a, int *b, void *opaque) 29 : { 30 18 : if (a == NULL || b == NULL) { 31 : return 0; 32 : } 33 : 34 18 : if (*a > *b) { 35 : return 1; 36 : } 37 : 38 9 : if (*a < *b) { 39 7 : return -1; 40 : } 41 : 42 : return 0; 43 : } 44 : 45 1 : static void test_ldb_qsort(void **state) 46 : { 47 1 : int a[6] = { 6, 3, 2, 7, 9, 4 }; 48 : 49 1 : ldb_qsort(a, 6, sizeof(int), NULL, (ldb_qsort_cmp_fn_t)cmp_integer); 50 : 51 1 : assert_int_equal(a[0], 2); 52 1 : assert_int_equal(a[1], 3); 53 1 : assert_int_equal(a[2], 4); 54 1 : assert_int_equal(a[3], 6); 55 1 : assert_int_equal(a[4], 7); 56 1 : assert_int_equal(a[5], 9); 57 1 : } 58 : 59 1 : int main(void) { 60 1 : const struct CMUnitTest tests[] = { 61 : cmocka_unit_test(test_ldb_qsort), 62 : }; 63 : 64 1 : cmocka_set_message_output(CM_OUTPUT_SUBUNIT); 65 1 : return cmocka_run_group_tests(tests, NULL, NULL); 66 : }