blob: 04daa55edcf211dbba01a6e01aef03ee6e8d773f [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
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include <stddef.h>
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "testing/gtest/include/gtest/gtest.h"
10
11namespace testing {
12namespace internal {
13
14#define GET_TYPE_NAME(type) \
15 template <> \
16 inline std::string GetTypeName<type>() { \
17 return #type; \
18 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040019GET_TYPE_NAME(bool)
20GET_TYPE_NAME(signed char)
21GET_TYPE_NAME(unsigned char)
22GET_TYPE_NAME(short)
23GET_TYPE_NAME(unsigned short)
24GET_TYPE_NAME(int)
25GET_TYPE_NAME(unsigned int)
26GET_TYPE_NAME(long)
27GET_TYPE_NAME(unsigned long)
28GET_TYPE_NAME(long long)
29GET_TYPE_NAME(unsigned long long)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030GET_TYPE_NAME(float)
31GET_TYPE_NAME(double)
32#undef GET_TYPE_NAME
33
34
35// TRACED_FOREACH(type, var, array) expands to a loop that assigns |var| every
36// item in the |array| and adds a SCOPED_TRACE() message for the |var| while
37// inside the loop body.
38// TODO(bmeurer): Migrate to C++11 once we're ready.
39#define TRACED_FOREACH(_type, _var, _array) \
40 for (size_t _i = 0; _i < arraysize(_array); ++_i) \
41 for (bool _done = false; !_done;) \
42 for (_type const _var = _array[_i]; !_done;) \
43 for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
44 !_done; _done = true)
45
46
47// TRACED_FORRANGE(type, var, low, high) expands to a loop that assigns |var|
48// every value in the range |low| to (including) |high| and adds a
49// SCOPED_TRACE() message for the |var| while inside the loop body.
50// TODO(bmeurer): Migrate to C++11 once we're ready.
51#define TRACED_FORRANGE(_type, _var, _low, _high) \
52 for (_type _i = _low; _i <= _high; ++_i) \
53 for (bool _done = false; !_done;) \
54 for (_type const _var = _i; !_done;) \
55 for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
56 !_done; _done = true)
57
58} // namespace internal
59} // namespace testing
60
61#endif // V8_TESTING_GTEST_SUPPORT_H_