aboutsummaryrefslogtreecommitdiff
path: root/tests/test_common
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tests/test_common
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'tests/test_common')
-rw-r--r--tests/test_common/keyboard_report_util.cpp62
-rw-r--r--tests/test_common/matrix.c32
-rw-r--r--tests/test_common/test_driver.cpp35
-rw-r--r--tests/test_common/test_fixture.cpp14
4 files changed, 48 insertions, 95 deletions
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp
index bf728b9a2..245072c0e 100644
--- a/tests/test_common/keyboard_report_util.cpp
+++ b/tests/test_common/keyboard_report_util.cpp
@@ -14,30 +14,29 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16 16
17 #include "keyboard_report_util.hpp" 17#include "keyboard_report_util.hpp"
18 #include <vector> 18#include <vector>
19 #include <algorithm> 19#include <algorithm>
20 using namespace testing; 20using namespace testing;
21 21
22 namespace 22namespace {
23 { 23std::vector<uint8_t> get_keys(const report_keyboard_t& report) {
24 std::vector<uint8_t> get_keys(const report_keyboard_t& report) { 24 std::vector<uint8_t> result;
25 std::vector<uint8_t> result; 25#if defined(NKRO_ENABLE)
26 #if defined(NKRO_ENABLE) 26# error NKRO support not implemented yet
27 #error NKRO support not implemented yet 27#elif defined(USB_6KRO_ENABLE)
28 #elif defined(USB_6KRO_ENABLE) 28# error 6KRO support not implemented yet
29 #error 6KRO support not implemented yet 29#else
30 #else 30 for (size_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
31 for(size_t i=0; i<KEYBOARD_REPORT_KEYS; i++) { 31 if (report.keys[i]) {
32 if (report.keys[i]) { 32 result.emplace_back(report.keys[i]);
33 result.emplace_back(report.keys[i]);
34 }
35 } 33 }
36 #endif 34 }
37 std::sort(result.begin(), result.end()); 35#endif
38 return result; 36 std::sort(result.begin(), result.end());
39 } 37 return result;
40 } 38}
39} // namespace
41 40
42bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) { 41bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
43 auto lhskeys = get_keys(lhs); 42 auto lhskeys = get_keys(lhs);
@@ -50,7 +49,7 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
50 stream << "Mods: " << (uint32_t)value.mods << std::endl; 49 stream << "Mods: " << (uint32_t)value.mods << std::endl;
51 stream << "Keys: "; 50 stream << "Keys: ";
52 // TODO: This should probably print friendly names for the keys 51 // TODO: This should probably print friendly names for the keys
53 for (uint32_t k: get_keys(value)) { 52 for (uint32_t k : get_keys(value)) {
54 stream << k << " "; 53 stream << k << " ";
55 } 54 }
56 stream << std::endl; 55 stream << std::endl;
@@ -59,24 +58,17 @@ std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
59 58
60KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) { 59KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
61 memset(m_report.raw, 0, sizeof(m_report.raw)); 60 memset(m_report.raw, 0, sizeof(m_report.raw));
62 for (auto k: keys) { 61 for (auto k : keys) {
63 if (IS_MOD(k)) { 62 if (IS_MOD(k)) {
64 m_report.mods |= MOD_BIT(k); 63 m_report.mods |= MOD_BIT(k);
65 } 64 } else {
66 else {
67 add_key_to_report(&m_report, k); 65 add_key_to_report(&m_report, k);
68 } 66 }
69 } 67 }
70} 68}
71 69
72bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const { 70bool KeyboardReportMatcher::MatchAndExplain(report_keyboard_t& report, MatchResultListener* listener) const { return m_report == report; }
73 return m_report == report;
74}
75 71
76void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const { 72void KeyboardReportMatcher::DescribeTo(::std::ostream* os) const { *os << "is equal to " << m_report; }
77 *os << "is equal to " << m_report;
78}
79 73
80void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const { 74void KeyboardReportMatcher::DescribeNegationTo(::std::ostream* os) const { *os << "is not equal to " << m_report; } \ No newline at end of file
81 *os << "is not equal to " << m_report;
82} \ No newline at end of file
diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c
index 4b501039b..9a92a801c 100644
--- a/tests/test_common/matrix.c
+++ b/tests/test_common/matrix.c
@@ -14,7 +14,6 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16 16
17
18#include "matrix.h" 17#include "matrix.h"
19#include "test_matrix.h" 18#include "test_matrix.h"
20#include <string.h> 19#include <string.h>
@@ -31,33 +30,18 @@ uint8_t matrix_scan(void) {
31 return 1; 30 return 1;
32} 31}
33 32
34matrix_row_t matrix_get_row(uint8_t row) { 33matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; }
35 return matrix[row];
36}
37
38void matrix_print(void) {
39
40}
41
42void matrix_init_kb(void) {
43 34
44} 35void matrix_print(void) {}
45 36
46void matrix_scan_kb(void) { 37void matrix_init_kb(void) {}
47 38
48} 39void matrix_scan_kb(void) {}
49 40
50void press_key(uint8_t col, uint8_t row) { 41void press_key(uint8_t col, uint8_t row) { matrix[row] |= 1 << col; }
51 matrix[row] |= 1 << col;
52}
53 42
54void release_key(uint8_t col, uint8_t row) { 43void release_key(uint8_t col, uint8_t row) { matrix[row] &= ~(1 << col); }
55 matrix[row] &= ~(1 << col);
56}
57 44
58void clear_all_keys(void) { 45void clear_all_keys(void) { memset(matrix, 0, sizeof(matrix)); }
59 memset(matrix, 0, sizeof(matrix));
60}
61 46
62void led_set(uint8_t usb_led) { 47void led_set(uint8_t usb_led) {}
63}
diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp
index 511309969..84e249d83 100644
--- a/tests/test_common/test_driver.cpp
+++ b/tests/test_common/test_driver.cpp
@@ -18,40 +18,19 @@
18 18
19TestDriver* TestDriver::m_this = nullptr; 19TestDriver* TestDriver::m_this = nullptr;
20 20
21TestDriver::TestDriver() 21TestDriver::TestDriver() : m_driver{&TestDriver::keyboard_leds, &TestDriver::send_keyboard, &TestDriver::send_mouse, &TestDriver::send_system, &TestDriver::send_consumer} {
22 : m_driver{
23 &TestDriver::keyboard_leds,
24 &TestDriver::send_keyboard,
25 &TestDriver::send_mouse,
26 &TestDriver::send_system,
27 &TestDriver::send_consumer
28 }
29{
30 host_set_driver(&m_driver); 22 host_set_driver(&m_driver);
31 m_this = this; 23 m_this = this;
32} 24}
33 25
34TestDriver::~TestDriver() { 26TestDriver::~TestDriver() { m_this = nullptr; }
35 m_this = nullptr;
36}
37 27
38uint8_t TestDriver::keyboard_leds(void) { 28uint8_t TestDriver::keyboard_leds(void) { return m_this->m_leds; }
39 return m_this->m_leds;
40}
41 29
42void TestDriver::send_keyboard(report_keyboard_t* report) { 30void TestDriver::send_keyboard(report_keyboard_t* report) { m_this->send_keyboard_mock(*report); }
43 m_this->send_keyboard_mock(*report);
44 31
45} 32void TestDriver::send_mouse(report_mouse_t* report) { m_this->send_mouse_mock(*report); }
46 33
47void TestDriver::send_mouse(report_mouse_t* report) { 34void TestDriver::send_system(uint16_t data) { m_this->send_system_mock(data); }
48 m_this->send_mouse_mock(*report);
49}
50 35
51void TestDriver::send_system(uint16_t data) { 36void TestDriver::send_consumer(uint16_t data) { m_this->send_consumer(data); }
52 m_this->send_system_mock(data);
53}
54
55void TestDriver::send_consumer(uint16_t data) {
56 m_this->send_consumer(data);
57}
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp
index d86681eea..8caf1fca4 100644
--- a/tests/test_common/test_fixture.cpp
+++ b/tests/test_common/test_fixture.cpp
@@ -11,14 +11,14 @@ extern "C" {
11} 11}
12 12
13extern "C" { 13extern "C" {
14 void set_time(uint32_t t); 14void set_time(uint32_t t);
15 void advance_time(uint32_t ms); 15void advance_time(uint32_t ms);
16} 16}
17 17
18using testing::_; 18using testing::_;
19using testing::AnyNumber; 19using testing::AnyNumber;
20using testing::Return;
21using testing::Between; 20using testing::Between;
21using testing::Return;
22 22
23void TestFixture::SetUpTestCase() { 23void TestFixture::SetUpTestCase() {
24 TestDriver driver; 24 TestDriver driver;
@@ -26,11 +26,9 @@ void TestFixture::SetUpTestCase() {
26 keyboard_init(); 26 keyboard_init();
27} 27}
28 28
29void TestFixture::TearDownTestCase() { 29void TestFixture::TearDownTestCase() {}
30}
31 30
32TestFixture::TestFixture() { 31TestFixture::TestFixture() {}
33}
34 32
35TestFixture::~TestFixture() { 33TestFixture::~TestFixture() {
36 TestDriver driver; 34 TestDriver driver;
@@ -50,7 +48,7 @@ void TestFixture::run_one_scan_loop() {
50} 48}
51 49
52void TestFixture::idle_for(unsigned time) { 50void TestFixture::idle_for(unsigned time) {
53 for (unsigned i=0; i<time; i++) { 51 for (unsigned i = 0; i < time; i++) {
54 run_one_scan_loop(); 52 run_one_scan_loop();
55 } 53 }
56} 54}