From 59c3e0a8135371df6aa8990056f5a83b5e9660ce Mon Sep 17 00:00:00 2001 From: gdpinchina Date: Sat, 8 Sep 2018 14:12:10 +0800 Subject: [PATCH] fix gga char alignment problem in test.c In c compiler, a char takes 4 bytes in a structure though its size is 1 bytes. The initialization for `struct minmea_sentence_gga`: ``` struct minmea_sentence_gga expected = { .time = { 12, 35, 19, 0 }, .latitude = { 4807038, 1000 }, .longitude = { 1131000, 1000 }, .fix_quality = 1, .satellites_tracked = 8, .hdop = { 9, 10 }, .altitude = { 5454, 10 }, .altitude_units = 'M', .height = { 469, 10 }, .height_units = 'M', .dgps_age = { 0, 0 }, }; ``` has the binary sequence like these: ``` 0c 00 00 00 23 00 00 00 13 00 00 00 00 00 00 00 7e 59 49 00 e8 03 00 00 f8 41 11 00 e8 03 00 00 01 00 00 00 08 00 00 00 09 00 00 00 0a 00 00 00 4e 15 00 00 0a 00 00 00 4d cc cc cc d5 01 00 00 0a 00 00 00 4d cc cc cc 00 00 00 00 00 00 00 00 ``` which the `4d cc cc cc` is the `'M'`, and cause memcmp return none zero. Therefore I add some code to remove `cc cc cc`: ``` memset(&expected.altitude_units + 1, 0, 3); memset(&expected.height_units + 1, 0, 3); ``` --- tests.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests.c b/tests.c index fff286d..f55e17a 100644 --- a/tests.c +++ b/tests.c @@ -508,7 +508,7 @@ START_TEST(test_minmea_parse_gga1) { const char *sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47"; struct minmea_sentence_gga frame = {}; - static const struct minmea_sentence_gga expected = { + struct minmea_sentence_gga expected = { .time = { 12, 35, 19, 0 }, .latitude = { 4807038, 1000 }, .longitude = { 1131000, 1000 }, @@ -519,11 +519,13 @@ START_TEST(test_minmea_parse_gga1) .altitude_units = 'M', .height = { 469, 10 }, .height_units = 'M', - .dgps_age = { 0, 10 }, + .dgps_age = { 0, 0 }, }; ck_assert(minmea_check(sentence, false) == true); ck_assert(minmea_check(sentence, true) == true); ck_assert(minmea_parse_gga(&frame, sentence) == true); + memset(&expected.altitude_units + 1, 0, 3); + memset(&expected.height_units + 1, 0, 3); ck_assert(!memcmp(&frame, &expected, sizeof(frame))); } END_TEST