[ion] Add a test for the events

Change-Id: Ia15b137b151831a7b4140c176f41621dad1f48ef
This commit is contained in:
Romain Goyet
2017-05-01 19:01:15 +02:00
parent c1e01cffe5
commit 61ed9a128f
3 changed files with 32 additions and 0 deletions

View File

@@ -17,4 +17,5 @@ objs += $(addprefix ion/src/shared/, \
tests += $(addprefix ion/test/,\
crc32.cpp\
events.cpp\
)

View File

@@ -20,6 +20,15 @@ enum class Key : uint8_t {
I1=48, I2=49, I3=50, I4=51, I5=52, // I6=53,
};
constexpr Key ValidKeys[] = {
Key::A1, Key::A2, Key::A3, Key::A4, Key::A5, Key::A6, Key::B1, Key::B2,
Key::C1, Key::C2, Key::C3, Key::C4, Key::C5, Key::C6, Key::D1, Key::D2,
Key::D3, Key::D4, Key::D5, Key::D6, Key::E1, Key::E2, Key::E3, Key::E4,
Key::E5, Key::E6, Key::F1, Key::F2, Key::F3, Key::F4, Key::F5, Key::G1,
Key::G2, Key::G3, Key::G4, Key::G5, Key::H1, Key::H2, Key::H3, Key::H4,
Key::H5, Key::I1, Key::I2, Key::I3, Key::I4, Key::I5,
};
constexpr int NumberOfKeys = 54;
typedef uint64_t State;

22
ion/test/events.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <quiz.h>
#include <ion.h>
#include <assert.h>
using namespace Ion::Keyboard;
using namespace Ion::Events;
QUIZ_CASE(ion_events_from_keyboard) {
/* Ensure all events generated from the keyboard are properly defined */
for (Key k : ValidKeys) {
assert(Event(k, false, false).isDefined());
assert(Event(k, true, false).isDefined());
assert(Event(k, false, true).isDefined());
assert(Event(k, true, true).isDefined());
}
// Test some fallbacks
assert(Event(Key::I5, false, false) == EXE);
assert(Event(Key::I5, true, false) == EXE);
assert(Event(Key::I5, false, true) == EXE);
assert(Event(Key::I5, true, true) == EXE);
}