libqb/tests/check_list.c
Chrissie Caulfield d0ec0a6a57
UPDATED: doc (ABI comparison) and various other fixes (#324)
* doc: qbarray.h: fix garbled Doxygen markup

* build: follow-up for and fine-tuning of a rushed 6d62b64 commit
  (It made a service as-was, but being afforded more time, this would
  have accompanied that commit right away, for better understanding,
  brevity and uniformity.)

* build: prune superfluous Makefile declarations within tests directory
  There was a significant redundancy wrt. build flags and EXTRA_DIST
  assignment (the latter become redundant as of f6e4042 at latest)
  spread all over the place (vivat copy&paste).  Also, in one instance,
  CPPFLAGS (used) was confused with CFLAGS (meant).

* maint: check abi: fix two issues with abi-compliance-checker/libstdc++
1. ABICC >= 2 needs to be passed -cxx-incompatible switch because C is
   no longer a default for this tool (used to be vice versa),
   plus current version will stop choking on C vs. C++ (our C code with
   C++ compatibility wrapping being viewed from C++ perspective for the
   purpose of dumping the declared symbols, which somewhat conflicts
   with internal masking of the C++ keywords being used as valid C
   identifiers [yet some instances must not be masked here, see
   https://github.com/lvc/abi-compliance-checker/issues/64) only
  if _also_ something like this is applied:
   https://github.com/lvc/abi-compliance-checker/pull/70
2. since 20246f5, libqb.so no longer poses a symlink to the actual
   version-qualified shared library, but rather a standalone linker
   script, which confuses ABICC, so blacklist that file for the scanning
   purposes explicitly, together with referring to the library through
   it's basic version qualification (which alone, sadly, is not
   sufficient as ABICC proceeds to scan whole containing directory
   despite particular file is specified)

* maint: check abi: switch to abi-dumper for creating "ABI dumps"
Beside avoiding issues with abi-compliance-checker in the role of ABI
dumps producer (see the preceding commit), it also seems to generate
more accurate picture (maybe because it expressly requires compiling
with debugging information requested).

* Low: qblist.h: fix incompatibility with C++ & check it regularly

* tests: check_list.c: start zeroing in on the gaps in tests' coverage

* tests: print_ver: make preprocessor emit "note" rather than warning

IIRC, Chrissie asked about this around inclusion of the test at
hand, and it seemed there was no way but to emit a warning to get
something output at all.  Now it turns wrong, and moreover, we
make the code not fixed on GCC specific pragmas, with a bit of
luck, "#pragma message" approach is adopted more widely by compilers.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>

* Replace ck_assert_uint_eq() with ck_assert_int_eq()
it's not available in check 0.9

* Proper check for C++ compiler (from Fabio)
* add (c) to copyright dates
2018-09-25 08:38:37 +01:00

108 lines
2.9 KiB
C

/*
* Copyright (c) 2018 Red Hat, Inc.
*
* All rights reserved.
*
* Author: Jan Pokorny <jpokorny@redhat.com>
*
* This file is part of libqb.
*
* libqb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* libqb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os_base.h"
#include "check_common.h"
#include <qb/qblist.h>
#include <qb/qblog.h>
typedef struct {
struct qb_list_head list;
size_t i;
} enlistable_num_t;
#define DIMOF(_a) sizeof(_a)/sizeof(*(_a))
START_TEST(test_list_iter)
{
QB_LIST_DECLARE(mylist);
enlistable_num_t reference_head[] = { {.i=0}, {.i=1}, {.i=2}, {.i=3} };
enlistable_num_t reference_tail[] = { {.i=4}, {.i=5}, {.i=6}, {.i=7} };
enlistable_num_t *iter, replacement = {.i=8};
size_t iter_i;
for (iter_i = DIMOF(reference_head); iter_i > 0; iter_i--) {
/* prepends in reverse order */
qb_list_add(&reference_head[iter_i-1].list, &mylist);
}
for (iter_i = 0; iter_i < DIMOF(reference_tail); iter_i++) {
/* appends in natural order */
qb_list_add_tail(&reference_tail[iter_i].list, &mylist);
}
/* assert the constructed list corresponds to ordered sequence... */
/* ... increasing when iterating forward */
iter_i = 0;
qb_list_for_each_entry(iter, &mylist, list) {
ck_assert_int_eq(iter->i, iter_i);
iter_i++;
}
/* ... and decreasing when iterating backward */
qb_list_for_each_entry_reverse(iter, &mylist, list) {
ck_assert_int_gt(iter_i, 0);
ck_assert_int_eq(iter->i, iter_i-1);
iter_i--;
}
ck_assert_int_eq(iter_i, 0);
/* also check qb_list_replace and qb_list_first_entry */
qb_list_replace(mylist.next, &replacement.list);
ck_assert_int_eq(qb_list_first_entry(&mylist, enlistable_num_t, list)->i,
replacement.i);
}
END_TEST
static Suite *array_suite(void)
{
TCase *tc;
Suite *s = suite_create("qb_list");
add_tcase(s, tc, test_list_iter);
return s;
}
int32_t main(void)
{
int32_t number_failed;
Suite *s = array_suite();
SRunner *sr = srunner_create(s);
qb_log_init("check", LOG_USER, LOG_EMERG);
atexit(qb_log_fini);
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD,
QB_LOG_FILTER_FILE, "*", LOG_INFO);
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);
srunner_run_all(sr, CK_VERBOSE);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}