2016-09-21 03:57:24 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Józef Kucia for CodeWeavers
|
|
|
|
*
|
2017-06-16 12:05:54 -07:00
|
|
|
* 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.
|
2016-09-21 03:57:24 -07:00
|
|
|
*
|
2017-06-16 12:05:54 -07:00
|
|
|
* 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.
|
2016-09-21 03:57:24 -07:00
|
|
|
*
|
2017-06-16 12:05:54 -07:00
|
|
|
* 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
|
2016-09-21 03:57:24 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VKD3D_TEST_H
|
|
|
|
#define __VKD3D_TEST_H
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
#include <assert.h>
|
2016-10-10 02:22:50 -07:00
|
|
|
#include <inttypes.h>
|
2016-09-21 03:57:24 -07:00
|
|
|
#include <stdarg.h>
|
2016-10-24 04:20:09 -07:00
|
|
|
#include <stdbool.h>
|
2016-09-21 03:57:24 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-10-10 02:22:50 -07:00
|
|
|
#include "vkd3d_common.h"
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
static void vkd3d_test_main(int argc, char **argv);
|
2016-09-21 03:57:24 -07:00
|
|
|
static const char *vkd3d_test_name;
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
#define START_TEST(name) \
|
|
|
|
static const char *vkd3d_test_name = #name; \
|
|
|
|
static void vkd3d_test_main(int argc, char **argv)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define ok ok_(__LINE__)
|
2016-09-28 00:42:49 -07:00
|
|
|
#define todo todo_(__LINE__)
|
2016-09-21 03:57:24 -07:00
|
|
|
#define skip skip_(__LINE__)
|
|
|
|
#define trace trace_(__LINE__)
|
|
|
|
|
|
|
|
#define ok_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_OK
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define VKD3D_TEST_OK(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_ok(vkd3d_line, args); } while (0)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2016-09-28 00:42:49 -07:00
|
|
|
#define todo_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_TODO
|
2016-09-28 00:42:49 -07:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define VKD3D_TEST_TODO(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_ok(vkd3d_line, args); } while (0)
|
2016-09-28 00:42:49 -07:00
|
|
|
#else
|
|
|
|
# define VKD3D_TEST_TODO(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_todo(vkd3d_line, args); } while (0)
|
2016-09-28 00:42:49 -07:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
#define skip_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_SKIP
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define VKD3D_TEST_SKIP(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_skip(vkd3d_line, args); } while (0)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define trace_(line) \
|
2016-10-17 05:24:22 -07:00
|
|
|
do { \
|
|
|
|
unsigned int vkd3d_line = line; \
|
|
|
|
VKD3D_TEST_TRACE
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define VKD3D_TEST_TRACE(args...) \
|
2016-10-17 05:24:22 -07:00
|
|
|
vkd3d_test_trace(vkd3d_line, args); } while (0)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
static struct
|
|
|
|
{
|
2016-10-10 02:22:50 -07:00
|
|
|
LONG success_count;
|
|
|
|
LONG failure_count;
|
|
|
|
LONG skip_count;
|
|
|
|
LONG todo_count;
|
|
|
|
LONG todo_success_count;
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
unsigned int debug_level;
|
2016-09-21 03:57:24 -07:00
|
|
|
} vkd3d_test_state;
|
|
|
|
|
2016-10-17 05:24:22 -07:00
|
|
|
static void VKD3D_PRINTF_FUNC(3, 4) VKD3D_UNUSED
|
2016-10-24 04:20:09 -07:00
|
|
|
vkd3d_test_ok(unsigned int line, bool result, const char *fmt, ...)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
{
|
2016-11-09 05:46:37 -08:00
|
|
|
if (vkd3d_test_state.debug_level > 1)
|
2016-09-28 00:42:49 -07:00
|
|
|
printf("%s:%d: Test succeeded.\n", vkd3d_test_name, line);
|
2016-10-10 02:22:50 -07:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.success_count);
|
2016-09-21 03:57:24 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
printf("%s:%d: Test failed: ", vkd3d_test_name, line);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
2016-10-10 02:22:50 -07:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.failure_count);
|
2016-09-21 03:57:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 05:24:22 -07:00
|
|
|
static void VKD3D_PRINTF_FUNC(3, 4) VKD3D_UNUSED
|
2016-10-24 04:20:09 -07:00
|
|
|
vkd3d_test_todo(unsigned int line, bool result, const char *fmt, ...)
|
2016-09-28 00:42:49 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
printf("%s:%d Todo succeeded: ", vkd3d_test_name, line);
|
2016-10-10 02:22:50 -07:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.todo_success_count);
|
2016-09-28 00:42:49 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%s:%d: Todo: ", vkd3d_test_name, line);
|
2016-10-10 02:22:50 -07:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.todo_count);
|
2016-09-28 00:42:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2016-10-17 05:24:22 -07:00
|
|
|
static void VKD3D_PRINTF_FUNC(2, 3) VKD3D_UNUSED
|
|
|
|
vkd3d_test_skip(unsigned int line, const char *fmt, ...)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
printf("%s:%d: Test skipped: ", vkd3d_test_name, line);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
2016-10-10 02:22:50 -07:00
|
|
|
InterlockedIncrement(&vkd3d_test_state.skip_count);
|
2016-09-21 03:57:24 -07:00
|
|
|
}
|
|
|
|
|
2016-10-17 05:24:22 -07:00
|
|
|
static void VKD3D_PRINTF_FUNC(2, 3) VKD3D_UNUSED
|
|
|
|
vkd3d_test_trace(unsigned int line, const char *fmt, ...)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
printf("%s:%d: ", vkd3d_test_name, line);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
static void VKD3D_PRINTF_FUNC(1, 2) VKD3D_UNUSED
|
|
|
|
vkd3d_test_debug(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
|
|
|
va_list args;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
size = snprintf(buffer, sizeof(buffer), "%s: ", vkd3d_test_name);
|
|
|
|
if (0 < size && size < sizeof(buffer))
|
|
|
|
{
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buffer + size, sizeof(buffer) - size, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
OutputDebugStringA(buffer);
|
|
|
|
#endif
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
if (vkd3d_test_state.debug_level > 0)
|
2016-11-09 05:46:37 -08:00
|
|
|
printf("%s\n", buffer);
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
int main(int argc, char **argv)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
2016-11-09 05:46:37 -08:00
|
|
|
const char *debug_level = getenv("VKD3D_TEST_DEBUG");
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
memset(&vkd3d_test_state, 0, sizeof(vkd3d_test_state));
|
2016-11-09 05:46:37 -08:00
|
|
|
vkd3d_test_state.debug_level = !debug_level ? 0 : atoi(debug_level);
|
2016-09-28 00:42:49 -07:00
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
vkd3d_test_main(argc, argv);
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2016-10-10 02:22:50 -07:00
|
|
|
printf("%s: %lu tests executed (%lu failures, %lu skipped, %lu todo).\n",
|
2016-09-21 03:57:24 -07:00
|
|
|
vkd3d_test_name,
|
2016-10-10 02:22:50 -07:00
|
|
|
(unsigned long)(vkd3d_test_state.success_count
|
|
|
|
+ vkd3d_test_state.failure_count + vkd3d_test_state.todo_count
|
|
|
|
+ vkd3d_test_state.todo_success_count),
|
|
|
|
(unsigned long)(vkd3d_test_state.failure_count
|
|
|
|
+ vkd3d_test_state.todo_success_count),
|
|
|
|
(unsigned long)vkd3d_test_state.skip_count,
|
|
|
|
(unsigned long)vkd3d_test_state.todo_count);
|
2016-09-21 03:57:24 -07:00
|
|
|
|
2016-09-28 00:42:49 -07:00
|
|
|
return vkd3d_test_state.failure_count || vkd3d_test_state.todo_success_count;
|
2016-09-21 03:57:24 -07:00
|
|
|
}
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
static char *vkd3d_test_strdupWtoA(WCHAR *str)
|
|
|
|
{
|
|
|
|
char *out;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!(len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL)))
|
|
|
|
return NULL;
|
|
|
|
if (!(out = malloc(len)))
|
|
|
|
return NULL;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, str, -1, out, len, NULL, NULL);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wmain(int argc, WCHAR **wargv)
|
|
|
|
{
|
|
|
|
char **argv;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
argv = malloc(argc * sizeof(*argv));
|
|
|
|
assert(argv);
|
|
|
|
for (i = 0; i < argc; ++i)
|
|
|
|
{
|
|
|
|
if (!(argv[i] = vkd3d_test_strdupWtoA(wargv[i])))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(i == argc);
|
|
|
|
|
|
|
|
ret = main(argc, argv);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i)
|
|
|
|
free(argv[i]);
|
|
|
|
free(argv);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2016-11-09 05:46:37 -08:00
|
|
|
typedef void (*vkd3d_test_pfn)(void);
|
|
|
|
|
|
|
|
static inline void vkd3d_run_test(const char *name, vkd3d_test_pfn test_pfn)
|
|
|
|
{
|
|
|
|
vkd3d_test_debug(name);
|
|
|
|
test_pfn();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define run_test(test_pfn) \
|
|
|
|
vkd3d_run_test(#test_pfn, test_pfn)
|
|
|
|
|
2016-10-24 04:20:09 -07:00
|
|
|
#endif /* __VKD3D_TEST_H */
|