summaryrefslogtreecommitdiff
path: root/src/shared/test-tables.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-07-16 12:01:01 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-07-16 12:04:31 -0400
commitdaabe5491ee0c78b735336c9e69b7f6ea57464e0 (patch)
treeb2b02be86dfa1928d9d91bd8eed747e0194abc23 /src/shared/test-tables.h
parent21c72713ae89cfc2c4096c383af9bb482665e0a6 (diff)
test-tables: allow sparse tables and check mapping for -1
Jan: test-tables fails on my system. The one it's failing on is: syscall: 222 → (null) → -1 ... and indeed, our own tables should not have holes, but syscall tables certainly might.
Diffstat (limited to 'src/shared/test-tables.h')
-rw-r--r--src/shared/test-tables.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/shared/test-tables.h b/src/shared/test-tables.h
index deebec2ed..326130207 100644
--- a/src/shared/test-tables.h
+++ b/src/shared/test-tables.h
@@ -26,10 +26,11 @@ typedef int (*reverse_t)(const char*);
static inline void _test_table(const char *name,
lookup_t lookup,
reverse_t reverse,
- int size) {
+ int size,
+ bool sparse) {
int i;
- for (i = 0; i < size + 1; i++) {
+ for (i = -1; i < size + 1; i++) {
const char* val = lookup(i);
int rev;
@@ -39,10 +40,12 @@ static inline void _test_table(const char *name,
rev = reverse("--no-such--value----");
printf("%s: %d → %s → %d\n", name, i, val, rev);
- if (i < size ? val == NULL || rev != i : val != NULL || rev != -1)
+ if (i >= 0 && i < size ?
+ sparse ? rev != i && rev != -1 : val == NULL || rev != i :
+ val != NULL || rev != -1)
exit(EXIT_FAILURE);
}
}
#define test_table(lower, upper) \
- _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX)
+ _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, false)