2016-09-21 03:57:24 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Józef Kucia for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VKD3D_TEST_H
|
|
|
|
#define __VKD3D_TEST_H
|
|
|
|
|
2016-10-10 02:22:50 -07:00
|
|
|
#include <inttypes.h>
|
2016-09-21 03:57:24 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-10-10 02:22:50 -07:00
|
|
|
#include "vkd3d_common.h"
|
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
static void vkd3d_test_main(void);
|
|
|
|
static const char *vkd3d_test_name;
|
|
|
|
|
|
|
|
#define START_TEST(name) static const char *vkd3d_test_name = #name; \
|
|
|
|
static void vkd3d_test_main(void)
|
|
|
|
|
|
|
|
#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) \
|
|
|
|
do { \
|
2016-10-10 02:22:50 -07:00
|
|
|
unsigned int vkd3d_line = line; \
|
2016-09-21 03:57:24 -07:00
|
|
|
VKD3D_TEST_OK
|
|
|
|
|
|
|
|
#define VKD3D_TEST_OK(args...) \
|
2016-10-10 02:22:50 -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) \
|
|
|
|
do { \
|
2016-10-10 02:22:50 -07:00
|
|
|
unsigned int vkd3d_line = line; \
|
2016-09-28 00:42:49 -07:00
|
|
|
VKD3D_TEST_TODO
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define VKD3D_TEST_TODO(args...) \
|
2016-10-10 02:22:50 -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-10 02:22:50 -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) \
|
|
|
|
do { \
|
2016-10-10 02:22:50 -07:00
|
|
|
unsigned int vkd3d_line = line; \
|
2016-09-21 03:57:24 -07:00
|
|
|
VKD3D_TEST_SKIP
|
|
|
|
|
|
|
|
#define VKD3D_TEST_SKIP(args...) \
|
2016-10-10 02:22:50 -07:00
|
|
|
vkd3d_test_skip(vkd3d_line, args); } while (0)
|
2016-09-21 03:57:24 -07:00
|
|
|
|
|
|
|
#define trace_(line) \
|
|
|
|
do { \
|
2016-10-10 02:22:50 -07:00
|
|
|
unsigned int vkd3d_line = line; \
|
2016-09-21 03:57:24 -07:00
|
|
|
VKD3D_TEST_TRACE
|
|
|
|
|
|
|
|
#define VKD3D_TEST_TRACE(args...) \
|
2016-10-10 02:22:50 -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
|
|
|
|
|
|
|
unsigned int debug;
|
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
|
|
|
|
vkd3d_test_ok(unsigned int line, int result, const char *fmt, ...)
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
{
|
2016-09-28 00:42:49 -07:00
|
|
|
if (vkd3d_test_state.debug)
|
|
|
|
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
|
|
|
|
vkd3d_test_todo(unsigned int line, int 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-09-30 00:58:43 -07:00
|
|
|
#ifdef _WIN32
|
2016-09-29 10:32:19 -07:00
|
|
|
int wmain(void)
|
2016-09-30 00:58:43 -07:00
|
|
|
#else
|
|
|
|
int main(void)
|
|
|
|
#endif
|
2016-09-21 03:57:24 -07:00
|
|
|
{
|
2016-09-28 00:42:49 -07:00
|
|
|
const char *vkd3d_test_debug;
|
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
memset(&vkd3d_test_state, 0, sizeof(vkd3d_test_state));
|
|
|
|
|
2016-09-28 00:42:49 -07:00
|
|
|
vkd3d_test_state.debug = (vkd3d_test_debug = getenv("VKD3D_TEST_DEBUG"))
|
|
|
|
&& (*vkd3d_test_debug == 'y' || *vkd3d_test_debug == '1');
|
|
|
|
|
2016-09-21 03:57:24 -07:00
|
|
|
vkd3d_test_main();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __VKD3D_TEST__H */
|