aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fastmouse_test.cc84
1 files changed, 81 insertions, 3 deletions
diff --git a/src/fastmouse_test.cc b/src/fastmouse_test.cc
index 9cfa3f2..36d13e3 100644
--- a/src/fastmouse_test.cc
+++ b/src/fastmouse_test.cc
@@ -1,6 +1,84 @@
-#include "fastmouse.h"
#include "gtest/gtest.h"
+#include <iostream>
+
+#define FASTMOUSE_IMPL
+#include "fastmouse.h"
+#undef FASTMOUSE_IMPL
-TEST(TestTest, basictesttest) {
- EXPECT_EQ(5 * 1761, 8805);
+constexpr float EPSILON = 0.000001;
+// Wrappers to avoid specifying params we do not use here.
+static void input_emit() {
+ fastmouse_input_emit(nullptr);
}
+static void input_event(movement_type m, const int value) {
+ input_event_fastmouse_log(nullptr, EV_REL, m, value);
+}
+
+class FastmouseTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ static auto fp = fastmouse;
+ static auto mp = movement;
+ fastmouse = fp;
+ movement = mp;
+ }
+};
+
+TEST_F(FastmouseTest, test_noop) {
+ EXPECT_EQ(movement.x, 0);
+ EXPECT_EQ(movement.y, 0);
+
+ input_event(REL_X, 1);
+ input_event(REL_Y, 1);
+ input_emit();
+
+ EXPECT_EQ(movement.x, 1);
+ EXPECT_EQ(movement.y, 1);
+}
+
+TEST_F(FastmouseTest, simple_division) {
+ fastmouse.division = 2;
+ input_event(REL_X, 1);
+ input_emit();
+
+ EXPECT_EQ(movement.x, 0);
+ EXPECT_EQ(movement.y, 0);
+
+ // Loss of precision shows immediately here, it's not a big issue that the first
+ // two dots do not emit an event, it only occurs again after the next INT_MAX dots.
+ // All tests will exhibit this behaviour where the first division dots do not emit an event
+ // as expected unless INT_MAX % division == 0.
+ input_event(REL_X, 2);
+ input_emit();
+
+ EXPECT_EQ(movement.x, 1);
+ EXPECT_EQ(movement.y, 0);
+
+ input_event(REL_Y, 3);
+ input_emit();
+ EXPECT_EQ(movement.x, 1);
+ EXPECT_EQ(movement.y, 1);
+}
+
+TEST_F(FastmouseTest, high_division) {
+ fastmouse.division = 20;
+ for (auto i = 0; i < 20; ++i) {
+ input_event(REL_X, 1);
+ input_emit();
+ EXPECT_EQ(movement.x, 0);
+ EXPECT_EQ(movement.y, 0);
+ }
+ input_event(REL_X, 1);
+ input_emit();
+ EXPECT_EQ(movement.x, 1);
+}
+
+TEST_F(FastmouseTest, different_axis_division) {
+ fastmouse.division = 10;
+
+ input_event(REL_X, 201);
+ input_event(REL_Y, 51);
+ input_emit();
+ EXPECT_EQ(movement.x, 20);
+ EXPECT_EQ(movement.y, 5);
+} \ No newline at end of file