Browse Source

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);
```
gdpinchina 7 years ago
parent
commit
59c3e0a813
1 changed files with 4 additions and 2 deletions
  1. 4 2
      tests.c

+ 4 - 2
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";
     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 = {};
     struct minmea_sentence_gga frame = {};
-    static const struct minmea_sentence_gga expected = {
+    struct minmea_sentence_gga expected = {
         .time = { 12, 35, 19, 0 },
         .time = { 12, 35, 19, 0 },
         .latitude = { 4807038, 1000 },
         .latitude = { 4807038, 1000 },
         .longitude = { 1131000, 1000 },
         .longitude = { 1131000, 1000 },
@@ -519,11 +519,13 @@ START_TEST(test_minmea_parse_gga1)
         .altitude_units = 'M',
         .altitude_units = 'M',
         .height = { 469, 10 },
         .height = { 469, 10 },
         .height_units = 'M',
         .height_units = 'M',
-        .dgps_age = { 0, 10 },
+        .dgps_age = { 0, 0 },
     };
     };
     ck_assert(minmea_check(sentence, false) == true);
     ck_assert(minmea_check(sentence, false) == true);
     ck_assert(minmea_check(sentence, true) == true);
     ck_assert(minmea_check(sentence, true) == true);
     ck_assert(minmea_parse_gga(&frame, sentence) == 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)));
     ck_assert(!memcmp(&frame, &expected, sizeof(frame)));
 }
 }
 END_TEST
 END_TEST