Skip to content

Commit c148d99

Browse files
committed
Tighten checksum parsing and pin the WPL fixture checksum
Require exactly two hex digits followed by the sentence terminator, and assert both WPL overloads against a known checksum instead of comparing them to each other.
1 parent e4c6422 commit c148d99

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

test/test_nmea_wpl/test_main.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include "NMEAWPL.h"
33
#include "TestUtil.h"
44
#include "mesh-pb-constants.h"
5+
#include <cctype>
56
#include <cstdint>
7+
#include <cstdio>
68
#include <cstring>
79
#include <unity.h>
810

@@ -46,6 +48,9 @@ static uint32_t emittedChecksum(const char *buf)
4648
{
4749
const char *star = strrchr(buf, '*');
4850
TEST_ASSERT_NOT_NULL(star);
51+
TEST_ASSERT_TRUE(isxdigit((unsigned char)star[1]));
52+
TEST_ASSERT_TRUE(isxdigit((unsigned char)star[2]));
53+
TEST_ASSERT_TRUE(star[3] == '\r' || star[3] == '\0');
4954
unsigned parsed = 0;
5055
TEST_ASSERT_EQUAL_INT(1, sscanf(star + 1, "%02X", &parsed));
5156
return parsed;
@@ -93,6 +98,7 @@ void test_gga_checksum(void)
9398

9499
void test_crlf_prefix_does_not_change_checksum(void)
95100
{
101+
const uint32_t fixtureChecksum = 0x69;
96102
char withPrefix[128];
97103
char withoutPrefix[128];
98104
meshtastic_PositionLite lite = makePositionLite();
@@ -101,7 +107,8 @@ void test_crlf_prefix_does_not_change_checksum(void)
101107
printWPL(withPrefix, sizeof(withPrefix), lite, "Test", false);
102108
printWPL(withoutPrefix, sizeof(withoutPrefix), pos, "Test", false);
103109

104-
TEST_ASSERT_EQUAL_UINT32(emittedChecksum(withoutPrefix), emittedChecksum(withPrefix));
110+
TEST_ASSERT_EQUAL_UINT32(fixtureChecksum, emittedChecksum(withPrefix));
111+
TEST_ASSERT_EQUAL_UINT32(fixtureChecksum, emittedChecksum(withoutPrefix));
105112
}
106113

107114
void test_zero_sized_buffer_writes_nothing(void)

0 commit comments

Comments
 (0)