11cb0ef41Sopenharmony_ci// Copyright 2014 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_TESTING_GTEST_SUPPORT_H_
61cb0ef41Sopenharmony_ci#define V8_TESTING_GTEST_SUPPORT_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "testing/gtest/include/gtest/gtest.h"
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinamespace testing {
111cb0ef41Sopenharmony_cinamespace internal {
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#define GET_TYPE_NAME(type)                \
141cb0ef41Sopenharmony_ci  template <>                              \
151cb0ef41Sopenharmony_ci  inline std::string GetTypeName<type>() { \
161cb0ef41Sopenharmony_ci    return #type;                          \
171cb0ef41Sopenharmony_ci  }
181cb0ef41Sopenharmony_ciGET_TYPE_NAME(bool)
191cb0ef41Sopenharmony_ciGET_TYPE_NAME(signed char)
201cb0ef41Sopenharmony_ciGET_TYPE_NAME(unsigned char)
211cb0ef41Sopenharmony_ciGET_TYPE_NAME(short)
221cb0ef41Sopenharmony_ciGET_TYPE_NAME(unsigned short)
231cb0ef41Sopenharmony_ciGET_TYPE_NAME(int)
241cb0ef41Sopenharmony_ciGET_TYPE_NAME(unsigned int)
251cb0ef41Sopenharmony_ciGET_TYPE_NAME(long)
261cb0ef41Sopenharmony_ciGET_TYPE_NAME(unsigned long)
271cb0ef41Sopenharmony_ciGET_TYPE_NAME(long long)
281cb0ef41Sopenharmony_ciGET_TYPE_NAME(unsigned long long)
291cb0ef41Sopenharmony_ciGET_TYPE_NAME(float)
301cb0ef41Sopenharmony_ciGET_TYPE_NAME(double)
311cb0ef41Sopenharmony_ci#undef GET_TYPE_NAME
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci// TRACED_FOREACH(type, var, container) expands to a loop that assigns |var|
351cb0ef41Sopenharmony_ci// every item in the |container| and adds a SCOPED_TRACE() message for the
361cb0ef41Sopenharmony_ci// |var| while inside the loop body.
371cb0ef41Sopenharmony_ci#define TRACED_FOREACH(_type, _var, _container)                          \
381cb0ef41Sopenharmony_ci  for (_type const _var : _container)                                    \
391cb0ef41Sopenharmony_ci    for (bool _var##_done = false; !_var##_done;)                        \
401cb0ef41Sopenharmony_ci      for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
411cb0ef41Sopenharmony_ci           !_var##_done; _var##_done = true)
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci// TRACED_FORRANGE(type, var, low, high) expands to a loop that assigns |var|
441cb0ef41Sopenharmony_ci// every value in the range |low| to (including) |high| and adds a
451cb0ef41Sopenharmony_ci// SCOPED_TRACE() message for the |var| while inside the loop body.
461cb0ef41Sopenharmony_ci// TODO(bmeurer): Migrate to C++11 once we're ready.
471cb0ef41Sopenharmony_ci#define TRACED_FORRANGE(_type, _var, _low, _high)                          \
481cb0ef41Sopenharmony_ci  for (_type _var##_i = _low; _var##_i <= _high; ++_var##_i)               \
491cb0ef41Sopenharmony_ci    for (bool _var##_done = false; !_var##_done;)                          \
501cb0ef41Sopenharmony_ci      for (_type const _var = _var##_i; !_var##_done;)                     \
511cb0ef41Sopenharmony_ci        for (SCOPED_TRACE(::testing::Message() << #_var << " = " << _var); \
521cb0ef41Sopenharmony_ci             !_var##_done; _var##_done = true)
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci}  // namespace internal
551cb0ef41Sopenharmony_ci}  // namespace testing
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci#endif  // V8_TESTING_GTEST_SUPPORT_H_
58