First unit test working!

Must be run with the bundle checked out to `epan/build/justlib`. Also,
the build process is awkward. To be improved in a follow-up.

cd testing && make common && cd kaleidoscope && make

Signed-off-by: Eric Paniagua <epaniagua@google.com>
epan/testing/readable
Eric Paniagua 4 years ago
parent b6d607be62
commit a9f1e960cc

@ -59,26 +59,18 @@ Runtime_::setup(void) {
void
Runtime_::loop(void) {
std::cout << "epan 2.2.1.1" << std::endl;
millis_at_cycle_start_ = millis();
std::cout << "epan 2.2.1.2" << std::endl;
kaleidoscope::Hooks::beforeEachCycle();
std::cout << "epan 2.2.1.3" << std::endl;
device().scanMatrix();
std::cout << "epan 2.2.1.4" << std::endl;
kaleidoscope::Hooks::beforeReportingState();
std::cout << "epan 2.2.1.5" << std::endl;
device().hid().keyboard().sendReport();
std::cout << "epan 2.2.1.6" << std::endl;
device().hid().keyboard().releaseAllKeys();
std::cout << "epan 2.2.1.7" << std::endl;
kaleidoscope::Hooks::afterEachCycle();
std::cout << "epan 2.2.1.8" << std::endl;
}
Runtime_ Runtime;

@ -1,5 +1,5 @@
/* kailedoscope::sim - Simulator for Unit Testing Kaleidoscope
* Copyright (C) 2020 epan <epaniagua@google.com>
* Copyright (C) 2020 Eric Paniagua <epaniagua@google.com>
*
* 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
@ -24,9 +24,7 @@ namespace kaleidoscope {
namespace testing {
void Simulator::RunCycle() {
std::cout << "epan 2.2.1" << std::endl;
Kaleidoscope.loop();
std::cout << "epan 2.2.2" << std::endl;
}
void Simulator::RunCycles(size_t n) {

@ -20,11 +20,8 @@ namespace kaleidoscope {
namespace testing {
void VirtualDeviceTest::RunCycle() {
std::cout << "epan 2.1" << std::endl;
state_.Clear();
std::cout << "epan 2.2" << std::endl;
sim_.RunCycle();
std::cout << "epan 2.3" << std::endl;
}
void VirtualDeviceTest::RunCycles(size_t n) {

@ -14,9 +14,9 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
// We intentionally omit `#pragma once` since we need to set up macros per
// compilation unit.
// #pragma once
#pragma once
#include "Kaleidoscope.h"
#undef min
#undef max
@ -27,6 +27,8 @@
#define SETUP_GOOGLETEST() \
void executeTestFunction() { \
setup(); /* setup Kaleidoscope */ \
/* Turn off virtual_io's input. */ \
Kaleidoscope.device().keyScanner().setEnableReadMatrix(false); \
testing::InitGoogleTest(); \
RUN_ALL_TESTS(); \
}

@ -11,7 +11,7 @@ TEST_OBJS=$(patsubst %.cpp,${OBJ_DIR}/%.o,$(TEST_FILES))
run: ${BIN_DIR}/${BIN_FILE}
@echo "run"
"./${BIN_DIR}/${BIN_FILE}" -t
"./${BIN_DIR}/${BIN_FILE}" -t -q
${BIN_DIR}/${BIN_FILE}: ${TEST_OBJS} FORCE
@echo "link"

@ -12,7 +12,7 @@ TEST_OBJS=$(patsubst $(SRC_DIR)/%.cpp,${OBJ_DIR}/%.o,$(TEST_FILES))
run: ${BIN_DIR}/${BIN_FILE}
@echo "run"
"./${BIN_DIR}/${BIN_FILE}" -t
"./${BIN_DIR}/${BIN_FILE}" -t -q
${BIN_DIR}/${BIN_FILE}: ${TEST_OBJS} FORCE
@echo "link"

@ -38,27 +38,21 @@ using ::testing::IsEmpty;
class KeyboardReports : public VirtualDeviceTest {};
TEST_F(KeyboardReports, KeysActiveWhenPressed) {
std::cout << "epan 1" << std::endl;
sim_.Press(2, 1); // A
std::cout << "epan 2" << std::endl;
RunCycle();
std::cout << "epan 3" << std::endl;
EXPECT_EQ(Result().KeyboardReports().size(), 1);
std::cout << "epan 4" << std::endl;
EXPECT_THAT(
Result().KeyboardReports(0).ActiveKeycodes(),
ContainsKey(Key_A));
std::cout << "epan 5" << std::endl;
sim_.Release(2, 1); // A
std::cout << "epan 6" << std::endl;
RunCycles(2);
std::cout << "epan 7" << std::endl;
std::cout << "epan 8" << std::endl;
EXPECT_THAT(Result().KeyboardReports(), IsEmpty());
std::cout << "epan 9" << std::endl;
EXPECT_EQ(Result().KeyboardReports().size(), 1);
EXPECT_THAT(
Result().KeyboardReports(0).ActiveKeycodes(),
IsEmpty());
}
} // namespace

Loading…
Cancel
Save