Skip to content

Commit

Permalink
feat: add test for SynthPointer
Browse files Browse the repository at this point in the history
Add a new test file `test_SynthPointer.c` to test the functionality of the `SynthPointer` library. The test includes functions to check the creation of the synthetic pointer device, hover exit, down move, up move, and screen to global conversion.
  • Loading branch information
dikkadev committed Aug 5, 2023
1 parent 1dd120d commit 3ad7d28
Show file tree
Hide file tree
Showing 5 changed files with 4,380 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ set(CMAKE_C_STANDARD 99)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_library(SynthPointer SHARED SynthPointer.c)

include_directories(${CMAKE_SOURCE_DIR}/test)

add_executable(tests test/test_SynthPointer.c test/unity.c)
target_link_libraries(tests SynthPointer)
77 changes: 77 additions & 0 deletions test/test_SynthPointer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "../SynthPointer.h"
#include "unity.h"
#include <windows.h>

HSYNTHETICPOINTERDEVICE device;
POINTER_TYPE_INFO *info;
DEVMODE devMode;

typedef enum {
PEN_STATE_MASK = (POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_DOWN | POINTER_FLAG_UP | POINTER_FLAG_UPDATE),
PEN_HOVER = (POINTER_FLAG_INRANGE | POINTER_FLAG_UPDATE),
PEN_DOWN = (POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_DOWN),
PEN_CONTACT = (POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE),
PEN_UP = (POINTER_FLAG_INRANGE | POINTER_FLAG_UP),
PEN_ENDHOVER = (POINTER_FLAG_UPDATE),
} PEN_STATES;

void setUp(void) {
device = CreateSynthPointer();
info = GetDefaultPointerTypeInfo();
devMode.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode);
}

void tearDown(void) {
}

void test_DBG(void) {
POINT global0 = _ScreenToGlobal(0, 0, 0);
POINT global1 = _ScreenToGlobal(0, 0, 1);

printf("global0: %d, %d\n", global0.x, global0.y);
printf("global1: %d, %d\n", global1.x, global1.y);

info->penInfo.pointerInfo.ptPixelLocation.x = global1.x;
info->penInfo.pointerInfo.ptPixelLocation.y = global1.y;
info->penInfo.pointerInfo.pointerFlags = PEN_CONTACT;

_injectPointer(device, info);
}

void test_CreateSynthPointer(void) {
TEST_ASSERT_NOT_NULL(device);
}

void test_HoverExit(void) {
HoverExit(device, info);
TEST_ASSERT_EQUAL_INT(PEN_ENDHOVER, info->penInfo.pointerInfo.pointerFlags);
}

void test_DownMove(void) {
Down(device, info);
TEST_ASSERT_EQUAL_INT(PEN_DOWN, info->penInfo.pointerInfo.pointerFlags);
}

void test_UpMove(void) {
Up(device, info);
TEST_ASSERT_EQUAL_INT(PEN_UP, info->penInfo.pointerInfo.pointerFlags);
}

void test_ScreenToGlobal(void) {
// This test is specific to my screen setup
POINT global = _ScreenToGlobal(0, 0, 1);
TEST_ASSERT_EQUAL_INT(1920, global.x);
TEST_ASSERT_EQUAL_INT(0, global.y);
}

int main(void) {
UNITY_BEGIN();
RUN_TEST(test_CreateSynthPointer);
RUN_TEST(test_HoverExit);
RUN_TEST(test_DownMove);
RUN_TEST(test_UpMove);
/* RUN_TEST(test_ScreenToGlobal); */
/* RUN_TEST(test_DBG); */
return UNITY_END();
}
Loading

0 comments on commit 3ad7d28

Please sign in to comment.