gmock-internal-utils.h revision 79a367eb217fcd47e2beaf8c0f87fe6d5926f739
1e35fdd936d133bf8a48de140a3c666897588a05shiqian// Copyright 2007, Google Inc.
2e35fdd936d133bf8a48de140a3c666897588a05shiqian// All rights reserved.
3e35fdd936d133bf8a48de140a3c666897588a05shiqian//
4e35fdd936d133bf8a48de140a3c666897588a05shiqian// Redistribution and use in source and binary forms, with or without
5e35fdd936d133bf8a48de140a3c666897588a05shiqian// modification, are permitted provided that the following conditions are
6e35fdd936d133bf8a48de140a3c666897588a05shiqian// met:
7e35fdd936d133bf8a48de140a3c666897588a05shiqian//
8e35fdd936d133bf8a48de140a3c666897588a05shiqian//     * Redistributions of source code must retain the above copyright
9e35fdd936d133bf8a48de140a3c666897588a05shiqian// notice, this list of conditions and the following disclaimer.
10e35fdd936d133bf8a48de140a3c666897588a05shiqian//     * Redistributions in binary form must reproduce the above
11e35fdd936d133bf8a48de140a3c666897588a05shiqian// copyright notice, this list of conditions and the following disclaimer
12e35fdd936d133bf8a48de140a3c666897588a05shiqian// in the documentation and/or other materials provided with the
13e35fdd936d133bf8a48de140a3c666897588a05shiqian// distribution.
14e35fdd936d133bf8a48de140a3c666897588a05shiqian//     * Neither the name of Google Inc. nor the names of its
15e35fdd936d133bf8a48de140a3c666897588a05shiqian// contributors may be used to endorse or promote products derived from
16e35fdd936d133bf8a48de140a3c666897588a05shiqian// this software without specific prior written permission.
17e35fdd936d133bf8a48de140a3c666897588a05shiqian//
18e35fdd936d133bf8a48de140a3c666897588a05shiqian// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19e35fdd936d133bf8a48de140a3c666897588a05shiqian// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20e35fdd936d133bf8a48de140a3c666897588a05shiqian// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21e35fdd936d133bf8a48de140a3c666897588a05shiqian// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22e35fdd936d133bf8a48de140a3c666897588a05shiqian// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23e35fdd936d133bf8a48de140a3c666897588a05shiqian// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24e35fdd936d133bf8a48de140a3c666897588a05shiqian// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25e35fdd936d133bf8a48de140a3c666897588a05shiqian// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26e35fdd936d133bf8a48de140a3c666897588a05shiqian// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27e35fdd936d133bf8a48de140a3c666897588a05shiqian// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28e35fdd936d133bf8a48de140a3c666897588a05shiqian// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29e35fdd936d133bf8a48de140a3c666897588a05shiqian//
30e35fdd936d133bf8a48de140a3c666897588a05shiqian// Author: wan@google.com (Zhanyong Wan)
31e35fdd936d133bf8a48de140a3c666897588a05shiqian
32e35fdd936d133bf8a48de140a3c666897588a05shiqian// Google Mock - a framework for writing C++ mock classes.
33e35fdd936d133bf8a48de140a3c666897588a05shiqian//
34e35fdd936d133bf8a48de140a3c666897588a05shiqian// This file defines some utilities useful for implementing Google
35e35fdd936d133bf8a48de140a3c666897588a05shiqian// Mock.  They are subject to change without notice, so please DO NOT
36e35fdd936d133bf8a48de140a3c666897588a05shiqian// USE THEM IN USER CODE.
37e35fdd936d133bf8a48de140a3c666897588a05shiqian
38e35fdd936d133bf8a48de140a3c666897588a05shiqian#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
39e35fdd936d133bf8a48de140a3c666897588a05shiqian#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
40e35fdd936d133bf8a48de140a3c666897588a05shiqian
41e35fdd936d133bf8a48de140a3c666897588a05shiqian#include <stdio.h>
42e35fdd936d133bf8a48de140a3c666897588a05shiqian#include <ostream>  // NOLINT
43e35fdd936d133bf8a48de140a3c666897588a05shiqian#include <string>
44e35fdd936d133bf8a48de140a3c666897588a05shiqian
4553e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gmock/internal/gmock-generated-internal-utils.h"
4653e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gmock/internal/gmock-port.h"
4753e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gtest/gtest.h"
48e35fdd936d133bf8a48de140a3c666897588a05shiqian
49e35fdd936d133bf8a48de140a3c666897588a05shiqiannamespace testing {
50e35fdd936d133bf8a48de140a3c666897588a05shiqiannamespace internal {
51e35fdd936d133bf8a48de140a3c666897588a05shiqian
52ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan// Converts an identifier name to a space-separated list of lower-case
53ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan// words.  Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
54ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan// treated as one word.  For example, both "FooBar123" and
55ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan// "foo_bar_123" are converted to "foo bar 123".
56587c1b37c2f0b6d430fb13ce09326db0135b557cvladlosevGTEST_API_ string ConvertIdentifierNameToWords(const char* id_name);
57ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan
58e35fdd936d133bf8a48de140a3c666897588a05shiqian// PointeeOf<Pointer>::type is the type of a value pointed to by a
59e35fdd936d133bf8a48de140a3c666897588a05shiqian// Pointer, which can be either a smart pointer or a raw pointer.  The
60e35fdd936d133bf8a48de140a3c666897588a05shiqian// following default implementation is for the case where Pointer is a
61e35fdd936d133bf8a48de140a3c666897588a05shiqian// smart pointer.
62e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename Pointer>
63e35fdd936d133bf8a48de140a3c666897588a05shiqianstruct PointeeOf {
64e35fdd936d133bf8a48de140a3c666897588a05shiqian  // Smart pointer classes define type element_type as the type of
65e35fdd936d133bf8a48de140a3c666897588a05shiqian  // their pointees.
66e35fdd936d133bf8a48de140a3c666897588a05shiqian  typedef typename Pointer::element_type type;
67e35fdd936d133bf8a48de140a3c666897588a05shiqian};
68e35fdd936d133bf8a48de140a3c666897588a05shiqian// This specialization is for the raw pointer case.
69e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename T>
70e35fdd936d133bf8a48de140a3c666897588a05shiqianstruct PointeeOf<T*> { typedef T type; };  // NOLINT
71e35fdd936d133bf8a48de140a3c666897588a05shiqian
72e35fdd936d133bf8a48de140a3c666897588a05shiqian// GetRawPointer(p) returns the raw pointer underlying p when p is a
73e35fdd936d133bf8a48de140a3c666897588a05shiqian// smart pointer, or returns p itself when p is already a raw pointer.
74e35fdd936d133bf8a48de140a3c666897588a05shiqian// The following default implementation is for the smart pointer case.
75e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename Pointer>
76e35fdd936d133bf8a48de140a3c666897588a05shiqianinline typename Pointer::element_type* GetRawPointer(const Pointer& p) {
77e35fdd936d133bf8a48de140a3c666897588a05shiqian  return p.get();
78e35fdd936d133bf8a48de140a3c666897588a05shiqian}
79e35fdd936d133bf8a48de140a3c666897588a05shiqian// This overloaded version is for the raw pointer case.
80e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename Element>
81e35fdd936d133bf8a48de140a3c666897588a05shiqianinline Element* GetRawPointer(Element* p) { return p; }
82e35fdd936d133bf8a48de140a3c666897588a05shiqian
83e35fdd936d133bf8a48de140a3c666897588a05shiqian// This comparator allows linked_ptr to be stored in sets.
84e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename T>
85e35fdd936d133bf8a48de140a3c666897588a05shiqianstruct LinkedPtrLessThan {
8616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan  bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
87e35fdd936d133bf8a48de140a3c666897588a05shiqian                  const ::testing::internal::linked_ptr<T>& rhs) const {
88e35fdd936d133bf8a48de140a3c666897588a05shiqian    return lhs.get() < rhs.get();
89e35fdd936d133bf8a48de140a3c666897588a05shiqian  }
90e35fdd936d133bf8a48de140a3c666897588a05shiqian};
91e35fdd936d133bf8a48de140a3c666897588a05shiqian
9295b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// Symbian compilation can be done with wchar_t being either a native
9395b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// type or a typedef.  Using Google Mock with OpenC without wchar_t
9495b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// should require the definition of _STLP_NO_WCHAR_T.
9595b12332c345cee508a8e2b68e007280392506e0zhanyong.wan//
9695b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// MSVC treats wchar_t as a native type usually, but treats it as the
9795b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// same as unsigned short when the compiler option /Zc:wchar_t- is
9895b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// specified.  It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
9995b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// is a native type.
10095b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
10195b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
10295b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// wchar_t is a typedef.
10395b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#else
104658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan# define GMOCK_WCHAR_T_IS_NATIVE_ 1
10595b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#endif
10695b12332c345cee508a8e2b68e007280392506e0zhanyong.wan
10795b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
10895b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// Using them is a bad practice and not portable.  So DON'T use them.
10995b12332c345cee508a8e2b68e007280392506e0zhanyong.wan//
11095b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// Still, Google Mock is designed to work even if the user uses signed
11195b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// wchar_t or unsigned wchar_t (obviously, assuming the compiler
11295b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// supports them).
11395b12332c345cee508a8e2b68e007280392506e0zhanyong.wan//
11495b12332c345cee508a8e2b68e007280392506e0zhanyong.wan// To gcc,
11595b12332c345cee508a8e2b68e007280392506e0zhanyong.wan//   wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
11695b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#ifdef __GNUC__
117658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan// signed/unsigned wchar_t are valid types.
118658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan# define GMOCK_HAS_SIGNED_WCHAR_T_ 1
11995b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#endif
12095b12332c345cee508a8e2b68e007280392506e0zhanyong.wan
12116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// In what follows, we use the term "kind" to indicate whether a type
12216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// is bool, an integer type (excluding bool), a floating-point type,
12316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// or none of them.  This categorization is useful for determining
12416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// when a matcher argument type can be safely converted to another
12516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// type in the implementation of SafeMatcherCast.
12616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanenum TypeKind {
12716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan  kBool, kInteger, kFloatingPoint, kOther
12816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan};
12916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
13016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// KindOf<T>::value is the kind of type T.
13116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename T> struct KindOf {
13216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan  enum { value = kOther };  // The default kind.
13316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan};
13416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
13516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// This macro declares that the kind of 'type' is 'kind'.
13616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#define GMOCK_DECLARE_KIND_(type, kind) \
13716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan  template <> struct KindOf<type> { enum { value = kind }; }
13816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
13916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(bool, kBool);
14016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
14116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// All standard integer types.
14216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(char, kInteger);
14316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(signed char, kInteger);
14416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(unsigned char, kInteger);
14516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(short, kInteger);  // NOLINT
14616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(unsigned short, kInteger);  // NOLINT
14716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(int, kInteger);
14816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(unsigned int, kInteger);
14916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(long, kInteger);  // NOLINT
15016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(unsigned long, kInteger);  // NOLINT
15116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
15295b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#if GMOCK_WCHAR_T_IS_NATIVE_
15316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(wchar_t, kInteger);
15416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#endif
15516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
15616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Non-standard integer types.
15716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(Int64, kInteger);
15816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(UInt64, kInteger);
15916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
16016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// All standard floating-point types.
16116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(float, kFloatingPoint);
16216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(double, kFloatingPoint);
16316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanGMOCK_DECLARE_KIND_(long double, kFloatingPoint);
16416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
16516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#undef GMOCK_DECLARE_KIND_
16616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
16716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Evaluates to the kind of 'type'.
16816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#define GMOCK_KIND_OF_(type) \
16916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan  static_cast< ::testing::internal::TypeKind>( \
17016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan      ::testing::internal::KindOf<type>::value)
17116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
17216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Evaluates to true iff integer type T is signed.
17316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
17416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
17516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
17616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// is true iff arithmetic type From can be losslessly converted to
17716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// arithmetic type To.
17816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan//
17916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// It's the user's responsibility to ensure that both From and To are
18016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// raw (i.e. has no CV modifier, is not a pointer, and is not a
18116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// reference) built-in arithmetic types, kFromKind is the kind of
18216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// From, and kToKind is the kind of To; the value is
18316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// implementation-defined when the above pre-condition is violated.
18416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
18516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl : public false_type {};
18616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
18716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting bool to bool is lossless.
18816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <>
18916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
19016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public true_type {};  // NOLINT
19116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
19216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting bool to any integer type is lossless.
19316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename To>
19416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
19516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public true_type {};  // NOLINT
19616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
19716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting bool to any floating-point type is lossless.
19816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename To>
19916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
20016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public true_type {};  // NOLINT
20116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
20216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting an integer to bool is lossy.
20316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename From>
20416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
20516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public false_type {};  // NOLINT
20616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
20716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting an integer to another non-bool integer is lossless iff
20816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// the target type's range encloses the source type's range.
20916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename From, typename To>
21016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
21116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public bool_constant<
21216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan      // When converting from a smaller size to a larger size, we are
21316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan      // fine as long as we are not converting from signed to unsigned.
21416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan      ((sizeof(From) < sizeof(To)) &&
21516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan       (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
21616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan      // When converting between the same size, the signedness must match.
21716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan      ((sizeof(From) == sizeof(To)) &&
21816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan       (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {};  // NOLINT
21916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
22016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#undef GMOCK_IS_SIGNED_
22116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
22216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting an integer to a floating-point type may be lossy, since
22316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// the format of a floating-point number is implementation-defined.
22416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename From, typename To>
22516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
22616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public false_type {};  // NOLINT
22716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
22816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting a floating-point to bool is lossy.
22916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename From>
23016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
23116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public false_type {};  // NOLINT
23216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
23316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting a floating-point to an integer is lossy.
23416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename From, typename To>
23516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
23616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public false_type {};  // NOLINT
23716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
23816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Converting a floating-point to another floating-point is lossless
23916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// iff the target type is at least as big as the source type.
24016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename From, typename To>
24116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertibleImpl<
24216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan  kFloatingPoint, From, kFloatingPoint, To>
24316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public bool_constant<sizeof(From) <= sizeof(To)> {};  // NOLINT
24416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
24516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// LosslessArithmeticConvertible<From, To>::value is true iff arithmetic
24616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// type From can be losslessly converted to arithmetic type To.
24716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan//
24816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// It's the user's responsibility to ensure that both From and To are
24916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// raw (i.e. has no CV modifier, is not a pointer, and is not a
25016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// reference) built-in arithmetic types; the value is
25116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// implementation-defined when the above pre-condition is violated.
25216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename From, typename To>
25316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanstruct LosslessArithmeticConvertible
25416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan    : public LosslessArithmeticConvertibleImpl<
25516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan  GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {};  // NOLINT
25616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
257e35fdd936d133bf8a48de140a3c666897588a05shiqian// This interface knows how to report a Google Mock failure (either
258e35fdd936d133bf8a48de140a3c666897588a05shiqian// non-fatal or fatal).
259e35fdd936d133bf8a48de140a3c666897588a05shiqianclass FailureReporterInterface {
260e35fdd936d133bf8a48de140a3c666897588a05shiqian public:
261e35fdd936d133bf8a48de140a3c666897588a05shiqian  // The type of a failure (either non-fatal or fatal).
262e35fdd936d133bf8a48de140a3c666897588a05shiqian  enum FailureType {
263e35fdd936d133bf8a48de140a3c666897588a05shiqian    NONFATAL, FATAL
264e35fdd936d133bf8a48de140a3c666897588a05shiqian  };
265e35fdd936d133bf8a48de140a3c666897588a05shiqian
266e35fdd936d133bf8a48de140a3c666897588a05shiqian  virtual ~FailureReporterInterface() {}
267e35fdd936d133bf8a48de140a3c666897588a05shiqian
268e35fdd936d133bf8a48de140a3c666897588a05shiqian  // Reports a failure that occurred at the given source file location.
269e35fdd936d133bf8a48de140a3c666897588a05shiqian  virtual void ReportFailure(FailureType type, const char* file, int line,
270e35fdd936d133bf8a48de140a3c666897588a05shiqian                             const string& message) = 0;
271e35fdd936d133bf8a48de140a3c666897588a05shiqian};
272e35fdd936d133bf8a48de140a3c666897588a05shiqian
273e35fdd936d133bf8a48de140a3c666897588a05shiqian// Returns the failure reporter used by Google Mock.
274587c1b37c2f0b6d430fb13ce09326db0135b557cvladlosevGTEST_API_ FailureReporterInterface* GetFailureReporter();
275e35fdd936d133bf8a48de140a3c666897588a05shiqian
276e35fdd936d133bf8a48de140a3c666897588a05shiqian// Asserts that condition is true; aborts the process with the given
277e35fdd936d133bf8a48de140a3c666897588a05shiqian// message if condition is false.  We cannot use LOG(FATAL) or CHECK()
278e35fdd936d133bf8a48de140a3c666897588a05shiqian// as Google Mock might be used to mock the log sink itself.  We
279e35fdd936d133bf8a48de140a3c666897588a05shiqian// inline this function to prevent it from showing up in the stack
280e35fdd936d133bf8a48de140a3c666897588a05shiqian// trace.
281e35fdd936d133bf8a48de140a3c666897588a05shiqianinline void Assert(bool condition, const char* file, int line,
282e35fdd936d133bf8a48de140a3c666897588a05shiqian                   const string& msg) {
283e35fdd936d133bf8a48de140a3c666897588a05shiqian  if (!condition) {
284e35fdd936d133bf8a48de140a3c666897588a05shiqian    GetFailureReporter()->ReportFailure(FailureReporterInterface::FATAL,
285e35fdd936d133bf8a48de140a3c666897588a05shiqian                                        file, line, msg);
286e35fdd936d133bf8a48de140a3c666897588a05shiqian  }
287e35fdd936d133bf8a48de140a3c666897588a05shiqian}
288e35fdd936d133bf8a48de140a3c666897588a05shiqianinline void Assert(bool condition, const char* file, int line) {
289e35fdd936d133bf8a48de140a3c666897588a05shiqian  Assert(condition, file, line, "Assertion failed.");
290e35fdd936d133bf8a48de140a3c666897588a05shiqian}
291e35fdd936d133bf8a48de140a3c666897588a05shiqian
292e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that condition is true; generates a non-fatal failure if
293e35fdd936d133bf8a48de140a3c666897588a05shiqian// condition is false.
294e35fdd936d133bf8a48de140a3c666897588a05shiqianinline void Expect(bool condition, const char* file, int line,
295e35fdd936d133bf8a48de140a3c666897588a05shiqian                   const string& msg) {
296e35fdd936d133bf8a48de140a3c666897588a05shiqian  if (!condition) {
297e35fdd936d133bf8a48de140a3c666897588a05shiqian    GetFailureReporter()->ReportFailure(FailureReporterInterface::NONFATAL,
298e35fdd936d133bf8a48de140a3c666897588a05shiqian                                        file, line, msg);
299e35fdd936d133bf8a48de140a3c666897588a05shiqian  }
300e35fdd936d133bf8a48de140a3c666897588a05shiqian}
301e35fdd936d133bf8a48de140a3c666897588a05shiqianinline void Expect(bool condition, const char* file, int line) {
302e35fdd936d133bf8a48de140a3c666897588a05shiqian  Expect(condition, file, line, "Expectation failed.");
303e35fdd936d133bf8a48de140a3c666897588a05shiqian}
304e35fdd936d133bf8a48de140a3c666897588a05shiqian
305e35fdd936d133bf8a48de140a3c666897588a05shiqian// Severity level of a log.
306e35fdd936d133bf8a48de140a3c666897588a05shiqianenum LogSeverity {
307e35fdd936d133bf8a48de140a3c666897588a05shiqian  INFO = 0,
308ab29bb6fcd992d76625a139418e80599cd2c8823vladlosev  WARNING = 1
309e35fdd936d133bf8a48de140a3c666897588a05shiqian};
310e35fdd936d133bf8a48de140a3c666897588a05shiqian
311e35fdd936d133bf8a48de140a3c666897588a05shiqian// Valid values for the --gmock_verbose flag.
312e35fdd936d133bf8a48de140a3c666897588a05shiqian
313e35fdd936d133bf8a48de140a3c666897588a05shiqian// All logs (informational and warnings) are printed.
314e35fdd936d133bf8a48de140a3c666897588a05shiqianconst char kInfoVerbosity[] = "info";
315e35fdd936d133bf8a48de140a3c666897588a05shiqian// Only warnings are printed.
316e35fdd936d133bf8a48de140a3c666897588a05shiqianconst char kWarningVerbosity[] = "warning";
317e35fdd936d133bf8a48de140a3c666897588a05shiqian// No logs are printed.
318e35fdd936d133bf8a48de140a3c666897588a05shiqianconst char kErrorVerbosity[] = "error";
319e35fdd936d133bf8a48de140a3c666897588a05shiqian
3209413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan// Returns true iff a log with the given severity is visible according
3219413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan// to the --gmock_verbose flag.
322587c1b37c2f0b6d430fb13ce09326db0135b557cvladlosevGTEST_API_ bool LogIsVisible(LogSeverity severity);
3239413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan
324e35fdd936d133bf8a48de140a3c666897588a05shiqian// Prints the given message to stdout iff 'severity' >= the level
325e35fdd936d133bf8a48de140a3c666897588a05shiqian// specified by the --gmock_verbose flag.  If stack_frames_to_skip >=
326e35fdd936d133bf8a48de140a3c666897588a05shiqian// 0, also prints the stack trace excluding the top
327e35fdd936d133bf8a48de140a3c666897588a05shiqian// stack_frames_to_skip frames.  In opt mode, any positive
328e35fdd936d133bf8a48de140a3c666897588a05shiqian// stack_frames_to_skip is treated as 0, since we don't know which
329e35fdd936d133bf8a48de140a3c666897588a05shiqian// function calls will be inlined by the compiler and need to be
330e35fdd936d133bf8a48de140a3c666897588a05shiqian// conservative.
331587c1b37c2f0b6d430fb13ce09326db0135b557cvladlosevGTEST_API_ void Log(LogSeverity severity,
332587c1b37c2f0b6d430fb13ce09326db0135b557cvladlosev                    const string& message,
333587c1b37c2f0b6d430fb13ce09326db0135b557cvladlosev                    int stack_frames_to_skip);
334e35fdd936d133bf8a48de140a3c666897588a05shiqian
33516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// TODO(wan@google.com): group all type utilities together.
33616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan
337e35fdd936d133bf8a48de140a3c666897588a05shiqian// Type traits.
338e35fdd936d133bf8a48de140a3c666897588a05shiqian
339e35fdd936d133bf8a48de140a3c666897588a05shiqian// is_reference<T>::value is non-zero iff T is a reference type.
340e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename T> struct is_reference : public false_type {};
341e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename T> struct is_reference<T&> : public true_type {};
342e35fdd936d133bf8a48de140a3c666897588a05shiqian
343e35fdd936d133bf8a48de140a3c666897588a05shiqian// type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type.
344e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename T1, typename T2> struct type_equals : public false_type {};
345e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename T> struct type_equals<T, T> : public true_type {};
346e35fdd936d133bf8a48de140a3c666897588a05shiqian
347e35fdd936d133bf8a48de140a3c666897588a05shiqian// remove_reference<T>::type removes the reference from type T, if any.
34816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename T> struct remove_reference { typedef T type; };  // NOLINT
34916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wantemplate <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT
350e35fdd936d133bf8a48de140a3c666897588a05shiqian
351e35fdd936d133bf8a48de140a3c666897588a05shiqian// Invalid<T>() returns an invalid value of type T.  This is useful
352e35fdd936d133bf8a48de140a3c666897588a05shiqian// when a value of type T is needed for compilation, but the statement
353e35fdd936d133bf8a48de140a3c666897588a05shiqian// will not really be executed (or we don't care if the statement
354e35fdd936d133bf8a48de140a3c666897588a05shiqian// crashes).
355e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <typename T>
356e35fdd936d133bf8a48de140a3c666897588a05shiqianinline T Invalid() {
35779a367eb217fcd47e2beaf8c0f87fe6d5926f739jgm  return const_cast<typename remove_reference<T>::type&>(
35879a367eb217fcd47e2beaf8c0f87fe6d5926f739jgm      *static_cast<volatile typename remove_reference<T>::type*>(NULL));
359e35fdd936d133bf8a48de140a3c666897588a05shiqian}
360e35fdd936d133bf8a48de140a3c666897588a05shiqiantemplate <>
361e35fdd936d133bf8a48de140a3c666897588a05shiqianinline void Invalid<void>() {}
362e35fdd936d133bf8a48de140a3c666897588a05shiqian
363b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// Given a raw type (i.e. having no top-level reference or const
364b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// modifier) RawContainer that's either an STL-style container or a
365b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// native array, class StlContainerView<RawContainer> has the
366b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// following members:
367b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//
368b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//   - type is a type that provides an STL-style container view to
369b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//     (i.e. implements the STL container concept for) RawContainer;
370b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//   - const_reference is a type that provides a reference to a const
371b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//     RawContainer;
372b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//   - ConstReference(raw_container) returns a const reference to an STL-style
373b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//     container view to raw_container, which is a RawContainer.
374b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//   - Copy(raw_container) returns an STL-style container view of a
375b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//     copy of raw_container, which is a RawContainer.
376b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan//
377b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// This generic version is used when RawContainer itself is already an
378b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// STL-style container.
379b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wantemplate <class RawContainer>
380b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanclass StlContainerView {
381b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan public:
382b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  typedef RawContainer type;
383b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  typedef const type& const_reference;
384b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan
385b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  static const_reference ConstReference(const RawContainer& container) {
386b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan    // Ensures that RawContainer is not a const type.
387b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan    testing::StaticAssertTypeEq<RawContainer,
38802f7106557fde1f1075dc53d65ef1f7a11851f93zhanyong.wan        GTEST_REMOVE_CONST_(RawContainer)>();
389b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan    return container;
390b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  }
391b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  static type Copy(const RawContainer& container) { return container; }
392b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan};
393b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan
394b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// This specialization is used when RawContainer is a native array type.
395b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wantemplate <typename Element, size_t N>
396b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanclass StlContainerView<Element[N]> {
397b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan public:
39802f7106557fde1f1075dc53d65ef1f7a11851f93zhanyong.wan  typedef GTEST_REMOVE_CONST_(Element) RawElement;
399b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  typedef internal::NativeArray<RawElement> type;
400b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  // NativeArray<T> can represent a native array either by value or by
401b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  // reference (selected by a constructor argument), so 'const type'
402b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  // can be used to reference a const native array.  We cannot
403b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  // 'typedef const type& const_reference' here, as that would mean
404b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  // ConstReference() has to return a reference to a local variable.
405b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  typedef const type const_reference;
406b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan
407b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  static const_reference ConstReference(const Element (&array)[N]) {
408b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan    // Ensures that Element is not a const type.
409b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan    testing::StaticAssertTypeEq<Element, RawElement>();
41095b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#if GTEST_OS_SYMBIAN
41195b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // The Nokia Symbian compiler confuses itself in template instantiation
41295b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // for this call without the cast to Element*:
41395b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // function call '[testing::internal::NativeArray<char *>].NativeArray(
41495b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    //     {lval} const char *[4], long, testing::internal::RelationToSource)'
41595b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    //     does not match
41695b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // 'testing::internal::NativeArray<char *>::NativeArray(
41795b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    //     char *const *, unsigned int, testing::internal::RelationToSource)'
41895b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // (instantiating: 'testing::internal::ContainsMatcherImpl
41995b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    //     <const char * (&)[4]>::Matches(const char * (&)[4]) const')
42095b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // (instantiating: 'testing::internal::StlContainerView<char *[4]>::
42195b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    //     ConstReference(const char * (&)[4])')
42295b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // (and though the N parameter type is mismatched in the above explicit
42395b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    // conversion of it doesn't help - only the conversion of the array).
42495b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    return type(const_cast<Element*>(&array[0]), N, kReference);
42595b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#else
4264bd79e4f25a86f3a2a99f6af06cc43cdacc55853zhanyong.wan    return type(array, N, kReference);
42795b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#endif  // GTEST_OS_SYMBIAN
428b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  }
429b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  static type Copy(const Element (&array)[N]) {
43095b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#if GTEST_OS_SYMBIAN
43195b12332c345cee508a8e2b68e007280392506e0zhanyong.wan    return type(const_cast<Element*>(&array[0]), N, kCopy);
43295b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#else
4334bd79e4f25a86f3a2a99f6af06cc43cdacc55853zhanyong.wan    return type(array, N, kCopy);
43495b12332c345cee508a8e2b68e007280392506e0zhanyong.wan#endif  // GTEST_OS_SYMBIAN
435b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  }
436b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan};
437b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan
438b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// This specialization is used when RawContainer is a native array
439b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// represented as a (pointer, size) tuple.
440b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wantemplate <typename ElementPointer, typename Size>
441b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanclass StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > {
442b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan public:
44302f7106557fde1f1075dc53d65ef1f7a11851f93zhanyong.wan  typedef GTEST_REMOVE_CONST_(
444b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan      typename internal::PointeeOf<ElementPointer>::type) RawElement;
445b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  typedef internal::NativeArray<RawElement> type;
446b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  typedef const type const_reference;
447b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan
448b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  static const_reference ConstReference(
449b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan      const ::std::tr1::tuple<ElementPointer, Size>& array) {
4504bd79e4f25a86f3a2a99f6af06cc43cdacc55853zhanyong.wan    using ::std::tr1::get;
4514bd79e4f25a86f3a2a99f6af06cc43cdacc55853zhanyong.wan    return type(get<0>(array), get<1>(array), kReference);
452b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  }
453b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) {
4544bd79e4f25a86f3a2a99f6af06cc43cdacc55853zhanyong.wan    using ::std::tr1::get;
4554bd79e4f25a86f3a2a99f6af06cc43cdacc55853zhanyong.wan    return type(get<0>(array), get<1>(array), kCopy);
456b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan  }
457b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan};
458b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan
459b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// The following specialization prevents the user from instantiating
460b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// StlContainer with a reference type.
461b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wantemplate <typename T> class StlContainerView<T&>;
462b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan
46379a367eb217fcd47e2beaf8c0f87fe6d5926f739jgm// Mapping from booleans to types. Similar to boost::bool_<kValue> and
46479a367eb217fcd47e2beaf8c0f87fe6d5926f739jgm// std::integral_constant<bool, kValue>.
46579a367eb217fcd47e2beaf8c0f87fe6d5926f739jgmtemplate <bool kValue>
46679a367eb217fcd47e2beaf8c0f87fe6d5926f739jgmstruct BooleanConstant {};
46779a367eb217fcd47e2beaf8c0f87fe6d5926f739jgm
468e35fdd936d133bf8a48de140a3c666897588a05shiqian}  // namespace internal
469e35fdd936d133bf8a48de140a3c666897588a05shiqian}  // namespace testing
470e35fdd936d133bf8a48de140a3c666897588a05shiqian
471e35fdd936d133bf8a48de140a3c666897588a05shiqian#endif  // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
472