11b362b15af34006e6a11974088a46d42b903418eJohann// Copyright 2008, Google Inc. 21b362b15af34006e6a11974088a46d42b903418eJohann// All rights reserved. 31b362b15af34006e6a11974088a46d42b903418eJohann// 41b362b15af34006e6a11974088a46d42b903418eJohann// Redistribution and use in source and binary forms, with or without 51b362b15af34006e6a11974088a46d42b903418eJohann// modification, are permitted provided that the following conditions are 61b362b15af34006e6a11974088a46d42b903418eJohann// met: 71b362b15af34006e6a11974088a46d42b903418eJohann// 81b362b15af34006e6a11974088a46d42b903418eJohann// * Redistributions of source code must retain the above copyright 91b362b15af34006e6a11974088a46d42b903418eJohann// notice, this list of conditions and the following disclaimer. 101b362b15af34006e6a11974088a46d42b903418eJohann// * Redistributions in binary form must reproduce the above 111b362b15af34006e6a11974088a46d42b903418eJohann// copyright notice, this list of conditions and the following disclaimer 121b362b15af34006e6a11974088a46d42b903418eJohann// in the documentation and/or other materials provided with the 131b362b15af34006e6a11974088a46d42b903418eJohann// distribution. 141b362b15af34006e6a11974088a46d42b903418eJohann// * Neither the name of Google Inc. nor the names of its 151b362b15af34006e6a11974088a46d42b903418eJohann// contributors may be used to endorse or promote products derived from 161b362b15af34006e6a11974088a46d42b903418eJohann// this software without specific prior written permission. 171b362b15af34006e6a11974088a46d42b903418eJohann// 181b362b15af34006e6a11974088a46d42b903418eJohann// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 191b362b15af34006e6a11974088a46d42b903418eJohann// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 201b362b15af34006e6a11974088a46d42b903418eJohann// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 211b362b15af34006e6a11974088a46d42b903418eJohann// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 221b362b15af34006e6a11974088a46d42b903418eJohann// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 231b362b15af34006e6a11974088a46d42b903418eJohann// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 241b362b15af34006e6a11974088a46d42b903418eJohann// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251b362b15af34006e6a11974088a46d42b903418eJohann// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261b362b15af34006e6a11974088a46d42b903418eJohann// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271b362b15af34006e6a11974088a46d42b903418eJohann// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 281b362b15af34006e6a11974088a46d42b903418eJohann// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291b362b15af34006e6a11974088a46d42b903418eJohann// 301b362b15af34006e6a11974088a46d42b903418eJohann// Author: mheule@google.com (Markus Heule) 311b362b15af34006e6a11974088a46d42b903418eJohann// 321b362b15af34006e6a11974088a46d42b903418eJohann// Google C++ Testing Framework (Google Test) 331b362b15af34006e6a11974088a46d42b903418eJohann// 341b362b15af34006e6a11974088a46d42b903418eJohann// Sometimes it's desirable to build Google Test by compiling a single file. 351b362b15af34006e6a11974088a46d42b903418eJohann// This file serves this purpose. 361b362b15af34006e6a11974088a46d42b903418eJohann 371b362b15af34006e6a11974088a46d42b903418eJohann// This line ensures that gtest.h can be compiled on its own, even 381b362b15af34006e6a11974088a46d42b903418eJohann// when it's fused. 391b362b15af34006e6a11974088a46d42b903418eJohann#include "gtest/gtest.h" 401b362b15af34006e6a11974088a46d42b903418eJohann 411b362b15af34006e6a11974088a46d42b903418eJohann// The following lines pull in the real gtest *.cc files. 425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Copyright 2005, Google Inc. 435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// All rights reserved. 445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Redistribution and use in source and binary forms, with or without 465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// modification, are permitted provided that the following conditions are 475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// met: 485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Redistributions of source code must retain the above copyright 505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// notice, this list of conditions and the following disclaimer. 515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Redistributions in binary form must reproduce the above 525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// copyright notice, this list of conditions and the following disclaimer 535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// in the documentation and/or other materials provided with the 545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// distribution. 555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Neither the name of Google Inc. nor the names of its 565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// contributors may be used to endorse or promote products derived from 575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// this software without specific prior written permission. 585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Author: wan@google.com (Zhanyong Wan) 725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// The Google C++ Testing Framework (Google Test) 745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Copyright 2007, Google Inc. 765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// All rights reserved. 775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Redistribution and use in source and binary forms, with or without 795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// modification, are permitted provided that the following conditions are 805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// met: 815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Redistributions of source code must retain the above copyright 835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// notice, this list of conditions and the following disclaimer. 845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Redistributions in binary form must reproduce the above 855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// copyright notice, this list of conditions and the following disclaimer 865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// in the documentation and/or other materials provided with the 875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// distribution. 885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Neither the name of Google Inc. nor the names of its 895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// contributors may be used to endorse or promote products derived from 905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// this software without specific prior written permission. 915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 1045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Author: wan@google.com (Zhanyong Wan) 1055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 1065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Utilities for testing Google Test itself and code that uses Google Test 1075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// (e.g. frameworks built on top of Google Test). 1085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 1105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 1115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangnamespace testing { 1145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// This helper class can be used to mock out Google Test failure reporting 1165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// so that we can test Google Test or code that builds on Google Test. 1175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 1185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// An object of this class appends a TestPartResult object to the 1195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// TestPartResultArray object given in the constructor whenever a Google Test 1205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// failure is reported. It can either intercept only failures that are 1215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// generated in the same thread that created this object or it can intercept 1225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// all generated failures. The scope of this mock object can be controlled with 1235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// the second argument to the two arguments constructor. 1245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass GTEST_API_ ScopedFakeTestPartResultReporter 1255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang : public TestPartResultReporterInterface { 1265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public: 1275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // The two possible mocking modes of this object. 1285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang enum InterceptMode { 1295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures. 1305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang INTERCEPT_ALL_THREADS // Intercepts all failures. 1315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang }; 1325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // The c'tor sets this object as the test part result reporter used 1345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // by Google Test. The 'result' parameter specifies where to report the 1355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // results. This reporter will only catch failures generated in the current 1365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // thread. DEPRECATED 1375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result); 1385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Same as above, but you can choose the interception scope of this object. 1405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ScopedFakeTestPartResultReporter(InterceptMode intercept_mode, 1415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang TestPartResultArray* result); 1425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // The d'tor restores the previous test part result reporter. 1445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang virtual ~ScopedFakeTestPartResultReporter(); 1455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Appends the TestPartResult object to the TestPartResultArray 1475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // received in the constructor. 1485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // 1495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // This method is from the TestPartResultReporterInterface 1505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // interface. 1515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang virtual void ReportTestPartResult(const TestPartResult& result); 1525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang private: 1535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang void Init(); 1545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const InterceptMode intercept_mode_; 1565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang TestPartResultReporterInterface* old_reporter_; 1575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang TestPartResultArray* const result_; 1585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter); 1605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang}; 1615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangnamespace internal { 1635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A helper class for implementing EXPECT_FATAL_FAILURE() and 1655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given 1665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// TestPartResultArray contains exactly one failure that has the given 1675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// type and contains the given substring. If that's not the case, a 1685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// non-fatal failure will be generated. 1695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass GTEST_API_ SingleFailureChecker { 1705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public: 1715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // The constructor remembers the arguments. 1725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang SingleFailureChecker(const TestPartResultArray* results, 1735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang TestPartResult::Type type, 1745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const string& substr); 1755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ~SingleFailureChecker(); 1765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang private: 1775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const TestPartResultArray* const results_; 1785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const TestPartResult::Type type_; 1795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const string substr_; 1805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); 1825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang}; 1835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} // namespace internal 1855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} // namespace testing 1875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 1885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A set of macros for testing Google Test assertions or code that's expected 1895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// to generate Google Test fatal failures. It verifies that the given 1905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// statement will cause exactly one fatal Google Test failure with 'substr' 1915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// being part of the failure message. 1925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 1935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// There are two different versions of this macro. EXPECT_FATAL_FAILURE only 1945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// affects and considers failures generated in the current thread and 1955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 1965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 1975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// The verification of the assertion is done correctly even when the statement 1985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// throws an exception or aborts the current function. 1995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Known restrictions: 2015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// - 'statement' cannot reference local non-static variables or 2025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// non-static members of the current object. 2035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// - 'statement' cannot return a value. 2045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// - You cannot stream a failure message to this macro. 2055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Note that even though the implementations of the following two 2075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// macros are much alike, we cannot refactor them to use a common 2085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// helper macro, due to some peculiarity in how the preprocessor 2095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// works. The AcceptsMacroThatExpandsToUnprotectedComma test in 2105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// gtest_unittest.cc will fail to compile if we do that. 2115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#define EXPECT_FATAL_FAILURE(statement, substr) \ 2125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang do { \ 2135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang class GTestExpectFatalFailureHelper {\ 2145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public:\ 2155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static void Execute() { statement; }\ 2165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang };\ 2175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::TestPartResultArray gtest_failures;\ 2185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::internal::SingleFailureChecker gtest_checker(\ 2195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ 2205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang {\ 2215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 2225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter:: \ 2235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ 2245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTestExpectFatalFailureHelper::Execute();\ 2255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang }\ 2265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } while (::testing::internal::AlwaysFalse()) 2275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 2285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 2295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang do { \ 2305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang class GTestExpectFatalFailureHelper {\ 2315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public:\ 2325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static void Execute() { statement; }\ 2335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang };\ 2345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::TestPartResultArray gtest_failures;\ 2355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::internal::SingleFailureChecker gtest_checker(\ 2365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ 2375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang {\ 2385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 2395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter:: \ 2405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang INTERCEPT_ALL_THREADS, >est_failures);\ 2415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTestExpectFatalFailureHelper::Execute();\ 2425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang }\ 2435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } while (::testing::internal::AlwaysFalse()) 2445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 2455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A macro for testing Google Test assertions or code that's expected to 2465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// generate Google Test non-fatal failures. It asserts that the given 2475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// statement will cause exactly one non-fatal Google Test failure with 'substr' 2485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// being part of the failure message. 2495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only 2515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// affects and considers failures generated in the current thread and 2525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. 2535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 'statement' is allowed to reference local variables and members of 2555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// the current object. 2565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// The verification of the assertion is done correctly even when the statement 2585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// throws an exception or aborts the current function. 2595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Known restrictions: 2615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// - You cannot stream a failure message to this macro. 2625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Note that even though the implementations of the following two 2645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// macros are much alike, we cannot refactor them to use a common 2655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// helper macro, due to some peculiarity in how the preprocessor 2665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// works. If we do that, the code won't compile when the user gives 2675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that 2685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// expands to code containing an unprotected comma. The 2695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc 2705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// catches that. 2715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 2725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// For the same reason, we have to write 2735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// if (::testing::internal::AlwaysTrue()) { statement; } 2745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// instead of 2755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 2765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// to avoid an MSVC warning on unreachable code. 2775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#define EXPECT_NONFATAL_FAILURE(statement, substr) \ 2785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang do {\ 2795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::TestPartResultArray gtest_failures;\ 2805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::internal::SingleFailureChecker gtest_checker(\ 2815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 2825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang (substr));\ 2835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang {\ 2845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 2855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter:: \ 2865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ 2875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang if (::testing::internal::AlwaysTrue()) { statement; }\ 2885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang }\ 2895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } while (::testing::internal::AlwaysFalse()) 2905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 2915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ 2925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang do {\ 2935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::TestPartResultArray gtest_failures;\ 2945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::internal::SingleFailureChecker gtest_checker(\ 2955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ 2965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang (substr));\ 2975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang {\ 2985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ 2995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ 3005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang >est_failures);\ 3015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang if (::testing::internal::AlwaysTrue()) { statement; }\ 3025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang }\ 3035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } while (::testing::internal::AlwaysFalse()) 3045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_ 3065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <ctype.h> 3085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <math.h> 3095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <stdarg.h> 3105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <stdio.h> 3115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <stdlib.h> 3125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <time.h> 3135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <wchar.h> 3145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <wctype.h> 3155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <algorithm> 3175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <iomanip> 3185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <limits> 3195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <ostream> // NOLINT 3205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <sstream> 3215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <vector> 3225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#if GTEST_OS_LINUX 3245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// TODO(kenton@google.com): Use autoconf to detect availability of 3265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// gettimeofday(). 3275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# define GTEST_HAS_GETTIMEOFDAY_ 1 3285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <fcntl.h> // NOLINT 3305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <limits.h> // NOLINT 3315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sched.h> // NOLINT 3325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Declares vsnprintf(). This header is not available on Windows. 3335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <strings.h> // NOLINT 3345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/mman.h> // NOLINT 3355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/time.h> // NOLINT 3365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <unistd.h> // NOLINT 3375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <string> 3385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#elif GTEST_OS_SYMBIAN 3405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# define GTEST_HAS_GETTIMEOFDAY_ 1 3415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/time.h> // NOLINT 3425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#elif GTEST_OS_ZOS 3445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# define GTEST_HAS_GETTIMEOFDAY_ 1 3455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/time.h> // NOLINT 3465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// On z/OS we additionally need strings.h for strcasecmp. 3485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <strings.h> // NOLINT 3495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. 3515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <windows.h> // NOLINT 3535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#elif GTEST_OS_WINDOWS // We are on Windows proper. 3555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <io.h> // NOLINT 3575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/timeb.h> // NOLINT 3585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/types.h> // NOLINT 3595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/stat.h> // NOLINT 3605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# if GTEST_OS_WINDOWS_MINGW 3625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// MinGW has gettimeofday() but not _ftime64(). 3635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// TODO(kenton@google.com): Use autoconf to detect availability of 3645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// gettimeofday(). 3655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// TODO(kenton@google.com): There are other ways to get the time on 3665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Windows, like GetTickCount() or GetSystemTimeAsFileTime(). MinGW 3675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// supports these. consider using them instead. 3685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# define GTEST_HAS_GETTIMEOFDAY_ 1 3695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/time.h> // NOLINT 3705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# endif // GTEST_OS_WINDOWS_MINGW 3715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// cpplint thinks that the header is already included, so we want to 3735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// silence it. 3745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <windows.h> // NOLINT 3755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#else 3775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Assume other platforms have gettimeofday(). 3795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// TODO(kenton@google.com): Use autoconf to detect availability of 3805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// gettimeofday(). 3815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# define GTEST_HAS_GETTIMEOFDAY_ 1 3825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// cpplint thinks that the header is already included, so we want to 3845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// silence it. 3855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <sys/time.h> // NOLINT 3865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <unistd.h> // NOLINT 3875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif // GTEST_OS_LINUX 3895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#if GTEST_HAS_EXCEPTIONS 3915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <stdexcept> 3925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif 3935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#if GTEST_CAN_STREAM_RESULTS_ 3955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <arpa/inet.h> // NOLINT 3965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <netdb.h> // NOLINT 3975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif 3985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 3995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Indicates that this translation unit is part of Google Test's 4005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// implementation. It must come before gtest-internal-inl.h is 4015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// included, or there will be a compiler error. This trick is to 4025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// prevent a user from accidentally including gtest-internal-inl.h in 4035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// his code. 4045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#define GTEST_IMPLEMENTATION_ 1 4055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Copyright 2005, Google Inc. 4065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// All rights reserved. 4075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 4085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Redistribution and use in source and binary forms, with or without 4095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// modification, are permitted provided that the following conditions are 4105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// met: 4115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 4125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Redistributions of source code must retain the above copyright 4135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// notice, this list of conditions and the following disclaimer. 4145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Redistributions in binary form must reproduce the above 4155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// copyright notice, this list of conditions and the following disclaimer 4165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// in the documentation and/or other materials provided with the 4175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// distribution. 4185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// * Neither the name of Google Inc. nor the names of its 4195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// contributors may be used to endorse or promote products derived from 4205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// this software without specific prior written permission. 4215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 4225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 4295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 4305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 4315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 4325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Utility functions and classes used by the Google C++ testing framework. 4355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 4365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Author: wan@google.com (Zhanyong Wan) 4375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 4385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// This file contains purely Google Test's internal implementation. Please 4395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// DO NOT #INCLUDE IT IN A USER PROGRAM. 4405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_ 4425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#define GTEST_SRC_GTEST_INTERNAL_INL_H_ 4435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is 4455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// part of Google Test's implementation; otherwise it's undefined. 4465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#if !GTEST_IMPLEMENTATION_ 4475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A user is trying to include this from his code - just say no. 4485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# error "gtest-internal-inl.h is part of Google Test's internal implementation." 4495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# error "It must not be included except by Google Test itself." 4505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif // GTEST_IMPLEMENTATION_ 4515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#ifndef _WIN32_WCE 4535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <errno.h> 4545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif // !_WIN32_WCE 4555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <stddef.h> 4565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <stdlib.h> // For strtoll/_strtoul64/malloc/free. 4575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <string.h> // For memmove. 4585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <algorithm> 4605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <string> 4615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#include <vector> 4625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#if GTEST_CAN_STREAM_RESULTS_ 4655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <arpa/inet.h> // NOLINT 4665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <netdb.h> // NOLINT 4675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif 4685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#if GTEST_OS_WINDOWS 4705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang# include <windows.h> // NOLINT 4715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif // GTEST_OS_WINDOWS 4725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangnamespace testing { 4755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Declares the flags. 4775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 4785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// We don't want the users to modify this flag in the code, but want 4795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Google Test's own unit tests to be able to access it. Therefore we 4805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// declare it here as opposed to in gtest.h. 4815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_DECLARE_bool_(death_test_use_fork); 4825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangnamespace internal { 4845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// The value of GetTestTypeId() as seen from within the Google Test 4865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// library. This is solely for testing GetTestTypeId(). 4875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ extern const TypeId kTestTypeIdInGoogleTest; 4885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 4895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Names of the flags (needed for parsing Google Test flags). 4905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests"; 4915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kBreakOnFailureFlag[] = "break_on_failure"; 4925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kCatchExceptionsFlag[] = "catch_exceptions"; 4935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kColorFlag[] = "color"; 4945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kFilterFlag[] = "filter"; 4955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kListTestsFlag[] = "list_tests"; 4965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kOutputFlag[] = "output"; 4975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kPrintTimeFlag[] = "print_time"; 4985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kRandomSeedFlag[] = "random_seed"; 4995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kRepeatFlag[] = "repeat"; 5005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kShuffleFlag[] = "shuffle"; 5015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kStackTraceDepthFlag[] = "stack_trace_depth"; 5025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kStreamResultToFlag[] = "stream_result_to"; 5035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst char kThrowOnFailureFlag[] = "throw_on_failure"; 5045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A valid random seed must be in [1, kMaxRandomSeed]. 5065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangconst int kMaxRandomSeed = 99999; 5075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// g_help_flag is true iff the --help flag or an equivalent form is 5095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// specified on the command line. 5105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ extern bool g_help_flag; 5115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Returns the current time in milliseconds. 5135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ TimeInMillis GetTimeInMillis(); 5145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Returns true iff Google Test should use colors in the output. 5165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ bool ShouldUseColor(bool stdout_is_tty); 5175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Formats the given time in milliseconds as seconds. 5195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms); 5205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Converts the given time in milliseconds to a date string in the ISO 8601 5225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// format, without the timezone information. N.B.: due to the use the 5235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// non-reentrant localtime() function, this function is not thread safe. Do 5245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// not use it in any code that can be called from multiple threads. 5255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms); 5265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Parses a string for an Int32 flag, in the form of "--flag=value". 5285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 5295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// On success, stores the value of the flag in *value, and returns 5305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// true. On failure, returns false without changing *value. 5315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ bool ParseInt32Flag( 5325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const char* str, const char* flag, Int32* value); 5335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Returns a random seed in range [1, kMaxRandomSeed] based on the 5355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// given --gtest_random_seed flag value. 5365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuanginline int GetRandomSeedFromFlag(Int32 random_seed_flag) { 5375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const unsigned int raw_seed = (random_seed_flag == 0) ? 5385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static_cast<unsigned int>(GetTimeInMillis()) : 5395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static_cast<unsigned int>(random_seed_flag); 5405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Normalizes the actual seed to range [1, kMaxRandomSeed] such that 5425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // it's easy to type. 5435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const int normalized_seed = 5445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static_cast<int>((raw_seed - 1U) % 5455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static_cast<unsigned int>(kMaxRandomSeed)) + 1; 5465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang return normalized_seed; 5475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 5485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Returns the first valid random seed after 'seed'. The behavior is 5505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// undefined if 'seed' is invalid. The seed after kMaxRandomSeed is 5515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// considered to be 1. 5525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuanginline int GetNextRandomSeed(int seed) { 5535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed) 5545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang << "Invalid random seed " << seed << " - must be in [1, " 5555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang << kMaxRandomSeed << "]."; 5565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const int next_seed = seed + 1; 5575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang return (next_seed > kMaxRandomSeed) ? 1 : next_seed; 5585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 5595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// This class saves the values of all Google Test flags in its c'tor, and 5615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// restores them in its d'tor. 5625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass GTestFlagSaver { 5635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public: 5645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // The c'tor. 5655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTestFlagSaver() { 5665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests); 5675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang break_on_failure_ = GTEST_FLAG(break_on_failure); 5685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang catch_exceptions_ = GTEST_FLAG(catch_exceptions); 5695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang color_ = GTEST_FLAG(color); 5705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang death_test_style_ = GTEST_FLAG(death_test_style); 5715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang death_test_use_fork_ = GTEST_FLAG(death_test_use_fork); 5725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang filter_ = GTEST_FLAG(filter); 5735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang internal_run_death_test_ = GTEST_FLAG(internal_run_death_test); 5745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang list_tests_ = GTEST_FLAG(list_tests); 5755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang output_ = GTEST_FLAG(output); 5765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang print_time_ = GTEST_FLAG(print_time); 5775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang random_seed_ = GTEST_FLAG(random_seed); 5785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang repeat_ = GTEST_FLAG(repeat); 5795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang shuffle_ = GTEST_FLAG(shuffle); 5805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang stack_trace_depth_ = GTEST_FLAG(stack_trace_depth); 5815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang stream_result_to_ = GTEST_FLAG(stream_result_to); 5825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang throw_on_failure_ = GTEST_FLAG(throw_on_failure); 5835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } 5845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 5855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS. 5865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ~GTestFlagSaver() { 5875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_; 5885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(break_on_failure) = break_on_failure_; 5895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(catch_exceptions) = catch_exceptions_; 5905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(color) = color_; 5915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(death_test_style) = death_test_style_; 5925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(death_test_use_fork) = death_test_use_fork_; 5935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(filter) = filter_; 5945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(internal_run_death_test) = internal_run_death_test_; 5955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(list_tests) = list_tests_; 5965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(output) = output_; 5975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(print_time) = print_time_; 5985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(random_seed) = random_seed_; 5995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(repeat) = repeat_; 6005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(shuffle) = shuffle_; 6015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(stack_trace_depth) = stack_trace_depth_; 6025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(stream_result_to) = stream_result_to_; 6035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_FLAG(throw_on_failure) = throw_on_failure_; 6045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } 6055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang private: 6075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Fields for saving the original values of flags. 6085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool also_run_disabled_tests_; 6095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool break_on_failure_; 6105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool catch_exceptions_; 6115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::string color_; 6125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::string death_test_style_; 6135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool death_test_use_fork_; 6145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::string filter_; 6155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::string internal_run_death_test_; 6165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool list_tests_; 6175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::string output_; 6185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool print_time_; 6195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang internal::Int32 random_seed_; 6205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang internal::Int32 repeat_; 6215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool shuffle_; 6225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang internal::Int32 stack_trace_depth_; 6235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::string stream_result_to_; 6245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool throw_on_failure_; 6255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} GTEST_ATTRIBUTE_UNUSED_; 6265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Converts a Unicode code point to a narrow string in UTF-8 encoding. 6285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// code_point parameter is of type UInt32 because wchar_t may not be 6295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// wide enough to contain a code point. 6305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// If the code_point is not a valid Unicode code point 6315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted 6325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// to "(Invalid Unicode 0xXXXXXXXX)". 6335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ std::string CodePointToUtf8(UInt32 code_point); 6345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Converts a wide string to a narrow string in UTF-8 encoding. 6365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// The wide string is assumed to have the following encoding: 6375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS) 6385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// UTF-32 if sizeof(wchar_t) == 4 (on Linux) 6395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Parameter str points to a null-terminated wide string. 6405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Parameter num_chars may additionally limit the number 6415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// of wchar_t characters processed. -1 is used when the entire string 6425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// should be processed. 6435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// If the string contains code points that are not valid Unicode code points 6445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output 6455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding 6465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// and contains invalid UTF-16 surrogate pairs, values in those pairs 6475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// will be encoded as individual Unicode characters from Basic Normal Plane. 6485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars); 6495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file 6515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// if the variable is present. If a file already exists at this location, this 6525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// function will write over it. If the variable is present, but the file cannot 6535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// be created, prints an error and exits. 6545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangvoid WriteToShardStatusFileIfNeeded(); 6555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Checks whether sharding is enabled by examining the relevant 6575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// environment variable values. If the variables are present, 6585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// but inconsistent (e.g., shard_index >= total_shards), prints 6595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// an error and exits. If in_subprocess_for_death_test, sharding is 6605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// disabled because it must only be applied to the original test 6615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// process. Otherwise, we could filter out death tests we intended to execute. 6625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ bool ShouldShard(const char* total_shards_str, 6635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const char* shard_index_str, 6645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool in_subprocess_for_death_test); 6655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Parses the environment variable var as an Int32. If it is unset, 6675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// returns default_val. If it is not an Int32, prints an error and 6685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// and aborts. 6695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val); 6705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Given the total number of shards, the shard index, and the test id, 6725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// returns true iff the test should be run on this shard. The test id is 6735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// some arbitrary but unique non-negative integer assigned to each test 6745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// method. Assumes that 0 <= shard_index < total_shards. 6755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ bool ShouldRunTestOnShard( 6765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang int total_shards, int shard_index, int test_id); 6775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// STL container utilities. 6795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Returns the number of elements in the given container that satisfy 6815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// the given predicate. 6825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangtemplate <class Container, typename Predicate> 6835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuanginline int CountIf(const Container& c, Predicate predicate) { 6845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Implemented as an explicit loop since std::count_if() in libCstd on 6855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Solaris has a non-standard signature. 6865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang int count = 0; 6875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) { 6885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang if (predicate(*it)) 6895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ++count; 6905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } 6915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang return count; 6925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 6935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 6945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Applies a function/functor to each element in the container. 6955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangtemplate <class Container, typename Functor> 6965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangvoid ForEach(const Container& c, Functor functor) { 6975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::for_each(c.begin(), c.end(), functor); 6985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 6995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Returns the i-th element of the vector, or default_value if i is not 7015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// in range [0, v.size()). 7025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangtemplate <typename E> 7035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuanginline E GetElementOr(const std::vector<E>& v, int i, E default_value) { 7045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i]; 7055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 7065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Performs an in-place shuffle of a range of the vector's elements. 7085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 'begin' and 'end' are element indices as an STL-style range; 7095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// i.e. [begin, end) are shuffled, where 'end' == size() means to 7105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// shuffle to the end of the vector. 7115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangtemplate <typename E> 7125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangvoid ShuffleRange(internal::Random* random, int begin, int end, 7135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::vector<E>* v) { 7145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const int size = static_cast<int>(v->size()); 7155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_CHECK_(0 <= begin && begin <= size) 7165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang << "Invalid shuffle range start " << begin << ": must be in range [0, " 7175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang << size << "]."; 7185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_CHECK_(begin <= end && end <= size) 7195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang << "Invalid shuffle range finish " << end << ": must be in range [" 7205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang << begin << ", " << size << "]."; 7215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Fisher-Yates shuffle, from 7235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle 7245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang for (int range_width = end - begin; range_width >= 2; range_width--) { 7255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const int last_in_range = begin + range_width - 1; 7265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const int selected = begin + random->Generate(range_width); 7275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::swap((*v)[selected], (*v)[last_in_range]); 7285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } 7295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 7305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Performs an in-place shuffle of the vector's elements. 7325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangtemplate <typename E> 7335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuanginline void Shuffle(internal::Random* random, std::vector<E>* v) { 7345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang ShuffleRange(random, 0, static_cast<int>(v->size()), v); 7355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 7365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A function for deleting an object. Handy for being used as a 7385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// functor. 7395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangtemplate <typename T> 7405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangstatic void Delete(T* x) { 7415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang delete x; 7425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang} 7435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A predicate that checks the key of a TestProperty against a known key. 7455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 7465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// TestPropertyKeyIs is copyable. 7475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass TestPropertyKeyIs { 7485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public: 7495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Constructor. 7505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // 7515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // TestPropertyKeyIs has NO default constructor. 7525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang explicit TestPropertyKeyIs(const std::string& key) : key_(key) {} 7535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns true iff the test name of test property matches on key_. 7555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang bool operator()(const TestProperty& test_property) const { 7565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang return test_property.key() == key_; 7575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang } 7585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang private: 7605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang std::string key_; 7615ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang}; 7625ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7635ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Class UnitTestOptions. 7645ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 7655ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// This class contains functions for processing options the user 7665ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// specifies when running the tests. It has only static members. 7675ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// 7685ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// In most cases, the user can specify an option using either an 7695ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// environment variable or a command line flag. E.g. you can set the 7705ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// test filter using either GTEST_FILTER or --gtest_filter. If both 7715ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// the variable and the flag are present, the latter overrides the 7725ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// former. 7735ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass GTEST_API_ UnitTestOptions { 7745ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public: 7755ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Functions for processing the gtest_output flag. 7765ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7775ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns the output format, or "" for normal printed output. 7785ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static std::string GetOutputFormat(); 7795ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7805ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns the absolute path of the requested output file, or the 7815ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // default (test_detail.xml in the original working directory) if 7825ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // none was explicitly specified. 7835ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static std::string GetAbsolutePathToOutputFile(); 7845ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7855ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Functions for processing the gtest_filter flag. 7865ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7875ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns true iff the wildcard pattern matches the string. The 7885ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // first ':' or '\0' character in pattern marks the end of it. 7895ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // 7905ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // This recursive algorithm isn't very efficient, but is clear and 7915ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // works well enough for matching test names, which are short. 7925ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static bool PatternMatchesString(const char *pattern, const char *str); 7935ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7945ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns true iff the user-specified filter matches the test case 7955ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // name and the test name. 7965ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static bool FilterMatchesTest(const std::string &test_case_name, 7975ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang const std::string &test_name); 7985ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 7995ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#if GTEST_OS_WINDOWS 8005ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Function for supporting the gtest_catch_exception flag. 8015ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8025ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the 8035ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. 8045ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // This function is useful as an __except condition. 8055ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static int GTestShouldProcessSEH(DWORD exception_code); 8065ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang#endif // GTEST_OS_WINDOWS 8075ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8085ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns true if "name" matches the ':' separated list of glob-style 8095ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // filters in "filter". 8105ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static bool MatchesFilter(const std::string& name, const char* filter); 8115ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang}; 8125ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8135ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// Returns the current application's name, removing directory path if that 8145ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// is present. Used by UnitTestOptions::GetOutputFile. 8155ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangGTEST_API_ FilePath GetCurrentExecutableName(); 8165ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8175ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// The role interface for getting the OS stack trace as a string. 8185ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass OsStackTraceGetterInterface { 8195ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public: 8205ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang OsStackTraceGetterInterface() {} 8215ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang virtual ~OsStackTraceGetterInterface() {} 8225ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8235ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Returns the current OS stack trace as an std::string. Parameters: 8245ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // 8255ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // max_depth - the maximum number of stack frames to be included 8265ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // in the trace. 8275ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // skip_count - the number of top frames to be skipped; doesn't count 8285ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // against max_depth. 8295ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang virtual string CurrentStackTrace(int max_depth, int skip_count) = 0; 8305ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8315ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // UponLeavingGTest() should be called immediately before Google Test calls 8325ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // user code. It saves some information about the current stack that 8335ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // CurrentStackTrace() will use to find and hide Google Test stack frames. 8345ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang virtual void UponLeavingGTest() = 0; 8355ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8365ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang private: 8375ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface); 8385ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang}; 8395ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8405ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang// A working implementation of the OsStackTraceGetterInterface interface. 8415ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuangclass OsStackTraceGetter : public OsStackTraceGetterInterface { 8425ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang public: 8435ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang OsStackTraceGetter() : caller_frame_(NULL) {} 8445ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8455ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang virtual string CurrentStackTrace(int max_depth, int skip_count) 8465ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang GTEST_LOCK_EXCLUDED_(mutex_); 8475ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8485ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_); 8495ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8505ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // This string is inserted in place of stack frames that are part of 8515ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // Google Test's implementation. 8525ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang static const char* const kElidedFramesMarker; 8535ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8545ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang private: 8555ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang Mutex mutex_; // protects all internal state 8565ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang 8575ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // We save the stack frame below the frame that calls user code. 8585ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // We do this because the address of the frame immediately below 8595ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // the user code changes between the call to UponLeavingGTest() 8605ae7ac49f08a179e4f054d99fcfc9dce78d26e58hkuang // and any calls to CurrentStackTrace() from within the user code. 8615ae7ac49f08a179e4f054d99fcfc9dce78d26e58