add test_minmea_parse_vtg3 (fixes #57)
This commit is contained in:
parent
c0d2f58128
commit
a0da280f64
17
minmea.c
17
minmea.c
@ -594,7 +594,7 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence)
|
||||
char type[6];
|
||||
char c_true, c_magnetic, c_knots, c_kph, c_faa_mode;
|
||||
|
||||
if (!minmea_scan(sentence, "tfcfcfcfc;c",
|
||||
if (!minmea_scan(sentence, "t;fcfcfcfcc",
|
||||
type,
|
||||
&frame->true_track_degrees,
|
||||
&c_true,
|
||||
@ -608,12 +608,15 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence)
|
||||
return false;
|
||||
if (strcmp(type+2, "VTG"))
|
||||
return false;
|
||||
// check chars
|
||||
if (c_true != 'T' ||
|
||||
c_magnetic != 'M' ||
|
||||
c_knots != 'N' ||
|
||||
c_kph != 'K')
|
||||
return false;
|
||||
// values are only valid with the accompanying characters
|
||||
if (c_true != 'T')
|
||||
frame->true_track_degrees.scale = 0;
|
||||
if (c_magnetic != 'M')
|
||||
frame->magnetic_track_degrees.scale = 0;
|
||||
if (c_knots != 'N')
|
||||
frame->speed_knots.scale = 0;
|
||||
if (c_kph != 'K')
|
||||
frame->speed_kph.scale = 0;
|
||||
frame->faa_mode = (enum minmea_faa_mode)c_faa_mode;
|
||||
|
||||
return true;
|
||||
|
22
tests.c
22
tests.c
@ -895,6 +895,27 @@ START_TEST(test_minmea_parse_vtg2)
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_minmea_parse_vtg3)
|
||||
{
|
||||
// https://github.com/kosma/minmea/issues/57
|
||||
const char *sentence = "$GNVTG,,,,,,,,,N*2E";
|
||||
// clear structs before initialization to enable use of memcmp()
|
||||
struct minmea_sentence_vtg frame = {};
|
||||
struct minmea_sentence_vtg expected = {};
|
||||
expected = (struct minmea_sentence_vtg){
|
||||
.true_track_degrees = { 0, 0 },
|
||||
.magnetic_track_degrees = { 0, 0 },
|
||||
.speed_knots = { 0, 0 },
|
||||
.speed_kph = { 0, 0 },
|
||||
.faa_mode = MINMEA_FAA_MODE_NOT_VALID,
|
||||
};
|
||||
ck_assert(minmea_check(sentence, false) == true);
|
||||
ck_assert(minmea_check(sentence, true) == true);
|
||||
ck_assert(minmea_parse_vtg(&frame, sentence) == true);
|
||||
ck_assert(!memcmp(&frame, &expected, sizeof(frame)));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_minmea_parse_zda1)
|
||||
{
|
||||
const char *sentence = "$GPZDA,160012.71,11,03,2004,-1,00*7D";
|
||||
@ -1133,6 +1154,7 @@ static Suite *minmea_suite(void)
|
||||
tcase_add_test(tc_parse, test_minmea_parse_gsv5);
|
||||
tcase_add_test(tc_parse, test_minmea_parse_vtg1);
|
||||
tcase_add_test(tc_parse, test_minmea_parse_vtg2);
|
||||
tcase_add_test(tc_parse, test_minmea_parse_vtg3);
|
||||
tcase_add_test(tc_parse, test_minmea_parse_zda1);
|
||||
suite_add_tcase(s, tc_parse);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user