Public Access
M0 step 7: Settings, About, Storage, first-boot setup
- lib/apps_model (host-tested): SettingsMenu (rows, readable values, choices, validation messages) and SetupWizard (names, Region confirmation, timezone; saves only when finished) - AppManager: modal Apps that Home/Back can't leave (setup wizard) - SettingsApp: all settings plus Storage (usage, erase SD behind a dialog) and About (version, node id, battery, memory, uptime) pages, replacing the temporary Diagnostics App - SetupApp: first-boot wizard, opened modally until SetupDone - Node id and default names derived from the MAC like Meshtastic - Widget demo is now hidden (About, then w) - lib_ldf_mode = deep+ so libraries see each other's headers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "key_value_store.h"
|
||||
|
||||
// In-memory KeyValueStore for tests.
|
||||
struct MemoryStore : roro::KeyValueStore {
|
||||
std::map<std::string, int32_t> ints;
|
||||
std::map<std::string, std::string> strings;
|
||||
bool getInt(const char* key, int32_t& out) override {
|
||||
auto it = ints.find(key);
|
||||
if (it == ints.end()) return false;
|
||||
out = it->second;
|
||||
return true;
|
||||
}
|
||||
bool getString(const char* key, std::string& out) override {
|
||||
auto it = strings.find(key);
|
||||
if (it == strings.end()) return false;
|
||||
out = it->second;
|
||||
return true;
|
||||
}
|
||||
void putInt(const char* key, int32_t v) override { ints[key] = v; }
|
||||
void putString(const char* key, const std::string& v) override { strings[key] = v; }
|
||||
};
|
||||
@@ -155,6 +155,32 @@ void test_update_reaches_only_the_foreground_app() {
|
||||
TEST_ASSERT_EQUAL(0, f.launcher.lastUpdate);
|
||||
}
|
||||
|
||||
void test_modal_app_keeps_home_and_back() {
|
||||
Fixture f;
|
||||
f.manager.openModal("demo");
|
||||
f.manager.handleKey(KeyEvent::of(Key::Home));
|
||||
f.manager.handleKey(KeyEvent::of(Key::Back));
|
||||
TEST_ASSERT_EQUAL_PTR(&f.demo, &f.manager.foreground());
|
||||
TEST_ASSERT_EQUAL(2, f.demo.keys.size()); // both reached the App
|
||||
}
|
||||
|
||||
void test_ending_the_modal_returns_to_launcher_and_unlocks_home() {
|
||||
Fixture f;
|
||||
f.manager.openModal("demo");
|
||||
f.manager.endModal();
|
||||
TEST_ASSERT_EQUAL_PTR(&f.launcher, &f.manager.foreground());
|
||||
f.manager.open("notes");
|
||||
f.manager.handleKey(KeyEvent::of(Key::Home));
|
||||
TEST_ASSERT_EQUAL_PTR(&f.launcher, &f.manager.foreground());
|
||||
}
|
||||
|
||||
void test_modal_app_cannot_be_switched_away_by_open() {
|
||||
Fixture f;
|
||||
f.manager.openModal("demo");
|
||||
TEST_ASSERT_FALSE(f.manager.open("notes"));
|
||||
TEST_ASSERT_EQUAL_PTR(&f.demo, &f.manager.foreground());
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_launcher_is_in_foreground_after_begin);
|
||||
@@ -170,5 +196,8 @@ int main() {
|
||||
RUN_TEST(test_switching_apps_requests_a_redraw);
|
||||
RUN_TEST(test_app_can_request_its_own_redraw);
|
||||
RUN_TEST(test_update_reaches_only_the_foreground_app);
|
||||
RUN_TEST(test_modal_app_keeps_home_and_back);
|
||||
RUN_TEST(test_ending_the_modal_returns_to_launcher_and_unlocks_home);
|
||||
RUN_TEST(test_modal_app_cannot_be_switched_away_by_open);
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
@@ -4,29 +4,12 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "../memory_store.h"
|
||||
#include "event_bus.h"
|
||||
#include "settings.h"
|
||||
|
||||
using namespace roro;
|
||||
|
||||
struct MemoryStore : KeyValueStore {
|
||||
std::map<std::string, int32_t> ints;
|
||||
std::map<std::string, std::string> strings;
|
||||
bool getInt(const char* key, int32_t& out) override {
|
||||
auto it = ints.find(key);
|
||||
if (it == ints.end()) return false;
|
||||
out = it->second;
|
||||
return true;
|
||||
}
|
||||
bool getString(const char* key, std::string& out) override {
|
||||
auto it = strings.find(key);
|
||||
if (it == strings.end()) return false;
|
||||
out = it->second;
|
||||
return true;
|
||||
}
|
||||
void putInt(const char* key, int32_t v) override { ints[key] = v; }
|
||||
void putString(const char* key, const std::string& v) override { strings[key] = v; }
|
||||
};
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
#include <unity.h>
|
||||
|
||||
#include "../memory_store.h"
|
||||
#include "event_bus.h"
|
||||
#include "settings_menu.h"
|
||||
|
||||
using namespace roro;
|
||||
|
||||
struct Fixture {
|
||||
MemoryStore store;
|
||||
EventBus bus;
|
||||
Settings settings{store, bus};
|
||||
SettingsMenu menu{settings};
|
||||
Fixture() { settings.load(); }
|
||||
int row(SettingsMenu::Row r) {
|
||||
for (int i = 0; i < menu.count(); i++)
|
||||
if (menu.row(i) == r) return i;
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
void test_every_row_has_a_label() {
|
||||
Fixture f;
|
||||
TEST_ASSERT_TRUE(f.menu.count() > 0);
|
||||
for (int i = 0; i < f.menu.count(); i++) TEST_ASSERT_FALSE(f.menu.label(i).empty());
|
||||
}
|
||||
|
||||
void test_values_are_human_readable() {
|
||||
Fixture f;
|
||||
TEST_ASSERT_EQUAL_STRING("60%", f.menu.value(f.row(SettingsMenu::Row::Brightness)).c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("30 s", f.menu.value(f.row(SettingsMenu::Row::DimTimeout)).c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("1 min", f.menu.value(f.row(SettingsMenu::Row::OffTimeout)).c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("On", f.menu.value(f.row(SettingsMenu::Row::Sound)).c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("Brussels", f.menu.value(f.row(SettingsMenu::Row::Timezone)).c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("Raw", f.menu.value(f.row(SettingsMenu::Row::ProbeMacs)).c_str());
|
||||
}
|
||||
|
||||
void test_toggle_rows_flip_on_select() {
|
||||
Fixture f;
|
||||
int sound = f.row(SettingsMenu::Row::Sound);
|
||||
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Toggle), static_cast<int>(f.menu.kind(sound)));
|
||||
f.menu.toggle(sound);
|
||||
TEST_ASSERT_FALSE(f.settings.getBool(Setting::Sound));
|
||||
}
|
||||
|
||||
void test_choice_rows_list_options_and_mark_the_current_one() {
|
||||
Fixture f;
|
||||
int tz = f.row(SettingsMenu::Row::Timezone);
|
||||
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Choice), static_cast<int>(f.menu.kind(tz)));
|
||||
auto options = f.menu.choices(tz);
|
||||
TEST_ASSERT_TRUE(options.size() >= 3);
|
||||
TEST_ASSERT_EQUAL_STRING("Brussels", options[f.menu.currentChoice(tz)].c_str());
|
||||
}
|
||||
|
||||
void test_choosing_applies_the_setting() {
|
||||
Fixture f;
|
||||
int tz = f.row(SettingsMenu::Row::Timezone);
|
||||
auto options = f.menu.choices(tz);
|
||||
int utc = -1;
|
||||
for (size_t i = 0; i < options.size(); i++)
|
||||
if (options[i] == "UTC") utc = static_cast<int>(i);
|
||||
TEST_ASSERT_TRUE(f.menu.choose(tz, utc).empty());
|
||||
TEST_ASSERT_EQUAL_STRING("UTC0", f.settings.getString(Setting::Timezone).c_str());
|
||||
}
|
||||
|
||||
void test_choice_that_breaks_a_rule_is_refused_with_a_reason() {
|
||||
Fixture f;
|
||||
int dim = f.row(SettingsMenu::Row::DimTimeout);
|
||||
auto options = f.menu.choices(dim);
|
||||
int fiveMinutes = -1;
|
||||
for (size_t i = 0; i < options.size(); i++)
|
||||
if (options[i] == "5 min") fiveMinutes = static_cast<int>(i);
|
||||
TEST_ASSERT_TRUE(fiveMinutes >= 0);
|
||||
std::string error = f.menu.choose(dim, fiveMinutes); // screen off is 1 min
|
||||
TEST_ASSERT_FALSE(error.empty());
|
||||
TEST_ASSERT_EQUAL(30, f.settings.getInt(Setting::DimTimeoutS));
|
||||
}
|
||||
|
||||
void test_brightness_steps_with_left_right_within_bounds() {
|
||||
Fixture f;
|
||||
int b = f.row(SettingsMenu::Row::Brightness);
|
||||
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Slider), static_cast<int>(f.menu.kind(b)));
|
||||
f.menu.adjust(b, +1);
|
||||
TEST_ASSERT_EQUAL(70, f.settings.getInt(Setting::Brightness));
|
||||
for (int i = 0; i < 10; i++) f.menu.adjust(b, -1);
|
||||
TEST_ASSERT_EQUAL(10, f.settings.getInt(Setting::Brightness));
|
||||
}
|
||||
|
||||
void test_names_are_text_rows_with_their_byte_limits() {
|
||||
Fixture f;
|
||||
int shortName = f.row(SettingsMenu::Row::ShortName);
|
||||
TEST_ASSERT_EQUAL(static_cast<int>(SettingsMenu::Kind::Text), static_cast<int>(f.menu.kind(shortName)));
|
||||
TEST_ASSERT_EQUAL(4, f.menu.maxBytes(shortName));
|
||||
TEST_ASSERT_FALSE(f.menu.setText(shortName, "TOOLONG").empty());
|
||||
TEST_ASSERT_TRUE(f.menu.setText(shortName, "RORO").empty());
|
||||
TEST_ASSERT_EQUAL_STRING("RORO", f.menu.value(shortName).c_str());
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_every_row_has_a_label);
|
||||
RUN_TEST(test_values_are_human_readable);
|
||||
RUN_TEST(test_toggle_rows_flip_on_select);
|
||||
RUN_TEST(test_choice_rows_list_options_and_mark_the_current_one);
|
||||
RUN_TEST(test_choosing_applies_the_setting);
|
||||
RUN_TEST(test_choice_that_breaks_a_rule_is_refused_with_a_reason);
|
||||
RUN_TEST(test_brightness_steps_with_left_right_within_bounds);
|
||||
RUN_TEST(test_names_are_text_rows_with_their_byte_limits);
|
||||
return UNITY_END();
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
#include <unity.h>
|
||||
|
||||
#include "../memory_store.h"
|
||||
#include "event_bus.h"
|
||||
#include "setup_wizard.h"
|
||||
|
||||
using namespace roro;
|
||||
|
||||
struct Fixture {
|
||||
MemoryStore store;
|
||||
EventBus bus;
|
||||
Settings settings{store, bus};
|
||||
SetupWizard wizard{settings, "roro9stack 2fa4", "2fa4"};
|
||||
Fixture() { settings.load(); }
|
||||
};
|
||||
|
||||
using Step = SetupWizard::Step;
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
static void assertStep(Step expected, const SetupWizard& w) {
|
||||
TEST_ASSERT_EQUAL(static_cast<int>(expected), static_cast<int>(w.step()));
|
||||
}
|
||||
|
||||
void test_walks_through_every_step_with_defaults() {
|
||||
Fixture f;
|
||||
assertStep(Step::Welcome, f.wizard);
|
||||
TEST_ASSERT_TRUE(f.wizard.next());
|
||||
assertStep(Step::LongName, f.wizard);
|
||||
TEST_ASSERT_EQUAL_STRING("roro9stack 2fa4", f.wizard.editor().text().c_str());
|
||||
TEST_ASSERT_TRUE(f.wizard.next());
|
||||
assertStep(Step::ShortName, f.wizard);
|
||||
TEST_ASSERT_EQUAL_STRING("2fa4", f.wizard.editor().text().c_str());
|
||||
TEST_ASSERT_TRUE(f.wizard.next());
|
||||
assertStep(Step::Region, f.wizard);
|
||||
TEST_ASSERT_TRUE(f.wizard.next());
|
||||
assertStep(Step::Timezone, f.wizard);
|
||||
TEST_ASSERT_TRUE(f.wizard.next());
|
||||
assertStep(Step::Done, f.wizard);
|
||||
TEST_ASSERT_FALSE(f.wizard.finished());
|
||||
TEST_ASSERT_TRUE(f.wizard.next());
|
||||
TEST_ASSERT_TRUE(f.wizard.finished());
|
||||
}
|
||||
|
||||
void test_nothing_is_saved_until_the_end() {
|
||||
Fixture f;
|
||||
for (int i = 0; i < 5; i++) f.wizard.next();
|
||||
TEST_ASSERT_FALSE(f.settings.getBool(Setting::SetupDone));
|
||||
TEST_ASSERT_FALSE(f.settings.getBool(Setting::RegionConfirmed));
|
||||
TEST_ASSERT_TRUE(f.store.ints.empty() && f.store.strings.empty());
|
||||
}
|
||||
|
||||
void test_finishing_saves_names_region_timezone_and_marks_setup_done() {
|
||||
Fixture f;
|
||||
f.wizard.next();
|
||||
f.wizard.editor().setText("Cl\xC3\xA9ment");
|
||||
f.wizard.next();
|
||||
f.wizard.editor().setText("CLEM");
|
||||
f.wizard.next();
|
||||
f.wizard.next(); // region
|
||||
f.wizard.selectChoice(1); // second timezone
|
||||
f.wizard.next();
|
||||
f.wizard.next();
|
||||
TEST_ASSERT_EQUAL_STRING("Cl\xC3\xA9ment", f.settings.getString(Setting::LongName).c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("CLEM", f.settings.getString(Setting::ShortName).c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("EU868", f.settings.getString(Setting::Region).c_str());
|
||||
TEST_ASSERT_TRUE(f.settings.getBool(Setting::RegionConfirmed));
|
||||
TEST_ASSERT_TRUE(f.settings.getBool(Setting::SetupDone));
|
||||
TEST_ASSERT_TRUE(f.settings.getString(Setting::Timezone) != "CET-1CEST,M3.5.0,M10.5.0/3");
|
||||
}
|
||||
|
||||
void test_empty_name_cannot_advance_and_explains_why() {
|
||||
Fixture f;
|
||||
f.wizard.next();
|
||||
f.wizard.editor().setText("");
|
||||
TEST_ASSERT_FALSE(f.wizard.next());
|
||||
assertStep(Step::LongName, f.wizard);
|
||||
TEST_ASSERT_FALSE(f.wizard.error().empty());
|
||||
}
|
||||
|
||||
void test_short_name_editor_is_limited_to_four_bytes() {
|
||||
Fixture f;
|
||||
f.wizard.next();
|
||||
f.wizard.next();
|
||||
TEST_ASSERT_EQUAL(4, f.wizard.editor().maxBytes());
|
||||
}
|
||||
|
||||
void test_back_returns_to_the_previous_step_keeping_input() {
|
||||
Fixture f;
|
||||
f.wizard.next();
|
||||
f.wizard.editor().setText("Alice");
|
||||
f.wizard.next();
|
||||
f.wizard.back();
|
||||
assertStep(Step::LongName, f.wizard);
|
||||
TEST_ASSERT_EQUAL_STRING("Alice", f.wizard.editor().text().c_str());
|
||||
f.wizard.back();
|
||||
f.wizard.back();
|
||||
assertStep(Step::Welcome, f.wizard);
|
||||
}
|
||||
|
||||
void test_region_step_offers_eu868() {
|
||||
Fixture f;
|
||||
f.wizard.next();
|
||||
f.wizard.next();
|
||||
f.wizard.next();
|
||||
TEST_ASSERT_EQUAL(1, f.wizard.choiceCount());
|
||||
TEST_ASSERT_TRUE(f.wizard.choiceLabel(0).find("EU868") != std::string::npos);
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_walks_through_every_step_with_defaults);
|
||||
RUN_TEST(test_nothing_is_saved_until_the_end);
|
||||
RUN_TEST(test_finishing_saves_names_region_timezone_and_marks_setup_done);
|
||||
RUN_TEST(test_empty_name_cannot_advance_and_explains_why);
|
||||
RUN_TEST(test_short_name_editor_is_limited_to_four_bytes);
|
||||
RUN_TEST(test_back_returns_to_the_previous_step_keeping_input);
|
||||
RUN_TEST(test_region_step_offers_eu868);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user