blob: ba0e2f41f993bd1873d15460226e8f527f9fa1a2 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_TESTING_GTEST_SUPPORT_H_
6#define V8_TESTING_GTEST_SUPPORT_H_
7
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "testing/gtest/include/gtest/gtest.h"
9
10namespace testing {
11namespace internal {
12
13#define GET_TYPE_NAME(type) \
14 template <> \
15 inline std::string GetTypeName<type>() { \
16 return #type; \
17 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040018GET_TYPE_NAME(bool)
19GET_TYPE_NAME(signed char)
20GET_TYPE_NAME(unsigned char)
21GET_TYPE_NAME(short)
22GET_TYPE_NAME(unsigned short)
23GET_TYPE_NAME(int)
24GET_TYPE_NAME(unsigned int)
25GET_TYPE_NAME(long)
26GET_TYPE_NAME(unsigned long)
27GET_TYPE_NAME(long long)
28GET_TYPE_NAME(unsigned long long)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029GET_TYPE_NAME(float)
30GET_TYPE_NAME(double)
31#undef GET_TYPE_NAME
32
33
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034// TRACED_FOREACH(type, var, container) expands to a loop that assigns |var|
35// every item in the |container| and adds a SCOPED_TRACE() message for the
36// |var| while inside the loop body.
37#define TRACED_FOREACH(_type, _var, _container) \
38 for (_type const _var : _container) \
39 for (bool _done = false; !_done;) \
40 for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
41 !_done; _done = true)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042
43
44// TRACED_FORRANGE(type, var, low, high) expands to a loop that assigns |var|
45// every value in the range |low| to (including) |high| and adds a
46// SCOPED_TRACE() message for the |var| while inside the loop body.
47// TODO(bmeurer): Migrate to C++11 once we're ready.
48#define TRACED_FORRANGE(_type, _var, _low, _high) \
49 for (_type _i = _low; _i <= _high; ++_i) \
50 for (bool _done = false; !_done;) \
51 for (_type const _var = _i; !_done;) \
52 for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
53 !_done; _done = true)
54
55} // namespace internal
56} // namespace testing
57
58#endif // V8_TESTING_GTEST_SUPPORT_H_