LCOV - code coverage report
Current view: top level - shared - test-tables.h (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 15 15 100.0 %
Date: 2019-08-22 15:41:25 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <stdio.h>
       4             : #include <stdlib.h>
       5             : #include <string.h>
       6             : 
       7             : typedef const char* (*lookup_t)(int);
       8             : typedef int (*reverse_t)(const char*);
       9             : 
      10         124 : static inline void _test_table(const char *name,
      11             :                                lookup_t lookup,
      12             :                                reverse_t reverse,
      13             :                                int size,
      14             :                                bool sparse) {
      15         124 :         int i, boring = 0;
      16             : 
      17       38088 :         for (i = -1; i < size + 1; i++) {
      18       37964 :                 const char* val = lookup(i);
      19             :                 int rev;
      20             : 
      21       37964 :                 if (val) {
      22         937 :                         rev = reverse(val);
      23         937 :                         boring = 0;
      24             :                 } else {
      25       37027 :                         rev = reverse("--no-such--value----");
      26       37027 :                         boring += i >= 0;
      27             :                 }
      28             : 
      29       37964 :                 if (boring < 1 || i == size)
      30        1185 :                         printf("%s: %d → %s → %d\n", name, i, val, rev);
      31       36779 :                 else if (boring == 1)
      32          13 :                         printf("%*s  ...\n", (int) strlen(name), "");
      33             : 
      34       37964 :                 assert_se(!(i >= 0 && i < size ?
      35             :                             sparse ? rev != i && rev != -1 : val == NULL || rev != i :
      36             :                             val != NULL || rev != -1));
      37             :         }
      38         124 : }
      39             : 
      40             : #define test_table(lower, upper) \
      41             :         _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, false)
      42             : 
      43             : #define test_table_sparse(lower, upper) \
      44             :         _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, true)

Generated by: LCOV version 1.14