Browse Source

Using macros to reduce clutter in the mouse drag test.

David Piuva 1 year ago
parent
commit
0b325b8da5
1 changed files with 18 additions and 10 deletions
  1. 18 10
      Source/SDK/integrationTest/tests/inputTest.cpp

+ 18 - 10
Source/SDK/integrationTest/tests/inputTest.cpp

@@ -3,37 +3,42 @@
 
 using namespace dsr;
 
+#define TASK_IS(INDEX) context.taskIndex == INDEX
+#define EVENT_TYPE_IS(TYPE) event.mouseEventType == MouseEventType::TYPE
+
 void inputTests_populate(List<Test> &target, int buttonCount, bool relative, bool verticalScroll) {
-	// TODO: Make notes about which tests were skipped and why.
 	if (buttonCount >= 1) {
 		target.pushConstruct(
 			U"Mouse drag test"
 		,
 			[](AlignedImageRgbaU8 &canvas, TestContext &context) {
 				image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
-				if (context.taskIndex == 0) {
+				if (TASK_IS(0)) {
 					font_printLine(canvas, font_getDefault(), U"Hover the cursor over the window.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
-				} else if (context.taskIndex == 1) {
+				} else if (TASK_IS(1)) {
 					font_printLine(canvas, font_getDefault(), U"Press down the left mouse key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
-				} else if (context.taskIndex == 2) {
+				} else if (TASK_IS(2)) {
 					font_printLine(canvas, font_getDefault(), U"Drag the mouse over the window with the left key pressed down.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
-				} else if (context.taskIndex == 3) {
+				} else if (TASK_IS(3)) {
 					font_printLine(canvas, font_getDefault(), U"Release the left key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
 				}
+				// TODO: Draw expanding circles from lowering and raising buttons together with names of the keys used.
+				// TODO: Draw fading lines from move events.
+				// TODO: Make a reusable drawing system to be enabled or disabled as a reusable mouse visualization feature.
 			}
 		,
 			[](const MouseEvent& event, TestContext &context) {
-				if (context.taskIndex == 0 && event.mouseEventType == MouseEventType::MouseMove && !context.leftMouseDown && !context.middleMouseDown && !context.rightMouseDown) {
+				if (TASK_IS(0) && EVENT_TYPE_IS(MouseMove) && !context.leftMouseDown && !context.middleMouseDown && !context.rightMouseDown) {
 					context.passTask();
-				} else if (context.taskIndex == 1 && event.mouseEventType == MouseEventType::MouseDown) {
+				} else if (TASK_IS(1) && EVENT_TYPE_IS(MouseDown)) {
 					if (event.key == MouseKeyEnum::Left) {
 						context.passTask();
 					} else {
 						// TODO: Say which key was triggered instead and suggest skipping with escape if it can not be found.
 					}
-				} else if (context.taskIndex == 2 && event.mouseEventType == MouseEventType::MouseMove && context.leftMouseDown) {
+				} else if (TASK_IS(2) && EVENT_TYPE_IS(MouseMove) && context.leftMouseDown) {
 					context.passTask();
-				} else if (context.taskIndex == 3 && event.mouseEventType == MouseEventType::MouseUp) {
+				} else if (TASK_IS(3) && EVENT_TYPE_IS(MouseUp)) {
 					if (event.key == MouseKeyEnum::Left) {
 						context.finishTest(Grade::Passed);
 					} else {
@@ -47,6 +52,9 @@ void inputTests_populate(List<Test> &target, int buttonCount, bool relative, boo
 			false
 		);
 	} else {
-		sendWarning(U"Skipped the left mouse button test, because 0 mouse buttons were selected as available.");
+		sendWarning(U"Skipped the left mouse button test, because no mouse buttons were told to be available in the call to inputTests_populate.");
 	}
+	// TODO: Create tests for other mouse buttons by reusing code in functions.
+	// TODO: Create tests for keyboards, that display pressed physical keys on a QWERTY keyboard and unicode values of characters.
+	//       The actual printed values depend on language settings, so this might have to be checked manually.
 }