summaryrefslogtreecommitdiff
path: root/test_bits.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2012-04-19 17:44:25 -0400
committerEric S. Raymond <esr@thyrsus.com>2012-04-19 18:09:19 -0400
commit60eeb93321e753828050bb70c6c58c98700e8656 (patch)
tree309ad3f3bf317dd65412a36efe081dd144453b80 /test_bits.c
parent38e09bb74ccdd927768389b007a5f98872115849 (diff)
downloadgpsd-60eeb93321e753828050bb70c6c58c98700e8656.tar.gz
Prepare for unit tests of little-endian extraction.
All normal regression tests and the test_bits unit test pass.
Diffstat (limited to 'test_bits.c')
-rw-r--r--test_bits.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/test_bits.c b/test_bits.c
index 6caf531c..87b8af1c 100644
--- a/test_bits.c
+++ b/test_bits.c
@@ -110,6 +110,7 @@ struct unsigned_test
unsigned char *buf;
unsigned int start, width;
uint64_t expected;
+ bool le;
char *description;
};
@@ -119,14 +120,14 @@ int main(void)
/*@ -observertrans -usereleased @*/
struct unsigned_test *up, unsigned_tests[] = {
/* tests using the big buffer */
- {buf, 0, 1, 0, "first bit of first byte"},
- {buf, 0, 8, 0x01, "first 8 bits"},
- {buf, 32, 7, 2, "first seven bits of fifth byte"},
- {buf, 56, 12, 0x8f, "12 bits crossing 7th to 8th bytes (0x08ff)"},
- {buf, 78, 4, 11, "2 bits crossing 8th to 9th byte (0xfefd)"},
+ {buf, 0, 1, 0, false, "first bit of first byte"},
+ {buf, 0, 8, 0x01, false, "first 8 bits"},
+ {buf, 32, 7, 0x02, false, "first seven bits of fifth byte"},
+ {buf, 56, 12, 0x8f, false, "12 bits crossing 7th to 8th bytes (0x08ff)"},
+ {buf, 78, 4, 11, false, "2 bits crossing 8th to 9th byte (0xfefd)"},
/* sporadic tests based on found bugs */
{(unsigned char *)"\x19\x23\f6",
- 7, 2, 2, "2 bits crossing 1st to 2nd byte (0x1923)"},
+ 7, 2, 2, false, "2 bits crossing 1st to 2nd byte (0x1923)"},
};
unsigned char *sp;
@@ -196,10 +197,11 @@ int main(void)
up <
unsigned_tests + sizeof(unsigned_tests) / sizeof(unsigned_tests[0]);
up++) {
- uint64_t res = ubits((char *)buf, up->start, up->width, false);
- (void)printf("ubits(%s, %d, %d, false) %s should be %" PRIx64 ", is %" PRIx64 ": %s\n",
+ uint64_t res = ubits((char *)buf, up->start, up->width, up->le);
+ (void)printf("ubits(%s, %d, %d, %s) %s should be %" PRIx64 ", is %" PRIx64 ": %s\n",
hexdump(buf, strlen((char *)buf)),
- up->start, up->width, up->description, up->expected, res,
+ up->start, up->width, up->le ? "true" : "false",
+ up->description, up->expected, res,
res == up->expected ? "succeeded" : "FAILED");
}