summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-05-11 12:20:50 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-05-13 09:41:50 +1000
commitffd4874798ba54f86acac75779a15b4babeaa5f3 (patch)
tree8c6d1954542686e82734fa4f0999cddddd9284dd /test
parentc4f9c3a07dbb05b81c8e2193a083102f710ebb27 (diff)
include: add version_compare helper function
Compare two version numbers in the major.minor form. Switch the few users of manual version switching over to the new function. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jamey Sharp <jamey@minilop.net>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am3
-rw-r--r--test/misc.c62
2 files changed, 64 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index fe9bc1f2e..b7ee070a1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,7 +1,7 @@
if ENABLE_UNIT_TESTS
if HAVE_LD_WRAP
SUBDIRS= . xi2
-noinst_PROGRAMS = xkb input xtest list
+noinst_PROGRAMS = xkb input xtest list misc
check_LTLIBRARIES = libxservertest.la
TESTS=$(noinst_PROGRAMS)
@@ -18,6 +18,7 @@ xkb_LDADD=$(TEST_LDADD)
input_LDADD=$(TEST_LDADD)
xtest_LDADD=$(TEST_LDADD)
list_LDADD=$(TEST_LDADD)
+misc_LDADD=$(TEST_LDADD)
libxservertest_la_LIBADD = \
$(XSERVER_LIBS) \
diff --git a/test/misc.c b/test/misc.c
new file mode 100644
index 000000000..3d3b1a1e3
--- /dev/null
+++ b/test/misc.c
@@ -0,0 +1,62 @@
+/**
+ * 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 "misc.h"
+
+static void dix_version_compare(void)
+{
+ int rc;
+
+ rc = version_compare(0, 0, 1, 0);
+ assert(rc < 0);
+ rc = version_compare(1, 0, 0, 0);
+ assert(rc > 0);
+ rc = version_compare(0, 0, 0, 0);
+ assert(rc == 0);
+ rc = version_compare(1, 0, 1, 0);
+ assert(rc == 0);
+ rc = version_compare(1, 0, 0, 9);
+ assert(rc > 0);
+ rc = version_compare(0, 9, 1, 0);
+ assert(rc < 0);
+ rc = version_compare(1, 0, 1, 9);
+ assert(rc < 0);
+ rc = version_compare(1, 9, 1, 0);
+ assert(rc > 0);
+ rc = version_compare(2, 0, 1, 9);
+ assert(rc > 0);
+ rc = version_compare(1, 9, 2, 0);
+ assert(rc < 0);
+}
+
+int main(int argc, char** argv)
+{
+ dix_version_compare();
+
+ return 0;
+}