From 488d51979c9982cf6966d383e22269a9bbdbb8c3 Mon Sep 17 00:00:00 2001 From: mikecarper Date: Fri, 2 Oct 2026 13:09:11 -0700 Subject: [PATCH] Update button and reader fixtures for pairing wake API --- test/test_companion_reader.py | 14 ++++++++++-- test/test_message_navigation.py | 38 ++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/test/test_companion_reader.py b/test/test_companion_reader.py index cb1c1420..5cf9c247 100644 --- a/test/test_companion_reader.py +++ b/test/test_companion_reader.py @@ -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(); } ''' diff --git a/test/test_message_navigation.py b/test/test_message_navigation.py index 79b4bc7c..61879189 100644 --- a/test/test_message_navigation.py +++ b/test/test_message_navigation.py @@ -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 ', + '#include \n' + '#include ', +).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(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)