diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2010-04-14 00:32:06 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2010-04-14 00:32:06 -0400 |
commit | 4ab4b136c84acbe8c2434762f8fb0faf08c7a5bd (patch) | |
tree | 37c4e52ca307c6fb050459e9758add126d5f02ae /test_packet.c | |
parent | b40b09abde8b87faf6e17e0f539470cc420e0158 (diff) | |
download | gpsd-4ab4b136c84acbe8c2434762f8fb0faf08c7a5bd.tar.gz |
Reindent the test programs. All regression tests pass.
Diffstat (limited to 'test_packet.c')
-rw-r--r-- | test_packet.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/test_packet.c b/test_packet.c index e1fd8cbf..f2b8a64c 100644 --- a/test_packet.c +++ b/test_packet.c @@ -16,7 +16,7 @@ static int verbose = 0; -void gpsd_report(int errlevel, const char *fmt, ... ) +void gpsd_report(int errlevel, const char *fmt, ...) /* assemble command in printf(3) style, use stderr or syslog */ { if (errlevel <= verbose) { @@ -24,22 +24,25 @@ void gpsd_report(int errlevel, const char *fmt, ... ) va_list ap; buf[0] = '\0'; - va_start(ap, fmt) ; - (void)vsnprintf(buf + strlen(buf), sizeof(buf)-strlen(buf), fmt, ap); + va_start(ap, fmt); + (void)vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, + ap); va_end(ap); (void)fputs(buf, stderr); } } -struct map { - char *legend; - char test[MAX_PACKET_LENGTH+1]; - size_t testlen; - int garbage_offset; - int type; +struct map +{ + char *legend; + char test[MAX_PACKET_LENGTH + 1]; + size_t testlen; + int garbage_offset; + int type; }; +/* *INDENT-OFF* */ /*@ -initallelements +charint -usedef @*/ static struct map tests[] = { /* NMEA tests */ @@ -233,6 +236,7 @@ static struct map tests[] = { }, }; /*@ +initallelements -charint +usedef @*/ +/* *INDENT-ON* */ static int packet_test(struct map *mp) { @@ -240,21 +244,24 @@ static int packet_test(struct map *mp) int failure = 0; packet_init(&packet); - /*@i@*/memcpy(packet.inbufptr = packet.inbuffer, mp->test, mp->testlen); + /*@i@*/ memcpy(packet.inbufptr = packet.inbuffer, mp->test, mp->testlen); packet.inbuflen = mp->testlen; /*@ -compdef -uniondef -usedef -formatcode @*/ packet_parse(&packet); if (packet.type != mp->type) - printf("%2zi: %s test FAILED (packet type %d wrong).\n", mp-tests+1, mp->legend, packet.type); - else if (memcmp(mp->test + mp->garbage_offset, packet.outbuffer, packet.outbuflen)) { - printf("%2zi: %s test FAILED (data garbled).\n", mp-tests+1, mp->legend); + printf("%2zi: %s test FAILED (packet type %d wrong).\n", + mp - tests + 1, mp->legend, packet.type); + else if (memcmp + (mp->test + mp->garbage_offset, packet.outbuffer, + packet.outbuflen)) { + printf("%2zi: %s test FAILED (data garbled).\n", mp - tests + 1, + mp->legend); ++failure; } else - printf("%2zi: %s test succeeded.\n", mp-tests+1, mp->legend); + printf("%2zi: %s test succeeded.\n", mp - tests + 1, mp->legend); #ifdef DUMPIT - for (cp = packet.outbuffer; - cp < packet.outbuffer + packet.outbuflen; - cp++) { + for (cp = packet.outbuffer; + cp < packet.outbuffer + packet.outbuflen; cp++) { if (lexer->type != NMEA_PACKET) (void)printf(" 0x%02x", *cp); else if (*cp == '\r') @@ -286,7 +293,7 @@ int main(int argc, char *argv[]) singletest = atoi(optarg); break; case 'v': - verbose = atoi(optarg); + verbose = atoi(optarg); break; } } @@ -294,7 +301,7 @@ int main(int argc, char *argv[]) if (singletest) failcount += packet_test(tests + singletest - 1); else - for (mp = tests; mp < tests + sizeof(tests)/sizeof(tests[0]); mp++) + for (mp = tests; mp < tests + sizeof(tests) / sizeof(tests[0]); mp++) failcount += packet_test(mp); exit(failcount > 0 ? 1 : 0); } |