summaryrefslogtreecommitdiffstats
path: root/quantum/debounce/tests/debounce_test_common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/debounce/tests/debounce_test_common.cpp')
-rw-r--r--quantum/debounce/tests/debounce_test_common.cpp72
1 files changed, 24 insertions, 48 deletions
diff --git a/quantum/debounce/tests/debounce_test_common.cpp b/quantum/debounce/tests/debounce_test_common.cpp
index 1c5e7c9f4e..f9414e571d 100644
--- a/quantum/debounce/tests/debounce_test_common.cpp
+++ b/quantum/debounce/tests/debounce_test_common.cpp
@@ -31,9 +31,7 @@ void set_time(uint32_t t);
void advance_time(uint32_t ms);
}
-void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) {
- events_.insert(events_.end(), events.begin(), events.end());
-}
+void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { events_.insert(events_.end(), events.begin(), events.end()); }
void DebounceTest::runEvents() {
/* Run the test multiple times, from 1kHz to 10kHz scan rate */
@@ -54,7 +52,7 @@ void DebounceTest::runEvents() {
void DebounceTest::runEventsInternal() {
fast_timer_t previous = 0;
- bool first = true;
+ bool first = true;
/* Initialise keyboard with start time (offset to avoid testing at 0) and all keys UP */
debounce_init(MATRIX_ROWS);
@@ -80,7 +78,7 @@ void DebounceTest::runEventsInternal() {
}
}
- first = false;
+ first = false;
previous = event.time_;
/* Prepare input matrix */
@@ -98,12 +96,7 @@ void DebounceTest::runEventsInternal() {
/* Check output matrix has expected change events */
for (auto &output : event.outputs_) {
- EXPECT_EQ(!!(cooked_matrix_[output.row_] & (1U << output.col_)), directionValue(output.direction_))
- << "Missing event at " << strTime()
- << " expected key " << output.row_ << "," << output.col_ << " " << directionLabel(output.direction_)
- << "\ninput_matrix: changed=" << !event.inputs_.empty() << "\n" << strMatrix(input_matrix_)
- << "\nexpected_matrix:\n" << strMatrix(output_matrix_)
- << "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
+ EXPECT_EQ(!!(cooked_matrix_[output.row_] & (1U << output.col_)), directionValue(output.direction_)) << "Missing event at " << strTime() << " expected key " << output.row_ << "," << output.col_ << " " << directionLabel(output.direction_) << "\ninput_matrix: changed=" << !event.inputs_.empty() << "\n" << strMatrix(input_matrix_) << "\nexpected_matrix:\n" << strMatrix(output_matrix_) << "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
}
/* Check output matrix has no other changes */
@@ -133,27 +126,20 @@ void DebounceTest::runDebounce(bool changed) {
debounce(raw_matrix_, cooked_matrix_, MATRIX_ROWS, changed);
if (!std::equal(std::begin(input_matrix_), std::end(input_matrix_), std::begin(raw_matrix_))) {
- FAIL() << "Fatal error: debounce() modified raw matrix at " << strTime()
- << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_)
- << "\nraw_matrix:\n" << strMatrix(raw_matrix_);
+ FAIL() << "Fatal error: debounce() modified raw matrix at " << strTime() << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) << "\nraw_matrix:\n" << strMatrix(raw_matrix_);
}
}
void DebounceTest::checkCookedMatrix(bool changed, const std::string &error_message) {
if (!std::equal(std::begin(output_matrix_), std::end(output_matrix_), std::begin(cooked_matrix_))) {
- FAIL() << "Unexpected event: " << error_message << " at " << strTime()
- << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_)
- << "\nexpected_matrix:\n" << strMatrix(output_matrix_)
- << "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
+ FAIL() << "Unexpected event: " << error_message << " at " << strTime() << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) << "\nexpected_matrix:\n" << strMatrix(output_matrix_) << "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
}
}
std::string DebounceTest::strTime() {
std::stringstream text;
- text << "time " << (timer_read_fast() - time_offset_)
- << " (extra_iterations=" << extra_iterations_
- << ", auto_advance_time=" << auto_advance_time_ << ")";
+ text << "time " << (timer_read_fast() - time_offset_) << " (extra_iterations=" << extra_iterations_ << ", auto_advance_time=" << auto_advance_time_ << ")";
return text.str();
}
@@ -181,49 +167,39 @@ std::string DebounceTest::strMatrix(matrix_row_t matrix[]) {
bool DebounceTest::directionValue(Direction direction) {
switch (direction) {
- case DOWN:
- return true;
+ case DOWN:
+ return true;
- case UP:
- return false;
+ case UP:
+ return false;
}
}
std::string DebounceTest::directionLabel(Direction direction) {
switch (direction) {
- case DOWN:
- return "DOWN";
+ case DOWN:
+ return "DOWN";
- case UP:
- return "UP";
+ case UP:
+ return "UP";
}
}
/* Modify a matrix and verify that events always specify a change */
void DebounceTest::matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event) {
- ASSERT_NE(!!(matrix[event.row_] & (1U << event.col_)), directionValue(event.direction_))
- << "Test " << name << " at " << strTime()
- << " sets key " << event.row_ << "," << event.col_ << " " << directionLabel(event.direction_)
- << " but it is already " << directionLabel(event.direction_)
- << "\n" << name << "_matrix:\n" << strMatrix(matrix);
+ ASSERT_NE(!!(matrix[event.row_] & (1U << event.col_)), directionValue(event.direction_)) << "Test " << name << " at " << strTime() << " sets key " << event.row_ << "," << event.col_ << " " << directionLabel(event.direction_) << " but it is already " << directionLabel(event.direction_) << "\n" << name << "_matrix:\n" << strMatrix(matrix);
switch (event.direction_) {
- case DOWN:
- matrix[event.row_] |= (1U << event.col_);
- break;
+ case DOWN:
+ matrix[event.row_] |= (1U << event.col_);
+ break;
- case UP:
- matrix[event.row_] &= ~(1U << event.col_);
- break;
+ case UP:
+ matrix[event.row_] &= ~(1U << event.col_);
+ break;
}
}
-DebounceTestEvent::DebounceTestEvent(fast_timer_t time,
- std::initializer_list<MatrixTestEvent> inputs,
- std::initializer_list<MatrixTestEvent> outputs)
- : time_(time), inputs_(inputs), outputs_(outputs) {
-}
+DebounceTestEvent::DebounceTestEvent(fast_timer_t time, std::initializer_list<MatrixTestEvent> inputs, std::initializer_list<MatrixTestEvent> outputs) : time_(time), inputs_(inputs), outputs_(outputs) {}
-MatrixTestEvent::MatrixTestEvent(int row, int col, Direction direction)
- : row_(row), col_(col), direction_(direction) {
-}
+MatrixTestEvent::MatrixTestEvent(int row, int col, Direction direction) : row_(row), col_(col), direction_(direction) {}