1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2014 the V8 project authors. All rights reserved. 2b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// found in the LICENSE file. 4b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 5b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#ifndef V8_TESTING_GTEST_SUPPORT_H_ 6b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define V8_TESTING_GTEST_SUPPORT_H_ 7b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 8b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#include "testing/gtest/include/gtest/gtest.h" 9b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 10b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace testing { 11b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochnamespace internal { 12b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 13b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define GET_TYPE_NAME(type) \ 14b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch template <> \ 15b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch inline std::string GetTypeName<type>() { \ 16b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return #type; \ 17b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch } 18958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(bool) 19958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(signed char) 20958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(unsigned char) 21958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(short) 22958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(unsigned short) 23958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(int) 24958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(unsigned int) 25958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(long) 26958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(unsigned long) 27958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(long long) 28958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierGET_TYPE_NAME(unsigned long long) 29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochGET_TYPE_NAME(float) 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochGET_TYPE_NAME(double) 31b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#undef GET_TYPE_NAME 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 34014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// TRACED_FOREACH(type, var, container) expands to a loop that assigns |var| 35014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// every item in the |container| and adds a SCOPED_TRACE() message for the 36014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// |var| while inside the loop body. 37014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch#define TRACED_FOREACH(_type, _var, _container) \ 38014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch for (_type const _var : _container) \ 39014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch for (bool _done = false; !_done;) \ 40014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \ 41014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch !_done; _done = true) 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// TRACED_FORRANGE(type, var, low, high) expands to a loop that assigns |var| 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// every value in the range |low| to (including) |high| and adds a 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// SCOPED_TRACE() message for the |var| while inside the loop body. 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// TODO(bmeurer): Migrate to C++11 once we're ready. 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#define TRACED_FORRANGE(_type, _var, _low, _high) \ 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for (_type _i = _low; _i <= _high; ++_i) \ 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for (bool _done = false; !_done;) \ 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for (_type const _var = _i; !_done;) \ 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \ 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch !_done; _done = true) 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} // namespace internal 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} // namespace testing 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch#endif // V8_TESTING_GTEST_SUPPORT_H_ 59