Skip to content

Commit 1fece51

Browse files
committed
Adds Config and BitwiseInitialState tests and fixes Faces roundtrip test
1 parent 74b725a commit 1fece51

3 files changed

Lines changed: 74 additions & 16 deletions

File tree

test/embedded/embedded_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void setup()
3838
M5_LOGI("BOARD:%X", M5.getBoard());
3939
M5_LOGI("Heap: %u", esp_get_free_heap_size());
4040

41-
lcd.clear(TFT_DARKGRAY);
41+
lcd.fillScreen(TFT_DARKGRAY);
4242
::testing::InitGoogleTest();
4343

4444
#ifdef GTEST_FILTER

test/embedded/test_cardkb/cardkb_test.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@ constexpr Mode mode_table[] = {Mode::Conventional, Mode::M5UnitUnified};
3636

3737
} // namespace
3838

39+
TEST_F(TestCardKB, Config)
40+
{
41+
SCOPED_TRACE(ustr);
42+
43+
auto cfg = unit->config();
44+
EXPECT_TRUE(cfg.start_periodic);
45+
EXPECT_EQ(cfg.interval, 10U);
46+
EXPECT_EQ(cfg.mode, keyboard::Mode::Conventional);
47+
48+
cfg.interval = 50;
49+
unit->config(cfg);
50+
auto cfg2 = unit->config();
51+
EXPECT_EQ(cfg2.interval, 50U);
52+
53+
// Restore
54+
cfg.interval = 10;
55+
unit->config(cfg);
56+
}
57+
58+
TEST_F(TestCardKB, BitwiseInitialState)
59+
{
60+
SCOPED_TRACE(ustr);
61+
EXPECT_EQ(unit->nowBits(), 0U);
62+
EXPECT_EQ(unit->pressedBits(), 0U);
63+
EXPECT_EQ(unit->releasedBits(), 0U);
64+
EXPECT_EQ(unit->holdingBits(), 0U);
65+
EXPECT_EQ(unit->repeatingBits(), 0U);
66+
EXPECT_FALSE(unit->isPressed());
67+
}
68+
3969
TEST_F(TestCardKB, Periodic)
4070
{
4171
SCOPED_TRACE(ustr);
@@ -96,7 +126,7 @@ TEST_F(TestCardKB, CharacterToKeyIndexRoundtrip)
96126
if (kidx == 0xFF) {
97127
continue;
98128
}
99-
EXPECT_LT(kidx, UnitCardKB::NUMBER_OF_KEYS)
129+
EXPECT_LT(kidx, +UnitCardKB::NUMBER_OF_KEYS)
100130
<< "toKeyIndex(0x" << std::hex << c << ") returned out-of-range key index " << (int)kidx;
101131

102132
auto mbits = UnitCardKB::character_to_mode_bits(ch);
@@ -119,7 +149,7 @@ TEST_F(TestCardKB, CharacterToKeyIndexRoundtrip)
119149

120150
// Verify Fn characters (>= 0x80): toKeyIndex must return the correct key
121151
// CardKB Fn values are key_index + 128, so roundtrip must hold
122-
for (uint8_t kidx = 0; kidx < UnitCardKB::NUMBER_OF_KEYS; ++kidx) {
152+
for (uint8_t kidx = 0; kidx < +UnitCardKB::NUMBER_OF_KEYS; ++kidx) {
123153
uint8_t fn_char = kidx + 128;
124154
auto result = unit->toKeyIndex(static_cast<char>(fn_char));
125155
if (result == 0xFF) {

test/embedded/test_faces/faces_test.cpp

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ constexpr Mode mode_table[] = {Mode::Conventional, Mode::M5UnitUnified};
3535

3636
} // namespace
3737

38+
TEST_F(TestFacesQWERTY, Config)
39+
{
40+
SCOPED_TRACE(ustr);
41+
42+
auto cfg = unit->config();
43+
EXPECT_TRUE(cfg.start_periodic);
44+
EXPECT_EQ(cfg.interval, 10U);
45+
EXPECT_EQ(cfg.mode, keyboard::Mode::Conventional);
46+
EXPECT_FALSE(cfg.trigger_irq);
47+
48+
cfg.interval = 50;
49+
unit->config(cfg);
50+
auto cfg2 = unit->config();
51+
EXPECT_EQ(cfg2.interval, 50U);
52+
53+
// Restore
54+
cfg.interval = 10;
55+
unit->config(cfg);
56+
}
57+
58+
TEST_F(TestFacesQWERTY, BitwiseInitialState)
59+
{
60+
SCOPED_TRACE(ustr);
61+
EXPECT_EQ(unit->nowBits(), 0U);
62+
EXPECT_EQ(unit->pressedBits(), 0U);
63+
EXPECT_EQ(unit->releasedBits(), 0U);
64+
EXPECT_EQ(unit->holdingBits(), 0U);
65+
EXPECT_EQ(unit->repeatingBits(), 0U);
66+
EXPECT_FALSE(unit->isPressed());
67+
}
68+
3869
TEST_F(TestFacesQWERTY, Periodic)
3970
{
4071
SCOPED_TRACE(ustr);
@@ -92,7 +123,7 @@ TEST_F(TestFacesQWERTY, CharacterToKeyIndexRoundtrip)
92123
if (kidx == 0xFF) {
93124
continue;
94125
}
95-
EXPECT_LT(kidx, UnitFacesQWERTY::NUMBER_OF_KEYS)
126+
EXPECT_LT(kidx, +UnitFacesQWERTY::NUMBER_OF_KEYS)
96127
<< "toKeyIndex(0x" << std::hex << c << ") returned out-of-range key index " << (int)kidx;
97128

98129
auto mbits = UnitFacesQWERTY::character_to_mode_bits(ch);
@@ -105,23 +136,20 @@ TEST_F(TestFacesQWERTY, CharacterToKeyIndexRoundtrip)
105136
if (ch >= 'A' && ch <= 'Z') {
106137
EXPECT_TRUE(mbits & 0x02) << "char '" << ch << "' mode_bits=" << (int)mbits << " missing shift bit";
107138
}
108-
if (std::strchr("!@#$%^&*(){}[]|\\~`?/<>=+_-;:\"'", ch) && !(mbits & 0x03)) {
139+
// Sym-only: not in normal/shift AND not in fn
140+
if (std::strchr("!@#$%^&*(){}[]|\\~`?/<>=+_-;:\"'", ch) && !(mbits & 0x0B)) {
109141
EXPECT_TRUE(mbits & 0x04) << "char '" << ch << "' mode_bits=" << (int)mbits << " missing sym bit";
110142
}
111143
}
112144

113-
// Verify Fn characters (>= 0x80): roundtrip must hold
114-
for (uint8_t kidx = 0; kidx < UnitFacesQWERTY::NUMBER_OF_KEYS; ++kidx) {
115-
uint8_t fn_char = kidx + 128;
116-
auto result = unit->toKeyIndex(static_cast<char>(fn_char));
117-
if (result == 0xFF) {
145+
// Verify Fn characters: FacesQWERTY Fn chars are NOT kidx+128,
146+
// so only check range validity for all recognized >= 0x80 chars
147+
for (int c = 128; c < 256; ++c) {
148+
auto kidx = unit->toKeyIndex(static_cast<char>(c));
149+
if (kidx == 0xFF) {
118150
continue;
119151
}
120-
EXPECT_EQ(result, kidx) << "Fn char 0x" << std::hex << (int)fn_char << " mapped to key " << (int)result
121-
<< " instead of " << (int)kidx;
122-
123-
auto mbits = UnitFacesQWERTY::character_to_mode_bits(static_cast<char>(fn_char));
124-
EXPECT_EQ(mbits & 0x08, 0x08) << "Fn char 0x" << std::hex << (int)fn_char << " mode_bits=" << (int)mbits
125-
<< " missing function bit";
152+
EXPECT_LT(kidx, +UnitFacesQWERTY::NUMBER_OF_KEYS)
153+
<< "Fn char 0x" << std::hex << c << " mapped to out-of-range key index " << (int)kidx;
126154
}
127155
}

0 commit comments

Comments
 (0)