Update button and reader fixtures for pairing wake API

This commit is contained in:
mikecarper committed 2026-10-02 13:09:11 -07:00
1 parent a0105731f5
commit 488d51979c
2 files changed
+49 -3

No files matched your search

+12 -2
View File
@@ -10,7 +10,7 @@ import tempfile
import unittest
import zlib
from test_message_navigation import PREAMBLE
from test_message_navigation import PAIRING_PREAMBLE as PREAMBLE
from test_replay_reset_integration import extract_braced
ROOT = Path(__file__).resolve().parents[1]
@@ -174,7 +174,6 @@ struct ReaderScreen : Screen { int saves = 0; void flush() { ++saves; } };
uint32_t _pairing_screen_until = 0;
bool hasConnection() const { return false; }
bool isPairingScreenActive() const { return false; }
void showPairingPin() {}
void finishPairingScreen(bool) {}
void servicePairingState();
'''
@@ -222,6 +221,17 @@ int main() {
int before = reader.saves;
g_mock_millis += 5000; task.servicePairingState();
assert(!display.isOn() && reader.saves == before);
assert(task.pairing_previews == 0); // Bluetooth-disabled reader wakes stay ordinary.
task.bluetooth_enabled = true;
task.curr = &reader;
before = reader.saves;
assert(task.checkDisplayOn(KEY_NEXT) == 0 && display.isOn());
assert(task.pairing_previews == 1 && task.pairing_from_button);
assert(reader.saves == before); // PIN preview does not write the bookmark.
task.bluetooth_connected = true;
display.turnOff();
assert(task.checkDisplayOn(KEY_NEXT) == 0 && display.isOn());
assert(task.pairing_previews == 1); // No new PIN for a connected BLE peer.
task._display = nullptr; task.servicePairingState();
}
'''
+37 -1
View File
@@ -140,6 +140,29 @@ public:
};
'''
# Only fixtures extracting the real checkDisplayOn() need its pairing API.
# Keep PREAMBLE unchanged for inbox fixtures that supply their own BLE model.
PAIRING_PREAMBLE = PREAMBLE.replace(
'#include <helpers/ui/DisplayTextLayout.h>',
'#include <helpers/ui/DisplayTextLayout.h>\n'
'#include <helpers/ui/BluetoothPairingUiPolicy.h>',
).replace(
' bool notificationButton() { return false; }',
' bool notificationButton() { return false; }\n'
' uint32_t getBLEPin() const { return 246810; }',
).replace(' int getMsgCount() const { return 0; }', r'''
bool bluetooth_enabled=false, bluetooth_connected=false;
bool pairing_from_button=false;
int pairing_previews=0;
bool isBluetoothEnabled() const { return bluetooth_enabled; }
bool hasBluetoothConnection() const { return bluetooth_connected; }
void showPairingPin(bool from_button=false) {
++pairing_previews;
pairing_from_button=from_button;
}
int getMsgCount() const { return 0; }
''')
SCENARIOS = r'''
void gesture(UITask& task,int count) {
for (int tap=0;tap<count;++tap) {
@@ -240,6 +263,7 @@ int main() {
display.on=false;
gesture(task,4); // waking consumes the entire gesture
assert(display.on); expect("DM 1/1","direct message");
assert(task.pairing_previews==0); // Disabled Bluetooth must not claim the wake.
gesture(task,4); expect("Ch 3 0/0","No buffered messages");
gesture(task,4); expect("Ch 2 1/1","second");
#if UI_READER_TOUCH_BAR
@@ -358,6 +382,18 @@ int main() {
gesture(task,2); assert(home._page==HomeScreen::RADIO_STATUS);
gesture(task,2); assert(home._page==HomeScreen::RADIO2);
gesture(task,2); assert(home._page==HomeScreen::RADIO);
// Exercise the current production wake's pairing dependency rather than
// removing it from the extracted method to keep the navigation fixture green.
task.bluetooth_enabled=true;
display.on=false;
assert(task.checkDisplayOn(KEY_NEXT)==0);
assert(display.on && task.pairing_previews==1 && task.pairing_from_button);
assert(static_cast<uint8_t>(task.checkDisplayOn(KEY_NEXT))==KEY_NEXT);
assert(task.pairing_previews==1); // Already-awake navigation does not re-prompt.
task.bluetooth_connected=true;
display.on=false;
assert(task.checkDisplayOn(KEY_NEXT)==0 && display.on);
assert(task.pairing_previews==1); // Bonded/connected Bluetooth needs no PIN.
}
'''
@@ -409,7 +445,7 @@ class MessageNavigationTest(unittest.TestCase):
for enabled, signedness, canvas in product(
(0, 1), ("-fsigned-char", "-funsigned-char"), (0, 320, 480)):
with self.subTest(feature=enabled, signedness=signedness, canvas=canvas), tempfile.TemporaryDirectory() as temp:
preamble = PREAMBLE
preamble = PAIRING_PREAMBLE
flags = []
if canvas:
preamble = preamble.replace("MomentaryButton user_btn(7,1000,true,true,true);", button)