summaryrefslogtreecommitdiff
path: root/tests/test_common
diff options
context:
space:
mode:
authorFabian Topfstedt <topfstedt@schneevonmorgen.com>2017-07-20 08:22:44 +0200
committerFabian Topfstedt <topfstedt@schneevonmorgen.com>2017-07-20 08:22:44 +0200
commitee43856ff7ba37ea89d1a8a4700efba4e4f69571 (patch)
treeb0ed5b538396b0b2b027e69ad8ceac443c067c79 /tests/test_common
parent99b6e918eab31d4f53cabc04a995da945335ac7f (diff)
parent14c5160b1a94d5dc416002791b3c207ba0dca789 (diff)
Merge https://github.com/qmk/qmk_firmware
Diffstat (limited to 'tests/test_common')
-rw-r--r--tests/test_common/keyboard_report_util.cpp16
-rw-r--r--tests/test_common/keyboard_report_util.hpp (renamed from tests/test_common/keyboard_report_util.h)0
-rw-r--r--tests/test_common/matrix.c3
-rw-r--r--tests/test_common/test_common.hpp24
-rw-r--r--tests/test_common/test_driver.cpp2
-rw-r--r--tests/test_common/test_driver.hpp (renamed from tests/test_common/test_driver.h)2
-rw-r--r--tests/test_common/test_fixture.cpp27
-rw-r--r--tests/test_common/test_fixture.hpp (renamed from tests/test_common/test_fixture.h)2
8 files changed, 63 insertions, 13 deletions
diff --git a/tests/test_common/keyboard_report_util.cpp b/tests/test_common/keyboard_report_util.cpp
index aca4433dd6..bf728b9a2a 100644
--- a/tests/test_common/keyboard_report_util.cpp
+++ b/tests/test_common/keyboard_report_util.cpp
@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
- #include "keyboard_report_util.h"
+ #include "keyboard_report_util.hpp"
#include <vector>
#include <algorithm>
using namespace testing;
@@ -47,19 +47,25 @@ bool operator==(const report_keyboard_t& lhs, const report_keyboard_t& rhs) {
std::ostream& operator<<(std::ostream& stream, const report_keyboard_t& value) {
stream << "Keyboard report:" << std::endl;
- stream << "Mods: " << value.mods << std::endl;
+ stream << "Mods: " << (uint32_t)value.mods << std::endl;
+ stream << "Keys: ";
// TODO: This should probably print friendly names for the keys
for (uint32_t k: get_keys(value)) {
- stream << k << std::endl;
+ stream << k << " ";
}
+ stream << std::endl;
return stream;
}
KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
- // TODO: Support modifiers
memset(m_report.raw, 0, sizeof(m_report.raw));
for (auto k: keys) {
- add_key_to_report(&m_report, k);
+ if (IS_MOD(k)) {
+ m_report.mods |= MOD_BIT(k);
+ }
+ else {
+ add_key_to_report(&m_report, k);
+ }
}
}
diff --git a/tests/test_common/keyboard_report_util.h b/tests/test_common/keyboard_report_util.hpp
index 48543c2053..48543c2053 100644
--- a/tests/test_common/keyboard_report_util.h
+++ b/tests/test_common/keyboard_report_util.hpp
diff --git a/tests/test_common/matrix.c b/tests/test_common/matrix.c
index 0d9fa68b04..4b501039b6 100644
--- a/tests/test_common/matrix.c
+++ b/tests/test_common/matrix.c
@@ -58,3 +58,6 @@ void release_key(uint8_t col, uint8_t row) {
void clear_all_keys(void) {
memset(matrix, 0, sizeof(matrix));
}
+
+void led_set(uint8_t usb_led) {
+}
diff --git a/tests/test_common/test_common.hpp b/tests/test_common/test_common.hpp
new file mode 100644
index 0000000000..2398446339
--- /dev/null
+++ b/tests/test_common/test_common.hpp
@@ -0,0 +1,24 @@
+/* Copyright 2017 Fred Sundvik
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include "quantum.h"
+#include "test_driver.hpp"
+#include "test_matrix.h"
+#include "keyboard_report_util.hpp"
+#include "test_fixture.hpp" \ No newline at end of file
diff --git a/tests/test_common/test_driver.cpp b/tests/test_common/test_driver.cpp
index feb80563a1..5113099698 100644
--- a/tests/test_common/test_driver.cpp
+++ b/tests/test_common/test_driver.cpp
@@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "test_driver.h"
+#include "test_driver.hpp"
TestDriver* TestDriver::m_this = nullptr;
diff --git a/tests/test_common/test_driver.h b/tests/test_common/test_driver.hpp
index 0123fd539b..c3ae17b1a4 100644
--- a/tests/test_common/test_driver.h
+++ b/tests/test_common/test_driver.hpp
@@ -20,7 +20,7 @@
#include "gmock/gmock.h"
#include <stdint.h>
#include "host.h"
-#include "keyboard_report_util.h"
+#include "keyboard_report_util.hpp"
class TestDriver {
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp
index eef9b854b7..4084ee9c67 100644
--- a/tests/test_common/test_fixture.cpp
+++ b/tests/test_common/test_fixture.cpp
@@ -1,8 +1,15 @@
-#include "test_fixture.h"
+#include "test_fixture.hpp"
#include "gmock/gmock.h"
-#include "test_driver.h"
+#include "test_driver.hpp"
#include "test_matrix.h"
#include "keyboard.h"
+#include "action.h"
+#include "action_tapping.h"
+
+extern "C" {
+ void set_time(uint32_t t);
+ void advance_time(uint32_t ms);
+}
using testing::_;
using testing::AnyNumber;
@@ -25,12 +32,20 @@ TestFixture::~TestFixture() {
TestDriver driver;
clear_all_keys();
// Run for a while to make sure all keys are completely released
- // Should probably wait until tapping term etc, has timed out
EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
- for (int i=0; i<100; i++) {
- keyboard_task();
- }
+ idle_for(TAPPING_TERM + 10);
testing::Mock::VerifyAndClearExpectations(&driver);
// Verify that the matrix really is cleared
EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1));
+}
+
+void TestFixture::run_one_scan_loop() {
+ keyboard_task();
+ advance_time(1);
+}
+
+void TestFixture::idle_for(unsigned time) {
+ for (unsigned i=0; i<time; i++) {
+ run_one_scan_loop();
+ }
} \ No newline at end of file
diff --git a/tests/test_common/test_fixture.h b/tests/test_common/test_fixture.hpp
index a775a425aa..fb37e440fc 100644
--- a/tests/test_common/test_fixture.h
+++ b/tests/test_common/test_fixture.hpp
@@ -25,4 +25,6 @@ public:
static void SetUpTestCase();
static void TearDownTestCase();
+ void run_one_scan_loop();
+ void idle_for(unsigned ms);
}; \ No newline at end of file