aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/test/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/test/input.c')
-rw-r--r--xorg-server/test/input.c112
1 files changed, 111 insertions, 1 deletions
diff --git a/xorg-server/test/input.c b/xorg-server/test/input.c
index 240c2905b..abcc8926b 100644
--- a/xorg-server/test/input.c
+++ b/xorg-server/test/input.c
@@ -38,6 +38,7 @@
#include "exevents.h"
#include "dixgrabs.h"
#include "eventstr.h"
+#include "inpututils.h"
#include <glib.h>
/**
@@ -65,7 +66,6 @@ static void dix_init_valuators(void)
g_assert(val);
g_assert(val->numAxes == num_axes);
g_assert(val->numMotionEvents == 0);
- g_assert(val->mode == Absolute);
g_assert(val->axisVal);
for (i = 0; i < num_axes; i++)
@@ -73,6 +73,7 @@ static void dix_init_valuators(void)
g_assert(val->axisVal[i] == 0);
g_assert(val->axes->min_value == NO_AXIS_LIMITS);
g_assert(val->axes->max_value == NO_AXIS_LIMITS);
+ g_assert(val->axes->mode == Absolute);
}
g_assert(dev.last.numValuators == num_axes);
@@ -903,18 +904,127 @@ static void dix_input_attributes(void)
FreeInputAttributes(new);
}
+static void dix_input_valuator_masks(void)
+{
+ ValuatorMask *mask = NULL, *copy;
+ int nvaluators = MAX_VALUATORS;
+ int valuators[nvaluators];
+ int i;
+ int first_val, num_vals;
+
+ for (i = 0; i < nvaluators; i++)
+ valuators[i] = i;
+
+ mask = valuator_mask_new(nvaluators);
+ g_assert(mask != NULL);
+ g_assert(valuator_mask_size(mask) == 0);
+ g_assert(valuator_mask_num_valuators(mask) == 0);
+
+ for (i = 0; i < nvaluators; i++)
+ {
+ g_assert(!valuator_mask_isset(mask, i));
+ valuator_mask_set(mask, i, valuators[i]);
+ g_assert(valuator_mask_isset(mask, i));
+ g_assert(valuator_mask_get(mask, i) == valuators[i]);
+ g_assert(valuator_mask_size(mask) == i + 1);
+ g_assert(valuator_mask_num_valuators(mask) == i + 1);
+ }
+
+ for (i = 0; i < nvaluators; i++)
+ {
+ g_assert(valuator_mask_isset(mask, i));
+ valuator_mask_unset(mask, i);
+ /* we're removing valuators from the front, so size should stay the
+ * same until the last bit is removed */
+ if (i < nvaluators - 1)
+ g_assert(valuator_mask_size(mask) == nvaluators);
+ g_assert(!valuator_mask_isset(mask, i));
+ }
+
+ g_assert(valuator_mask_size(mask) == 0);
+ valuator_mask_zero(mask);
+ g_assert(valuator_mask_size(mask) == 0);
+ g_assert(valuator_mask_num_valuators(mask) == 0);
+ for (i = 0; i < nvaluators; i++)
+ g_assert(!valuator_mask_isset(mask, i));
+
+ first_val = 5;
+ num_vals = 6;
+
+ valuator_mask_set_range(mask, first_val, num_vals, valuators);
+ g_assert(valuator_mask_size(mask) == first_val + num_vals);
+ g_assert(valuator_mask_num_valuators(mask) == num_vals);
+ for (i = 0; i < nvaluators; i++)
+ {
+ if (i < first_val || i >= first_val + num_vals)
+ g_assert(!valuator_mask_isset(mask, i));
+ else
+ {
+ g_assert(valuator_mask_isset(mask, i));
+ g_assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
+ }
+ }
+
+ copy = valuator_mask_new(nvaluators);
+ valuator_mask_copy(copy, mask);
+ g_assert(mask != copy);
+ g_assert(valuator_mask_size(mask) == valuator_mask_size(copy));
+ g_assert(valuator_mask_num_valuators(mask) == valuator_mask_num_valuators(copy));
+
+ for (i = 0; i < nvaluators; i++)
+ {
+ g_assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
+ g_assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
+ }
+
+ free(mask);
+}
+
+static void dix_valuator_mode(void)
+{
+ DeviceIntRec dev;
+ const int num_axes = MAX_VALUATORS;
+ int i;
+ Atom atoms[MAX_VALUATORS] = { 0 };
+
+ memset(&dev, 0, sizeof(DeviceIntRec));
+ dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
+
+ g_assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
+ g_assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
+
+ for (i = 0; i < num_axes; i++)
+ {
+ g_assert(valuator_get_mode(&dev, i) == Absolute);
+ valuator_set_mode(&dev, i, Relative);
+ g_assert(dev.valuator->axes[i].mode == Relative);
+ g_assert(valuator_get_mode(&dev, i) == Relative);
+ }
+
+ valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute);
+ for (i = 0; i < num_axes; i++)
+ g_assert(valuator_get_mode(&dev, i) == Absolute);
+
+ valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative);
+ for (i = 0; i < num_axes; i++)
+ g_assert(valuator_get_mode(&dev, i) == Relative);
+}
+
+
int main(int argc, char** argv)
{
g_test_init(&argc, &argv,NULL);
g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
+ g_test_add_func("/dix/input/valuator-masks", dix_input_valuator_masks);
g_test_add_func("/dix/input/attributes", dix_input_attributes);
g_test_add_func("/dix/input/init-valuators", dix_init_valuators);
g_test_add_func("/dix/input/event-core-conversion", dix_event_to_core_conversion);
g_test_add_func("/dix/input/check-grab-values", dix_check_grab_values);
g_test_add_func("/dix/input/xi2-struct-sizes", xi2_struct_sizes);
g_test_add_func("/dix/input/grab_matching", dix_grab_matching);
+ g_test_add_func("/dix/input/valuator_mode", dix_valuator_mode);
g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
g_test_add_func("/Xi/xiproperty/register-unregister", xi_unregister_handlers);