diff --git a/tests/components/core/test_progmem_string_table.cpp b/tests/components/core/test_progmem_string_table.cpp index e0d8da56468..72a2c507507 100644 --- a/tests/components/core/test_progmem_string_table.cpp +++ b/tests/components/core/test_progmem_string_table.cpp @@ -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(Exactly256::get_progmem_str(4, 0)), + "01234567890123456789012345678901234567890123456789x"); +} + TEST(ProgmemStringTable, SmallTableKeepsOneByteOffsets) { static_assert(SmallStrings::BLOB_SIZE <= 255); static_assert(sizeof(SmallStrings::OFFSETS[0]) == 1);