38255
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
#include <stdlib.h>
|
|
26 |
#include <stdio.h>
|
|
27 |
|
|
28 |
#define GTEST_DONT_DEFINE_TEST 1
|
|
29 |
#include "gtest/gtest.h"
|
|
30 |
#ifdef assert
|
|
31 |
#undef assert
|
|
32 |
#endif
|
|
33 |
|
|
34 |
#define CONCAT(a, b) a ## b
|
|
35 |
|
|
36 |
#define TEST(category, name) GTEST_TEST(category, CONCAT(name, _test))
|
|
37 |
|
|
38 |
#define TEST_VM(category, name) GTEST_TEST(category, CONCAT(name, _test_vm))
|
|
39 |
|
|
40 |
#define TEST_VM_F(test_fixture, name) \
|
|
41 |
GTEST_TEST_(test_fixture, name ## _test_vm, test_fixture, \
|
|
42 |
::testing::internal::GetTypeId<test_fixture>())
|
|
43 |
|
|
44 |
#define TEST_OTHER_VM(category, name) \
|
|
45 |
static void test_ ## category ## _ ## name ## _(); \
|
|
46 |
\
|
|
47 |
static void child_ ## category ## _ ## name ## _() { \
|
|
48 |
::testing::GTEST_FLAG(throw_on_failure) = true; \
|
|
49 |
test_ ## category ## _ ## name ## _(); \
|
|
50 |
fprintf(stderr, "OKIDOKI"); \
|
|
51 |
exit(0); \
|
|
52 |
} \
|
|
53 |
\
|
|
54 |
TEST(category, CONCAT(name, _other_vm)) { \
|
|
55 |
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
|
|
56 |
::testing::ExitedWithCode(0), \
|
|
57 |
".*OKIDOKI.*"); \
|
|
58 |
} \
|
|
59 |
\
|
|
60 |
void test_ ## category ## _ ## name ## _()
|
|
61 |
|
|
62 |
#ifdef ASSERT
|
|
63 |
#define TEST_VM_ASSERT(category, name) \
|
|
64 |
static void test_ ## category ## _ ## name ## _(); \
|
|
65 |
\
|
|
66 |
static void child_ ## category ## _ ## name ## _() { \
|
|
67 |
::testing::GTEST_FLAG(throw_on_failure) = true; \
|
|
68 |
test_ ## category ## _ ## name ## _(); \
|
|
69 |
exit(0); \
|
|
70 |
} \
|
|
71 |
\
|
|
72 |
TEST(category, CONCAT(name, _vm_assert)) { \
|
|
73 |
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
|
|
74 |
::testing::ExitedWithCode(1), \
|
|
75 |
"assert failed"); \
|
|
76 |
} \
|
|
77 |
\
|
|
78 |
void test_ ## category ## _ ## name ## _()
|
|
79 |
#else
|
|
80 |
#define TEST_VM_ASSERT(...) \
|
|
81 |
TEST_VM_ASSERT is only available in debug builds
|
|
82 |
#endif
|
|
83 |
|
|
84 |
#ifdef ASSERT
|
|
85 |
#define TEST_VM_ASSERT_MSG(category, name, msg) \
|
|
86 |
static void test_ ## category ## _ ## name ## _(); \
|
|
87 |
\
|
|
88 |
static void child_ ## category ## _ ## name ## _() { \
|
|
89 |
::testing::GTEST_FLAG(throw_on_failure) = true; \
|
|
90 |
test_ ## category ## _ ## name ## _(); \
|
|
91 |
exit(0); \
|
|
92 |
} \
|
|
93 |
\
|
|
94 |
TEST(category, CONCAT(name, _vm_assert)) { \
|
|
95 |
ASSERT_EXIT(child_ ## category ## _ ## name ## _(), \
|
|
96 |
::testing::ExitedWithCode(1), \
|
|
97 |
"assert failed: " msg); \
|
|
98 |
} \
|
|
99 |
\
|
|
100 |
void test_ ## category ## _ ## name ## _()
|
|
101 |
#else
|
|
102 |
#define TEST_VM_ASSERT_MSG(...) \
|
|
103 |
TEST_VM_ASSERT_MSG is only available in debug builds
|
|
104 |
#endif
|