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 tests the internal utilities. 35e35fdd936d133bf8a48de140a3c666897588a05shiqian 3653e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gmock/internal/gmock-internal-utils.h" 3716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#include <stdlib.h> 38e35fdd936d133bf8a48de140a3c666897588a05shiqian#include <map> 39b78f858d0c12cc71d41607b261e3cfd6c6bfa185Billy Donahue#include <memory> 40e35fdd936d133bf8a48de140a3c666897588a05shiqian#include <string> 41e35fdd936d133bf8a48de140a3c666897588a05shiqian#include <sstream> 42e35fdd936d133bf8a48de140a3c666897588a05shiqian#include <vector> 4353e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gmock/gmock.h" 4453e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gmock/internal/gmock-port.h" 4553e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gtest/gtest.h" 4653e08c44dd34857ba57581d7c5774d6c96a8d0e1zhanyong.wan#include "gtest/gtest-spi.h" 47e35fdd936d133bf8a48de140a3c666897588a05shiqian 48e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak// Indicates that this translation unit is part of Google Test's 49e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak// implementation. It must come before gtest-internal-inl.h is 50e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak// included, or there will be a compiler error. This trick is to 51e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak// prevent a user from accidentally including gtest-internal-inl.h in 52e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak// his code. 53e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak#define GTEST_IMPLEMENTATION_ 1 54e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak#include "src/gtest-internal-inl.h" 55e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak#undef GTEST_IMPLEMENTATION_ 56e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 5716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#if GTEST_OS_CYGWIN 58658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan# include <sys/types.h> // For ssize_t. NOLINT 5916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#endif 6016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 610ea67f88aea208e7ef13c91b374b352679beab38zhanyong.wanclass ProtocolMessage; 620ea67f88aea208e7ef13c91b374b352679beab38zhanyong.wan 630ea67f88aea208e7ef13c91b374b352679beab38zhanyong.wannamespace proto2 { 640ea67f88aea208e7ef13c91b374b352679beab38zhanyong.wanclass Message; 650ea67f88aea208e7ef13c91b374b352679beab38zhanyong.wan} // namespace proto2 660ea67f88aea208e7ef13c91b374b352679beab38zhanyong.wan 67e35fdd936d133bf8a48de140a3c666897588a05shiqiannamespace testing { 68e35fdd936d133bf8a48de140a3c666897588a05shiqiannamespace internal { 69e35fdd936d133bf8a48de140a3c666897588a05shiqian 70e35fdd936d133bf8a48de140a3c666897588a05shiqiannamespace { 71e35fdd936d133bf8a48de140a3c666897588a05shiqian 72ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wanTEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) { 73ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("", ConvertIdentifierNameToWords("")); 74ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("", ConvertIdentifierNameToWords("_")); 75ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("", ConvertIdentifierNameToWords("__")); 76ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan} 77ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan 78ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wanTEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) { 79ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("1", ConvertIdentifierNameToWords("_1")); 80ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("2", ConvertIdentifierNameToWords("2_")); 81ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("34", ConvertIdentifierNameToWords("_34_")); 82ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("34 56", ConvertIdentifierNameToWords("_34_56")); 83ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan} 84ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan 85ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wanTEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) { 86ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("a big word", ConvertIdentifierNameToWords("ABigWord")); 87ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("FooBar")); 88ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo", ConvertIdentifierNameToWords("Foo_")); 89ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_Foo_Bar_")); 90ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_Foo__And_Bar")); 91ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan} 92ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan 93ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wanTEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) { 94ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("foo_bar")); 95ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo", ConvertIdentifierNameToWords("_foo_")); 96ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_foo_bar_")); 97ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_foo__and_bar")); 98ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan} 99ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan 100ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wanTEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) { 101ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("foo bar 123", ConvertIdentifierNameToWords("Foo_bar123")); 102ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan EXPECT_EQ("chapter 11 section 1", 103ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan ConvertIdentifierNameToWords("_Chapter11Section_1_")); 104ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan} 105ce198ff8997775d63b802615ee0cea5886ab82abzhanyong.wan 106e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(PointeeOfTest, WorksForSmartPointers) { 107e35fdd936d133bf8a48de140a3c666897588a05shiqian CompileAssertTypesEqual<const char, 108e35fdd936d133bf8a48de140a3c666897588a05shiqian PointeeOf<internal::linked_ptr<const char> >::type>(); 109cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#if GTEST_HAS_STD_UNIQUE_PTR_ 110cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>(); 111cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#endif // GTEST_HAS_STD_UNIQUE_PTR_ 112cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#if GTEST_HAS_STD_SHARED_PTR_ 113cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak CompileAssertTypesEqual<std::string, 114cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak PointeeOf<std::shared_ptr<std::string> >::type>(); 115cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#endif // GTEST_HAS_STD_SHARED_PTR_ 116e35fdd936d133bf8a48de140a3c666897588a05shiqian} 117e35fdd936d133bf8a48de140a3c666897588a05shiqian 118e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(PointeeOfTest, WorksForRawPointers) { 119e35fdd936d133bf8a48de140a3c666897588a05shiqian CompileAssertTypesEqual<int, PointeeOf<int*>::type>(); 120e35fdd936d133bf8a48de140a3c666897588a05shiqian CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>(); 121e35fdd936d133bf8a48de140a3c666897588a05shiqian CompileAssertTypesEqual<void, PointeeOf<void*>::type>(); 122e35fdd936d133bf8a48de140a3c666897588a05shiqian} 123e35fdd936d133bf8a48de140a3c666897588a05shiqian 124e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(GetRawPointerTest, WorksForSmartPointers) { 125cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#if GTEST_HAS_STD_UNIQUE_PTR_ 126cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak const char* const raw_p1 = new const char('a'); // NOLINT 127cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak const std::unique_ptr<const char> p1(raw_p1); 128cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak EXPECT_EQ(raw_p1, GetRawPointer(p1)); 129cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#endif // GTEST_HAS_STD_UNIQUE_PTR_ 130cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#if GTEST_HAS_STD_SHARED_PTR_ 131cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak double* const raw_p2 = new double(2.5); // NOLINT 132cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak const std::shared_ptr<double> p2(raw_p2); 133cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak EXPECT_EQ(raw_p2, GetRawPointer(p2)); 134cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak#endif // GTEST_HAS_STD_SHARED_PTR_ 135cac6c1bb539692045d6a6cf1d562aa56ac33d387kosak 136e35fdd936d133bf8a48de140a3c666897588a05shiqian const char* const raw_p4 = new const char('a'); // NOLINT 137e35fdd936d133bf8a48de140a3c666897588a05shiqian const internal::linked_ptr<const char> p4(raw_p4); 138e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_EQ(raw_p4, GetRawPointer(p4)); 139e35fdd936d133bf8a48de140a3c666897588a05shiqian} 140e35fdd936d133bf8a48de140a3c666897588a05shiqian 141e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(GetRawPointerTest, WorksForRawPointers) { 142e35fdd936d133bf8a48de140a3c666897588a05shiqian int* p = NULL; 14395b12332c345cee508a8e2b68e007280392506e0zhanyong.wan // Don't use EXPECT_EQ as no NULL-testing magic on Symbian. 14495b12332c345cee508a8e2b68e007280392506e0zhanyong.wan EXPECT_TRUE(NULL == GetRawPointer(p)); 145e35fdd936d133bf8a48de140a3c666897588a05shiqian int n = 1; 146e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_EQ(&n, GetRawPointer(&n)); 147e35fdd936d133bf8a48de140a3c666897588a05shiqian} 148e35fdd936d133bf8a48de140a3c666897588a05shiqian 14902f7106557fde1f1075dc53d65ef1f7a11851f93zhanyong.wan// Tests KindOf<T>. 15002f7106557fde1f1075dc53d65ef1f7a11851f93zhanyong.wan 151e35fdd936d133bf8a48de140a3c666897588a05shiqianclass Base {}; 152e35fdd936d133bf8a48de140a3c666897588a05shiqianclass Derived : public Base {}; 153e35fdd936d133bf8a48de140a3c666897588a05shiqian 15416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(KindOfTest, Bool) { 15516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool)); // NOLINT 15616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 15716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 15816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(KindOfTest, Integer) { 15916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT 16016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT 16116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT 16216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT 16316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT 16416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT 16516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT 16616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT 16716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT 16816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT 16916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(Int64)); // NOLINT 17016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(UInt64)); // NOLINT 17116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT 17216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN 17316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // ssize_t is not defined on Windows and possibly some other OSes. 17416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT 17516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan#endif 17616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 17716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 17816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(KindOfTest, FloatingPoint) { 17916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT 18016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT 18116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(long double)); // NOLINT 18216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 18316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 18416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(KindOfTest, Other) { 18516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*)); // NOLINT 18616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kOther, GMOCK_KIND_OF_(char**)); // NOLINT 18716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base)); // NOLINT 18816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 18916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 19016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan// Tests LosslessArithmeticConvertible<T, U>. 19116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 19216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, BoolToBool) { 19316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<bool, bool>::value)); 19416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 19516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 19616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, BoolToInteger) { 19716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<bool, char>::value)); 19816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<bool, int>::value)); 19916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE( 20016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan (LosslessArithmeticConvertible<bool, unsigned long>::value)); // NOLINT 20116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 20216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 20316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) { 20416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<bool, float>::value)); 20516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<bool, double>::value)); 20616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 20716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 20816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, IntegerToBool) { 20916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<unsigned char, bool>::value)); 21016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<int, bool>::value)); 21116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 21216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 21316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, IntegerToInteger) { 21416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Unsigned => larger signed is fine. 21516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value)); 21616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 21716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Unsigned => larger unsigned is fine. 21816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE( 21916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan (LosslessArithmeticConvertible<unsigned short, UInt64>::value)); // NOLINT 22016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 22116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Signed => unsigned is not fine. 22216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value)); // NOLINT 22316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible< 22416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan signed char, unsigned int>::value)); // NOLINT 22516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 22616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Same size and same signedness: fine too. 22716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible< 22816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan unsigned char, unsigned char>::value)); 22916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value)); 23016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value)); 23116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible< 23216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan unsigned long, unsigned long>::value)); // NOLINT 23316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 23416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Same size, different signedness: not fine. 23516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible< 23616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan unsigned char, signed char>::value)); 23716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value)); 23816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value)); 23916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 24016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Larger size => smaller size is not fine. 24116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value)); // NOLINT 24216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value)); 24316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<Int64, unsigned int>::value)); 24416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 24516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 24616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) { 24716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Integers cannot be losslessly converted to floating-points, as 24816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // the format of the latter is implementation-defined. 24916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value)); 25016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value)); 25116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible< 25216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan short, long double>::value)); // NOLINT 25316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 25416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 25516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) { 25616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<float, bool>::value)); 25716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<double, bool>::value)); 25816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 25916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 26016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) { 26116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value)); // NOLINT 26216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value)); 26316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value)); 26416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 26516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 26616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wanTEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) { 26716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Smaller size => larger size is fine. 26816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<float, double>::value)); 26916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<float, long double>::value)); 27016cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<double, long double>::value)); 27116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 27216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Same size: fine. 27316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<float, float>::value)); 27416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<double, double>::value)); 27516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 27616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // Larger size => smaller size is not fine. 27716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value)); 2781f5fdea417f1a55cffcfc0711d345d1d8ca2bc01billydonahue GTEST_INTENTIONAL_CONST_COND_PUSH_() 27916cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan if (sizeof(double) == sizeof(long double)) { // NOLINT 2801f5fdea417f1a55cffcfc0711d345d1d8ca2bc01billydonahue GTEST_INTENTIONAL_CONST_COND_POP_() 28116cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // In some implementations (e.g. MSVC), double and long double 28216cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan // have the same size. 28316cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value)); 28416cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan } else { 28516cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan EXPECT_FALSE((LosslessArithmeticConvertible<long double, double>::value)); 28616cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan } 28716cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan} 28816cf473930c01cd7a1a51dff65f22c541fbad5b8zhanyong.wan 289e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests the TupleMatches() template function. 290e35fdd936d133bf8a48de140a3c666897588a05shiqian 291e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TupleMatchesTest, WorksForSize0) { 292e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<> matchers; 293e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<> values; 294e35fdd936d133bf8a48de140a3c666897588a05shiqian 295e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(TupleMatches(matchers, values)); 296e35fdd936d133bf8a48de140a3c666897588a05shiqian} 297e35fdd936d133bf8a48de140a3c666897588a05shiqian 298e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TupleMatchesTest, WorksForSize1) { 299e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<Matcher<int> > matchers(Eq(1)); 300e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<int> values1(1), 301e35fdd936d133bf8a48de140a3c666897588a05shiqian values2(2); 302e35fdd936d133bf8a48de140a3c666897588a05shiqian 303e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(TupleMatches(matchers, values1)); 304e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values2)); 305e35fdd936d133bf8a48de140a3c666897588a05shiqian} 306e35fdd936d133bf8a48de140a3c666897588a05shiqian 307e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TupleMatchesTest, WorksForSize2) { 308e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a')); 309e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<int, char> values1(1, 'a'), 310e35fdd936d133bf8a48de140a3c666897588a05shiqian values2(1, 'b'), 311e35fdd936d133bf8a48de140a3c666897588a05shiqian values3(2, 'a'), 312e35fdd936d133bf8a48de140a3c666897588a05shiqian values4(2, 'b'); 313e35fdd936d133bf8a48de140a3c666897588a05shiqian 314e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(TupleMatches(matchers, values1)); 315e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values2)); 316e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values3)); 317e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values4)); 318e35fdd936d133bf8a48de140a3c666897588a05shiqian} 319e35fdd936d133bf8a48de140a3c666897588a05shiqian 320e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TupleMatchesTest, WorksForSize5) { 321e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>, // NOLINT 322e35fdd936d133bf8a48de140a3c666897588a05shiqian Matcher<string> > 323e35fdd936d133bf8a48de140a3c666897588a05shiqian matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi")); 324e35fdd936d133bf8a48de140a3c666897588a05shiqian tuple<int, char, bool, long, string> // NOLINT 325e35fdd936d133bf8a48de140a3c666897588a05shiqian values1(1, 'a', true, 2L, "hi"), 326e35fdd936d133bf8a48de140a3c666897588a05shiqian values2(1, 'a', true, 2L, "hello"), 327e35fdd936d133bf8a48de140a3c666897588a05shiqian values3(2, 'a', true, 2L, "hi"); 328e35fdd936d133bf8a48de140a3c666897588a05shiqian 329e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(TupleMatches(matchers, values1)); 330e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values2)); 331e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values3)); 332e35fdd936d133bf8a48de140a3c666897588a05shiqian} 333e35fdd936d133bf8a48de140a3c666897588a05shiqian 334e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Assert(true, ...) succeeds. 335e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(AssertTest, SucceedsOnTrue) { 336e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(true, __FILE__, __LINE__, "This should succeed."); 337e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(true, __FILE__, __LINE__); // This should succeed too. 338e35fdd936d133bf8a48de140a3c666897588a05shiqian} 339e35fdd936d133bf8a48de140a3c666897588a05shiqian 340e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Assert(false, ...) generates a fatal failure. 341e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(AssertTest, FailsFatallyOnFalse) { 34204d6ed817e40f676225e0bf20ff1470d8f0c4a20zhanyong.wan EXPECT_DEATH_IF_SUPPORTED({ 343e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(false, __FILE__, __LINE__, "This should fail."); 344e35fdd936d133bf8a48de140a3c666897588a05shiqian }, ""); 345e35fdd936d133bf8a48de140a3c666897588a05shiqian 34604d6ed817e40f676225e0bf20ff1470d8f0c4a20zhanyong.wan EXPECT_DEATH_IF_SUPPORTED({ 347e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(false, __FILE__, __LINE__); 348e35fdd936d133bf8a48de140a3c666897588a05shiqian }, ""); 349e35fdd936d133bf8a48de140a3c666897588a05shiqian} 350e35fdd936d133bf8a48de140a3c666897588a05shiqian 351e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Expect(true, ...) succeeds. 352e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectTest, SucceedsOnTrue) { 353e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(true, __FILE__, __LINE__, "This should succeed."); 354e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(true, __FILE__, __LINE__); // This should succeed too. 355e35fdd936d133bf8a48de140a3c666897588a05shiqian} 356e35fdd936d133bf8a48de140a3c666897588a05shiqian 357e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Expect(false, ...) generates a non-fatal failure. 358e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectTest, FailsNonfatallyOnFalse) { 359e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_NONFATAL_FAILURE({ // NOLINT 360e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(false, __FILE__, __LINE__, "This should fail."); 361e35fdd936d133bf8a48de140a3c666897588a05shiqian }, "This should fail"); 362e35fdd936d133bf8a48de140a3c666897588a05shiqian 363e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_NONFATAL_FAILURE({ // NOLINT 364e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(false, __FILE__, __LINE__); 365e35fdd936d133bf8a48de140a3c666897588a05shiqian }, "Expectation failed"); 366e35fdd936d133bf8a48de140a3c666897588a05shiqian} 367e35fdd936d133bf8a48de140a3c666897588a05shiqian 3689413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan// Tests LogIsVisible(). 3699413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3709413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanclass LogIsVisibleTest : public ::testing::Test { 3719413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan protected: 37281476f2f9070186027e7337854bbcf693b85c6c6zhanyong.wan virtual void SetUp() { 37338513a8bb154f0b6d0a4088814fe92552696d465jgm original_verbose_ = GMOCK_FLAG(verbose); 37481476f2f9070186027e7337854bbcf693b85c6c6zhanyong.wan } 37581476f2f9070186027e7337854bbcf693b85c6c6zhanyong.wan 3769413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; } 3779413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3789413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan string original_verbose_; 3799413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan}; 3809413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3819413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanTEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) { 3829413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan GMOCK_FLAG(verbose) = kInfoVerbosity; 3832fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_TRUE(LogIsVisible(kInfo)); 3842fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_TRUE(LogIsVisible(kWarning)); 3859413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan} 3869413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3879413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanTEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) { 3889413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan GMOCK_FLAG(verbose) = kErrorVerbosity; 3892fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_FALSE(LogIsVisible(kInfo)); 3902fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_FALSE(LogIsVisible(kWarning)); 3919413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan} 3929413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3939413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanTEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) { 3949413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan GMOCK_FLAG(verbose) = kWarningVerbosity; 3952fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_FALSE(LogIsVisible(kInfo)); 3962fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_TRUE(LogIsVisible(kWarning)); 3979413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan} 3989413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3992516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#if GTEST_HAS_STREAM_REDIRECTION 400e35fdd936d133bf8a48de140a3c666897588a05shiqian 401e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests the Log() function. 402e35fdd936d133bf8a48de140a3c666897588a05shiqian 403e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that Log() behaves correctly for the given verbosity level 404e35fdd936d133bf8a48de140a3c666897588a05shiqian// and log severity. 405e35fdd936d133bf8a48de140a3c666897588a05shiqianvoid TestLogWithSeverity(const string& verbosity, LogSeverity severity, 406e35fdd936d133bf8a48de140a3c666897588a05shiqian bool should_print) { 407e35fdd936d133bf8a48de140a3c666897588a05shiqian const string old_flag = GMOCK_FLAG(verbose); 408e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = verbosity; 409470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 410e35fdd936d133bf8a48de140a3c666897588a05shiqian Log(severity, "Test log.\n", 0); 411e35fdd936d133bf8a48de140a3c666897588a05shiqian if (should_print) { 412470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_THAT(GetCapturedStdout().c_str(), 413470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan ContainsRegex( 4142fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan severity == kWarning ? 415470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" : 416470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan "^\nTest log\\.\nStack trace:\n")); 417e35fdd936d133bf8a48de140a3c666897588a05shiqian } else { 418470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GetCapturedStdout().c_str()); 419e35fdd936d133bf8a48de140a3c666897588a05shiqian } 420e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = old_flag; 421e35fdd936d133bf8a48de140a3c666897588a05shiqian} 422e35fdd936d133bf8a48de140a3c666897588a05shiqian 423e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that when the stack_frames_to_skip parameter is negative, 424e35fdd936d133bf8a48de140a3c666897588a05shiqian// Log() doesn't include the stack trace in the output. 425e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) { 42676c1c612e23d87874669faf0b1c8f74caa4a7eb4vladlosev const string saved_flag = GMOCK_FLAG(verbose); 427e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = kInfoVerbosity; 428470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 4292fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan Log(kInfo, "Test log.\n", -1); 430470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str()); 43176c1c612e23d87874669faf0b1c8f74caa4a7eb4vladlosev GMOCK_FLAG(verbose) = saved_flag; 432e35fdd936d133bf8a48de140a3c666897588a05shiqian} 433e35fdd936d133bf8a48de140a3c666897588a05shiqian 434e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosakstruct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface { 435e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak virtual string CurrentStackTrace(int max_depth, int skip_count) { 436e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak return (testing::Message() << max_depth << "::" << skip_count << "\n") 437e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak .GetString(); 438e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak } 439e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak virtual void UponLeavingGTest() {} 440e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak}; 441e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 442e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that in opt mode, a positive stack_frames_to_skip argument is 443e35fdd936d133bf8a48de140a3c666897588a05shiqian// treated as 0. 444e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, NoSkippingStackFrameInOptMode) { 445e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak MockStackTraceGetter* mock_os_stack_trace_getter = new MockStackTraceGetter; 446e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter); 447e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 448470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 4492fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan Log(kWarning, "Test log.\n", 100); 45038513a8bb154f0b6d0a4088814fe92552696d465jgm const string log = GetCapturedStdout(); 451658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan 452e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak string expected_trace = 453e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak (testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString(); 454e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak string expected_message = 455e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak "\nGMOCK WARNING:\n" 456e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak "Test log.\n" 457e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak "Stack trace:\n" + 458e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak expected_trace; 459e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak EXPECT_THAT(log, HasSubstr(expected_message)); 460e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak int skip_count = atoi(log.substr(expected_message.size()).c_str()); 461e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 462e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak# if defined(NDEBUG) 463e35fdd936d133bf8a48de140a3c666897588a05shiqian // In opt mode, no stack frame should be skipped. 464e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak const int expected_skip_count = 0; 465658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan# else 466e35fdd936d133bf8a48de140a3c666897588a05shiqian // In dbg mode, the stack frames should be skipped. 467e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak const int expected_skip_count = 100; 468658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan# endif 469e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 470e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // Note that each inner implementation layer will +1 the number to remove 471e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // itself from the trace. This means that the value is a little higher than 472e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // expected, but close enough. 473e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak EXPECT_THAT(skip_count, 474e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10))); 475e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 476e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // Restores the default OS stack trace getter. 477e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak GetUnitTestImpl()->set_os_stack_trace_getter(NULL); 478e35fdd936d133bf8a48de140a3c666897588a05shiqian} 479e35fdd936d133bf8a48de140a3c666897588a05shiqian 480e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that all logs are printed when the value of the 481e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is "info". 482e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) { 4832fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kInfoVerbosity, kInfo, true); 4842fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kInfoVerbosity, kWarning, true); 485e35fdd936d133bf8a48de140a3c666897588a05shiqian} 486e35fdd936d133bf8a48de140a3c666897588a05shiqian 487e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that only warnings are printed when the value of the 488e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is "warning". 489e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) { 4902fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kWarningVerbosity, kInfo, false); 4912fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kWarningVerbosity, kWarning, true); 492e35fdd936d133bf8a48de140a3c666897588a05shiqian} 493e35fdd936d133bf8a48de140a3c666897588a05shiqian 494e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that no logs are printed when the value of the 495e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is "error". 496e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) { 4972fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kErrorVerbosity, kInfo, false); 4982fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kErrorVerbosity, kWarning, false); 499e35fdd936d133bf8a48de140a3c666897588a05shiqian} 500e35fdd936d133bf8a48de140a3c666897588a05shiqian 501e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that only warnings are printed when the value of the 502e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is invalid. 503e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { 5042fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity("invalid", kInfo, false); 5052fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity("invalid", kWarning, true); 506e35fdd936d133bf8a48de140a3c666897588a05shiqian} 507e35fdd936d133bf8a48de140a3c666897588a05shiqian 5082516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#endif // GTEST_HAS_STREAM_REDIRECTION 509e35fdd936d133bf8a48de140a3c666897588a05shiqian 510e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, true_type) { 511e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(true_type::value); 512e35fdd936d133bf8a48de140a3c666897588a05shiqian} 513e35fdd936d133bf8a48de140a3c666897588a05shiqian 514e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, false_type) { 515e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(false_type::value); 516e35fdd936d133bf8a48de140a3c666897588a05shiqian} 517e35fdd936d133bf8a48de140a3c666897588a05shiqian 518e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, is_reference) { 519e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_reference<int>::value); 520e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_reference<char*>::value); 521e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(is_reference<const int&>::value); 522e35fdd936d133bf8a48de140a3c666897588a05shiqian} 523e35fdd936d133bf8a48de140a3c666897588a05shiqian 524e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, is_pointer) { 525e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_pointer<int>::value); 526e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_pointer<char&>::value); 527e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(is_pointer<const int*>::value); 528e35fdd936d133bf8a48de140a3c666897588a05shiqian} 529e35fdd936d133bf8a48de140a3c666897588a05shiqian 530e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, type_equals) { 531e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE((type_equals<int, const int>::value)); 532e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE((type_equals<int, int&>::value)); 533e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE((type_equals<int, double>::value)); 534e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<char, char>::value)); 535e35fdd936d133bf8a48de140a3c666897588a05shiqian} 536e35fdd936d133bf8a48de140a3c666897588a05shiqian 537e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, remove_reference) { 538e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<char, remove_reference<char&>::type>::value)); 539e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<const int, 540e35fdd936d133bf8a48de140a3c666897588a05shiqian remove_reference<const int&>::type>::value)); 541e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<int, remove_reference<int>::type>::value)); 542e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<double*, remove_reference<double*>::type>::value)); 543e35fdd936d133bf8a48de140a3c666897588a05shiqian} 544e35fdd936d133bf8a48de140a3c666897588a05shiqian 5452516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#if GTEST_HAS_STREAM_REDIRECTION 546e35fdd936d133bf8a48de140a3c666897588a05shiqian 547e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that Log() behaves correctly for the given verbosity level 548e35fdd936d133bf8a48de140a3c666897588a05shiqian// and log severity. 54938513a8bb154f0b6d0a4088814fe92552696d465jgmstd::string GrabOutput(void(*logger)(), const char* verbosity) { 550e35fdd936d133bf8a48de140a3c666897588a05shiqian const string saved_flag = GMOCK_FLAG(verbose); 551e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = verbosity; 552470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 553e35fdd936d133bf8a48de140a3c666897588a05shiqian logger(); 554e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = saved_flag; 555470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan return GetCapturedStdout(); 556e35fdd936d133bf8a48de140a3c666897588a05shiqian} 557e35fdd936d133bf8a48de140a3c666897588a05shiqian 558e35fdd936d133bf8a48de140a3c666897588a05shiqianclass DummyMock { 559e35fdd936d133bf8a48de140a3c666897588a05shiqian public: 560e35fdd936d133bf8a48de140a3c666897588a05shiqian MOCK_METHOD0(TestMethod, void()); 561e35fdd936d133bf8a48de140a3c666897588a05shiqian MOCK_METHOD1(TestMethodArg, void(int dummy)); 562e35fdd936d133bf8a48de140a3c666897588a05shiqian}; 563e35fdd936d133bf8a48de140a3c666897588a05shiqian 564e35fdd936d133bf8a48de140a3c666897588a05shiqianvoid ExpectCallLogger() { 565e35fdd936d133bf8a48de140a3c666897588a05shiqian DummyMock mock; 566e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_CALL(mock, TestMethod()); 567e35fdd936d133bf8a48de140a3c666897588a05shiqian mock.TestMethod(); 568e35fdd936d133bf8a48de140a3c666897588a05shiqian}; 569e35fdd936d133bf8a48de140a3c666897588a05shiqian 570e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info". 571e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectCallTest, LogsWhenVerbosityIsInfo) { 57238513a8bb154f0b6d0a4088814fe92552696d465jgm EXPECT_THAT(std::string(GrabOutput(ExpectCallLogger, kInfoVerbosity)), 573e35fdd936d133bf8a48de140a3c666897588a05shiqian HasSubstr("EXPECT_CALL(mock, TestMethod())")); 574e35fdd936d133bf8a48de140a3c666897588a05shiqian} 575e35fdd936d133bf8a48de140a3c666897588a05shiqian 576e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that EXPECT_CALL doesn't log 577e35fdd936d133bf8a48de140a3c666897588a05shiqian// if the --gmock_verbose flag is set to "warning". 578e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) { 579470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str()); 580e35fdd936d133bf8a48de140a3c666897588a05shiqian} 581e35fdd936d133bf8a48de140a3c666897588a05shiqian 582e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that EXPECT_CALL doesn't log 583e35fdd936d133bf8a48de140a3c666897588a05shiqian// if the --gmock_verbose flag is set to "error". 584e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) { 585470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str()); 586e35fdd936d133bf8a48de140a3c666897588a05shiqian} 587e35fdd936d133bf8a48de140a3c666897588a05shiqian 588e35fdd936d133bf8a48de140a3c666897588a05shiqianvoid OnCallLogger() { 589e35fdd936d133bf8a48de140a3c666897588a05shiqian DummyMock mock; 590e35fdd936d133bf8a48de140a3c666897588a05shiqian ON_CALL(mock, TestMethod()); 591e35fdd936d133bf8a48de140a3c666897588a05shiqian}; 592e35fdd936d133bf8a48de140a3c666897588a05shiqian 593e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info". 594e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, LogsWhenVerbosityIsInfo) { 59538513a8bb154f0b6d0a4088814fe92552696d465jgm EXPECT_THAT(std::string(GrabOutput(OnCallLogger, kInfoVerbosity)), 596e35fdd936d133bf8a48de140a3c666897588a05shiqian HasSubstr("ON_CALL(mock, TestMethod())")); 597e35fdd936d133bf8a48de140a3c666897588a05shiqian} 598e35fdd936d133bf8a48de140a3c666897588a05shiqian 599e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL doesn't log 600e35fdd936d133bf8a48de140a3c666897588a05shiqian// if the --gmock_verbose flag is set to "warning". 601e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) { 602470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(OnCallLogger, kWarningVerbosity).c_str()); 603e35fdd936d133bf8a48de140a3c666897588a05shiqian} 604e35fdd936d133bf8a48de140a3c666897588a05shiqian 605e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL doesn't log if 606e35fdd936d133bf8a48de140a3c666897588a05shiqian// the --gmock_verbose flag is set to "error". 607e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, DoesNotLogWhenVerbosityIsError) { 608470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(OnCallLogger, kErrorVerbosity).c_str()); 609e35fdd936d133bf8a48de140a3c666897588a05shiqian} 610e35fdd936d133bf8a48de140a3c666897588a05shiqian 611e35fdd936d133bf8a48de140a3c666897588a05shiqianvoid OnCallAnyArgumentLogger() { 612e35fdd936d133bf8a48de140a3c666897588a05shiqian DummyMock mock; 613e35fdd936d133bf8a48de140a3c666897588a05shiqian ON_CALL(mock, TestMethodArg(_)); 614e35fdd936d133bf8a48de140a3c666897588a05shiqian} 615e35fdd936d133bf8a48de140a3c666897588a05shiqian 616e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL prints provided _ argument. 617e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, LogsAnythingArgument) { 61838513a8bb154f0b6d0a4088814fe92552696d465jgm EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)), 619e35fdd936d133bf8a48de140a3c666897588a05shiqian HasSubstr("ON_CALL(mock, TestMethodArg(_)")); 620e35fdd936d133bf8a48de140a3c666897588a05shiqian} 621e35fdd936d133bf8a48de140a3c666897588a05shiqian 6222516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#endif // GTEST_HAS_STREAM_REDIRECTION 623e35fdd936d133bf8a48de140a3c666897588a05shiqian 624b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// Tests StlContainerView. 625b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 626b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanTEST(StlContainerViewTest, WorksForStlContainer) { 627b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<std::vector<int>, 628b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<std::vector<int> >::type>(); 629b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<const std::vector<double>&, 630b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<std::vector<double> >::const_reference>(); 631b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 632b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan typedef std::vector<char> Chars; 633b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan Chars v1; 634b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan const Chars& v2(StlContainerView<Chars>::ConstReference(v1)); 635b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(&v1, &v2); 636b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 637b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan v1.push_back('a'); 638b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan Chars v3 = StlContainerView<Chars>::Copy(v1); 639b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_THAT(v3, Eq(v3)); 640b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan} 641b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 642b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanTEST(StlContainerViewTest, WorksForStaticNativeArray) { 643b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<int>, 644b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<int[3]>::type>(); 645b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<double>, 646b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<const double[4]>::type>(); 647b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<char[3]>, 648b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<const char[2][3]>::type>(); 649b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 650b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<const NativeArray<int>, 651b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<int[2]>::const_reference>(); 652b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 653b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan int a1[3] = { 0, 1, 2 }; 654b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1); 65532de5f53763125925e078498250f7e73a88de9edzhanyong.wan EXPECT_EQ(3U, a2.size()); 656b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(a1, a2.begin()); 657b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 658b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1); 65932de5f53763125925e078498250f7e73a88de9edzhanyong.wan ASSERT_EQ(3U, a3.size()); 660b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 661b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(1, a3.begin()[1]); 662b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(2, a3.begin()[2]); 663b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 664b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan // Makes sure a1 and a3 aren't aliases. 665b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan a1[0] = 3; 666b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 667b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan} 668b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 669b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanTEST(StlContainerViewTest, WorksForDynamicNativeArray) { 670b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<int>, 671b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<tuple<const int*, size_t> >::type>(); 672b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<double>, 673b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<tuple<linked_ptr<double>, int> >::type>(); 674b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 675b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<const NativeArray<int>, 676b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<tuple<const int*, int> >::const_reference>(); 677b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 678b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan int a1[3] = { 0, 1, 2 }; 67990c90f9250f19c3f3a5c2c0887c1d9e414afe41bzhanyong.wan const int* const p1 = a1; 680b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >:: 68190c90f9250f19c3f3a5c2c0887c1d9e414afe41bzhanyong.wan ConstReference(make_tuple(p1, 3)); 68232de5f53763125925e078498250f7e73a88de9edzhanyong.wan EXPECT_EQ(3U, a2.size()); 683b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(a1, a2.begin()); 684b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 685b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >:: 6862661c6821a4d7964697e48747c4d739e1ac3a243zhanyong.wan Copy(make_tuple(static_cast<int*>(a1), 3)); 68732de5f53763125925e078498250f7e73a88de9edzhanyong.wan ASSERT_EQ(3U, a3.size()); 688b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 689b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(1, a3.begin()[1]); 690b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(2, a3.begin()[2]); 691b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 692b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan // Makes sure a1 and a3 aren't aliases. 693b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan a1[0] = 3; 694b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 695b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan} 696b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 697e35fdd936d133bf8a48de140a3c666897588a05shiqian} // namespace 698e35fdd936d133bf8a48de140a3c666897588a05shiqian} // namespace internal 699e35fdd936d133bf8a48de140a3c666897588a05shiqian} // namespace testing 700