]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
add tests for action_layer.c and reset layer state after tests
authorColin T.A. Gray <colinta@gmail.com>
Thu, 14 Dec 2017 23:15:52 +0000 (16:15 -0700)
committerJack Humbert <jack.humb@gmail.com>
Fri, 15 Dec 2017 18:23:30 +0000 (13:23 -0500)
tests/basic/test_action_layer.cpp [new file with mode: 0644]
tests/test_common/test_common.hpp
tests/test_common/test_fixture.cpp

diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp
new file mode 100644 (file)
index 0000000..d00a085
--- /dev/null
@@ -0,0 +1,92 @@
+/* Copyright 2017 Colin T.A. Gray
+ *
+ * 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 "test_common.hpp"
+
+using testing::_;
+using testing::Return;
+
+class ActionLayer : public TestFixture {};
+
+// TEST_F(ActionLayer, LayerStateDBG) {
+//     layer_state_set(0);
+// }
+
+// TEST_F(ActionLayer, LayerStateSet) {
+//     layer_state_set(0);
+//     EXPECT_EQ(layer_state, 0);
+//     layer_state_set(0b001100);
+//     EXPECT_EQ(layer_state, 0b001100);
+// }
+
+// TEST_F(ActionLayer, LayerStateIs) {
+//     layer_state_set(0);
+//     EXPECT_EQ(layer_state_is(0), true);
+//     EXPECT_EQ(layer_state_is(1), true);
+//     layer_state_set(1);
+//     EXPECT_EQ(layer_state_is(0), true);
+//     EXPECT_EQ(layer_state_is(1), true);
+//     layer_state_set(2);
+//     EXPECT_EQ(layer_state_is(0), false);
+//     EXPECT_EQ(layer_state_is(1), false);
+//     EXPECT_EQ(layer_state_is(2), true);
+// }
+
+TEST_F(ActionLayer, LayerStateCmp) {
+    uint32_t prev_layer;
+
+    prev_layer = 0;
+    EXPECT_EQ(layer_state_cmp(prev_layer, 0), true);
+    EXPECT_EQ(layer_state_cmp(prev_layer, 1), false);
+
+    prev_layer = 1;
+    EXPECT_EQ(layer_state_cmp(prev_layer, 0), true);
+    EXPECT_EQ(layer_state_cmp(prev_layer, 1), false);
+
+    prev_layer = 2;
+    EXPECT_EQ(layer_state_cmp(prev_layer, 0), false);
+    EXPECT_EQ(layer_state_cmp(prev_layer, 1), true);
+    EXPECT_EQ(layer_state_cmp(prev_layer, 2), false);
+}
+
+// TEST_F(ActionLayer, LayerClear) {
+//     layer_clear();
+//     EXPECT_EQ(layer_state, 0);
+// }
+
+// TEST_F(ActionLayer, LayerMove) {
+//     layer_move(0);
+//     EXPECT_EQ(layer_state, 1);
+//     layer_move(3);
+//     EXPECT_EQ(layer_state, 0b1000);
+// }
+
+// TEST_F(ActionLayer, LayerOn) {
+//     layer_clear();
+//     layer_on(1);
+//     layer_on(3);
+//     layer_on(3);
+//     EXPECT_EQ(layer_state, 0b1010);
+// }
+
+// TEST_F(ActionLayer, LayerOff) {
+//     layer_clear();
+//     layer_on(1);
+//     layer_on(3);
+//     layer_off(3);
+//     layer_off(2);
+//     EXPECT_EQ(layer_state, 0b1000);
+// }
index 2398446339bbe6a073a40088720366017d86a8f8..a88fa8d7b8e36ba3747db38c50508daca7c33fda 100644 (file)
 #include "gtest/gtest.h"
 #include "gmock/gmock.h"
 
+extern "C" {
 #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
+#include "test_fixture.hpp"
index 4084ee9c676b77a08edab00af5ae68b60ffeff2c..d86681eeaa35b722c032cbb1cc32eea3312cf1c0 100644 (file)
@@ -6,6 +6,10 @@
 #include "action.h"
 #include "action_tapping.h"
 
+extern "C" {
+#include "action_layer.h"
+}
+
 extern "C" {
     void set_time(uint32_t t);
     void advance_time(uint32_t ms);
@@ -30,11 +34,12 @@ TestFixture::TestFixture() {
 
 TestFixture::~TestFixture() {
     TestDriver driver;
+    layer_clear();
     clear_all_keys();
     // Run for a while to make sure all keys are completely released
     EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber());
     idle_for(TAPPING_TERM + 10);
-    testing::Mock::VerifyAndClearExpectations(&driver); 
+    testing::Mock::VerifyAndClearExpectations(&driver);
     // Verify that the matrix really is cleared
     EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1));
 }
@@ -48,4 +53,4 @@ void TestFixture::idle_for(unsigned time) {
     for (unsigned i=0; i<time; i++) {
         run_one_scan_loop();
     }
-}
\ No newline at end of file
+}