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 52b70cf1a663ad30f77ab9867095a87d3d5429450dJonathan Wakely// their 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 32209fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber Matcher<std::string> > 323e35fdd936d133bf8a48de140a3c666897588a05shiqian matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi")); 32409fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber tuple<int, char, bool, long, std::string> // NOLINT 32509fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"), 326e35fdd936d133bf8a48de140a3c666897588a05shiqian values3(2, 'a', true, 2L, "hi"); 327e35fdd936d133bf8a48de140a3c666897588a05shiqian 328e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(TupleMatches(matchers, values1)); 329e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values2)); 330e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(TupleMatches(matchers, values3)); 331e35fdd936d133bf8a48de140a3c666897588a05shiqian} 332e35fdd936d133bf8a48de140a3c666897588a05shiqian 333e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Assert(true, ...) succeeds. 334e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(AssertTest, SucceedsOnTrue) { 335e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(true, __FILE__, __LINE__, "This should succeed."); 336e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(true, __FILE__, __LINE__); // This should succeed too. 337e35fdd936d133bf8a48de140a3c666897588a05shiqian} 338e35fdd936d133bf8a48de140a3c666897588a05shiqian 339e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Assert(false, ...) generates a fatal failure. 340e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(AssertTest, FailsFatallyOnFalse) { 34104d6ed817e40f676225e0bf20ff1470d8f0c4a20zhanyong.wan EXPECT_DEATH_IF_SUPPORTED({ 342e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(false, __FILE__, __LINE__, "This should fail."); 343e35fdd936d133bf8a48de140a3c666897588a05shiqian }, ""); 344e35fdd936d133bf8a48de140a3c666897588a05shiqian 34504d6ed817e40f676225e0bf20ff1470d8f0c4a20zhanyong.wan EXPECT_DEATH_IF_SUPPORTED({ 346e35fdd936d133bf8a48de140a3c666897588a05shiqian Assert(false, __FILE__, __LINE__); 347e35fdd936d133bf8a48de140a3c666897588a05shiqian }, ""); 348e35fdd936d133bf8a48de140a3c666897588a05shiqian} 349e35fdd936d133bf8a48de140a3c666897588a05shiqian 350e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Expect(true, ...) succeeds. 351e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectTest, SucceedsOnTrue) { 352e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(true, __FILE__, __LINE__, "This should succeed."); 353e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(true, __FILE__, __LINE__); // This should succeed too. 354e35fdd936d133bf8a48de140a3c666897588a05shiqian} 355e35fdd936d133bf8a48de140a3c666897588a05shiqian 356e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that Expect(false, ...) generates a non-fatal failure. 357e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectTest, FailsNonfatallyOnFalse) { 358e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_NONFATAL_FAILURE({ // NOLINT 359e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(false, __FILE__, __LINE__, "This should fail."); 360e35fdd936d133bf8a48de140a3c666897588a05shiqian }, "This should fail"); 361e35fdd936d133bf8a48de140a3c666897588a05shiqian 362e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_NONFATAL_FAILURE({ // NOLINT 363e35fdd936d133bf8a48de140a3c666897588a05shiqian Expect(false, __FILE__, __LINE__); 364e35fdd936d133bf8a48de140a3c666897588a05shiqian }, "Expectation failed"); 365e35fdd936d133bf8a48de140a3c666897588a05shiqian} 366e35fdd936d133bf8a48de140a3c666897588a05shiqian 3679413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan// Tests LogIsVisible(). 3689413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3699413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanclass LogIsVisibleTest : public ::testing::Test { 3709413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan protected: 37181476f2f9070186027e7337854bbcf693b85c6c6zhanyong.wan virtual void SetUp() { 37238513a8bb154f0b6d0a4088814fe92552696d465jgm original_verbose_ = GMOCK_FLAG(verbose); 37381476f2f9070186027e7337854bbcf693b85c6c6zhanyong.wan } 37481476f2f9070186027e7337854bbcf693b85c6c6zhanyong.wan 3759413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; } 3769413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 37709fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber std::string original_verbose_; 3789413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan}; 3799413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3809413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanTEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) { 3819413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan GMOCK_FLAG(verbose) = kInfoVerbosity; 3822fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_TRUE(LogIsVisible(kInfo)); 3832fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_TRUE(LogIsVisible(kWarning)); 3849413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan} 3859413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3869413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanTEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) { 3879413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan GMOCK_FLAG(verbose) = kErrorVerbosity; 3882fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_FALSE(LogIsVisible(kInfo)); 3892fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_FALSE(LogIsVisible(kWarning)); 3909413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan} 3919413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3929413f2ff615ae1b933580576183d316c4cb6376czhanyong.wanTEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) { 3939413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan GMOCK_FLAG(verbose) = kWarningVerbosity; 3942fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_FALSE(LogIsVisible(kInfo)); 3952fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan EXPECT_TRUE(LogIsVisible(kWarning)); 3969413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan} 3979413f2ff615ae1b933580576183d316c4cb6376czhanyong.wan 3982516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#if GTEST_HAS_STREAM_REDIRECTION 399e35fdd936d133bf8a48de140a3c666897588a05shiqian 400e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests the Log() function. 401e35fdd936d133bf8a48de140a3c666897588a05shiqian 402e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that Log() behaves correctly for the given verbosity level 403e35fdd936d133bf8a48de140a3c666897588a05shiqian// and log severity. 40409fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Webervoid TestLogWithSeverity(const std::string& verbosity, LogSeverity severity, 405e35fdd936d133bf8a48de140a3c666897588a05shiqian bool should_print) { 40609fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber const std::string old_flag = GMOCK_FLAG(verbose); 407e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = verbosity; 408470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 409e35fdd936d133bf8a48de140a3c666897588a05shiqian Log(severity, "Test log.\n", 0); 410e35fdd936d133bf8a48de140a3c666897588a05shiqian if (should_print) { 411470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_THAT(GetCapturedStdout().c_str(), 412470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan ContainsRegex( 4132fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan severity == kWarning ? 414470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" : 415470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan "^\nTest log\\.\nStack trace:\n")); 416e35fdd936d133bf8a48de140a3c666897588a05shiqian } else { 417470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GetCapturedStdout().c_str()); 418e35fdd936d133bf8a48de140a3c666897588a05shiqian } 419e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = old_flag; 420e35fdd936d133bf8a48de140a3c666897588a05shiqian} 421e35fdd936d133bf8a48de140a3c666897588a05shiqian 422e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that when the stack_frames_to_skip parameter is negative, 423e35fdd936d133bf8a48de140a3c666897588a05shiqian// Log() doesn't include the stack trace in the output. 424e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) { 42509fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber const std::string saved_flag = GMOCK_FLAG(verbose); 426e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = kInfoVerbosity; 427470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 4282fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan Log(kInfo, "Test log.\n", -1); 429470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str()); 43076c1c612e23d87874669faf0b1c8f74caa4a7eb4vladlosev GMOCK_FLAG(verbose) = saved_flag; 431e35fdd936d133bf8a48de140a3c666897588a05shiqian} 432e35fdd936d133bf8a48de140a3c666897588a05shiqian 433e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosakstruct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface { 43409fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber virtual std::string CurrentStackTrace(int max_depth, int skip_count) { 435e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak return (testing::Message() << max_depth << "::" << skip_count << "\n") 436e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak .GetString(); 437e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak } 438e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak virtual void UponLeavingGTest() {} 439e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak}; 440e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 441e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that in opt mode, a positive stack_frames_to_skip argument is 442e35fdd936d133bf8a48de140a3c666897588a05shiqian// treated as 0. 443e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, NoSkippingStackFrameInOptMode) { 444e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak MockStackTraceGetter* mock_os_stack_trace_getter = new MockStackTraceGetter; 445e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter); 446e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 447470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 4482fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan Log(kWarning, "Test log.\n", 100); 44909fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber const std::string log = GetCapturedStdout(); 450658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan 45109fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber std::string expected_trace = 452e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak (testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString(); 45309fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber std::string expected_message = 454e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak "\nGMOCK WARNING:\n" 455e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak "Test log.\n" 456e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak "Stack trace:\n" + 457e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak expected_trace; 458e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak EXPECT_THAT(log, HasSubstr(expected_message)); 459e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak int skip_count = atoi(log.substr(expected_message.size()).c_str()); 460e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 461e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak# if defined(NDEBUG) 462e35fdd936d133bf8a48de140a3c666897588a05shiqian // In opt mode, no stack frame should be skipped. 463e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak const int expected_skip_count = 0; 464658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan# else 465e35fdd936d133bf8a48de140a3c666897588a05shiqian // In dbg mode, the stack frames should be skipped. 466e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak const int expected_skip_count = 100; 467658ac0b71a350cc833ee4520536b6c4964c7b944zhanyong.wan# endif 468e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 469e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // Note that each inner implementation layer will +1 the number to remove 470e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // itself from the trace. This means that the value is a little higher than 471e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // expected, but close enough. 472e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak EXPECT_THAT(skip_count, 473e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10))); 474e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak 475e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak // Restores the default OS stack trace getter. 476e83085aeb11d2eb07cf5e75a8b8da3587ec28445kosak GetUnitTestImpl()->set_os_stack_trace_getter(NULL); 477e35fdd936d133bf8a48de140a3c666897588a05shiqian} 478e35fdd936d133bf8a48de140a3c666897588a05shiqian 479e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that all logs are printed when the value of the 480e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is "info". 481e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) { 4822fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kInfoVerbosity, kInfo, true); 4832fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kInfoVerbosity, kWarning, true); 484e35fdd936d133bf8a48de140a3c666897588a05shiqian} 485e35fdd936d133bf8a48de140a3c666897588a05shiqian 486e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that only warnings are printed when the value of the 487e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is "warning". 488e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) { 4892fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kWarningVerbosity, kInfo, false); 4902fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kWarningVerbosity, kWarning, true); 491e35fdd936d133bf8a48de140a3c666897588a05shiqian} 492e35fdd936d133bf8a48de140a3c666897588a05shiqian 493e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that no logs are printed when the value of the 494e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is "error". 495e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) { 4962fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kErrorVerbosity, kInfo, false); 4972fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity(kErrorVerbosity, kWarning, false); 498e35fdd936d133bf8a48de140a3c666897588a05shiqian} 499e35fdd936d133bf8a48de140a3c666897588a05shiqian 500e35fdd936d133bf8a48de140a3c666897588a05shiqian// Tests that only warnings are printed when the value of the 501e35fdd936d133bf8a48de140a3c666897588a05shiqian// --gmock_verbose flag is invalid. 502e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { 5032fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity("invalid", kInfo, false); 5042fd619edd3d1ec053f6276debdb513f1122ebcf3zhanyong.wan TestLogWithSeverity("invalid", kWarning, true); 505e35fdd936d133bf8a48de140a3c666897588a05shiqian} 506e35fdd936d133bf8a48de140a3c666897588a05shiqian 5072516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#endif // GTEST_HAS_STREAM_REDIRECTION 508e35fdd936d133bf8a48de140a3c666897588a05shiqian 509e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, true_type) { 510e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(true_type::value); 511e35fdd936d133bf8a48de140a3c666897588a05shiqian} 512e35fdd936d133bf8a48de140a3c666897588a05shiqian 513e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, false_type) { 514e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(false_type::value); 515e35fdd936d133bf8a48de140a3c666897588a05shiqian} 516e35fdd936d133bf8a48de140a3c666897588a05shiqian 517e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, is_reference) { 518e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_reference<int>::value); 519e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_reference<char*>::value); 520e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(is_reference<const int&>::value); 521e35fdd936d133bf8a48de140a3c666897588a05shiqian} 522e35fdd936d133bf8a48de140a3c666897588a05shiqian 523e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, is_pointer) { 524e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_pointer<int>::value); 525e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE(is_pointer<char&>::value); 526e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE(is_pointer<const int*>::value); 527e35fdd936d133bf8a48de140a3c666897588a05shiqian} 528e35fdd936d133bf8a48de140a3c666897588a05shiqian 529e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, type_equals) { 530e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE((type_equals<int, const int>::value)); 531e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE((type_equals<int, int&>::value)); 532e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_FALSE((type_equals<int, double>::value)); 533e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<char, char>::value)); 534e35fdd936d133bf8a48de140a3c666897588a05shiqian} 535e35fdd936d133bf8a48de140a3c666897588a05shiqian 536e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(TypeTraitsTest, remove_reference) { 537e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<char, remove_reference<char&>::type>::value)); 538e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<const int, 539e35fdd936d133bf8a48de140a3c666897588a05shiqian remove_reference<const int&>::type>::value)); 540e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<int, remove_reference<int>::type>::value)); 541e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_TRUE((type_equals<double*, remove_reference<double*>::type>::value)); 542e35fdd936d133bf8a48de140a3c666897588a05shiqian} 543e35fdd936d133bf8a48de140a3c666897588a05shiqian 5442516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#if GTEST_HAS_STREAM_REDIRECTION 545e35fdd936d133bf8a48de140a3c666897588a05shiqian 546e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that Log() behaves correctly for the given verbosity level 547e35fdd936d133bf8a48de140a3c666897588a05shiqian// and log severity. 54838513a8bb154f0b6d0a4088814fe92552696d465jgmstd::string GrabOutput(void(*logger)(), const char* verbosity) { 54909fd5b3ebfaac10b78bda664ec7f57fac74ef214Nico Weber const std::string saved_flag = GMOCK_FLAG(verbose); 550e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = verbosity; 551470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan CaptureStdout(); 552e35fdd936d133bf8a48de140a3c666897588a05shiqian logger(); 553e35fdd936d133bf8a48de140a3c666897588a05shiqian GMOCK_FLAG(verbose) = saved_flag; 554470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan return GetCapturedStdout(); 555e35fdd936d133bf8a48de140a3c666897588a05shiqian} 556e35fdd936d133bf8a48de140a3c666897588a05shiqian 557e35fdd936d133bf8a48de140a3c666897588a05shiqianclass DummyMock { 558e35fdd936d133bf8a48de140a3c666897588a05shiqian public: 559e35fdd936d133bf8a48de140a3c666897588a05shiqian MOCK_METHOD0(TestMethod, void()); 560e35fdd936d133bf8a48de140a3c666897588a05shiqian MOCK_METHOD1(TestMethodArg, void(int dummy)); 561e35fdd936d133bf8a48de140a3c666897588a05shiqian}; 562e35fdd936d133bf8a48de140a3c666897588a05shiqian 563e35fdd936d133bf8a48de140a3c666897588a05shiqianvoid ExpectCallLogger() { 564e35fdd936d133bf8a48de140a3c666897588a05shiqian DummyMock mock; 565e35fdd936d133bf8a48de140a3c666897588a05shiqian EXPECT_CALL(mock, TestMethod()); 566e35fdd936d133bf8a48de140a3c666897588a05shiqian mock.TestMethod(); 567e35fdd936d133bf8a48de140a3c666897588a05shiqian}; 568e35fdd936d133bf8a48de140a3c666897588a05shiqian 569e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info". 570e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectCallTest, LogsWhenVerbosityIsInfo) { 57138513a8bb154f0b6d0a4088814fe92552696d465jgm EXPECT_THAT(std::string(GrabOutput(ExpectCallLogger, kInfoVerbosity)), 572e35fdd936d133bf8a48de140a3c666897588a05shiqian HasSubstr("EXPECT_CALL(mock, TestMethod())")); 573e35fdd936d133bf8a48de140a3c666897588a05shiqian} 574e35fdd936d133bf8a48de140a3c666897588a05shiqian 575e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that EXPECT_CALL doesn't log 576e35fdd936d133bf8a48de140a3c666897588a05shiqian// if the --gmock_verbose flag is set to "warning". 577e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) { 578470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str()); 579e35fdd936d133bf8a48de140a3c666897588a05shiqian} 580e35fdd936d133bf8a48de140a3c666897588a05shiqian 581e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that EXPECT_CALL doesn't log 582e35fdd936d133bf8a48de140a3c666897588a05shiqian// if the --gmock_verbose flag is set to "error". 583e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) { 584470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str()); 585e35fdd936d133bf8a48de140a3c666897588a05shiqian} 586e35fdd936d133bf8a48de140a3c666897588a05shiqian 587e35fdd936d133bf8a48de140a3c666897588a05shiqianvoid OnCallLogger() { 588e35fdd936d133bf8a48de140a3c666897588a05shiqian DummyMock mock; 589e35fdd936d133bf8a48de140a3c666897588a05shiqian ON_CALL(mock, TestMethod()); 590e35fdd936d133bf8a48de140a3c666897588a05shiqian}; 591e35fdd936d133bf8a48de140a3c666897588a05shiqian 592e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info". 593e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, LogsWhenVerbosityIsInfo) { 59438513a8bb154f0b6d0a4088814fe92552696d465jgm EXPECT_THAT(std::string(GrabOutput(OnCallLogger, kInfoVerbosity)), 595e35fdd936d133bf8a48de140a3c666897588a05shiqian HasSubstr("ON_CALL(mock, TestMethod())")); 596e35fdd936d133bf8a48de140a3c666897588a05shiqian} 597e35fdd936d133bf8a48de140a3c666897588a05shiqian 598e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL doesn't log 599e35fdd936d133bf8a48de140a3c666897588a05shiqian// if the --gmock_verbose flag is set to "warning". 600e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) { 601470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(OnCallLogger, kWarningVerbosity).c_str()); 602e35fdd936d133bf8a48de140a3c666897588a05shiqian} 603e35fdd936d133bf8a48de140a3c666897588a05shiqian 604e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL doesn't log if 605e35fdd936d133bf8a48de140a3c666897588a05shiqian// the --gmock_verbose flag is set to "error". 606e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, DoesNotLogWhenVerbosityIsError) { 607470df42bad6a78531f0ec51e43a194f3e26c4f4dzhanyong.wan EXPECT_STREQ("", GrabOutput(OnCallLogger, kErrorVerbosity).c_str()); 608e35fdd936d133bf8a48de140a3c666897588a05shiqian} 609e35fdd936d133bf8a48de140a3c666897588a05shiqian 610e35fdd936d133bf8a48de140a3c666897588a05shiqianvoid OnCallAnyArgumentLogger() { 611e35fdd936d133bf8a48de140a3c666897588a05shiqian DummyMock mock; 612e35fdd936d133bf8a48de140a3c666897588a05shiqian ON_CALL(mock, TestMethodArg(_)); 613e35fdd936d133bf8a48de140a3c666897588a05shiqian} 614e35fdd936d133bf8a48de140a3c666897588a05shiqian 615e35fdd936d133bf8a48de140a3c666897588a05shiqian// Verifies that ON_CALL prints provided _ argument. 616e35fdd936d133bf8a48de140a3c666897588a05shiqianTEST(OnCallTest, LogsAnythingArgument) { 61738513a8bb154f0b6d0a4088814fe92552696d465jgm EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)), 618e35fdd936d133bf8a48de140a3c666897588a05shiqian HasSubstr("ON_CALL(mock, TestMethodArg(_)")); 619e35fdd936d133bf8a48de140a3c666897588a05shiqian} 620e35fdd936d133bf8a48de140a3c666897588a05shiqian 6212516f60da9073f3b04c0bbfc37d3aefffe11767ezhanyong.wan#endif // GTEST_HAS_STREAM_REDIRECTION 622e35fdd936d133bf8a48de140a3c666897588a05shiqian 623b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan// Tests StlContainerView. 624b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 625b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanTEST(StlContainerViewTest, WorksForStlContainer) { 626b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<std::vector<int>, 627b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<std::vector<int> >::type>(); 628b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<const std::vector<double>&, 629b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<std::vector<double> >::const_reference>(); 630b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 631b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan typedef std::vector<char> Chars; 632b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan Chars v1; 633b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan const Chars& v2(StlContainerView<Chars>::ConstReference(v1)); 634b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(&v1, &v2); 635b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 636b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan v1.push_back('a'); 637b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan Chars v3 = StlContainerView<Chars>::Copy(v1); 638b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_THAT(v3, Eq(v3)); 639b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan} 640b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 641b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanTEST(StlContainerViewTest, WorksForStaticNativeArray) { 642b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<int>, 643b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<int[3]>::type>(); 644b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<double>, 645b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<const double[4]>::type>(); 646b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<char[3]>, 647b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<const char[2][3]>::type>(); 648b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 649b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<const NativeArray<int>, 650b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<int[2]>::const_reference>(); 651b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 652b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan int a1[3] = { 0, 1, 2 }; 653b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1); 65432de5f53763125925e078498250f7e73a88de9edzhanyong.wan EXPECT_EQ(3U, a2.size()); 655b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(a1, a2.begin()); 656b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 657b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1); 65832de5f53763125925e078498250f7e73a88de9edzhanyong.wan ASSERT_EQ(3U, a3.size()); 659b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 660b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(1, a3.begin()[1]); 661b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(2, a3.begin()[2]); 662b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 663b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan // Makes sure a1 and a3 aren't aliases. 664b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan a1[0] = 3; 665b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 666b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan} 667b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 668b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wanTEST(StlContainerViewTest, WorksForDynamicNativeArray) { 669b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<int>, 670b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<tuple<const int*, size_t> >::type>(); 671b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<NativeArray<double>, 672b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<tuple<linked_ptr<double>, int> >::type>(); 673b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 674b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StaticAssertTypeEq<const NativeArray<int>, 675b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan StlContainerView<tuple<const int*, int> >::const_reference>(); 676b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 677b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan int a1[3] = { 0, 1, 2 }; 67890c90f9250f19c3f3a5c2c0887c1d9e414afe41bzhanyong.wan const int* const p1 = a1; 679b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >:: 68090c90f9250f19c3f3a5c2c0887c1d9e414afe41bzhanyong.wan ConstReference(make_tuple(p1, 3)); 68132de5f53763125925e078498250f7e73a88de9edzhanyong.wan EXPECT_EQ(3U, a2.size()); 682b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(a1, a2.begin()); 683b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 684b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >:: 6852661c6821a4d7964697e48747c4d739e1ac3a243zhanyong.wan Copy(make_tuple(static_cast<int*>(a1), 3)); 68632de5f53763125925e078498250f7e73a88de9edzhanyong.wan ASSERT_EQ(3U, a3.size()); 687b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 688b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(1, a3.begin()[1]); 689b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(2, a3.begin()[2]); 690b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 691b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan // Makes sure a1 and a3 aren't aliases. 692b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan a1[0] = 3; 693b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan EXPECT_EQ(0, a3.begin()[0]); 694b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan} 695b82431625d1842d1498f3c0e6f1923ce81837c6ezhanyong.wan 696e35fdd936d133bf8a48de140a3c666897588a05shiqian} // namespace 697e35fdd936d133bf8a48de140a3c666897588a05shiqian} // namespace internal 698e35fdd936d133bf8a48de140a3c666897588a05shiqian} // namespace testing 699