summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Martin <consume.noise@gmail.com>2017-10-27 16:11:56 +0200
committerAdam Jackson <ajax@redhat.com>2017-10-30 13:45:20 -0400
commitd5379b350fb63e42e604361c21ad9832b4c791b9 (patch)
tree9ff0602258e2d4afb74561614810fb8a8e0e1860 /test
parent15a32ee5d1fffa171bb05af9a0e5b472e4af1488 (diff)
Use ARRAY_SIZE all over the tree
Roundhouse kick replacing the various (sizeof(foo)/sizeof(foo[0])) with the ARRAY_SIZE macro from dix.h when possible. A semantic patch for coccinelle has been used first. Additionally, a few macros have been inlined as they had only one or two users. Signed-off-by: Daniel Martin <consume.noise@gmail.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/input.c2
-rw-r--r--test/signal-logging.c8
-rw-r--r--test/tests-common.h2
3 files changed, 7 insertions, 5 deletions
diff --git a/test/input.c b/test/input.c
index 8638f1443..9ff1a2fab 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1427,7 +1427,7 @@ include_bit_test_macros(void)
uint8_t mask[9] = { 0 };
int i;
- for (i = 0; i < sizeof(mask) / sizeof(mask[0]); i++) {
+ for (i = 0; i < ARRAY_SIZE(mask); i++) {
assert(BitIsOn(mask, i) == 0);
SetBit(mask, i);
assert(BitIsOn(mask, i) == 1);
diff --git a/test/signal-logging.c b/test/signal-logging.c
index ca327e9aa..afbdeb241 100644
--- a/test/signal-logging.c
+++ b/test/signal-logging.c
@@ -145,13 +145,13 @@ number_formatting(void)
-0x7FFFFFFFFFFFFFFF, /* Maximum 64-bit signed number */
} ;
- for (i = 0; i < sizeof(unsigned_tests) / sizeof(unsigned_tests[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(unsigned_tests); i++)
assert(check_number_format_test(unsigned_tests[i]));
- for (i = 0; i < sizeof(signed_tests) / sizeof(signed_tests[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(signed_tests); i++)
assert(check_signed_number_format_test(signed_tests[i]));
- for (i = 0; i < sizeof(float_tests) / sizeof(float_tests[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(float_tests); i++)
assert(check_float_format_test(float_tests[i]));
}
#pragma GCC diagnostic pop
@@ -366,7 +366,7 @@ static void logging_format(void)
} while(ptr);
- for (i = 0; i < sizeof(float_tests)/sizeof(float_tests[0]); i++) {
+ for (i = 0; i < ARRAY_SIZE(float_tests); i++) {
double d = float_tests[i];
char expected[30];
sprintf(expected, "(EE) %.2f\n", d);
diff --git a/test/tests-common.h b/test/tests-common.h
index d5286caf2..ea0642247 100644
--- a/test/tests-common.h
+++ b/test/tests-common.h
@@ -3,6 +3,8 @@
#include "tests.h"
+#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
+
#define run_test(func) run_test_in_child(func, #func)
void run_test_in_child(int (*func)(void), const char *funcname);