=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: tests: Add test for parsing version.
Alexandre Julliard
julliard at winehq.org
Tue Jun 18 17:21:29 CDT 2019
Module: vkd3d
Branch: master
Commit: f723a791d50a0e61c340cb0b706dfa3038c5e353
URL: https://source.winehq.org/git/vkd3d.git/?a=commit;h=f723a791d50a0e61c340cb0b706dfa3038c5e353
Author: Józef Kucia <jkucia at codeweavers.com>
Date: Mon Jun 17 15:43:31 2019 +0200
tests: Add test for parsing version.
Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
Makefile.am | 1 +
include/private/vkd3d_common.h | 14 ++++++++++++
libs/vkd3d/device.c | 15 +------------
tests/vkd3d_common.c | 49 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 65 insertions(+), 14 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 299ec26..fe3a363 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,7 @@ vkd3d_demos_shaders = \
vkd3d_tests = \
tests/vkd3d_api \
+ tests/vkd3d_common \
tests/vkd3d_shader_api
vkd3d_cross_tests = \
diff --git a/include/private/vkd3d_common.h b/include/private/vkd3d_common.h
index 16c31e6..c696f88 100644
--- a/include/private/vkd3d_common.h
+++ b/include/private/vkd3d_common.h
@@ -22,6 +22,8 @@
#include "config.h"
#include "vkd3d_windows.h"
+#include <ctype.h>
+
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#endif
@@ -137,4 +139,16 @@ static inline LONG InterlockedDecrement(LONG volatile *x)
# error "atomic_add_fetch() not implemented for this platform"
#endif /* HAVE_SYNC_ADD_AND_FETCH */
+static inline void vkd3d_parse_version(const char *version, int *major, int *minor)
+{
+ *major = atoi(version);
+
+ while (isdigit(*version))
+ ++version;
+ if (*version == '.')
+ ++version;
+
+ *minor = atoi(version);
+}
+
#endif /* __VKD3D_COMMON_H */
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index 1092cff..7522c41 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -18,8 +18,6 @@
#include "vkd3d_private.h"
-#include <ctype.h>
-
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
@@ -94,20 +92,9 @@ struct vk_struct
static uint32_t vkd3d_get_vk_version(void)
{
- const char *ptr = PACKAGE_VERSION;
int major, minor;
- major = atoi(ptr);
-
- while (isdigit(*ptr))
- ++ptr;
- if (*ptr == '.')
- ++ptr;
-
- minor = atoi(ptr);
-
- TRACE("Version %d.%d.\n", major, minor);
-
+ vkd3d_parse_version(PACKAGE_VERSION, &major, &minor);
return VK_MAKE_VERSION(major, minor, 0);
}
diff --git a/tests/vkd3d_common.c b/tests/vkd3d_common.c
new file mode 100644
index 0000000..379c8b0
--- /dev/null
+++ b/tests/vkd3d_common.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2019 Józef Kucia for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "vkd3d_common.h"
+#include "vkd3d_test.h"
+
+static void check_version(const char *v, int expected_major, int expected_minor)
+{
+ int major, minor;
+
+ vkd3d_parse_version(v, &major, &minor);
+ ok(major == expected_major && minor == expected_minor,
+ "Got %d.%d, expected %d.%d for %s.\n",
+ major, minor, expected_major, expected_minor, v);
+}
+
+static void test_parse_version(void)
+{
+ check_version("", 0, 0);
+ check_version(".3", 0, 3);
+ check_version(".4.5", 0, 4);
+
+ check_version("1", 1, 0);
+ check_version("2", 2, 0);
+
+ check_version("1.0", 1, 0);
+ check_version("1.1", 1, 1);
+ check_version("2.3.0", 2, 3);
+}
+
+START_TEST(vkd3d_common)
+{
+ run_test(test_parse_version);
+}
More information about the wine-cvs
mailing list