aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/test
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/test')
-rw-r--r--xorg-server/test/input.c67
-rw-r--r--xorg-server/test/list.c37
-rw-r--r--xorg-server/test/xi2/Makefile.am5
-rw-r--r--xorg-server/test/xi2/xi2.c129
4 files changed, 237 insertions, 1 deletions
diff --git a/xorg-server/test/input.c b/xorg-server/test/input.c
index 5b4c8c193..c44e5f613 100644
--- a/xorg-server/test/input.c
+++ b/xorg-server/test/input.c
@@ -1674,8 +1674,75 @@ mieq_test(void) {
mieqFini();
}
+/* Simple check that we're replaying events in-order */
+static void
+process_input_proc(InternalEvent *ev, DeviceIntPtr device)
+{
+ static int last_evtype = -1;
+
+ if (ev->any.header == 0xac)
+ last_evtype = -1;
+
+ assert(ev->any.type == ++last_evtype);
+}
+
+static void
+dix_enqueue_events(void) {
+#define NEVENTS 5
+ DeviceIntRec dev;
+ InternalEvent ev[NEVENTS];
+ SpriteInfoRec spriteInfo;
+ SpriteRec sprite;
+ QdEventPtr qe;
+ int i;
+
+ memset(&dev, 0, sizeof(dev));
+ dev.public.processInputProc = process_input_proc;
+
+ memset(&spriteInfo, 0, sizeof(spriteInfo));
+ memset(&sprite, 0, sizeof(sprite));
+ dev.spriteInfo = &spriteInfo;
+ spriteInfo.sprite = &sprite;
+
+ InitEvents();
+ assert(list_is_empty(&syncEvents.pending));
+
+ /* this way PlayReleasedEvents really runs through all events in the
+ * queue */
+ inputInfo.devices = &dev;
+
+ /* to reset process_input_proc */
+ ev[0].any.header = 0xac;
+
+ for (i = 0; i < NEVENTS; i++)
+ {
+ ev[i].any.length = sizeof(*ev);
+ ev[i].any.type = i;
+ EnqueueEvent(&ev[i], &dev);
+ assert(!list_is_empty(&syncEvents.pending));
+ qe = list_last_entry(&syncEvents.pending, QdEventRec, next);
+ assert(memcmp(qe->event, &ev[i], ev[i].any.length) == 0);
+ qe = list_first_entry(&syncEvents.pending, QdEventRec, next);
+ assert(memcmp(qe->event, &ev[0], ev[i].any.length) == 0);
+ }
+
+ /* calls process_input_proc */
+ dev.deviceGrab.sync.frozen = 1;
+ PlayReleasedEvents();
+ assert(!list_is_empty(&syncEvents.pending));
+
+
+ dev.deviceGrab.sync.frozen = 0;
+ PlayReleasedEvents();
+ assert(list_is_empty(&syncEvents.pending));
+
+ inputInfo.devices = NULL;
+}
+
+
int main(int argc, char** argv)
{
+ dix_enqueue_events();
dix_double_fp_conversion();
dix_input_valuator_masks();
dix_input_attributes();
diff --git a/xorg-server/test/list.c b/xorg-server/test/list.c
index f7d7bffce..ffb85efd0 100644
--- a/xorg-server/test/list.c
+++ b/xorg-server/test/list.c
@@ -89,6 +89,42 @@ test_list_add(void)
};
static void
+test_list_append(void)
+{
+ struct parent parent = {0};
+ struct child child[3];
+ struct child *c;
+ int i;
+
+ list_init(&parent.children);
+
+ list_append(&child[0].node, &parent.children);
+ assert(!list_is_empty(&parent.children));
+
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+ c = list_last_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+
+ list_append(&child[1].node, &parent.children);
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+ c = list_last_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
+
+ list_append(&child[2].node, &parent.children);
+ c = list_first_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+ c = list_last_entry(&parent.children, struct child, node);
+ assert(memcmp(c, &child[2], sizeof(struct child)) == 0);
+
+ i = 0;
+ list_for_each_entry(c, &parent.children, node) {
+ assert(memcmp(c, &child[i++], sizeof(struct child)) == 0);
+ }
+};
+
+static void
test_list_del(void)
{
struct parent parent = {0};
@@ -325,6 +361,7 @@ int main(int argc, char** argv)
{
test_list_init();
test_list_add();
+ test_list_append();
test_list_del();
test_list_for_each();
diff --git a/xorg-server/test/xi2/Makefile.am b/xorg-server/test/xi2/Makefile.am
index c6e93e78f..913ba0f8b 100644
--- a/xorg-server/test/xi2/Makefile.am
+++ b/xorg-server/test/xi2/Makefile.am
@@ -10,7 +10,8 @@ noinst_PROGRAMS = \
protocol-xipassivegrabdevice \
protocol-xiquerypointer \
protocol-xiwarppointer \
- protocol-eventconvert
+ protocol-eventconvert \
+ xi2
TESTS=$(noinst_PROGRAMS)
TESTS_ENVIRONMENT = $(XORG_MALLOC_DEBUG_ENV)
@@ -34,6 +35,7 @@ protocol_xiquerypointer_LDADD=$(TEST_LDADD)
protocol_xipassivegrabdevice_LDADD=$(TEST_LDADD)
protocol_xiwarppointer_LDADD=$(TEST_LDADD)
protocol_eventconvert_LDADD=$(TEST_LDADD)
+xi2_LDADD=$(TEST_LDADD)
protocol_xiqueryversion_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient
protocol_xiquerydevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient
@@ -44,6 +46,7 @@ protocol_xigetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-w
protocol_xipassivegrabdevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,GrabButton -Wl,-wrap,dixLookupWindow -Wl,-wrap,WriteToClient
protocol_xiquerypointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
protocol_xiwarppointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
+xi2_LDFLAGS=$(AM_LDFLAGS)
protocol_xiqueryversion_SOURCES=$(COMMON_SOURCES) protocol-xiqueryversion.c
protocol_xiquerydevice_SOURCES=$(COMMON_SOURCES) protocol-xiquerydevice.c
diff --git a/xorg-server/test/xi2/xi2.c b/xorg-server/test/xi2/xi2.c
new file mode 100644
index 000000000..5143caff8
--- /dev/null
+++ b/xorg-server/test/xi2/xi2.c
@@ -0,0 +1,129 @@
+/**
+ * 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 <stdint.h>
+#include "inpututils.h"
+#include "inputstr.h"
+#include "assert.h"
+
+static void xi2mask_test(void)
+{
+ XI2Mask *xi2mask = NULL,
+ *mergemask = NULL;
+ unsigned char *mask;
+ DeviceIntRec dev;
+ int i;
+
+ /* size >= nmasks * 2 for the test cases below */
+ xi2mask = xi2mask_new_with_size(MAXDEVICES + 2, (MAXDEVICES + 2) * 2);
+ assert(xi2mask);
+ assert(xi2mask->nmasks > 0);
+ assert(xi2mask->mask_size > 0);
+
+ assert(xi2mask_mask_size(xi2mask) == xi2mask->mask_size);
+ assert(xi2mask_num_masks(xi2mask) == xi2mask->nmasks);
+
+ mask = calloc(1, xi2mask_mask_size(xi2mask));
+ /* ensure zeros */
+ for (i = 0; i < xi2mask_num_masks(xi2mask); i++) {
+ const unsigned char *m = xi2mask_get_one_mask(xi2mask, i);
+ assert(memcmp(mask, m, xi2mask_mask_size(xi2mask)) == 0);
+ }
+
+ /* set various bits */
+ for (i = 0; i < xi2mask_num_masks(xi2mask); i++) {
+ const unsigned char *m;
+ xi2mask_set(xi2mask, i, i);
+
+ dev.id = i;
+ assert(xi2mask_isset(xi2mask, &dev, i));
+
+ m = xi2mask_get_one_mask(xi2mask, i);
+ SetBit(mask, i);
+ assert(memcmp(mask, m, xi2mask_mask_size(xi2mask)) == 0);
+ ClearBit(mask, i);
+ }
+
+ /* ensure zeros one-by-one */
+ for (i = 0; i < xi2mask_num_masks(xi2mask); i++) {
+ const unsigned char *m = xi2mask_get_one_mask(xi2mask, i);
+ assert(memcmp(mask, m, xi2mask_mask_size(xi2mask)) != 0);
+ xi2mask_zero(xi2mask, i);
+ assert(memcmp(mask, m, xi2mask_mask_size(xi2mask)) == 0);
+ }
+
+ /* re-set, zero all */
+ for (i = 0; i < xi2mask_num_masks(xi2mask); i++)
+ xi2mask_set(xi2mask, i, i);
+ xi2mask_zero(xi2mask, -1);
+
+ for (i = 0; i < xi2mask_num_masks(xi2mask); i++) {
+ const unsigned char *m = xi2mask_get_one_mask(xi2mask, i);
+ assert(memcmp(mask, m, xi2mask_mask_size(xi2mask)) == 0);
+ }
+
+ for (i = 0; i < xi2mask_num_masks(xi2mask); i++) {
+ const unsigned char *m;
+ SetBit(mask, i);
+ xi2mask_set_one_mask(xi2mask, i, mask, xi2mask_mask_size(xi2mask));
+ m = xi2mask_get_one_mask(xi2mask, i);
+ assert(memcmp(mask, m, xi2mask_mask_size(xi2mask)) == 0);
+ ClearBit(mask, i);
+ }
+
+ mergemask = xi2mask_new_with_size(MAXDEVICES + 2, (MAXDEVICES + 2) * 2);
+ for (i = 0; i < xi2mask_num_masks(mergemask); i++) {
+ dev.id = i;
+ xi2mask_set(mergemask, i, i * 2);
+ }
+
+ /* xi2mask still has all i bits set, should now also have all i * 2 bits */
+ xi2mask_merge(xi2mask, mergemask);
+ for (i = 0; i < xi2mask_num_masks(mergemask); i++) {
+ const unsigned char *m = xi2mask_get_one_mask(xi2mask, i);
+ SetBit(mask, i);
+ SetBit(mask, i * 2);
+ assert(memcmp(mask, m, xi2mask_mask_size(xi2mask)) == 0);
+ ClearBit(mask, i);
+ ClearBit(mask, i * 2);
+ }
+
+ xi2mask_free(&xi2mask);
+ assert(xi2mask == NULL);
+
+ xi2mask_free(&mergemask);
+ assert(mergemask == NULL);
+ free(mask);
+}
+
+
+int main(int argc, char** argv)
+{
+ xi2mask_test();
+
+ return 0;
+}