Pin the 255 and 256 byte switch point in the tests

This commit is contained in:
J. Nick Koston
2026-10-13 10:31:56 -10:00
parent c470bbb698
commit 962ba06ae9
@@ -16,6 +16,29 @@ PROGMEM_STRING_TABLE(LargeStrings, "0123456789012345678901234567890123456789",
"5123456789012345678901234567890123456789", "6123456789012345678901234567890123456789",
"7123456789012345678901234567890123456789");
// Five 50-character strings pack into exactly 255 bytes; one more byte needs two-byte offsets.
PROGMEM_STRING_TABLE(Exactly255, "01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789");
PROGMEM_STRING_TABLE(Exactly256, "01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789x");
TEST(ProgmemStringTable, OffsetWidthSwitchesAfter255Bytes) {
static_assert(Exactly255::BLOB_SIZE == 255);
static_assert(sizeof(Exactly255::OFFSETS[0]) == 1);
static_assert(Exactly256::BLOB_SIZE == 256);
static_assert(sizeof(Exactly256::OFFSETS[0]) == 2);
EXPECT_EQ(Exactly255::OFFSETS[4], 204);
EXPECT_EQ(Exactly256::OFFSETS[4], 204);
EXPECT_STREQ(reinterpret_cast<const char *>(Exactly256::get_progmem_str(4, 0)),
"01234567890123456789012345678901234567890123456789x");
}
TEST(ProgmemStringTable, SmallTableKeepsOneByteOffsets) {
static_assert(SmallStrings::BLOB_SIZE <= 255);
static_assert(sizeof(SmallStrings::OFFSETS[0]) == 1);