1167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// Copyright 2008, Google Inc.
2167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// All rights reserved.
3167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//
4167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// Redistribution and use in source and binary forms, with or without
5167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// modification, are permitted provided that the following conditions are
6167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// met:
7167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//
8167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//     * Redistributions of source code must retain the above copyright
9167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// notice, this list of conditions and the following disclaimer.
10167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//     * Redistributions in binary form must reproduce the above
11167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// copyright notice, this list of conditions and the following disclaimer
12167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// in the documentation and/or other materials provided with the
13167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// distribution.
14167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//     * Neither the name of Google Inc. nor the names of its
15167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// contributors may be used to endorse or promote products derived from
16167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// this software without specific prior written permission.
17167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//
18167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//
30167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// Author: mheule@google.com (Markus Heule)
31167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//
32167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// Google C++ Testing Framework (Google Test)
33167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org//
34167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// Sometimes it's desirable to build Google Test by compiling a single file.
35167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// This file serves this purpose.
36167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org
37167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// This line ensures that gtest.h can be compiled on its own, even
38167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// when it's fused.
39167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org#include "gtest/gtest.h"
40167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org
41167514562bbce1eb0566271d6cb41d90d2b5ffa0hclam@chromium.org// The following lines pull in the real gtest *.cc files.
420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Copyright 2005, Google Inc.
430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// All rights reserved.
440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Redistribution and use in source and binary forms, with or without
460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// modification, are permitted provided that the following conditions are
470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// met:
480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Redistributions of source code must retain the above copyright
500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// notice, this list of conditions and the following disclaimer.
510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Redistributions in binary form must reproduce the above
520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// copyright notice, this list of conditions and the following disclaimer
530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// in the documentation and/or other materials provided with the
540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// distribution.
550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Neither the name of Google Inc. nor the names of its
560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// contributors may be used to endorse or promote products derived from
570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// this software without specific prior written permission.
580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Author: wan@google.com (Zhanyong Wan)
720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The Google C++ Testing Framework (Google Test)
740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Copyright 2007, Google Inc.
760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// All rights reserved.
770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Redistribution and use in source and binary forms, with or without
790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// modification, are permitted provided that the following conditions are
800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// met:
810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Redistributions of source code must retain the above copyright
830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// notice, this list of conditions and the following disclaimer.
840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Redistributions in binary form must reproduce the above
850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// copyright notice, this list of conditions and the following disclaimer
860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// in the documentation and/or other materials provided with the
870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// distribution.
880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Neither the name of Google Inc. nor the names of its
890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// contributors may be used to endorse or promote products derived from
900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// this software without specific prior written permission.
910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
1040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Author: wan@google.com (Zhanyong Wan)
1050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
1060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Utilities for testing Google Test itself and code that uses Google Test
1070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// (e.g. frameworks built on top of Google Test).
1080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
1100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
1110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace testing {
1140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This helper class can be used to mock out Google Test failure reporting
1160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// so that we can test Google Test or code that builds on Google Test.
1170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
1180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// An object of this class appends a TestPartResult object to the
1190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TestPartResultArray object given in the constructor whenever a Google Test
1200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// failure is reported. It can either intercept only failures that are
1210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// generated in the same thread that created this object or it can intercept
1220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// all generated failures. The scope of this mock object can be controlled with
1230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// the second argument to the two arguments constructor.
1240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass GTEST_API_ ScopedFakeTestPartResultReporter
1250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    : public TestPartResultReporterInterface {
1260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
1270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The two possible mocking modes of this object.
1280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  enum InterceptMode {
1290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    INTERCEPT_ONLY_CURRENT_THREAD,  // Intercepts only thread local failures.
1300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    INTERCEPT_ALL_THREADS           // Intercepts all failures.
1310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  };
1320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The c'tor sets this object as the test part result reporter used
1340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // by Google Test.  The 'result' parameter specifies where to report the
1350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // results. This reporter will only catch failures generated in the current
1360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // thread. DEPRECATED
1370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);
1380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Same as above, but you can choose the interception scope of this object.
1400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
1410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                                   TestPartResultArray* result);
1420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The d'tor restores the previous test part result reporter.
1440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual ~ScopedFakeTestPartResultReporter();
1450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Appends the TestPartResult object to the TestPartResultArray
1470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // received in the constructor.
1480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
1490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // This method is from the TestPartResultReporterInterface
1500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // interface.
1510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual void ReportTestPartResult(const TestPartResult& result);
1520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
1530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void Init();
1540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const InterceptMode intercept_mode_;
1560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestPartResultReporterInterface* old_reporter_;
1570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestPartResultArray* const result_;
1580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
1600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
1610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace internal {
1630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A helper class for implementing EXPECT_FATAL_FAILURE() and
1650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// EXPECT_NONFATAL_FAILURE().  Its destructor verifies that the given
1660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TestPartResultArray contains exactly one failure that has the given
1670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// type and contains the given substring.  If that's not the case, a
1680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// non-fatal failure will be generated.
1690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass GTEST_API_ SingleFailureChecker {
1700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
1710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The constructor remembers the arguments.
1720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  SingleFailureChecker(const TestPartResultArray* results,
1730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                       TestPartResult::Type type,
1740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                       const string& substr);
1750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  ~SingleFailureChecker();
1760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
1770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TestPartResultArray* const results_;
1780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TestPartResult::Type type_;
1790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const string substr_;
1800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
1820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
1830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}  // namespace internal
1850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}  // namespace testing
1870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
1880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A set of macros for testing Google Test assertions or code that's expected
1890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// to generate Google Test fatal failures.  It verifies that the given
1900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// statement will cause exactly one fatal Google Test failure with 'substr'
1910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// being part of the failure message.
1920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
1930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// There are two different versions of this macro. EXPECT_FATAL_FAILURE only
1940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// affects and considers failures generated in the current thread and
1950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
1960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
1970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The verification of the assertion is done correctly even when the statement
1980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// throws an exception or aborts the current function.
1990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Known restrictions:
2010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   - 'statement' cannot reference local non-static variables or
2020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     non-static members of the current object.
2030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   - 'statement' cannot return a value.
2040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   - You cannot stream a failure message to this macro.
2050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Note that even though the implementations of the following two
2070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// macros are much alike, we cannot refactor them to use a common
2080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// helper macro, due to some peculiarity in how the preprocessor
2090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// works.  The AcceptsMacroThatExpandsToUnprotectedComma test in
2100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// gtest_unittest.cc will fail to compile if we do that.
2110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#define EXPECT_FATAL_FAILURE(statement, substr) \
2120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  do { \
2130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    class GTestExpectFatalFailureHelper {\
2140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org     public:\
2150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      static void Execute() { statement; }\
2160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    };\
2170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::TestPartResultArray gtest_failures;\
2180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::internal::SingleFailureChecker gtest_checker(\
2190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
2200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    {\
2210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
2220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          ::testing::ScopedFakeTestPartResultReporter:: \
2230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
2240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      GTestExpectFatalFailureHelper::Execute();\
2250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }\
2260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  } while (::testing::internal::AlwaysFalse())
2270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
2280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
2290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  do { \
2300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    class GTestExpectFatalFailureHelper {\
2310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org     public:\
2320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      static void Execute() { statement; }\
2330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    };\
2340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::TestPartResultArray gtest_failures;\
2350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::internal::SingleFailureChecker gtest_checker(\
2360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
2370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    {\
2380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
2390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          ::testing::ScopedFakeTestPartResultReporter:: \
2400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          INTERCEPT_ALL_THREADS, &gtest_failures);\
2410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      GTestExpectFatalFailureHelper::Execute();\
2420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }\
2430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  } while (::testing::internal::AlwaysFalse())
2440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
2450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A macro for testing Google Test assertions or code that's expected to
2460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// generate Google Test non-fatal failures.  It asserts that the given
2470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// statement will cause exactly one non-fatal Google Test failure with 'substr'
2480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// being part of the failure message.
2490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
2510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// affects and considers failures generated in the current thread and
2520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
2530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// 'statement' is allowed to reference local variables and members of
2550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// the current object.
2560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The verification of the assertion is done correctly even when the statement
2580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// throws an exception or aborts the current function.
2590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Known restrictions:
2610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   - You cannot stream a failure message to this macro.
2620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Note that even though the implementations of the following two
2640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// macros are much alike, we cannot refactor them to use a common
2650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// helper macro, due to some peculiarity in how the preprocessor
2660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// works.  If we do that, the code won't compile when the user gives
2670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
2680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// expands to code containing an unprotected comma.  The
2690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
2700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// catches that.
2710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
2720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// For the same reason, we have to write
2730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   if (::testing::internal::AlwaysTrue()) { statement; }
2740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// instead of
2750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
2760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// to avoid an MSVC warning on unreachable code.
2770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#define EXPECT_NONFATAL_FAILURE(statement, substr) \
2780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  do {\
2790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::TestPartResultArray gtest_failures;\
2800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::internal::SingleFailureChecker gtest_checker(\
2810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
2820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        (substr));\
2830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    {\
2840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
2850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          ::testing::ScopedFakeTestPartResultReporter:: \
2860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
2870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      if (::testing::internal::AlwaysTrue()) { statement; }\
2880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }\
2890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  } while (::testing::internal::AlwaysFalse())
2900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
2910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
2920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  do {\
2930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::TestPartResultArray gtest_failures;\
2940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ::testing::internal::SingleFailureChecker gtest_checker(\
2950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
2960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        (substr));\
2970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    {\
2980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
2990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
3000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          &gtest_failures);\
3010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      if (::testing::internal::AlwaysTrue()) { statement; }\
3020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }\
3030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  } while (::testing::internal::AlwaysFalse())
3040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
3060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <ctype.h>
3080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <math.h>
3090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <stdarg.h>
3100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <stdio.h>
3110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <stdlib.h>
3120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <time.h>
3130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <wchar.h>
3140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <wctype.h>
3150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <algorithm>
3170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <iomanip>
3180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <limits>
3190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <ostream>  // NOLINT
3200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <sstream>
3210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <vector>
3220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_OS_LINUX
3240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TODO(kenton@google.com): Use autoconf to detect availability of
3260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// gettimeofday().
3270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# define GTEST_HAS_GETTIMEOFDAY_ 1
3280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <fcntl.h>  // NOLINT
3300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <limits.h>  // NOLINT
3310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sched.h>  // NOLINT
3320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Declares vsnprintf().  This header is not available on Windows.
3330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <strings.h>  // NOLINT
3340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/mman.h>  // NOLINT
3350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/time.h>  // NOLINT
3360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <unistd.h>  // NOLINT
3370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <string>
3380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#elif GTEST_OS_SYMBIAN
3400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# define GTEST_HAS_GETTIMEOFDAY_ 1
3410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/time.h>  // NOLINT
3420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#elif GTEST_OS_ZOS
3440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# define GTEST_HAS_GETTIMEOFDAY_ 1
3450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/time.h>  // NOLINT
3460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// On z/OS we additionally need strings.h for strcasecmp.
3480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <strings.h>  // NOLINT
3490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#elif GTEST_OS_WINDOWS_MOBILE  // We are on Windows CE.
3510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <windows.h>  // NOLINT
3530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#elif GTEST_OS_WINDOWS  // We are on Windows proper.
3550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <io.h>  // NOLINT
3570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/timeb.h>  // NOLINT
3580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/types.h>  // NOLINT
3590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/stat.h>  // NOLINT
3600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# if GTEST_OS_WINDOWS_MINGW
3620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// MinGW has gettimeofday() but not _ftime64().
3630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TODO(kenton@google.com): Use autoconf to detect availability of
3640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   gettimeofday().
3650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TODO(kenton@google.com): There are other ways to get the time on
3660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   Windows, like GetTickCount() or GetSystemTimeAsFileTime().  MinGW
3670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   supports these.  consider using them instead.
3680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#  define GTEST_HAS_GETTIMEOFDAY_ 1
3690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#  include <sys/time.h>  // NOLINT
3700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# endif  // GTEST_OS_WINDOWS_MINGW
3710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// cpplint thinks that the header is already included, so we want to
3730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// silence it.
3740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <windows.h>  // NOLINT
3750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#else
3770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Assume other platforms have gettimeofday().
3790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TODO(kenton@google.com): Use autoconf to detect availability of
3800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   gettimeofday().
3810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# define GTEST_HAS_GETTIMEOFDAY_ 1
3820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// cpplint thinks that the header is already included, so we want to
3840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// silence it.
3850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <sys/time.h>  // NOLINT
3860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <unistd.h>  // NOLINT
3870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_OS_LINUX
3890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_HAS_EXCEPTIONS
3910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <stdexcept>
3920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif
3930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_CAN_STREAM_RESULTS_
3950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <arpa/inet.h>  // NOLINT
3960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <netdb.h>  // NOLINT
3970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif
3980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
3990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Indicates that this translation unit is part of Google Test's
4000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// implementation.  It must come before gtest-internal-inl.h is
4010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// included, or there will be a compiler error.  This trick is to
4020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// prevent a user from accidentally including gtest-internal-inl.h in
4030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// his code.
4040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#define GTEST_IMPLEMENTATION_ 1
4050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Copyright 2005, Google Inc.
4060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// All rights reserved.
4070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
4080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Redistribution and use in source and binary forms, with or without
4090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// modification, are permitted provided that the following conditions are
4100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// met:
4110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
4120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Redistributions of source code must retain the above copyright
4130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// notice, this list of conditions and the following disclaimer.
4140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Redistributions in binary form must reproduce the above
4150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// copyright notice, this list of conditions and the following disclaimer
4160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// in the documentation and/or other materials provided with the
4170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// distribution.
4180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//     * Neither the name of Google Inc. nor the names of its
4190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// contributors may be used to endorse or promote products derived from
4200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// this software without specific prior written permission.
4210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
4220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Utility functions and classes used by the Google C++ testing framework.
4350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
4360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Author: wan@google.com (Zhanyong Wan)
4370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
4380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This file contains purely Google Test's internal implementation.  Please
4390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// DO NOT #INCLUDE IT IN A USER PROGRAM.
4400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
4420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#define GTEST_SRC_GTEST_INTERNAL_INL_H_
4430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
4450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// part of Google Test's implementation; otherwise it's undefined.
4460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if !GTEST_IMPLEMENTATION_
4470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A user is trying to include this from his code - just say no.
4480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# error "gtest-internal-inl.h is part of Google Test's internal implementation."
4490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# error "It must not be included except by Google Test itself."
4500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_IMPLEMENTATION_
4510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#ifndef _WIN32_WCE
4530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <errno.h>
4540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // !_WIN32_WCE
4550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <stddef.h>
4560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <stdlib.h>  // For strtoll/_strtoul64/malloc/free.
4570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <string.h>  // For memmove.
4580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <algorithm>
4600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <string>
4610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#include <vector>
4620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_CAN_STREAM_RESULTS_
4650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <arpa/inet.h>  // NOLINT
4660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <netdb.h>  // NOLINT
4670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif
4680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_OS_WINDOWS
4700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# include <windows.h>  // NOLINT
4710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_OS_WINDOWS
4720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace testing {
4750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Declares the flags.
4770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
4780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// We don't want the users to modify this flag in the code, but want
4790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Google Test's own unit tests to be able to access it. Therefore we
4800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// declare it here as opposed to in gtest.h.
4810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DECLARE_bool_(death_test_use_fork);
4820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace internal {
4840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The value of GetTestTypeId() as seen from within the Google Test
4860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// library.  This is solely for testing GetTestTypeId().
4870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
4880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
4890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Names of the flags (needed for parsing Google Test flags).
4900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
4910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kBreakOnFailureFlag[] = "break_on_failure";
4920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kCatchExceptionsFlag[] = "catch_exceptions";
4930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kColorFlag[] = "color";
4940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kFilterFlag[] = "filter";
4950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kListTestsFlag[] = "list_tests";
4960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kOutputFlag[] = "output";
4970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kPrintTimeFlag[] = "print_time";
4980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kRandomSeedFlag[] = "random_seed";
4990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kRepeatFlag[] = "repeat";
5000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kShuffleFlag[] = "shuffle";
5010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kStackTraceDepthFlag[] = "stack_trace_depth";
5020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kStreamResultToFlag[] = "stream_result_to";
5030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kThrowOnFailureFlag[] = "throw_on_failure";
5040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A valid random seed must be in [1, kMaxRandomSeed].
5060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst int kMaxRandomSeed = 99999;
5070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// g_help_flag is true iff the --help flag or an equivalent form is
5090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// specified on the command line.
5100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ extern bool g_help_flag;
5110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the current time in milliseconds.
5130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ TimeInMillis GetTimeInMillis();
5140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns true iff Google Test should use colors in the output.
5160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
5170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Formats the given time in milliseconds as seconds.
5190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
5200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Converts the given time in milliseconds to a date string in the ISO 8601
5220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// format, without the timezone information.  N.B.: due to the use the
5230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// non-reentrant localtime() function, this function is not thread safe.  Do
5240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// not use it in any code that can be called from multiple threads.
5250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
5260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Parses a string for an Int32 flag, in the form of "--flag=value".
5280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
5290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// On success, stores the value of the flag in *value, and returns
5300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// true.  On failure, returns false without changing *value.
5310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool ParseInt32Flag(
5320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const char* str, const char* flag, Int32* value);
5330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns a random seed in range [1, kMaxRandomSeed] based on the
5350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// given --gtest_random_seed flag value.
5360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orginline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
5370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const unsigned int raw_seed = (random_seed_flag == 0) ?
5380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      static_cast<unsigned int>(GetTimeInMillis()) :
5390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      static_cast<unsigned int>(random_seed_flag);
5400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
5420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // it's easy to type.
5430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const int normalized_seed =
5440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      static_cast<int>((raw_seed - 1U) %
5450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                       static_cast<unsigned int>(kMaxRandomSeed)) + 1;
5460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return normalized_seed;
5470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
5480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the first valid random seed after 'seed'.  The behavior is
5500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// undefined if 'seed' is invalid.  The seed after kMaxRandomSeed is
5510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// considered to be 1.
5520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orginline int GetNextRandomSeed(int seed) {
5530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
5540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << "Invalid random seed " << seed << " - must be in [1, "
5550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << kMaxRandomSeed << "].";
5560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const int next_seed = seed + 1;
5570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
5580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
5590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This class saves the values of all Google Test flags in its c'tor, and
5610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// restores them in its d'tor.
5620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass GTestFlagSaver {
5630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
5640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The c'tor.
5650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTestFlagSaver() {
5660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
5670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    break_on_failure_ = GTEST_FLAG(break_on_failure);
5680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    catch_exceptions_ = GTEST_FLAG(catch_exceptions);
5690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    color_ = GTEST_FLAG(color);
5700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    death_test_style_ = GTEST_FLAG(death_test_style);
5710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
5720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    filter_ = GTEST_FLAG(filter);
5730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
5740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    list_tests_ = GTEST_FLAG(list_tests);
5750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    output_ = GTEST_FLAG(output);
5760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    print_time_ = GTEST_FLAG(print_time);
5770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    random_seed_ = GTEST_FLAG(random_seed);
5780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    repeat_ = GTEST_FLAG(repeat);
5790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    shuffle_ = GTEST_FLAG(shuffle);
5800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
5810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    stream_result_to_ = GTEST_FLAG(stream_result_to);
5820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    throw_on_failure_ = GTEST_FLAG(throw_on_failure);
5830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
5840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
5850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The d'tor is not virtual.  DO NOT INHERIT FROM THIS CLASS.
5860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  ~GTestFlagSaver() {
5870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
5880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(break_on_failure) = break_on_failure_;
5890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(catch_exceptions) = catch_exceptions_;
5900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(color) = color_;
5910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(death_test_style) = death_test_style_;
5920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
5930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(filter) = filter_;
5940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
5950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(list_tests) = list_tests_;
5960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(output) = output_;
5970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(print_time) = print_time_;
5980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(random_seed) = random_seed_;
5990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(repeat) = repeat_;
6000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(shuffle) = shuffle_;
6010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
6020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(stream_result_to) = stream_result_to_;
6030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_FLAG(throw_on_failure) = throw_on_failure_;
6040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
6050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
6070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Fields for saving the original values of flags.
6080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool also_run_disabled_tests_;
6090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool break_on_failure_;
6100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool catch_exceptions_;
6110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string color_;
6120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string death_test_style_;
6130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool death_test_use_fork_;
6140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string filter_;
6150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string internal_run_death_test_;
6160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool list_tests_;
6170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string output_;
6180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool print_time_;
6190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::Int32 random_seed_;
6200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::Int32 repeat_;
6210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool shuffle_;
6220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::Int32 stack_trace_depth_;
6230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string stream_result_to_;
6240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool throw_on_failure_;
6250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org} GTEST_ATTRIBUTE_UNUSED_;
6260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Converts a Unicode code point to a narrow string in UTF-8 encoding.
6280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// code_point parameter is of type UInt32 because wchar_t may not be
6290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// wide enough to contain a code point.
6300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// If the code_point is not a valid Unicode code point
6310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
6320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// to "(Invalid Unicode 0xXXXXXXXX)".
6330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
6340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Converts a wide string to a narrow string in UTF-8 encoding.
6360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The wide string is assumed to have the following encoding:
6370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
6380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//   UTF-32 if sizeof(wchar_t) == 4 (on Linux)
6390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Parameter str points to a null-terminated wide string.
6400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Parameter num_chars may additionally limit the number
6410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// of wchar_t characters processed. -1 is used when the entire string
6420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// should be processed.
6430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// If the string contains code points that are not valid Unicode code points
6440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
6450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
6460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// and contains invalid UTF-16 surrogate pairs, values in those pairs
6470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// will be encoded as individual Unicode characters from Basic Normal Plane.
6480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
6490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
6510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// if the variable is present. If a file already exists at this location, this
6520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// function will write over it. If the variable is present, but the file cannot
6530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// be created, prints an error and exits.
6540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid WriteToShardStatusFileIfNeeded();
6550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Checks whether sharding is enabled by examining the relevant
6570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// environment variable values. If the variables are present,
6580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// but inconsistent (e.g., shard_index >= total_shards), prints
6590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// an error and exits. If in_subprocess_for_death_test, sharding is
6600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// disabled because it must only be applied to the original test
6610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// process. Otherwise, we could filter out death tests we intended to execute.
6620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool ShouldShard(const char* total_shards_str,
6630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                            const char* shard_index_str,
6640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                            bool in_subprocess_for_death_test);
6650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Parses the environment variable var as an Int32. If it is unset,
6670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// returns default_val. If it is not an Int32, prints an error and
6680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// and aborts.
6690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
6700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Given the total number of shards, the shard index, and the test id,
6720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// returns true iff the test should be run on this shard. The test id is
6730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// some arbitrary but unique non-negative integer assigned to each test
6740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// method. Assumes that 0 <= shard_index < total_shards.
6750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool ShouldRunTestOnShard(
6760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    int total_shards, int shard_index, int test_id);
6770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// STL container utilities.
6790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the number of elements in the given container that satisfy
6810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// the given predicate.
6820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgtemplate <class Container, typename Predicate>
6830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orginline int CountIf(const Container& c, Predicate predicate) {
6840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Implemented as an explicit loop since std::count_if() in libCstd on
6850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Solaris has a non-standard signature.
6860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int count = 0;
6870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
6880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    if (predicate(*it))
6890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      ++count;
6900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
6910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return count;
6920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
6930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
6940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Applies a function/functor to each element in the container.
6950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgtemplate <class Container, typename Functor>
6960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid ForEach(const Container& c, Functor functor) {
6970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::for_each(c.begin(), c.end(), functor);
6980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
6990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the i-th element of the vector, or default_value if i is not
7010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// in range [0, v.size()).
7020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgtemplate <typename E>
7030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orginline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
7040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
7050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
7060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Performs an in-place shuffle of a range of the vector's elements.
7080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// 'begin' and 'end' are element indices as an STL-style range;
7090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// i.e. [begin, end) are shuffled, where 'end' == size() means to
7100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// shuffle to the end of the vector.
7110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgtemplate <typename E>
7120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid ShuffleRange(internal::Random* random, int begin, int end,
7130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                  std::vector<E>* v) {
7140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const int size = static_cast<int>(v->size());
7150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_CHECK_(0 <= begin && begin <= size)
7160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << "Invalid shuffle range start " << begin << ": must be in range [0, "
7170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << size << "].";
7180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_CHECK_(begin <= end && end <= size)
7190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << "Invalid shuffle range finish " << end << ": must be in range ["
7200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << begin << ", " << size << "].";
7210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Fisher-Yates shuffle, from
7230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
7240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  for (int range_width = end - begin; range_width >= 2; range_width--) {
7250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const int last_in_range = begin + range_width - 1;
7260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const int selected = begin + random->Generate(range_width);
7270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    std::swap((*v)[selected], (*v)[last_in_range]);
7280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
7290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
7300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Performs an in-place shuffle of the vector's elements.
7320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgtemplate <typename E>
7330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orginline void Shuffle(internal::Random* random, std::vector<E>* v) {
7340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  ShuffleRange(random, 0, static_cast<int>(v->size()), v);
7350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
7360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A function for deleting an object.  Handy for being used as a
7380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// functor.
7390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgtemplate <typename T>
7400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic void Delete(T* x) {
7410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  delete x;
7420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
7430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A predicate that checks the key of a TestProperty against a known key.
7450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
7460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TestPropertyKeyIs is copyable.
7470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass TestPropertyKeyIs {
7480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
7490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Constructor.
7500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
7510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // TestPropertyKeyIs has NO default constructor.
7520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  explicit TestPropertyKeyIs(const std::string& key) : key_(key) {}
7530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns true iff the test name of test property matches on key_.
7550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool operator()(const TestProperty& test_property) const {
7560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return test_property.key() == key_;
7570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
7580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
7600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string key_;
7610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
7620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Class UnitTestOptions.
7640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
7650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This class contains functions for processing options the user
7660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// specifies when running the tests.  It has only static members.
7670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
7680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// In most cases, the user can specify an option using either an
7690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// environment variable or a command line flag.  E.g. you can set the
7700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// test filter using either GTEST_FILTER or --gtest_filter.  If both
7710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// the variable and the flag are present, the latter overrides the
7720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// former.
7730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass GTEST_API_ UnitTestOptions {
7740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
7750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Functions for processing the gtest_output flag.
7760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the output format, or "" for normal printed output.
7780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static std::string GetOutputFormat();
7790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the absolute path of the requested output file, or the
7810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // default (test_detail.xml in the original working directory) if
7820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // none was explicitly specified.
7830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static std::string GetAbsolutePathToOutputFile();
7840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Functions for processing the gtest_filter flag.
7860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns true iff the wildcard pattern matches the string.  The
7880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // first ':' or '\0' character in pattern marks the end of it.
7890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
7900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // This recursive algorithm isn't very efficient, but is clear and
7910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // works well enough for matching test names, which are short.
7920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static bool PatternMatchesString(const char *pattern, const char *str);
7930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns true iff the user-specified filter matches the test case
7950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // name and the test name.
7960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static bool FilterMatchesTest(const std::string &test_case_name,
7970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                                const std::string &test_name);
7980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
7990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_OS_WINDOWS
8000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Function for supporting the gtest_catch_exception flag.
8010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
8030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
8040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // This function is useful as an __except condition.
8050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static int GTestShouldProcessSEH(DWORD exception_code);
8060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_OS_WINDOWS
8070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns true if "name" matches the ':' separated list of glob-style
8090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // filters in "filter".
8100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static bool MatchesFilter(const std::string& name, const char* filter);
8110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
8120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the current application's name, removing directory path if that
8140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// is present.  Used by UnitTestOptions::GetOutputFile.
8150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ FilePath GetCurrentExecutableName();
8160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The role interface for getting the OS stack trace as a string.
8180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass OsStackTraceGetterInterface {
8190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
8200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  OsStackTraceGetterInterface() {}
8210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual ~OsStackTraceGetterInterface() {}
8220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the current OS stack trace as an std::string.  Parameters:
8240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
8250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   max_depth  - the maximum number of stack frames to be included
8260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //                in the trace.
8270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   skip_count - the number of top frames to be skipped; doesn't count
8280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //                against max_depth.
8290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
8300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // UponLeavingGTest() should be called immediately before Google Test calls
8320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // user code. It saves some information about the current stack that
8330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // CurrentStackTrace() will use to find and hide Google Test stack frames.
8340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual void UponLeavingGTest() = 0;
8350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
8370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
8380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
8390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A working implementation of the OsStackTraceGetterInterface interface.
8410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass OsStackTraceGetter : public OsStackTraceGetterInterface {
8420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
8430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  OsStackTraceGetter() : caller_frame_(NULL) {}
8440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual string CurrentStackTrace(int max_depth, int skip_count)
8460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      GTEST_LOCK_EXCLUDED_(mutex_);
8470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
8490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // This string is inserted in place of stack frames that are part of
8510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Google Test's implementation.
8520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static const char* const kElidedFramesMarker;
8530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
8550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  Mutex mutex_;  // protects all internal state
8560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // We save the stack frame below the frame that calls user code.
8580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // We do this because the address of the frame immediately below
8590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // the user code changes between the call to UponLeavingGTest()
8600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // and any calls to CurrentStackTrace() from within the user code.
8610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void* caller_frame_;
8620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
8640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
8650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Information about a Google Test trace point.
8670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstruct TraceInfo {
8680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char* file;
8690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int line;
8700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string message;
8710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
8720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This is the default global test part result reporter used in UnitTestImpl.
8740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This class should only be used by UnitTestImpl.
8750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass DefaultGlobalTestPartResultReporter
8760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  : public TestPartResultReporterInterface {
8770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
8780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
8790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Implements the TestPartResultReporterInterface. Reports the test part
8800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // result in the current test.
8810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual void ReportTestPartResult(const TestPartResult& result);
8820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
8840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  UnitTestImpl* const unit_test_;
8850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
8870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
8880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This is the default per thread test part result reporter used in
8900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// UnitTestImpl. This class should only be used by UnitTestImpl.
8910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass DefaultPerThreadTestPartResultReporter
8920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    : public TestPartResultReporterInterface {
8930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
8940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
8950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Implements the TestPartResultReporterInterface. The implementation just
8960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // delegates to the current global test part result reporter of *unit_test_.
8970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual void ReportTestPartResult(const TestPartResult& result);
8980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
8990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
9000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  UnitTestImpl* const unit_test_;
9010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
9030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
9040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The private implementation of the UnitTest class.  We don't protect
9060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// the methods under a mutex, as this class is not accessible by a
9070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// user and the UnitTest class that delegates work to this class does
9080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// proper locking.
9090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass GTEST_API_ UnitTestImpl {
9100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
9110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  explicit UnitTestImpl(UnitTest* parent);
9120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  virtual ~UnitTestImpl();
9130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // There are two different ways to register your own TestPartResultReporter.
9150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // You can register your own repoter to listen either only for test results
9160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // from the current thread or for results from all threads.
9170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // By default, each per-thread test result repoter just passes a new
9180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // TestPartResult to the global test result reporter, which registers the
9190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // test part result for the currently running test.
9200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the global test part result reporter.
9220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
9230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Sets the global test part result reporter.
9250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void SetGlobalTestPartResultReporter(
9260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      TestPartResultReporterInterface* reporter);
9270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the test part result reporter for the current thread.
9290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
9300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Sets the test part result reporter for the current thread.
9320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void SetTestPartResultReporterForCurrentThread(
9330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      TestPartResultReporterInterface* reporter);
9340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of successful test cases.
9360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int successful_test_case_count() const;
9370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of failed test cases.
9390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int failed_test_case_count() const;
9400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of all test cases.
9420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int total_test_case_count() const;
9430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of all test cases that contain at least one test
9450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // that should run.
9460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int test_case_to_run_count() const;
9470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of successful tests.
9490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int successful_test_count() const;
9500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of failed tests.
9520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int failed_test_count() const;
9530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of disabled tests that will be reported in the XML report.
9550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int reportable_disabled_test_count() const;
9560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of disabled tests.
9580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int disabled_test_count() const;
9590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of tests to be printed in the XML report.
9610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int reportable_test_count() const;
9620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of all tests.
9640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int total_test_count() const;
9650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the number of tests that should run.
9670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int test_to_run_count() const;
9680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the time of the test program start, in ms from the start of the
9700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // UNIX epoch.
9710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TimeInMillis start_timestamp() const { return start_timestamp_; }
9720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the elapsed time, in milliseconds.
9740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TimeInMillis elapsed_time() const { return elapsed_time_; }
9750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns true iff the unit test passed (i.e. all test cases passed).
9770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool Passed() const { return !Failed(); }
9780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns true iff the unit test failed (i.e. some test case failed
9800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // or something outside of all tests failed).
9810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool Failed() const {
9820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
9830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
9840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the i-th test case among all the test cases. i can range from 0 to
9860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // total_test_case_count() - 1. If i is not in that range, returns NULL.
9870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TestCase* GetTestCase(int i) const {
9880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const int index = GetElementOr(test_case_indices_, i, -1);
9890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return index < 0 ? NULL : test_cases_[i];
9900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
9910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the i-th test case among all the test cases. i can range from 0 to
9930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // total_test_case_count() - 1. If i is not in that range, returns NULL.
9940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestCase* GetMutableTestCase(int i) {
9950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const int index = GetElementOr(test_case_indices_, i, -1);
9960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return index < 0 ? NULL : test_cases_[index];
9970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
9980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
9990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Provides access to the event listener list.
10000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestEventListeners* listeners() { return &listeners_; }
10010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the TestResult for the test that's currently running, or
10030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // the TestResult for the ad hoc test if no test is running.
10040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestResult* current_test_result();
10050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the TestResult for the ad hoc test.
10070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
10080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Sets the OS stack trace getter.
10100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
10110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Does nothing if the input and the current OS stack trace getter
10120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // are the same; otherwise, deletes the old getter and makes the
10130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // input the current getter.
10140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
10150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the current OS stack trace getter if it is not NULL;
10170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // otherwise, creates an OsStackTraceGetter, makes it the current
10180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // getter, and returns it.
10190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  OsStackTraceGetterInterface* os_stack_trace_getter();
10200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the current OS stack trace as an std::string.
10220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
10230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The maximum number of stack frames to be included is specified by
10240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // the gtest_stack_trace_depth flag.  The skip_count parameter
10250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // specifies the number of top frames to be skipped, which doesn't
10260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // count against the number of frames to be included.
10270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
10280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // For example, if Foo() calls Bar(), which in turn calls
10290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
10300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
10310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
10320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Finds and returns a TestCase with the given name.  If one doesn't
10340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // exist, creates one and returns it.
10350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
10360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Arguments:
10370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
10380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   test_case_name: name of the test case
10390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   type_param:     the name of the test's type parameter, or NULL if
10400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //                   this is not a typed or a type-parameterized test.
10410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   set_up_tc:      pointer to the function that sets up the test case
10420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   tear_down_tc:   pointer to the function that tears down the test case
10430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestCase* GetTestCase(const char* test_case_name,
10440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                        const char* type_param,
10450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                        Test::SetUpTestCaseFunc set_up_tc,
10460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                        Test::TearDownTestCaseFunc tear_down_tc);
10470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Adds a TestInfo to the unit test.
10490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
10500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Arguments:
10510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
10520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   set_up_tc:    pointer to the function that sets up the test case
10530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   tear_down_tc: pointer to the function that tears down the test case
10540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   test_info:    the TestInfo object
10550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
10560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                   Test::TearDownTestCaseFunc tear_down_tc,
10570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                   TestInfo* test_info) {
10580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // In order to support thread-safe death tests, we need to
10590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // remember the original working directory when the test program
10600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // was first invoked.  We cannot do this in RUN_ALL_TESTS(), as
10610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // the user may have changed the current directory before calling
10620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // RUN_ALL_TESTS().  Therefore we capture the current directory in
10630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // AddTestInfo(), which is called to register a TEST or TEST_F
10640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // before main() is reached.
10650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    if (original_working_dir_.IsEmpty()) {
10660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      original_working_dir_.Set(FilePath::GetCurrentDir());
10670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      GTEST_CHECK_(!original_working_dir_.IsEmpty())
10680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          << "Failed to get the current working directory.";
10690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
10700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GetTestCase(test_info->test_case_name(),
10720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                test_info->type_param(),
10730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                set_up_tc,
10740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                tear_down_tc)->AddTestInfo(test_info);
10750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
10760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_HAS_PARAM_TEST
10780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns ParameterizedTestCaseRegistry object used to keep track of
10790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // value-parameterized tests and instantiate and register them.
10800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
10810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return parameterized_test_registry_;
10820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
10830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_HAS_PARAM_TEST
10840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Sets the TestCase object for the test that's currently running.
10860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void set_current_test_case(TestCase* a_current_test_case) {
10870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    current_test_case_ = a_current_test_case;
10880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
10890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Sets the TestInfo object for the test that's currently running.  If
10910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // current_test_info is NULL, the assertion results will be stored in
10920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // ad_hoc_test_result_.
10930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void set_current_test_info(TestInfo* a_current_test_info) {
10940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    current_test_info_ = a_current_test_info;
10950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
10960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
10970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Registers all parameterized tests defined using TEST_P and
10980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
10990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // combination. This method can be called more then once; it has guards
11000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // protecting from registering the tests more then once.  If
11010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // value-parameterized tests are disabled, RegisterParameterizedTests is
11020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // present but does nothing.
11030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void RegisterParameterizedTests();
11040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Runs all tests in this UnitTest object, prints the result, and
11060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // returns true if all tests are successful.  If any exception is
11070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // thrown during a test, this test is considered to be failed, but
11080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // the rest of the tests will still be run.
11090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool RunAllTests();
11100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Clears the results of all tests, except the ad hoc tests.
11120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void ClearNonAdHocTestResult() {
11130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ForEach(test_cases_, TestCase::ClearTestCaseResult);
11140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
11150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Clears the results of ad-hoc test assertions.
11170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void ClearAdHocTestResult() {
11180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    ad_hoc_test_result_.Clear();
11190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
11200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Adds a TestProperty to the current TestResult object when invoked in a
11220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // context of a test or a test case, or to the global property set. If the
11230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // result already contains a property with the same key, the value will be
11240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // updated.
11250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void RecordProperty(const TestProperty& test_property);
11260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  enum ReactionToSharding {
11280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    HONOR_SHARDING_PROTOCOL,
11290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    IGNORE_SHARDING_PROTOCOL
11300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  };
11310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Matches the full name of each test against the user-specified
11330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // filter to decide whether the test should run, then records the
11340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // result in each TestCase and TestInfo object.
11350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
11360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // based on sharding variables in the environment.
11370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the number of tests that should run.
11380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int FilterTests(ReactionToSharding shard_tests);
11390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Prints the names of the tests matching the user-specified filter flag.
11410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void ListTestsMatchingFilter();
11420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TestCase* current_test_case() const { return current_test_case_; }
11440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestInfo* current_test_info() { return current_test_info_; }
11450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TestInfo* current_test_info() const { return current_test_info_; }
11460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the vector of environments that need to be set-up/torn-down
11480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // before/after the tests are run.
11490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::vector<Environment*>& environments() { return environments_; }
11500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Getters for the per-thread Google Test trace stack.
11520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::vector<TraceInfo>& gtest_trace_stack() {
11530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return *(gtest_trace_stack_.pointer());
11540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
11550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const std::vector<TraceInfo>& gtest_trace_stack() const {
11560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return gtest_trace_stack_.get();
11570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
11580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_HAS_DEATH_TEST
11600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void InitDeathTestSubprocessControlInfo() {
11610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
11620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
11630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns a pointer to the parsed --gtest_internal_run_death_test
11640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // flag, or NULL if that flag was not specified.
11650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // This information is useful only in a death test child process.
11660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Must not be called before a call to InitGoogleTest.
11670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
11680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return internal_run_death_test_flag_.get();
11690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
11700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns a pointer to the current death test factory.
11720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::DeathTestFactory* death_test_factory() {
11730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return death_test_factory_.get();
11740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
11750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void SuppressTestEventsIfInSubprocess();
11770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  friend class ReplaceDeathTestFactory;
11790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_HAS_DEATH_TEST
11800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Initializes the event listener performing XML output as specified by
11820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // UnitTestOptions. Must not be called before InitGoogleTest.
11830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void ConfigureXmlOutput();
11840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_CAN_STREAM_RESULTS_
11860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Initializes the event listener for streaming test results to a socket.
11870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Must not be called before InitGoogleTest.
11880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void ConfigureStreamingOutput();
11890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif
11900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Performs initialization dependent upon flag values obtained in
11920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // ParseGoogleTestFlagsOnly.  Is called from InitGoogleTest after the call to
11930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // ParseGoogleTestFlagsOnly.  In case a user neglects to call InitGoogleTest
11940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // this function is also called from RunAllTests.  Since this function can be
11950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // called more than once, it has to be idempotent.
11960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void PostFlagParsingInit();
11970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
11980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the random seed used at the start of the current test iteration.
11990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int random_seed() const { return random_seed_; }
12000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Gets the random number generator.
12020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::Random* random() { return &random_; }
12030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Shuffles all test cases, and the tests within each test case,
12050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // making sure that death tests are still run first.
12060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void ShuffleTests();
12070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Restores the test cases and tests to their order before the first shuffle.
12090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void UnshuffleTests();
12100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
12120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // UnitTest::Run() starts.
12130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool catch_exceptions() const { return catch_exceptions_; }
12140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
12160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  friend class ::testing::UnitTest;
12170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Used by UnitTest::Run() to capture the state of
12190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // GTEST_FLAG(catch_exceptions) at the moment it starts.
12200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
12210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The UnitTest object that owns this implementation object.
12230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  UnitTest* const parent_;
12240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The working directory when the first TEST() or TEST_F() was
12260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // executed.
12270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::FilePath original_working_dir_;
12280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The default test part result reporters.
12300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
12310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  DefaultPerThreadTestPartResultReporter
12320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      default_per_thread_test_part_result_reporter_;
12330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Points to (but doesn't own) the global test part result reporter.
12350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestPartResultReporterInterface* global_test_part_result_repoter_;
12360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Protects read and write access to global_test_part_result_reporter_.
12380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::Mutex global_test_part_result_reporter_mutex_;
12390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Points to (but doesn't own) the per-thread test part result reporter.
12410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::ThreadLocal<TestPartResultReporterInterface*>
12420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      per_thread_test_part_result_reporter_;
12430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The vector of environments that need to be set-up/torn-down
12450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // before/after the tests are run.
12460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::vector<Environment*> environments_;
12470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The vector of TestCases in their original order.  It owns the
12490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // elements in the vector.
12500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::vector<TestCase*> test_cases_;
12510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Provides a level of indirection for the test case list to allow
12530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // easy shuffling and restoring the test case order.  The i-th
12540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // element of this vector is the index of the i-th test case in the
12550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // shuffled order.
12560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::vector<int> test_case_indices_;
12570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_HAS_PARAM_TEST
12590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // ParameterizedTestRegistry object used to register value-parameterized
12600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // tests.
12610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
12620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Indicates whether RegisterParameterizedTests() has been called already.
12640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool parameterized_tests_registered_;
12650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_HAS_PARAM_TEST
12660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Index of the last death test case registered.  Initially -1.
12680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int last_death_test_case_;
12690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // This points to the TestCase for the currently running test.  It
12710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // changes as Google Test goes through one test case after another.
12720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // When no test is running, this is set to NULL and Google Test
12730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // stores assertion results in ad_hoc_test_result_.  Initially NULL.
12740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestCase* current_test_case_;
12750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // This points to the TestInfo for the currently running test.  It
12770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // changes as Google Test goes through one test after another.  When
12780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // no test is running, this is set to NULL and Google Test stores
12790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // assertion results in ad_hoc_test_result_.  Initially NULL.
12800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestInfo* current_test_info_;
12810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Normally, a user only writes assertions inside a TEST or TEST_F,
12830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // or inside a function called by a TEST or TEST_F.  Since Google
12840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Test keeps track of which test is current running, it can
12850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // associate such an assertion with the test it belongs to.
12860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
12870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // If an assertion is encountered when no TEST or TEST_F is running,
12880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Google Test attributes the assertion result to an imaginary "ad hoc"
12890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // test, and records the result in ad_hoc_test_result_.
12900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestResult ad_hoc_test_result_;
12910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The list of event listeners that can be used to track events inside
12930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Google Test.
12940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TestEventListeners listeners_;
12950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
12960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The OS stack trace getter.  Will be deleted when the UnitTest
12970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // object is destructed.  By default, an OsStackTraceGetter is used,
12980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // but the user can set this field to use a custom getter if that is
12990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // desired.
13000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  OsStackTraceGetterInterface* os_stack_trace_getter_;
13010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // True iff PostFlagParsingInit() has been called.
13030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool post_flag_parse_init_performed_;
13040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The random number seed used at the beginning of the test run.
13060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int random_seed_;
13070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Our random number generator.
13090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::Random random_;
13100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The time of the test program start, in ms from the start of the
13120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // UNIX epoch.
13130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TimeInMillis start_timestamp_;
13140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // How long the test took to run, in milliseconds.
13160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  TimeInMillis elapsed_time_;
13170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_HAS_DEATH_TEST
13190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The decomposed components of the gtest_internal_run_death_test flag,
13200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // parsed when RUN_ALL_TESTS is called.
13210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
13220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
13230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_HAS_DEATH_TEST
13240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // A per-thread stack of traces created by the SCOPED_TRACE() macro.
13260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
13270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
13290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // starts.
13300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool catch_exceptions_;
13310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
13330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};  // class UnitTestImpl
13340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Convenience function for accessing the global UnitTest
13360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// implementation object.
13370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orginline UnitTestImpl* GetUnitTestImpl() {
13380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return UnitTest::GetInstance()->impl();
13390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
13400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_USES_SIMPLE_RE
13420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Internal helper functions for implementing the simple regular
13440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// expression matcher.
13450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool IsInSet(char ch, const char* str);
13460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool IsAsciiDigit(char ch);
13470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool IsAsciiPunct(char ch);
13480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool IsRepeat(char ch);
13490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool IsAsciiWhiteSpace(char ch);
13500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool IsAsciiWordChar(char ch);
13510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool IsValidEscape(char ch);
13520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
13530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool ValidateRegex(const char* regex);
13540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
13550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool MatchRepetitionAndRegexAtHead(
13560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    bool escaped, char ch, char repeat, const char* regex, const char* str);
13570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
13580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_USES_SIMPLE_RE
13600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Parses the command line for Google Test flags, without initializing
13620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// other parts of Google Test.
13630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
13640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
13650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_HAS_DEATH_TEST
13670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the message describing the last system error, regardless of the
13690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// platform.
13700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ std::string GetLastErrnoDescription();
13710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# if GTEST_OS_WINDOWS
13730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Provides leak-safe Windows kernel handle ownership.
13740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass AutoHandle {
13750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
13760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
13770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  explicit AutoHandle(HANDLE handle) : handle_(handle) {}
13780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  ~AutoHandle() { Reset(); }
13800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  HANDLE Get() const { return handle_; }
13820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void Reset() { Reset(INVALID_HANDLE_VALUE); }
13830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void Reset(HANDLE handle) {
13840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    if (handle != handle_) {
13850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      if (handle_ != INVALID_HANDLE_VALUE)
13860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        ::CloseHandle(handle_);
13870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      handle_ = handle;
13880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
13890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
13900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
13920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  HANDLE handle_;
13930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
13950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
13960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# endif  // GTEST_OS_WINDOWS
13970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
13980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Attempts to parse a string into a positive integer pointed to by the
13990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// number parameter.  Returns true if that is possible.
14000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
14010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// it here.
14020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgtemplate <typename Integer>
14030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgbool ParseNaturalNumber(const ::std::string& str, Integer* number) {
14040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Fail fast if the given string does not begin with a digit;
14050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // this bypasses strtoXXX's "optional leading whitespace and plus
14060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // or minus sign" semantics, which are undesirable here.
14070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (str.empty() || !IsDigit(str[0])) {
14080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return false;
14090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
14100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  errno = 0;
14110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  char* end;
14130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // BiggestConvertible is the largest integer type that system-provided
14140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // string-to-number conversion routines can return.
14150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# if GTEST_OS_WINDOWS && !defined(__GNUC__)
14170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // MSVC and C++ Builder define __int64 instead of the standard long long.
14190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  typedef unsigned __int64 BiggestConvertible;
14200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
14210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# else
14230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  typedef unsigned long long BiggestConvertible;  // NOLINT
14250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
14260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# endif  // GTEST_OS_WINDOWS && !defined(__GNUC__)
14280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const bool parse_success = *end == '\0' && errno == 0;
14300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // TODO(vladl@google.com): Convert this to compile time assertion when it is
14320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // available.
14330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
14340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const Integer result = static_cast<Integer>(parsed);
14360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
14370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    *number = result;
14380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return true;
14390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
14400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return false;
14410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
14420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_HAS_DEATH_TEST
14430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TestResult contains some private methods that should be hidden from
14450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Google Test user but are required for testing. This class allow our tests
14460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// to access them.
14470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
14480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This class is supplied only for the purpose of testing Google Test's own
14490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// constructs. Do not use it in user tests, either directly or indirectly.
14500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass TestResultAccessor {
14510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
14520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static void RecordProperty(TestResult* test_result,
14530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                             const std::string& xml_element,
14540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                             const TestProperty& property) {
14550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    test_result->RecordProperty(xml_element, property);
14560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
14570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static void ClearTestPartResults(TestResult* test_result) {
14590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    test_result->ClearTestPartResults();
14600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
14610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static const std::vector<testing::TestPartResult>& test_part_results(
14630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      const TestResult& test_result) {
14640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return test_result.test_part_results();
14650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
14660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};
14670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_CAN_STREAM_RESULTS_
14690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Streams test results to the given port on the given host machine.
14710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgclass StreamingListener : public EmptyTestEventListener {
14720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org public:
14730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Abstract base class for writing strings to a socket.
14740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  class AbstractSocketWriter {
14750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org   public:
14760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    virtual ~AbstractSocketWriter() {}
14770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Sends a string to the socket.
14790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    virtual void Send(const string& message) = 0;
14800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Closes the socket.
14820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    virtual void CloseConnection() {}
14830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Sends a string and a newline to the socket.
14850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    void SendLn(const string& message) {
14860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      Send(message + "\n");
14870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
14880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  };
14890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Concrete class for actually writing strings to a socket.
14910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  class SocketWriter : public AbstractSocketWriter {
14920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org   public:
14930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SocketWriter(const string& host, const string& port)
14940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        : sockfd_(-1), host_name_(host), port_num_(port) {
14950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      MakeConnection();
14960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
14970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
14980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    virtual ~SocketWriter() {
14990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      if (sockfd_ != -1)
15000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        CloseConnection();
15010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
15020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Sends a string to the socket.
15040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    virtual void Send(const string& message) {
15050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      GTEST_CHECK_(sockfd_ != -1)
15060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          << "Send() can be called only when there is a connection.";
15070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      const int len = static_cast<int>(message.length());
15090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      if (write(sockfd_, message.c_str(), len) != len) {
15100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        GTEST_LOG_(WARNING)
15110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org            << "stream_result_to: failed to stream to "
15120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org            << host_name_ << ":" << port_num_;
15130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      }
15140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
15150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org   private:
15170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Creates a client socket and connects to the server.
15180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    void MakeConnection();
15190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Closes the socket.
15210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    void CloseConnection() {
15220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      GTEST_CHECK_(sockfd_ != -1)
15230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          << "CloseConnection() can be called only when there is a connection.";
15240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      close(sockfd_);
15260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      sockfd_ = -1;
15270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
15280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    int sockfd_;  // socket file descriptor
15300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const string host_name_;
15310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const string port_num_;
15320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
15340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  };  // class SocketWriter
15350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Escapes '=', '&', '%', and '\n' characters in str as "%xx".
15370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  static string UrlEncode(const char* str);
15380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  StreamingListener(const string& host, const string& port)
15400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      : socket_writer_(new SocketWriter(host, port)) { Start(); }
15410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  explicit StreamingListener(AbstractSocketWriter* socket_writer)
15430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      : socket_writer_(socket_writer) { Start(); }
15440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestProgramStart(const UnitTest& /* unit_test */) {
15460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn("event=TestProgramStart");
15470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestProgramEnd(const UnitTest& unit_test) {
15500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Note that Google Test current only report elapsed time for each
15510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // test iteration, not for the entire test program.
15520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
15530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Notify the streaming server to stop.
15550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    socket_writer_->CloseConnection();
15560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {
15590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn("event=TestIterationStart&iteration=" +
15600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           StreamableToString(iteration));
15610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {
15640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn("event=TestIterationEnd&passed=" +
15650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           FormatBool(unit_test.Passed()) + "&elapsed_time=" +
15660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           StreamableToString(unit_test.elapsed_time()) + "ms");
15670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestCaseStart(const TestCase& test_case) {
15700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
15710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestCaseEnd(const TestCase& test_case) {
15740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
15750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           + "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
15760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           + "ms");
15770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestStart(const TestInfo& test_info) {
15800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn(std::string("event=TestStart&name=") + test_info.name());
15810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestEnd(const TestInfo& test_info) {
15840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn("event=TestEnd&passed=" +
15850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           FormatBool((test_info.result())->Passed()) +
15860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           "&elapsed_time=" +
15870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           StreamableToString((test_info.result())->elapsed_time()) + "ms");
15880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void OnTestPartResult(const TestPartResult& test_part_result) {
15910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const char* file_name = test_part_result.file_name();
15920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    if (file_name == NULL)
15930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      file_name = "";
15940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
15950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           "&line=" + StreamableToString(test_part_result.line_number()) +
15960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org           "&message=" + UrlEncode(test_part_result.message()));
15970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
15980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
15990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org private:
16000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Sends the given message and a newline to the socket.
16010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void SendLn(const string& message) { socket_writer_->SendLn(message); }
16020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Called at the start of streaming to notify the receiver what
16040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // protocol we are using.
16050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
16060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  string FormatBool(bool value) { return value ? "1" : "0"; }
16080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const scoped_ptr<AbstractSocketWriter> socket_writer_;
16100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
16120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org};  // class StreamingListener
16130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_CAN_STREAM_RESULTS_
16150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}  // namespace internal
16170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}  // namespace testing
16180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_SRC_GTEST_INTERNAL_INL_H_
16200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#undef GTEST_IMPLEMENTATION_
16210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_OS_WINDOWS
16230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# define vsnprintf _vsnprintf
16240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_OS_WINDOWS
16250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace testing {
16270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgusing internal::CountIf;
16290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgusing internal::ForEach;
16300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgusing internal::GetElementOr;
16310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgusing internal::Shuffle;
16320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Constants.
16340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A test whose test case name or test name matches this filter is
16360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// disabled and not run.
16370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char kDisableTestFilter[] = "DISABLED_*:*/DISABLED_*";
16380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A test case whose name matches this filter is considered a death
16400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// test case and will be run before test cases whose name doesn't
16410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// match this filter.
16420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char kDeathTestCaseFilter[] = "*DeathTest:*DeathTest/*";
16430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A test filter that matches everything.
16450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char kUniversalFilter[] = "*";
16460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The default output file for XML output.
16480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char kDefaultOutputFile[] = "test_detail.xml";
16490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The environment variable name for the test shard index.
16510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char kTestShardIndex[] = "GTEST_SHARD_INDEX";
16520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The environment variable name for the total number of test shards.
16530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS";
16540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The environment variable name for the test shard status file.
16550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE";
16560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace internal {
16580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The text used in failure messages to indicate the start of the
16600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// stack trace.
16610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgconst char kStackTraceMarker[] = "\nStack trace:\n";
16620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// g_help_flag is true iff the --help flag or an equivalent form is
16640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// specified on the command line.
16650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgbool g_help_flag = false;
16660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}  // namespace internal
16680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic const char* GetDefaultFilter() {
16700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return kUniversalFilter;
16710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
16720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(
16740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    also_run_disabled_tests,
16750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::BoolFromGTestEnv("also_run_disabled_tests", false),
16760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "Run disabled tests too, in addition to the tests normally being run.");
16770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(
16790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    break_on_failure,
16800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::BoolFromGTestEnv("break_on_failure", false),
16810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "True iff a failed assertion should be a debugger break-point.");
16820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(
16840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    catch_exceptions,
16850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::BoolFromGTestEnv("catch_exceptions", true),
16860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "True iff " GTEST_NAME_
16870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    " should catch exceptions and treat them as test failures.");
16880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_string_(
16900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    color,
16910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::StringFromGTestEnv("color", "auto"),
16920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "Whether to use colors in the output.  Valid values: yes, no, "
16930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "and auto.  'auto' means to use colors if the output is "
16940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "being sent to a terminal and the TERM environment variable "
16950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "is set to a terminal type that supports colors.");
16960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
16970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_string_(
16980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    filter,
16990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::StringFromGTestEnv("filter", GetDefaultFilter()),
17000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "A colon-separated list of glob (not regex) patterns "
17010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "for filtering the tests to run, optionally followed by a "
17020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "'-' and a : separated list of negative patterns (tests to "
17030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "exclude).  A test is run if it matches one of the positive "
17040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "patterns and does not match any of the negative patterns.");
17050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(list_tests, false,
17070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                   "List all tests without running them.");
17080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_string_(
17100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    output,
17110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::StringFromGTestEnv("output", ""),
17120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "A format (currently must be \"xml\"), optionally followed "
17130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "by a colon and an output file name or directory. A directory "
17140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "is indicated by a trailing pathname separator. "
17150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
17160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "If a directory is specified, output files will be created "
17170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "within that directory, with file-names based on the test "
17180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "executable's name and, if necessary, made unique by adding "
17190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "digits.");
17200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(
17220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    print_time,
17230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::BoolFromGTestEnv("print_time", true),
17240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "True iff " GTEST_NAME_
17250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    " should display elapsed time in text output.");
17260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_int32_(
17280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    random_seed,
17290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::Int32FromGTestEnv("random_seed", 0),
17300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "Random number seed to use when shuffling test orders.  Must be in range "
17310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "[1, 99999], or 0 to use a seed based on the current time.");
17320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_int32_(
17340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    repeat,
17350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::Int32FromGTestEnv("repeat", 1),
17360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "How many times to repeat each test.  Specify a negative number "
17370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "for repeating forever.  Useful for shaking out flaky tests.");
17380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(
17400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    show_internal_stack_frames, false,
17410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "True iff " GTEST_NAME_ " should include internal stack frames when "
17420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "printing test failure stack traces.");
17430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(
17450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    shuffle,
17460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::BoolFromGTestEnv("shuffle", false),
17470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "True iff " GTEST_NAME_
17480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    " should randomize tests' order on every run.");
17490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_int32_(
17510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    stack_trace_depth,
17520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::Int32FromGTestEnv("stack_trace_depth", kMaxStackTraceDepth),
17530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "The maximum number of stack frames to print when an "
17540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "assertion fails.  The valid range is 0 through 100, inclusive.");
17550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_string_(
17570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    stream_result_to,
17580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::StringFromGTestEnv("stream_result_to", ""),
17590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "This flag specifies the host name and the port number on which to stream "
17600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "test results. Example: \"localhost:555\". The flag is effective only on "
17610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "Linux.");
17620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_DEFINE_bool_(
17640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    throw_on_failure,
17650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    internal::BoolFromGTestEnv("throw_on_failure", false),
17660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "When this flag is specified, a failed assertion will throw an exception "
17670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "if exceptions are enabled or exit the program with a non-zero code "
17680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    "otherwise.");
17690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace internal {
17710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Generates a random number from [0, range), using a Linear
17730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Congruential Generator (LCG).  Crashes if 'range' is 0 or greater
17740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// than kMaxRange.
17750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgUInt32 Random::Generate(UInt32 range) {
17760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // These constants are the same as are used in glibc's rand(3).
17770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  state_ = (1103515245U*state_ + 12345U) % kMaxRange;
17780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_CHECK_(range > 0)
17800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << "Cannot generate a number in the range [0, 0).";
17810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GTEST_CHECK_(range <= kMaxRange)
17820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << "Generation of a number in [0, " << range << ") was requested, "
17830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      << "but this can only generate numbers in [0, " << kMaxRange << ").";
17840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Converting via modulus introduces a bit of downward bias, but
17860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // it's simple, and a linear congruential generator isn't too good
17870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // to begin with.
17880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return state_ % range;
17890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
17900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
17910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// GTestIsInitialized() returns true iff the user has initialized
17920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Google Test.  Useful for catching the user mistake of not initializing
17930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Google Test before calling RUN_ALL_TESTS().
17940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
17950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// A user must call testing::InitGoogleTest() to initialize Google
17960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Test.  g_init_gtest_count is set to the number of times
17970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// InitGoogleTest() has been called.  We don't protect this variable
17980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// under a mutex as it is only accessed in the main thread.
17990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ int g_init_gtest_count = 0;
18000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic bool GTestIsInitialized() { return g_init_gtest_count != 0; }
18010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Iterates over a vector of TestCases, keeping a running sum of the
18030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// results of calling a given int-returning method on each.
18040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the sum.
18050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic int SumOverTestCaseList(const std::vector<TestCase*>& case_list,
18060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                               int (TestCase::*method)() const) {
18070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  int sum = 0;
18080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  for (size_t i = 0; i < case_list.size(); i++) {
18090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    sum += (case_list[i]->*method)();
18100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
18110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return sum;
18120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns true iff the test case passed.
18150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic bool TestCasePassed(const TestCase* test_case) {
18160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return test_case->should_run() && test_case->Passed();
18170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns true iff the test case failed.
18200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic bool TestCaseFailed(const TestCase* test_case) {
18210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return test_case->should_run() && test_case->Failed();
18220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns true iff test_case contains at least one test that should
18250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// run.
18260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstatic bool ShouldRunTestCase(const TestCase* test_case) {
18270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return test_case->should_run();
18280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// AssertHelper constructor.
18310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgAssertHelper::AssertHelper(TestPartResult::Type type,
18320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                           const char* file,
18330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                           int line,
18340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                           const char* message)
18350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    : data_(new AssertHelperData(type, file, line, message)) {
18360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgAssertHelper::~AssertHelper() {
18390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  delete data_;
18400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Message assignment, for assertion streaming support.
18430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid AssertHelper::operator=(const Message& message) const {
18440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  UnitTest::GetInstance()->
18450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    AddTestPartResult(data_->type, data_->file, data_->line,
18460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                      AppendUserMessage(data_->message, message),
18470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                      UnitTest::GetInstance()->impl()
18480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                      ->CurrentOsStackTraceExceptTop(1)
18490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                      // Skips the stack frame for this function itself.
18500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                      );  // NOLINT
18510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Mutex for linked pointers.
18540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgGTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex);
18550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Application pathname gotten in InitGoogleTest.
18570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstd::string g_executable_path;
18580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the current application's name, removing directory path if that
18600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// is present.
18610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgFilePath GetCurrentExecutableName() {
18620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  FilePath result;
18630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_OS_WINDOWS
18650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  result.Set(FilePath(g_executable_path).RemoveExtension("exe"));
18660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#else
18670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  result.Set(FilePath(g_executable_path));
18680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_OS_WINDOWS
18690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return result.RemoveDirectoryName();
18710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Functions for processing the gtest_output flag.
18740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the output format, or "" for normal printed output.
18760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstd::string UnitTestOptions::GetOutputFormat() {
18770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
18780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (gtest_output_flag == NULL) return std::string("");
18790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char* const colon = strchr(gtest_output_flag, ':');
18810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return (colon == NULL) ?
18820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      std::string(gtest_output_flag) :
18830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      std::string(gtest_output_flag, colon - gtest_output_flag);
18840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
18850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the name of the requested output file, or the default if none
18870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// was explicitly specified.
18880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstd::string UnitTestOptions::GetAbsolutePathToOutputFile() {
18890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
18900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (gtest_output_flag == NULL)
18910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return "";
18920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
18930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char* const colon = strchr(gtest_output_flag, ':');
18940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (colon == NULL)
18950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return internal::FilePath::ConcatPaths(
18960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        internal::FilePath(
18970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org            UnitTest::GetInstance()->original_working_dir()),
18980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        internal::FilePath(kDefaultOutputFile)).string();
18990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::FilePath output_name(colon + 1);
19010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (!output_name.IsAbsolutePath())
19020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // TODO(wan@google.com): on Windows \some\path is not an absolute
19030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // path (as its meaning depends on the current drive), yet the
19040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // following logic for turning it into an absolute path is wrong.
19050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Fix it.
19060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    output_name = internal::FilePath::ConcatPaths(
19070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        internal::FilePath(UnitTest::GetInstance()->original_working_dir()),
19080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        internal::FilePath(colon + 1));
19090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (!output_name.IsDirectory())
19110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return output_name.string();
19120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::FilePath result(internal::FilePath::GenerateUniqueFileName(
19140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      output_name, internal::GetCurrentExecutableName(),
19150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      GetOutputFormat().c_str()));
19160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return result.string();
19170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
19180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns true iff the wildcard pattern matches the string.  The
19200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// first ':' or '\0' character in pattern marks the end of it.
19210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
19220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This recursive algorithm isn't very efficient, but is clear and
19230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// works well enough for matching test names, which are short.
19240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgbool UnitTestOptions::PatternMatchesString(const char *pattern,
19250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                                           const char *str) {
19260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  switch (*pattern) {
19270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    case '\0':
19280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    case ':':  // Either ':' or '\0' marks the end of the pattern.
19290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      return *str == '\0';
19300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    case '?':  // Matches any single character.
19310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      return *str != '\0' && PatternMatchesString(pattern + 1, str + 1);
19320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    case '*':  // Matches any string (possibly empty) of characters.
19330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      return (*str != '\0' && PatternMatchesString(pattern, str + 1)) ||
19340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          PatternMatchesString(pattern + 1, str);
19350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    default:  // Non-special character.  Matches itself.
19360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      return *pattern == *str &&
19370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          PatternMatchesString(pattern + 1, str + 1);
19380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
19390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
19400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgbool UnitTestOptions::MatchesFilter(
19420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const std::string& name, const char* filter) {
19430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char *cur_pattern = filter;
19440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  for (;;) {
19450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    if (PatternMatchesString(cur_pattern, name.c_str())) {
19460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      return true;
19470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
19480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Finds the next pattern in the filter.
19500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    cur_pattern = strchr(cur_pattern, ':');
19510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Returns if no more pattern can be found.
19530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    if (cur_pattern == NULL) {
19540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      return false;
19550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
19560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    // Skips the pattern separater (the ':' character).
19580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    cur_pattern++;
19590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
19600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
19610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns true iff the user-specified filter matches the test case
19630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// name and the test name.
19640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgbool UnitTestOptions::FilterMatchesTest(const std::string &test_case_name,
19650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                                        const std::string &test_name) {
19660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const std::string& full_name = test_case_name + "." + test_name.c_str();
19670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Split --gtest_filter at '-', if there is one, to separate into
19690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // positive filter and negative filter portions
19700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char* const p = GTEST_FLAG(filter).c_str();
19710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const char* const dash = strchr(p, '-');
19720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string positive;
19730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  std::string negative;
19740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (dash == NULL) {
19750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    positive = GTEST_FLAG(filter).c_str();  // Whole string is a positive filter
19760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    negative = "";
19770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  } else {
19780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    positive = std::string(p, dash);   // Everything up to the dash
19790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    negative = std::string(dash + 1);  // Everything after the dash
19800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    if (positive.empty()) {
19810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      // Treat '-test1' as the same as '*-test1'
19820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      positive = kUniversalFilter;
19830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
19840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
19850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // A filter is a colon-separated list of patterns.  It matches a
19870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // test if any pattern in it matches the test.
19880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return (MatchesFilter(full_name, positive.c_str()) &&
19890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org          !MatchesFilter(full_name, negative.c_str()));
19900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
19910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
19920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_HAS_SEH
19930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
19940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
19950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This function is useful as an __except condition.
19960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
19970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Google Test should handle a SEH exception if:
19980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   1. the user wants it to, AND
19990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   2. this is not a breakpoint exception, AND
20000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   3. this is not a C++ exception (VC++ implements them via SEH,
20010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //      apparently).
20020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //
20030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // SEH exception code for C++ exceptions.
20040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // (see http://support.microsoft.com/kb/185294 for more information).
20050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const DWORD kCxxExceptionCode = 0xe06d7363;
20060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  bool should_handle = true;
20080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (!GTEST_FLAG(catch_exceptions))
20100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    should_handle = false;
20110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  else if (exception_code == EXCEPTION_BREAKPOINT)
20120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    should_handle = false;
20130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  else if (exception_code == kCxxExceptionCode)
20140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    should_handle = false;
20150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
20170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
20180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif  // GTEST_HAS_SEH
20190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}  // namespace internal
20210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The c'tor sets this object as the test part result reporter used by
20230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Google Test.  The 'result' parameter specifies where to report the
20240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// results. Intercepts only failures from the current thread.
20250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
20260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    TestPartResultArray* result)
20270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
20280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      result_(result) {
20290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  Init();
20300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
20310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The c'tor sets this object as the test part result reporter used by
20330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Google Test.  The 'result' parameter specifies where to report the
20340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// results.
20350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
20360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    InterceptMode intercept_mode, TestPartResultArray* result)
20370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    : intercept_mode_(intercept_mode),
20380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      result_(result) {
20390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  Init();
20400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
20410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid ScopedFakeTestPartResultReporter::Init() {
20430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
20440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
20450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    old_reporter_ = impl->GetGlobalTestPartResultReporter();
20460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    impl->SetGlobalTestPartResultReporter(this);
20470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  } else {
20480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
20490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    impl->SetTestPartResultReporterForCurrentThread(this);
20500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
20510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
20520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The d'tor restores the test part result reporter used by Google Test
20540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// before.
20550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
20560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
20570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
20580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    impl->SetGlobalTestPartResultReporter(old_reporter_);
20590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  } else {
20600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
20610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
20620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
20630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Increments the test part result count and remembers the result.
20650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This method is from the TestPartResultReporterInterface interface.
20660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid ScopedFakeTestPartResultReporter::ReportTestPartResult(
20670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const TestPartResult& result) {
20680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  result_->Append(result);
20690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
20700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgnamespace internal {
20720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the type ID of ::testing::Test.  We should always call this
20740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// instead of GetTypeId< ::testing::Test>() to get the type ID of
20750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// testing::Test.  This is to work around a suspected linker bug when
20760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// using Google Test as a framework on Mac OS X.  The bug causes
20770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// GetTypeId< ::testing::Test>() to return different values depending
20780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// on whether the call is from the Google Test framework itself or
20790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// from user test code.  GetTestTypeId() is guaranteed to always
20800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// return the same value, as it always calls GetTypeId<>() from the
20810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// gtest.cc, which is within the Google Test framework.
20820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgTypeId GetTestTypeId() {
20830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return GetTypeId<Test>();
20840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
20850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The value of GetTestTypeId() as seen from within the Google Test
20870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// library.  This is solely for testing GetTestTypeId().
20880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgextern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();
20890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
20900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// This predicate-formatter checks that 'results' contains a test part
20910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// failure of the given type and that the failure message contains the
20920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// given substring.
20930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgAssertionResult HasOneFailure(const char* /* results_expr */,
20940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              const char* /* type_expr */,
20950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              const char* /* substr_expr */,
20960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              const TestPartResultArray& results,
20970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              TestPartResult::Type type,
20980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              const string& substr) {
20990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const std::string expected(type == TestPartResult::kFatalFailure ?
21000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                        "1 fatal failure" :
21010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                        "1 non-fatal failure");
21020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  Message msg;
21030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (results.size() != 1) {
21040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    msg << "Expected: " << expected << "\n"
21050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org        << "  Actual: " << results.size() << " failures";
21060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    for (int i = 0; i < results.size(); i++) {
21070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      msg << "\n" << results.GetTestPartResult(i);
21080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    }
21090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return AssertionFailure() << msg;
21100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
21110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TestPartResult& r = results.GetTestPartResult(0);
21130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (r.type() != type) {
21140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return AssertionFailure() << "Expected: " << expected << "\n"
21150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              << "  Actual:\n"
21160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              << r;
21170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
21180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (strstr(r.message(), substr.c_str()) == NULL) {
21200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return AssertionFailure() << "Expected: " << expected << " containing \""
21210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              << substr << "\"\n"
21220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              << "  Actual:\n"
21230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                              << r;
21240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
21250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return AssertionSuccess();
21270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The constructor of SingleFailureChecker remembers where to look up
21300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// test part results, what type of failure we expect, and what
21310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// substring the failure message should contain.
21320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgSingleFailureChecker:: SingleFailureChecker(
21330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const TestPartResultArray* results,
21340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    TestPartResult::Type type,
21350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const string& substr)
21360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    : results_(results),
21370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      type_(type),
21380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      substr_(substr) {}
21390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The destructor of SingleFailureChecker verifies that the given
21410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// TestPartResultArray contains exactly one failure that has the given
21420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// type and contains the given substring.  If that's not the case, a
21430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// non-fatal failure will be generated.
21440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgSingleFailureChecker::~SingleFailureChecker() {
21450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  EXPECT_PRED_FORMAT3(HasOneFailure, *results_, type_, substr_);
21460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgDefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
21490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    UnitTestImpl* unit_test) : unit_test_(unit_test) {}
21500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid DefaultGlobalTestPartResultReporter::ReportTestPartResult(
21520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const TestPartResult& result) {
21530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  unit_test_->current_test_result()->AddTestPartResult(result);
21540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  unit_test_->listeners()->repeater()->OnTestPartResult(result);
21550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgDefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
21580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    UnitTestImpl* unit_test) : unit_test_(unit_test) {}
21590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
21610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    const TestPartResult& result) {
21620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
21630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the global test part result reporter.
21660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgTestPartResultReporterInterface*
21670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgUnitTestImpl::GetGlobalTestPartResultReporter() {
21680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
21690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return global_test_part_result_repoter_;
21700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Sets the global test part result reporter.
21730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid UnitTestImpl::SetGlobalTestPartResultReporter(
21740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    TestPartResultReporterInterface* reporter) {
21750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
21760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  global_test_part_result_repoter_ = reporter;
21770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the test part result reporter for the current thread.
21800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgTestPartResultReporterInterface*
21810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgUnitTestImpl::GetTestPartResultReporterForCurrentThread() {
21820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return per_thread_test_part_result_reporter_.get();
21830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Sets the test part result reporter for the current thread.
21860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgvoid UnitTestImpl::SetTestPartResultReporterForCurrentThread(
21870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    TestPartResultReporterInterface* reporter) {
21880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  per_thread_test_part_result_reporter_.set(reporter);
21890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of successful test cases.
21920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::successful_test_case_count() const {
21930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return CountIf(test_cases_, TestCasePassed);
21940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
21950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
21960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of failed test cases.
21970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::failed_test_case_count() const {
21980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return CountIf(test_cases_, TestCaseFailed);
21990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of all test cases.
22020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::total_test_case_count() const {
22030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return static_cast<int>(test_cases_.size());
22040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of all test cases that contain at least one test
22070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// that should run.
22080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::test_case_to_run_count() const {
22090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return CountIf(test_cases_, ShouldRunTestCase);
22100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of successful tests.
22130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::successful_test_count() const {
22140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return SumOverTestCaseList(test_cases_, &TestCase::successful_test_count);
22150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of failed tests.
22180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::failed_test_count() const {
22190d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return SumOverTestCaseList(test_cases_, &TestCase::failed_test_count);
22200d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22210d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22220d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of disabled tests that will be reported in the XML report.
22230d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::reportable_disabled_test_count() const {
22240d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return SumOverTestCaseList(test_cases_,
22250d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org                             &TestCase::reportable_disabled_test_count);
22260d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22270d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22280d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of disabled tests.
22290d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::disabled_test_count() const {
22300d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return SumOverTestCaseList(test_cases_, &TestCase::disabled_test_count);
22310d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22320d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22330d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of tests to be printed in the XML report.
22340d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::reportable_test_count() const {
22350d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return SumOverTestCaseList(test_cases_, &TestCase::reportable_test_count);
22360d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22370d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22380d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of all tests.
22390d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::total_test_count() const {
22400d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return SumOverTestCaseList(test_cases_, &TestCase::total_test_count);
22410d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22420d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22430d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Gets the number of tests that should run.
22440d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgint UnitTestImpl::test_to_run_count() const {
22450d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return SumOverTestCaseList(test_cases_, &TestCase::test_to_run_count);
22460d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22470d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22480d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the current OS stack trace as an std::string.
22490d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
22500d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// The maximum number of stack frames to be included is specified by
22510d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// the gtest_stack_trace_depth flag.  The skip_count parameter
22520d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// specifies the number of top frames to be skipped, which doesn't
22530d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// count against the number of frames to be included.
22540d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org//
22550d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// For example, if Foo() calls Bar(), which in turn calls
22560d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
22570d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
22580d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgstd::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
22590d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  (void)skip_count;
22600d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return "";
22610d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
22620d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22630d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Returns the current time in milliseconds.
22640d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.orgTimeInMillis GetTimeInMillis() {
22650d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
22660d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // Difference between 1970-01-01 and 1601-01-01 in milliseconds.
22670d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // http://analogous.blogspot.com/2005/04/epoch.html
22680d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const TimeInMillis kJavaEpochToWinFileTimeDelta =
22690d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    static_cast<TimeInMillis>(116444736UL) * 100000UL;
22700d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  const DWORD kTenthMicrosInMilliSecond = 10000;
22710d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22720d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  SYSTEMTIME now_systime;
22730d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  FILETIME now_filetime;
22740d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  ULARGE_INTEGER now_int64;
22750d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // TODO(kenton@google.com): Shouldn't this just use
22760d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   GetSystemTimeAsFileTime()?
22770d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  GetSystemTime(&now_systime);
22780d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
22790d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    now_int64.LowPart = now_filetime.dwLowDateTime;
22800d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    now_int64.HighPart = now_filetime.dwHighDateTime;
22810d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
22820d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org      kJavaEpochToWinFileTimeDelta;
22830d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org    return now_int64.QuadPart;
22840d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  }
22850d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return 0;
22860d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
22870d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  __timeb64 now;
22880d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22890d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# ifdef _MSC_VER
22900d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
22910d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
22920d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // (deprecated function) there.
22930d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  // TODO(kenton@google.com): Use GetTickCount()?  Or use
22940d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  //   SystemTimeToFileTime()
22950d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#  pragma warning(push)          // Saves the current warning state.
22960d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#  pragma warning(disable:4996)  // Temporarily disables warning 4996.
22970d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  _ftime64(&now);
22980d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#  pragma warning(pop)           // Restores the warning state.
22990d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# else
23000d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
23010d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  _ftime64(&now);
23020d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
23030d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# endif  // _MSC_VER
23040d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
23050d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
23060d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#elif GTEST_HAS_GETTIMEOFDAY_
23070d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  struct timeval now;
23080d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  gettimeofday(&now, NULL);
23090d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org  return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
23100d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#else
23110d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org# error "Don't know how to get the current time on your system."
23120d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org#endif
23130d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org}
23140d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
23150d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// Utilities
23160d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
23170d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org// class String.
23180d106b34dc08439a7c6887d1316a3e1a35f8f0cajohannkoenig@chromium.org
2319