summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2012-07-09 19:12:44 -0700
committerKeith Packard <keithp@keithp.com>2012-07-09 22:52:30 -0700
commitad4092cf7d59a89b1b2922440eef65be5c0c5ebd (patch)
treeec5d4d32e3b05d70e000771492638eb3e8ff2914 /test
parent2b1c1300cc23912ee1c59f8dde938dd4d7287f4a (diff)
Replace padlength tables with inline functions from misc.h
Adds new function padding_for_int32() and uses existing pad_to_int32() depending on required results. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Keith Packard <keithp@keithp.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Tested-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'test')
-rw-r--r--test/input.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/input.c b/test/input.c
index 90ab9aea3..191c81789 100644
--- a/test/input.c
+++ b/test/input.c
@@ -965,6 +965,19 @@ test_pad_to_int32(int i)
}
static void
+test_padding_for_int32(int i)
+{
+ static const int padlength[4] = { 0, 3, 2, 1 };
+ int expected_bytes = (((i + 3) / 4) * 4) - i;
+
+ assert(padding_for_int32(i) >= 0);
+ assert(padding_for_int32(i) <= 3);
+ assert(padding_for_int32(i) == expected_bytes);
+ assert(padding_for_int32(i) == padlength[i & 3]);
+ assert((padding_for_int32(i) + i) == pad_to_int32(i));
+}
+
+static void
include_byte_padding_macros(void)
{
printf("Testing bits_to_bytes()\n");
@@ -996,12 +1009,12 @@ include_byte_padding_macros(void)
test_bytes_to_int32(INT_MAX - 4);
test_bytes_to_int32(INT_MAX - 3);
- printf("Testing pad_to_int32\n");
+ printf("Testing pad_to_int32()\n");
test_pad_to_int32(0);
- test_pad_to_int32(0);
test_pad_to_int32(1);
test_pad_to_int32(2);
+ test_pad_to_int32(3);
test_pad_to_int32(7);
test_pad_to_int32(8);
test_pad_to_int32(0xFF);
@@ -1012,6 +1025,23 @@ include_byte_padding_macros(void)
test_pad_to_int32(0x1000000);
test_pad_to_int32(INT_MAX - 4);
test_pad_to_int32(INT_MAX - 3);
+
+ printf("Testing padding_for_int32()\n");
+
+ test_padding_for_int32(0);
+ test_padding_for_int32(1);
+ test_padding_for_int32(2);
+ test_padding_for_int32(3);
+ test_padding_for_int32(7);
+ test_padding_for_int32(8);
+ test_padding_for_int32(0xFF);
+ test_padding_for_int32(0x100);
+ test_padding_for_int32(0xFFFF);
+ test_padding_for_int32(0x10000);
+ test_padding_for_int32(0xFFFFFF);
+ test_padding_for_int32(0x1000000);
+ test_padding_for_int32(INT_MAX - 4);
+ test_padding_for_int32(INT_MAX - 3);
}
static void