aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/test/fixes.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-06-03 08:22:14 +0200
committermarha <marha@users.sourceforge.net>2011-06-03 08:22:14 +0200
commit6aea3a7470dfb2c513378b82c27f0ad87afda7f3 (patch)
treecefb863bdf986b740d8f9475514df400a56ff003 /xorg-server/test/fixes.c
parent5e835037510a4ccf001fb8f0a9aed29a28072fec (diff)
parentcda19b1d226d565f1ca4327aeae827c621b3dfd6 (diff)
downloadvcxsrv-6aea3a7470dfb2c513378b82c27f0ad87afda7f3.tar.gz
vcxsrv-6aea3a7470dfb2c513378b82c27f0ad87afda7f3.tar.bz2
vcxsrv-6aea3a7470dfb2c513378b82c27f0ad87afda7f3.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/configs/linux-dri mesalib/src/gallium/auxiliary/util/u_math.h mesalib/src/mapi/glapi/gen/Makefile mesalib/src/mapi/glapi/glapi_mapi_tmp.h mesalib/src/mapi/glapi/glapi_sparc.S mesalib/src/mapi/glapi/glapi_x86-64.S mesalib/src/mapi/glapi/glapi_x86.S mesalib/src/mapi/glapi/glapitable.h mesalib/src/mapi/glapi/glapitemp.h mesalib/src/mapi/glapi/glprocs.h mesalib/src/mesa/drivers/dri/Makefile.template mesalib/src/mesa/main/dd.h mesalib/src/mesa/main/fbobject.c mesalib/src/mesa/main/remap_helper.h mesalib/src/mesa/main/shaderapi.c mesalib/src/mesa/main/teximage.c mesalib/src/mesa/main/uniforms.c mesalib/src/mesa/state_tracker/st_format.c mesalib/src/mesa/vbo/vbo_exec_array.c xorg-server/configure.ac xorg-server/dix/main.c xorg-server/dix/window.c xorg-server/hw/xquartz/GL/indirect.c xorg-server/hw/xquartz/X11Application.m xorg-server/hw/xquartz/darwin.c xorg-server/hw/xquartz/darwin.h xorg-server/hw/xquartz/mach-startup/Makefile.am xorg-server/hw/xquartz/pbproxy/app-main.m xorg-server/hw/xquartz/pbproxy/pbproxy.h xorg-server/hw/xquartz/pbproxy/x-selection.m xorg-server/hw/xquartz/xpr/xpr.h xorg-server/hw/xquartz/xpr/xprEvent.c xorg-server/hw/xquartz/xpr/xprScreen.c xorg-server/include/privates.h xorg-server/include/protocol-versions.h xorg-server/test/Makefile.am xorg-server/xfixes/cursor.c xorg-server/xfixes/xfixes.c xorg-server/xkeyboard-config/configure.in xorg-server/xkeyboard-config/rules/base.extras.xml.in xorg-server/xkeyboard-config/rules/base.xml.in xorg-server/xkeyboard-config/symbols/de xorg-server/xkeyboard-config/symbols/lk xorg-server/xkeyboard-config/symbols/ru
Diffstat (limited to 'xorg-server/test/fixes.c')
-rw-r--r--xorg-server/test/fixes.c327
1 files changed, 327 insertions, 0 deletions
diff --git a/xorg-server/test/fixes.c b/xorg-server/test/fixes.c
new file mode 100644
index 000000000..8c804ba26
--- /dev/null
+++ b/xorg-server/test/fixes.c
@@ -0,0 +1,327 @@
+/**
+ * Copyright © 2011 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/X.h>
+#include <xfixesint.h>
+#include <X11/extensions/xfixeswire.h>
+
+static void
+_fixes_test_direction(struct PointerBarrier *barrier, int d[4], int permitted)
+{
+ BOOL blocking;
+ int i, j;
+ int dir = barrier_get_direction(d[0], d[1], d[2], d[3]);
+
+ barrier->directions = 0;
+ blocking = barrier_is_blocking_direction(barrier, dir);
+ assert(blocking);
+
+ for (j = 0; j <= BarrierNegativeY; j++)
+ {
+ for (i = 0; i <= BarrierNegativeY; i++)
+ {
+ barrier->directions |= 1 << i;
+ blocking = barrier_is_blocking_direction(barrier, dir);
+ assert((barrier->directions & permitted) == permitted ? !blocking : blocking);
+ }
+ }
+
+}
+
+static void
+fixes_pointer_barrier_direction_test(void)
+{
+ struct PointerBarrier barrier;
+
+ int x = 100;
+ int y = 100;
+
+ int directions[8][4] = {
+ { x, y, x, y + 100}, /* S */
+ { x + 50, y, x - 50, y + 100}, /* SW */
+ { x + 100, y, x, y}, /* W */
+ { x + 100, y + 50, x, y - 50}, /* NW */
+ { x, y + 100, x, y}, /* N */
+ { x - 50, y + 100, x + 50, y}, /* NE */
+ { x, y, x + 100, y}, /* E */
+ { x, y - 50, x + 100, y + 50}, /* SE */
+ };
+
+ barrier.x1 = x;
+ barrier.x2 = x;
+ barrier.y1 = y - 50;
+ barrier.y2 = y + 49;
+
+
+ _fixes_test_direction(&barrier, directions[0], BarrierPositiveY);
+ _fixes_test_direction(&barrier, directions[1], BarrierPositiveY | BarrierNegativeX);
+ _fixes_test_direction(&barrier, directions[2], BarrierNegativeX);
+ _fixes_test_direction(&barrier, directions[3], BarrierNegativeY | BarrierNegativeX);
+ _fixes_test_direction(&barrier, directions[4], BarrierNegativeY);
+ _fixes_test_direction(&barrier, directions[5], BarrierPositiveX | BarrierNegativeY);
+ _fixes_test_direction(&barrier, directions[6], BarrierPositiveX);
+ _fixes_test_direction(&barrier, directions[7], BarrierPositiveY | BarrierPositiveX);
+
+
+}
+
+
+static void
+fixes_pointer_barriers_test(void)
+{
+ struct PointerBarrier barrier;
+ int x1, y1, x2, y2;
+ double distance;
+
+ int x = 100;
+ int y = 100;
+
+ /* vert barrier */
+ barrier.x1 = x;
+ barrier.x2 = x;
+ barrier.y1 = y - 50;
+ barrier.y2 = y + 50;
+
+ /* across at half-way */
+ x1 = x + 1;
+ x2 = x - 1;
+ y1 = y;
+ y2 = y;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+ assert(distance == 1);
+
+ /* definitely not across */
+ x1 = x + 10;
+ x2 = x + 5;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* across, but outside of y range */
+ x1 = x + 1;
+ x2 = x -1;
+ y1 = y + 100;
+ y2 = y + 100;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* across, diagonally */
+ x1 = x + 5;
+ x2 = x - 5;
+ y1 = y + 5;
+ y2 = y - 5;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* across but outside boundary, diagonally */
+ x1 = x + 5;
+ x2 = x - 5;
+ y1 = y + 100;
+ y2 = y + 50;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: startpoint of movement on barrier → blocking */
+ x1 = x;
+ x2 = x - 1;
+ y1 = y;
+ y2 = y;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: startpoint of movement on barrier → not blocking, positive */
+ x1 = x;
+ x2 = x + 1;
+ y1 = y;
+ y2 = y;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: startpoint of movement on barrier → not blocking, negative */
+ x1 = x - 1;
+ x2 = x - 2;
+ y1 = y;
+ y2 = y;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: endpoint of movement on barrier → blocking */
+ x1 = x + 1;
+ x2 = x;
+ y1 = y;
+ y2 = y;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* startpoint on barrier but outside y range */
+ x1 = x;
+ x2 = x - 1;
+ y1 = y + 100;
+ y2 = y + 100;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* endpoint on barrier but outside y range */
+ x1 = x + 1;
+ x2 = x;
+ y1 = y + 100;
+ y2 = y + 100;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+
+ /* horizontal barrier */
+ barrier.x1 = x - 50;
+ barrier.x2 = x + 50;
+ barrier.y1 = y;
+ barrier.y2 = y;
+
+ /* across at half-way */
+ x1 = x;
+ x2 = x;
+ y1 = y - 1;
+ y2 = y + 1;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* definitely not across */
+ y1 = y + 10;
+ y2 = y + 5;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* across, but outside of y range */
+ x1 = x + 100;
+ x2 = x + 100;
+ y1 = y + 1;
+ y2 = y -1;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* across, diagonally */
+ y1 = y + 5;
+ y2 = y - 5;
+ x1 = x + 5;
+ x2 = x - 5;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* across but outside boundary, diagonally */
+ y1 = y + 5;
+ y2 = y - 5;
+ x1 = x + 100;
+ x2 = x + 50;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: startpoint of movement on barrier → blocking */
+ y1 = y;
+ y2 = y - 1;
+ x1 = x;
+ x2 = x;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: startpoint of movement on barrier → not blocking, positive */
+ y1 = y;
+ y2 = y + 1;
+ x1 = x;
+ x2 = x;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: startpoint of movement on barrier → not blocking, negative */
+ y1 = y - 1;
+ y2 = y - 2;
+ x1 = x;
+ x2 = x;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* edge case: endpoint of movement on barrier → blocking */
+ y1 = y + 1;
+ y2 = y;
+ x1 = x;
+ x2 = x;
+ assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* startpoint on barrier but outside y range */
+ y1 = y;
+ y2 = y - 1;
+ x1 = x + 100;
+ x2 = x + 100;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+ /* endpoint on barrier but outside y range */
+ y1 = y + 1;
+ y2 = y;
+ x1 = x + 100;
+ x2 = x + 100;
+ assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+}
+
+static void fixes_pointer_barrier_clamp_test(void)
+{
+ struct PointerBarrier barrier;
+
+ int x = 100;
+ int y = 100;
+
+ int cx, cy; /* clamped */
+
+ /* vert barrier */
+ barrier.x1 = x;
+ barrier.x2 = x;
+ barrier.y1 = y - 50;
+ barrier.y2 = y + 49;
+ barrier.directions = 0;
+
+ cx = INT_MAX;
+ cy = INT_MAX;
+ barrier_clamp_to_barrier(&barrier, BarrierPositiveX, &cx, &cy);
+ assert(cx == barrier.x1 - 1);
+ assert(cy == INT_MAX);
+
+ cx = 0;
+ cy = INT_MAX;
+ barrier_clamp_to_barrier(&barrier, BarrierNegativeX, &cx, &cy);
+ assert(cx == barrier.x1);
+ assert(cy == INT_MAX);
+
+ /* horiz barrier */
+ barrier.x1 = x - 50;
+ barrier.x2 = x + 49;
+ barrier.y1 = y;
+ barrier.y2 = y;
+ barrier.directions = 0;
+
+ cx = INT_MAX;
+ cy = INT_MAX;
+ barrier_clamp_to_barrier(&barrier, BarrierPositiveY, &cx, &cy);
+ assert(cx == INT_MAX);
+ assert(cy == barrier.y1 - 1);
+
+ cx = INT_MAX;
+ cy = 0;
+ barrier_clamp_to_barrier(&barrier, BarrierNegativeY, &cx, &cy);
+ assert(cx == INT_MAX);
+ assert(cy == barrier.y1);
+}
+
+int main(int argc, char** argv)
+{
+
+ fixes_pointer_barriers_test();
+ fixes_pointer_barrier_direction_test();
+ fixes_pointer_barrier_clamp_test();
+
+ return 0;
+}