diff options
| author | Colin T.A. Gray <colinta@gmail.com> | 2017-12-14 16:15:52 -0700 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2017-12-15 13:23:30 -0500 |
| commit | 4ea3bbdb4cbb02310623c9dfc464d84e4f653492 (patch) | |
| tree | 7914b5019cb55d0a343ec89385d95795f597cac5 | |
| parent | bad839e6ac815f9fc0836d8170b716838fbc87b7 (diff) | |
| download | qmk_firmware-4ea3bbdb4cbb02310623c9dfc464d84e4f653492.tar.gz qmk_firmware-4ea3bbdb4cbb02310623c9dfc464d84e4f653492.zip | |
add tests for action_layer.c and reset layer state after tests
| -rw-r--r-- | tests/basic/test_action_layer.cpp | 92 | ||||
| -rw-r--r-- | tests/test_common/test_common.hpp | 4 | ||||
| -rw-r--r-- | tests/test_common/test_fixture.cpp | 9 |
3 files changed, 102 insertions, 3 deletions
diff --git a/tests/basic/test_action_layer.cpp b/tests/basic/test_action_layer.cpp new file mode 100644 index 000000000..d00a0859b --- /dev/null +++ b/tests/basic/test_action_layer.cpp | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* Copyright 2017 Colin T.A. Gray | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "test_common.hpp" | ||
| 18 | |||
| 19 | using testing::_; | ||
| 20 | using testing::Return; | ||
| 21 | |||
| 22 | class ActionLayer : public TestFixture {}; | ||
| 23 | |||
| 24 | // TEST_F(ActionLayer, LayerStateDBG) { | ||
| 25 | // layer_state_set(0); | ||
| 26 | // } | ||
| 27 | |||
| 28 | // TEST_F(ActionLayer, LayerStateSet) { | ||
| 29 | // layer_state_set(0); | ||
| 30 | // EXPECT_EQ(layer_state, 0); | ||
| 31 | // layer_state_set(0b001100); | ||
| 32 | // EXPECT_EQ(layer_state, 0b001100); | ||
| 33 | // } | ||
| 34 | |||
| 35 | // TEST_F(ActionLayer, LayerStateIs) { | ||
| 36 | // layer_state_set(0); | ||
| 37 | // EXPECT_EQ(layer_state_is(0), true); | ||
| 38 | // EXPECT_EQ(layer_state_is(1), true); | ||
| 39 | // layer_state_set(1); | ||
| 40 | // EXPECT_EQ(layer_state_is(0), true); | ||
| 41 | // EXPECT_EQ(layer_state_is(1), true); | ||
| 42 | // layer_state_set(2); | ||
| 43 | // EXPECT_EQ(layer_state_is(0), false); | ||
| 44 | // EXPECT_EQ(layer_state_is(1), false); | ||
| 45 | // EXPECT_EQ(layer_state_is(2), true); | ||
| 46 | // } | ||
| 47 | |||
| 48 | TEST_F(ActionLayer, LayerStateCmp) { | ||
| 49 | uint32_t prev_layer; | ||
| 50 | |||
| 51 | prev_layer = 0; | ||
| 52 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), true); | ||
| 53 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), false); | ||
| 54 | |||
| 55 | prev_layer = 1; | ||
| 56 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), true); | ||
| 57 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), false); | ||
| 58 | |||
| 59 | prev_layer = 2; | ||
| 60 | EXPECT_EQ(layer_state_cmp(prev_layer, 0), false); | ||
| 61 | EXPECT_EQ(layer_state_cmp(prev_layer, 1), true); | ||
| 62 | EXPECT_EQ(layer_state_cmp(prev_layer, 2), false); | ||
| 63 | } | ||
| 64 | |||
| 65 | // TEST_F(ActionLayer, LayerClear) { | ||
| 66 | // layer_clear(); | ||
| 67 | // EXPECT_EQ(layer_state, 0); | ||
| 68 | // } | ||
| 69 | |||
| 70 | // TEST_F(ActionLayer, LayerMove) { | ||
| 71 | // layer_move(0); | ||
| 72 | // EXPECT_EQ(layer_state, 1); | ||
| 73 | // layer_move(3); | ||
| 74 | // EXPECT_EQ(layer_state, 0b1000); | ||
| 75 | // } | ||
| 76 | |||
| 77 | // TEST_F(ActionLayer, LayerOn) { | ||
| 78 | // layer_clear(); | ||
| 79 | // layer_on(1); | ||
| 80 | // layer_on(3); | ||
| 81 | // layer_on(3); | ||
| 82 | // EXPECT_EQ(layer_state, 0b1010); | ||
| 83 | // } | ||
| 84 | |||
| 85 | // TEST_F(ActionLayer, LayerOff) { | ||
| 86 | // layer_clear(); | ||
| 87 | // layer_on(1); | ||
| 88 | // layer_on(3); | ||
| 89 | // layer_off(3); | ||
| 90 | // layer_off(2); | ||
| 91 | // EXPECT_EQ(layer_state, 0b1000); | ||
| 92 | // } | ||
diff --git a/tests/test_common/test_common.hpp b/tests/test_common/test_common.hpp index 239844633..a88fa8d7b 100644 --- a/tests/test_common/test_common.hpp +++ b/tests/test_common/test_common.hpp | |||
| @@ -17,8 +17,10 @@ | |||
| 17 | #include "gtest/gtest.h" | 17 | #include "gtest/gtest.h" |
| 18 | #include "gmock/gmock.h" | 18 | #include "gmock/gmock.h" |
| 19 | 19 | ||
| 20 | extern "C" { | ||
| 20 | #include "quantum.h" | 21 | #include "quantum.h" |
| 22 | } | ||
| 21 | #include "test_driver.hpp" | 23 | #include "test_driver.hpp" |
| 22 | #include "test_matrix.h" | 24 | #include "test_matrix.h" |
| 23 | #include "keyboard_report_util.hpp" | 25 | #include "keyboard_report_util.hpp" |
| 24 | #include "test_fixture.hpp" \ No newline at end of file | 26 | #include "test_fixture.hpp" |
diff --git a/tests/test_common/test_fixture.cpp b/tests/test_common/test_fixture.cpp index 4084ee9c6..d86681eea 100644 --- a/tests/test_common/test_fixture.cpp +++ b/tests/test_common/test_fixture.cpp | |||
| @@ -7,6 +7,10 @@ | |||
| 7 | #include "action_tapping.h" | 7 | #include "action_tapping.h" |
| 8 | 8 | ||
| 9 | extern "C" { | 9 | extern "C" { |
| 10 | #include "action_layer.h" | ||
| 11 | } | ||
| 12 | |||
| 13 | extern "C" { | ||
| 10 | void set_time(uint32_t t); | 14 | void set_time(uint32_t t); |
| 11 | void advance_time(uint32_t ms); | 15 | void advance_time(uint32_t ms); |
| 12 | } | 16 | } |
| @@ -30,11 +34,12 @@ TestFixture::TestFixture() { | |||
| 30 | 34 | ||
| 31 | TestFixture::~TestFixture() { | 35 | TestFixture::~TestFixture() { |
| 32 | TestDriver driver; | 36 | TestDriver driver; |
| 37 | layer_clear(); | ||
| 33 | clear_all_keys(); | 38 | clear_all_keys(); |
| 34 | // Run for a while to make sure all keys are completely released | 39 | // Run for a while to make sure all keys are completely released |
| 35 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); | 40 | EXPECT_CALL(driver, send_keyboard_mock(_)).Times(AnyNumber()); |
| 36 | idle_for(TAPPING_TERM + 10); | 41 | idle_for(TAPPING_TERM + 10); |
| 37 | testing::Mock::VerifyAndClearExpectations(&driver); | 42 | testing::Mock::VerifyAndClearExpectations(&driver); |
| 38 | // Verify that the matrix really is cleared | 43 | // Verify that the matrix really is cleared |
| 39 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); | 44 | EXPECT_CALL(driver, send_keyboard_mock(KeyboardReport())).Times(Between(0, 1)); |
| 40 | } | 45 | } |
| @@ -48,4 +53,4 @@ void TestFixture::idle_for(unsigned time) { | |||
| 48 | for (unsigned i=0; i<time; i++) { | 53 | for (unsigned i=0; i<time; i++) { |
| 49 | run_one_scan_loop(); | 54 | run_one_scan_loop(); |
| 50 | } | 55 | } |
| 51 | } \ No newline at end of file | 56 | } |
