mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-09-25 06:56:49 +00:00
Restore the V4 WiFi setup QR with a one-pixel border
This commit is contained in:
@@ -106,6 +106,7 @@ public:
|
||||
int qr_x = -1;
|
||||
int qr_y = -1;
|
||||
int qr_size = -1;
|
||||
int qr_border = -1;
|
||||
|
||||
QrTestDisplay(int width, int height, int glyph_width)
|
||||
: TestDisplay(width, height, glyph_width) {}
|
||||
@@ -116,6 +117,11 @@ public:
|
||||
qr_size = size;
|
||||
return true;
|
||||
}
|
||||
bool drawQrCodeWithBorder(const char* text, int x, int y, int size,
|
||||
int border) override {
|
||||
qr_border = border;
|
||||
return drawQrCode(text, x, y, size);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -163,6 +169,31 @@ TEST(WiFiSetupQrPayload, EncodesOpenSetupNetwork) {
|
||||
EXPECT_LE(strlen(small_payload), 17U);
|
||||
}
|
||||
|
||||
TEST(DisplayDriver, V4QrUsesOnePixelBorderAndKeepsActionsBesideTheCode) {
|
||||
QrTestDisplay display(128, 64, 6);
|
||||
ASSERT_TRUE(mesh::ui::drawWiFiSetupQr(
|
||||
display, "MC-F7F0", "192.168.4.1", true, "HOLD STOP"));
|
||||
EXPECT_EQ(44, display.qr_size);
|
||||
EXPECT_EQ(1, display.qr_border);
|
||||
EXPECT_EQ(21 * 2 + 2 * display.qr_border, display.qr_size);
|
||||
ASSERT_EQ(5U, display.rows.size());
|
||||
EXPECT_EQ("SCAN JOIN", display.rows[0].text);
|
||||
EXPECT_EQ("HOLD STOP", display.rows[1].text);
|
||||
EXPECT_EQ("192.168.4.1", display.rows.back().text);
|
||||
for (const auto& row : display.rows) {
|
||||
EXPECT_GE(row.x, display.qr_size + 4);
|
||||
EXPECT_LE(row.x + display.getTextWidth(row.text.c_str()), display.width());
|
||||
EXPECT_LE(row.y + 8, display.height());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DisplayDriver, V4QrKeepsFallbackWhenRendererIsUnavailable) {
|
||||
TestDisplay display(128, 64, 6);
|
||||
EXPECT_FALSE(mesh::ui::drawWiFiSetupQr(
|
||||
display, "MC-F7F0", "192.168.4.1", true, "HOLD STOP"));
|
||||
EXPECT_TRUE(display.rows.empty());
|
||||
}
|
||||
|
||||
TEST(WiFiSetupQrPayload, EscapesProtectedNetworkFields) {
|
||||
char payload[96];
|
||||
EXPECT_TRUE(mesh::ui::buildWiFiSetupQrPayload(
|
||||
|
||||
Reference in New Issue
Block a user