media/webrtc/trunk/testing/gtest/src/gtest-internal-inl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/testing/gtest/src/gtest-internal-inl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1056 @@
     1.4 +// Copyright 2005, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// Utility functions and classes used by the Google C++ testing framework.
    1.34 +//
    1.35 +// Author: wan@google.com (Zhanyong Wan)
    1.36 +//
    1.37 +// This file contains purely Google Test's internal implementation.  Please
    1.38 +// DO NOT #INCLUDE IT IN A USER PROGRAM.
    1.39 +
    1.40 +#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
    1.41 +#define GTEST_SRC_GTEST_INTERNAL_INL_H_
    1.42 +
    1.43 +// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
    1.44 +// part of Google Test's implementation; otherwise it's undefined.
    1.45 +#if !GTEST_IMPLEMENTATION_
    1.46 +// A user is trying to include this from his code - just say no.
    1.47 +# error "gtest-internal-inl.h is part of Google Test's internal implementation."
    1.48 +# error "It must not be included except by Google Test itself."
    1.49 +#endif  // GTEST_IMPLEMENTATION_
    1.50 +
    1.51 +#ifndef _WIN32_WCE
    1.52 +# include <errno.h>
    1.53 +#endif  // !_WIN32_WCE
    1.54 +#include <stddef.h>
    1.55 +#include <stdlib.h>  // For strtoll/_strtoul64/malloc/free.
    1.56 +#include <string.h>  // For memmove.
    1.57 +
    1.58 +#include <algorithm>
    1.59 +#include <string>
    1.60 +#include <vector>
    1.61 +
    1.62 +#include "gtest/internal/gtest-port.h"
    1.63 +
    1.64 +#if GTEST_OS_WINDOWS
    1.65 +# include <windows.h>  // NOLINT
    1.66 +#endif  // GTEST_OS_WINDOWS
    1.67 +
    1.68 +#include "gtest/gtest.h"  // NOLINT
    1.69 +#include "gtest/gtest-spi.h"
    1.70 +
    1.71 +namespace testing {
    1.72 +
    1.73 +// Declares the flags.
    1.74 +//
    1.75 +// We don't want the users to modify this flag in the code, but want
    1.76 +// Google Test's own unit tests to be able to access it. Therefore we
    1.77 +// declare it here as opposed to in gtest.h.
    1.78 +GTEST_DECLARE_bool_(death_test_use_fork);
    1.79 +
    1.80 +namespace internal {
    1.81 +
    1.82 +// The value of GetTestTypeId() as seen from within the Google Test
    1.83 +// library.  This is solely for testing GetTestTypeId().
    1.84 +GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
    1.85 +
    1.86 +// Names of the flags (needed for parsing Google Test flags).
    1.87 +const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
    1.88 +const char kBreakOnFailureFlag[] = "break_on_failure";
    1.89 +const char kCatchExceptionsFlag[] = "catch_exceptions";
    1.90 +const char kColorFlag[] = "color";
    1.91 +const char kFilterFlag[] = "filter";
    1.92 +const char kListTestsFlag[] = "list_tests";
    1.93 +const char kOutputFlag[] = "output";
    1.94 +const char kPrintTimeFlag[] = "print_time";
    1.95 +const char kRandomSeedFlag[] = "random_seed";
    1.96 +const char kRepeatFlag[] = "repeat";
    1.97 +const char kShuffleFlag[] = "shuffle";
    1.98 +const char kStackTraceDepthFlag[] = "stack_trace_depth";
    1.99 +const char kStreamResultToFlag[] = "stream_result_to";
   1.100 +const char kThrowOnFailureFlag[] = "throw_on_failure";
   1.101 +
   1.102 +// A valid random seed must be in [1, kMaxRandomSeed].
   1.103 +const int kMaxRandomSeed = 99999;
   1.104 +
   1.105 +// g_help_flag is true iff the --help flag or an equivalent form is
   1.106 +// specified on the command line.
   1.107 +GTEST_API_ extern bool g_help_flag;
   1.108 +
   1.109 +// Returns the current time in milliseconds.
   1.110 +GTEST_API_ TimeInMillis GetTimeInMillis();
   1.111 +
   1.112 +// Returns true iff Google Test should use colors in the output.
   1.113 +GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
   1.114 +
   1.115 +// Formats the given time in milliseconds as seconds.
   1.116 +GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
   1.117 +
   1.118 +// Converts the given time in milliseconds to a date string in the ISO 8601
   1.119 +// format, without the timezone information.  N.B.: due to the use the
   1.120 +// non-reentrant localtime() function, this function is not thread safe.  Do
   1.121 +// not use it in any code that can be called from multiple threads.
   1.122 +GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
   1.123 +
   1.124 +// Parses a string for an Int32 flag, in the form of "--flag=value".
   1.125 +//
   1.126 +// On success, stores the value of the flag in *value, and returns
   1.127 +// true.  On failure, returns false without changing *value.
   1.128 +GTEST_API_ bool ParseInt32Flag(
   1.129 +    const char* str, const char* flag, Int32* value);
   1.130 +
   1.131 +// Returns a random seed in range [1, kMaxRandomSeed] based on the
   1.132 +// given --gtest_random_seed flag value.
   1.133 +inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
   1.134 +  const unsigned int raw_seed = (random_seed_flag == 0) ?
   1.135 +      static_cast<unsigned int>(GetTimeInMillis()) :
   1.136 +      static_cast<unsigned int>(random_seed_flag);
   1.137 +
   1.138 +  // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
   1.139 +  // it's easy to type.
   1.140 +  const int normalized_seed =
   1.141 +      static_cast<int>((raw_seed - 1U) %
   1.142 +                       static_cast<unsigned int>(kMaxRandomSeed)) + 1;
   1.143 +  return normalized_seed;
   1.144 +}
   1.145 +
   1.146 +// Returns the first valid random seed after 'seed'.  The behavior is
   1.147 +// undefined if 'seed' is invalid.  The seed after kMaxRandomSeed is
   1.148 +// considered to be 1.
   1.149 +inline int GetNextRandomSeed(int seed) {
   1.150 +  GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
   1.151 +      << "Invalid random seed " << seed << " - must be in [1, "
   1.152 +      << kMaxRandomSeed << "].";
   1.153 +  const int next_seed = seed + 1;
   1.154 +  return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
   1.155 +}
   1.156 +
   1.157 +// This class saves the values of all Google Test flags in its c'tor, and
   1.158 +// restores them in its d'tor.
   1.159 +class GTestFlagSaver {
   1.160 + public:
   1.161 +  // The c'tor.
   1.162 +  GTestFlagSaver() {
   1.163 +    also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
   1.164 +    break_on_failure_ = GTEST_FLAG(break_on_failure);
   1.165 +    catch_exceptions_ = GTEST_FLAG(catch_exceptions);
   1.166 +    color_ = GTEST_FLAG(color);
   1.167 +    death_test_style_ = GTEST_FLAG(death_test_style);
   1.168 +    death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
   1.169 +    filter_ = GTEST_FLAG(filter);
   1.170 +    internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
   1.171 +    list_tests_ = GTEST_FLAG(list_tests);
   1.172 +    output_ = GTEST_FLAG(output);
   1.173 +    print_time_ = GTEST_FLAG(print_time);
   1.174 +    random_seed_ = GTEST_FLAG(random_seed);
   1.175 +    repeat_ = GTEST_FLAG(repeat);
   1.176 +    shuffle_ = GTEST_FLAG(shuffle);
   1.177 +    stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
   1.178 +    stream_result_to_ = GTEST_FLAG(stream_result_to);
   1.179 +    throw_on_failure_ = GTEST_FLAG(throw_on_failure);
   1.180 +  }
   1.181 +
   1.182 +  // The d'tor is not virtual.  DO NOT INHERIT FROM THIS CLASS.
   1.183 +  ~GTestFlagSaver() {
   1.184 +    GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
   1.185 +    GTEST_FLAG(break_on_failure) = break_on_failure_;
   1.186 +    GTEST_FLAG(catch_exceptions) = catch_exceptions_;
   1.187 +    GTEST_FLAG(color) = color_;
   1.188 +    GTEST_FLAG(death_test_style) = death_test_style_;
   1.189 +    GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
   1.190 +    GTEST_FLAG(filter) = filter_;
   1.191 +    GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
   1.192 +    GTEST_FLAG(list_tests) = list_tests_;
   1.193 +    GTEST_FLAG(output) = output_;
   1.194 +    GTEST_FLAG(print_time) = print_time_;
   1.195 +    GTEST_FLAG(random_seed) = random_seed_;
   1.196 +    GTEST_FLAG(repeat) = repeat_;
   1.197 +    GTEST_FLAG(shuffle) = shuffle_;
   1.198 +    GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
   1.199 +    GTEST_FLAG(stream_result_to) = stream_result_to_;
   1.200 +    GTEST_FLAG(throw_on_failure) = throw_on_failure_;
   1.201 +  }
   1.202 +
   1.203 + private:
   1.204 +  // Fields for saving the original values of flags.
   1.205 +  bool also_run_disabled_tests_;
   1.206 +  bool break_on_failure_;
   1.207 +  bool catch_exceptions_;
   1.208 +  String color_;
   1.209 +  String death_test_style_;
   1.210 +  bool death_test_use_fork_;
   1.211 +  String filter_;
   1.212 +  String internal_run_death_test_;
   1.213 +  bool list_tests_;
   1.214 +  String output_;
   1.215 +  bool print_time_;
   1.216 +  bool pretty_;
   1.217 +  internal::Int32 random_seed_;
   1.218 +  internal::Int32 repeat_;
   1.219 +  bool shuffle_;
   1.220 +  internal::Int32 stack_trace_depth_;
   1.221 +  String stream_result_to_;
   1.222 +  bool throw_on_failure_;
   1.223 +} GTEST_ATTRIBUTE_UNUSED_;
   1.224 +
   1.225 +// Converts a Unicode code point to a narrow string in UTF-8 encoding.
   1.226 +// code_point parameter is of type UInt32 because wchar_t may not be
   1.227 +// wide enough to contain a code point.
   1.228 +// The output buffer str must containt at least 32 characters.
   1.229 +// The function returns the address of the output buffer.
   1.230 +// If the code_point is not a valid Unicode code point
   1.231 +// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output
   1.232 +// as '(Invalid Unicode 0xXXXXXXXX)'.
   1.233 +GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);
   1.234 +
   1.235 +// Converts a wide string to a narrow string in UTF-8 encoding.
   1.236 +// The wide string is assumed to have the following encoding:
   1.237 +//   UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
   1.238 +//   UTF-32 if sizeof(wchar_t) == 4 (on Linux)
   1.239 +// Parameter str points to a null-terminated wide string.
   1.240 +// Parameter num_chars may additionally limit the number
   1.241 +// of wchar_t characters processed. -1 is used when the entire string
   1.242 +// should be processed.
   1.243 +// If the string contains code points that are not valid Unicode code points
   1.244 +// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
   1.245 +// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
   1.246 +// and contains invalid UTF-16 surrogate pairs, values in those pairs
   1.247 +// will be encoded as individual Unicode characters from Basic Normal Plane.
   1.248 +GTEST_API_ String WideStringToUtf8(const wchar_t* str, int num_chars);
   1.249 +
   1.250 +// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
   1.251 +// if the variable is present. If a file already exists at this location, this
   1.252 +// function will write over it. If the variable is present, but the file cannot
   1.253 +// be created, prints an error and exits.
   1.254 +void WriteToShardStatusFileIfNeeded();
   1.255 +
   1.256 +// Checks whether sharding is enabled by examining the relevant
   1.257 +// environment variable values. If the variables are present,
   1.258 +// but inconsistent (e.g., shard_index >= total_shards), prints
   1.259 +// an error and exits. If in_subprocess_for_death_test, sharding is
   1.260 +// disabled because it must only be applied to the original test
   1.261 +// process. Otherwise, we could filter out death tests we intended to execute.
   1.262 +GTEST_API_ bool ShouldShard(const char* total_shards_str,
   1.263 +                            const char* shard_index_str,
   1.264 +                            bool in_subprocess_for_death_test);
   1.265 +
   1.266 +// Parses the environment variable var as an Int32. If it is unset,
   1.267 +// returns default_val. If it is not an Int32, prints an error and
   1.268 +// and aborts.
   1.269 +GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
   1.270 +
   1.271 +// Given the total number of shards, the shard index, and the test id,
   1.272 +// returns true iff the test should be run on this shard. The test id is
   1.273 +// some arbitrary but unique non-negative integer assigned to each test
   1.274 +// method. Assumes that 0 <= shard_index < total_shards.
   1.275 +GTEST_API_ bool ShouldRunTestOnShard(
   1.276 +    int total_shards, int shard_index, int test_id);
   1.277 +
   1.278 +// STL container utilities.
   1.279 +
   1.280 +// Returns the number of elements in the given container that satisfy
   1.281 +// the given predicate.
   1.282 +template <class Container, typename Predicate>
   1.283 +inline int CountIf(const Container& c, Predicate predicate) {
   1.284 +  // Implemented as an explicit loop since std::count_if() in libCstd on
   1.285 +  // Solaris has a non-standard signature.
   1.286 +  int count = 0;
   1.287 +  for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
   1.288 +    if (predicate(*it))
   1.289 +      ++count;
   1.290 +  }
   1.291 +  return count;
   1.292 +}
   1.293 +
   1.294 +// Applies a function/functor to each element in the container.
   1.295 +template <class Container, typename Functor>
   1.296 +void ForEach(const Container& c, Functor functor) {
   1.297 +  std::for_each(c.begin(), c.end(), functor);
   1.298 +}
   1.299 +
   1.300 +// Returns the i-th element of the vector, or default_value if i is not
   1.301 +// in range [0, v.size()).
   1.302 +template <typename E>
   1.303 +inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
   1.304 +  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
   1.305 +}
   1.306 +
   1.307 +// Performs an in-place shuffle of a range of the vector's elements.
   1.308 +// 'begin' and 'end' are element indices as an STL-style range;
   1.309 +// i.e. [begin, end) are shuffled, where 'end' == size() means to
   1.310 +// shuffle to the end of the vector.
   1.311 +template <typename E>
   1.312 +void ShuffleRange(internal::Random* random, int begin, int end,
   1.313 +                  std::vector<E>* v) {
   1.314 +  const int size = static_cast<int>(v->size());
   1.315 +  GTEST_CHECK_(0 <= begin && begin <= size)
   1.316 +      << "Invalid shuffle range start " << begin << ": must be in range [0, "
   1.317 +      << size << "].";
   1.318 +  GTEST_CHECK_(begin <= end && end <= size)
   1.319 +      << "Invalid shuffle range finish " << end << ": must be in range ["
   1.320 +      << begin << ", " << size << "].";
   1.321 +
   1.322 +  // Fisher-Yates shuffle, from
   1.323 +  // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
   1.324 +  for (int range_width = end - begin; range_width >= 2; range_width--) {
   1.325 +    const int last_in_range = begin + range_width - 1;
   1.326 +    const int selected = begin + random->Generate(range_width);
   1.327 +    std::swap((*v)[selected], (*v)[last_in_range]);
   1.328 +  }
   1.329 +}
   1.330 +
   1.331 +// Performs an in-place shuffle of the vector's elements.
   1.332 +template <typename E>
   1.333 +inline void Shuffle(internal::Random* random, std::vector<E>* v) {
   1.334 +  ShuffleRange(random, 0, static_cast<int>(v->size()), v);
   1.335 +}
   1.336 +
   1.337 +// A function for deleting an object.  Handy for being used as a
   1.338 +// functor.
   1.339 +template <typename T>
   1.340 +static void Delete(T* x) {
   1.341 +  delete x;
   1.342 +}
   1.343 +
   1.344 +// A predicate that checks the key of a TestProperty against a known key.
   1.345 +//
   1.346 +// TestPropertyKeyIs is copyable.
   1.347 +class TestPropertyKeyIs {
   1.348 + public:
   1.349 +  // Constructor.
   1.350 +  //
   1.351 +  // TestPropertyKeyIs has NO default constructor.
   1.352 +  explicit TestPropertyKeyIs(const char* key)
   1.353 +      : key_(key) {}
   1.354 +
   1.355 +  // Returns true iff the test name of test property matches on key_.
   1.356 +  bool operator()(const TestProperty& test_property) const {
   1.357 +    return String(test_property.key()).Compare(key_) == 0;
   1.358 +  }
   1.359 +
   1.360 + private:
   1.361 +  String key_;
   1.362 +};
   1.363 +
   1.364 +// Class UnitTestOptions.
   1.365 +//
   1.366 +// This class contains functions for processing options the user
   1.367 +// specifies when running the tests.  It has only static members.
   1.368 +//
   1.369 +// In most cases, the user can specify an option using either an
   1.370 +// environment variable or a command line flag.  E.g. you can set the
   1.371 +// test filter using either GTEST_FILTER or --gtest_filter.  If both
   1.372 +// the variable and the flag are present, the latter overrides the
   1.373 +// former.
   1.374 +class GTEST_API_ UnitTestOptions {
   1.375 + public:
   1.376 +  // Functions for processing the gtest_output flag.
   1.377 +
   1.378 +  // Returns the output format, or "" for normal printed output.
   1.379 +  static String GetOutputFormat();
   1.380 +
   1.381 +  // Returns the absolute path of the requested output file, or the
   1.382 +  // default (test_detail.xml in the original working directory) if
   1.383 +  // none was explicitly specified.
   1.384 +  static String GetAbsolutePathToOutputFile();
   1.385 +
   1.386 +  // Functions for processing the gtest_filter flag.
   1.387 +
   1.388 +  // Returns true iff the wildcard pattern matches the string.  The
   1.389 +  // first ':' or '\0' character in pattern marks the end of it.
   1.390 +  //
   1.391 +  // This recursive algorithm isn't very efficient, but is clear and
   1.392 +  // works well enough for matching test names, which are short.
   1.393 +  static bool PatternMatchesString(const char *pattern, const char *str);
   1.394 +
   1.395 +  // Returns true iff the user-specified filter matches the test case
   1.396 +  // name and the test name.
   1.397 +  static bool FilterMatchesTest(const String &test_case_name,
   1.398 +                                const String &test_name);
   1.399 +
   1.400 +#if GTEST_OS_WINDOWS
   1.401 +  // Function for supporting the gtest_catch_exception flag.
   1.402 +
   1.403 +  // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
   1.404 +  // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
   1.405 +  // This function is useful as an __except condition.
   1.406 +  static int GTestShouldProcessSEH(DWORD exception_code);
   1.407 +#endif  // GTEST_OS_WINDOWS
   1.408 +
   1.409 +  // Returns true if "name" matches the ':' separated list of glob-style
   1.410 +  // filters in "filter".
   1.411 +  static bool MatchesFilter(const String& name, const char* filter);
   1.412 +};
   1.413 +
   1.414 +// Returns the current application's name, removing directory path if that
   1.415 +// is present.  Used by UnitTestOptions::GetOutputFile.
   1.416 +GTEST_API_ FilePath GetCurrentExecutableName();
   1.417 +
   1.418 +// The role interface for getting the OS stack trace as a string.
   1.419 +class OsStackTraceGetterInterface {
   1.420 + public:
   1.421 +  OsStackTraceGetterInterface() {}
   1.422 +  virtual ~OsStackTraceGetterInterface() {}
   1.423 +
   1.424 +  // Returns the current OS stack trace as a String.  Parameters:
   1.425 +  //
   1.426 +  //   max_depth  - the maximum number of stack frames to be included
   1.427 +  //                in the trace.
   1.428 +  //   skip_count - the number of top frames to be skipped; doesn't count
   1.429 +  //                against max_depth.
   1.430 +  virtual String CurrentStackTrace(int max_depth, int skip_count) = 0;
   1.431 +
   1.432 +  // UponLeavingGTest() should be called immediately before Google Test calls
   1.433 +  // user code. It saves some information about the current stack that
   1.434 +  // CurrentStackTrace() will use to find and hide Google Test stack frames.
   1.435 +  virtual void UponLeavingGTest() = 0;
   1.436 +
   1.437 + private:
   1.438 +  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
   1.439 +};
   1.440 +
   1.441 +// A working implementation of the OsStackTraceGetterInterface interface.
   1.442 +class OsStackTraceGetter : public OsStackTraceGetterInterface {
   1.443 + public:
   1.444 +  OsStackTraceGetter() : caller_frame_(NULL) {}
   1.445 +
   1.446 +  virtual String CurrentStackTrace(int max_depth, int skip_count)
   1.447 +      GTEST_LOCK_EXCLUDED_(mutex_);
   1.448 +
   1.449 +  virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
   1.450 +
   1.451 +  // This string is inserted in place of stack frames that are part of
   1.452 +  // Google Test's implementation.
   1.453 +  static const char* const kElidedFramesMarker;
   1.454 +
   1.455 + private:
   1.456 +  Mutex mutex_;  // protects all internal state
   1.457 +
   1.458 +  // We save the stack frame below the frame that calls user code.
   1.459 +  // We do this because the address of the frame immediately below
   1.460 +  // the user code changes between the call to UponLeavingGTest()
   1.461 +  // and any calls to CurrentStackTrace() from within the user code.
   1.462 +  void* caller_frame_;
   1.463 +
   1.464 +  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
   1.465 +};
   1.466 +
   1.467 +// Information about a Google Test trace point.
   1.468 +struct TraceInfo {
   1.469 +  const char* file;
   1.470 +  int line;
   1.471 +  String message;
   1.472 +};
   1.473 +
   1.474 +// This is the default global test part result reporter used in UnitTestImpl.
   1.475 +// This class should only be used by UnitTestImpl.
   1.476 +class DefaultGlobalTestPartResultReporter
   1.477 +  : public TestPartResultReporterInterface {
   1.478 + public:
   1.479 +  explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
   1.480 +  // Implements the TestPartResultReporterInterface. Reports the test part
   1.481 +  // result in the current test.
   1.482 +  virtual void ReportTestPartResult(const TestPartResult& result);
   1.483 +
   1.484 + private:
   1.485 +  UnitTestImpl* const unit_test_;
   1.486 +
   1.487 +  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
   1.488 +};
   1.489 +
   1.490 +// This is the default per thread test part result reporter used in
   1.491 +// UnitTestImpl. This class should only be used by UnitTestImpl.
   1.492 +class DefaultPerThreadTestPartResultReporter
   1.493 +    : public TestPartResultReporterInterface {
   1.494 + public:
   1.495 +  explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
   1.496 +  // Implements the TestPartResultReporterInterface. The implementation just
   1.497 +  // delegates to the current global test part result reporter of *unit_test_.
   1.498 +  virtual void ReportTestPartResult(const TestPartResult& result);
   1.499 +
   1.500 + private:
   1.501 +  UnitTestImpl* const unit_test_;
   1.502 +
   1.503 +  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
   1.504 +};
   1.505 +
   1.506 +// The private implementation of the UnitTest class.  We don't protect
   1.507 +// the methods under a mutex, as this class is not accessible by a
   1.508 +// user and the UnitTest class that delegates work to this class does
   1.509 +// proper locking.
   1.510 +class GTEST_API_ UnitTestImpl {
   1.511 + public:
   1.512 +  explicit UnitTestImpl(UnitTest* parent);
   1.513 +  virtual ~UnitTestImpl();
   1.514 +
   1.515 +  // There are two different ways to register your own TestPartResultReporter.
   1.516 +  // You can register your own repoter to listen either only for test results
   1.517 +  // from the current thread or for results from all threads.
   1.518 +  // By default, each per-thread test result repoter just passes a new
   1.519 +  // TestPartResult to the global test result reporter, which registers the
   1.520 +  // test part result for the currently running test.
   1.521 +
   1.522 +  // Returns the global test part result reporter.
   1.523 +  TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
   1.524 +
   1.525 +  // Sets the global test part result reporter.
   1.526 +  void SetGlobalTestPartResultReporter(
   1.527 +      TestPartResultReporterInterface* reporter);
   1.528 +
   1.529 +  // Returns the test part result reporter for the current thread.
   1.530 +  TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
   1.531 +
   1.532 +  // Sets the test part result reporter for the current thread.
   1.533 +  void SetTestPartResultReporterForCurrentThread(
   1.534 +      TestPartResultReporterInterface* reporter);
   1.535 +
   1.536 +  // Gets the number of successful test cases.
   1.537 +  int successful_test_case_count() const;
   1.538 +
   1.539 +  // Gets the number of failed test cases.
   1.540 +  int failed_test_case_count() const;
   1.541 +
   1.542 +  // Gets the number of all test cases.
   1.543 +  int total_test_case_count() const;
   1.544 +
   1.545 +  // Gets the number of all test cases that contain at least one test
   1.546 +  // that should run.
   1.547 +  int test_case_to_run_count() const;
   1.548 +
   1.549 +  // Gets the number of successful tests.
   1.550 +  int successful_test_count() const;
   1.551 +
   1.552 +  // Gets the number of failed tests.
   1.553 +  int failed_test_count() const;
   1.554 +
   1.555 +  // Gets the number of disabled tests.
   1.556 +  int disabled_test_count() const;
   1.557 +
   1.558 +  // Gets the number of all tests.
   1.559 +  int total_test_count() const;
   1.560 +
   1.561 +  // Gets the number of tests that should run.
   1.562 +  int test_to_run_count() const;
   1.563 +
   1.564 +  // Gets the time of the test program start, in ms from the start of the
   1.565 +  // UNIX epoch.
   1.566 +  TimeInMillis start_timestamp() const { return start_timestamp_; }
   1.567 +
   1.568 +  // Gets the elapsed time, in milliseconds.
   1.569 +  TimeInMillis elapsed_time() const { return elapsed_time_; }
   1.570 +
   1.571 +  // Returns true iff the unit test passed (i.e. all test cases passed).
   1.572 +  bool Passed() const { return !Failed(); }
   1.573 +
   1.574 +  // Returns true iff the unit test failed (i.e. some test case failed
   1.575 +  // or something outside of all tests failed).
   1.576 +  bool Failed() const {
   1.577 +    return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
   1.578 +  }
   1.579 +
   1.580 +  // Gets the i-th test case among all the test cases. i can range from 0 to
   1.581 +  // total_test_case_count() - 1. If i is not in that range, returns NULL.
   1.582 +  const TestCase* GetTestCase(int i) const {
   1.583 +    const int index = GetElementOr(test_case_indices_, i, -1);
   1.584 +    return index < 0 ? NULL : test_cases_[i];
   1.585 +  }
   1.586 +
   1.587 +  // Gets the i-th test case among all the test cases. i can range from 0 to
   1.588 +  // total_test_case_count() - 1. If i is not in that range, returns NULL.
   1.589 +  TestCase* GetMutableTestCase(int i) {
   1.590 +    const int index = GetElementOr(test_case_indices_, i, -1);
   1.591 +    return index < 0 ? NULL : test_cases_[index];
   1.592 +  }
   1.593 +
   1.594 +  // Provides access to the event listener list.
   1.595 +  TestEventListeners* listeners() { return &listeners_; }
   1.596 +
   1.597 +  // Returns the TestResult for the test that's currently running, or
   1.598 +  // the TestResult for the ad hoc test if no test is running.
   1.599 +  TestResult* current_test_result();
   1.600 +
   1.601 +  // Returns the TestResult for the ad hoc test.
   1.602 +  const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
   1.603 +
   1.604 +  // Sets the OS stack trace getter.
   1.605 +  //
   1.606 +  // Does nothing if the input and the current OS stack trace getter
   1.607 +  // are the same; otherwise, deletes the old getter and makes the
   1.608 +  // input the current getter.
   1.609 +  void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
   1.610 +
   1.611 +  // Returns the current OS stack trace getter if it is not NULL;
   1.612 +  // otherwise, creates an OsStackTraceGetter, makes it the current
   1.613 +  // getter, and returns it.
   1.614 +  OsStackTraceGetterInterface* os_stack_trace_getter();
   1.615 +
   1.616 +  // Returns the current OS stack trace as a String.
   1.617 +  //
   1.618 +  // The maximum number of stack frames to be included is specified by
   1.619 +  // the gtest_stack_trace_depth flag.  The skip_count parameter
   1.620 +  // specifies the number of top frames to be skipped, which doesn't
   1.621 +  // count against the number of frames to be included.
   1.622 +  //
   1.623 +  // For example, if Foo() calls Bar(), which in turn calls
   1.624 +  // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
   1.625 +  // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
   1.626 +  String CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
   1.627 +
   1.628 +  // Finds and returns a TestCase with the given name.  If one doesn't
   1.629 +  // exist, creates one and returns it.
   1.630 +  //
   1.631 +  // Arguments:
   1.632 +  //
   1.633 +  //   test_case_name: name of the test case
   1.634 +  //   type_param:     the name of the test's type parameter, or NULL if
   1.635 +  //                   this is not a typed or a type-parameterized test.
   1.636 +  //   set_up_tc:      pointer to the function that sets up the test case
   1.637 +  //   tear_down_tc:   pointer to the function that tears down the test case
   1.638 +  TestCase* GetTestCase(const char* test_case_name,
   1.639 +                        const char* type_param,
   1.640 +                        Test::SetUpTestCaseFunc set_up_tc,
   1.641 +                        Test::TearDownTestCaseFunc tear_down_tc);
   1.642 +
   1.643 +  // Adds a TestInfo to the unit test.
   1.644 +  //
   1.645 +  // Arguments:
   1.646 +  //
   1.647 +  //   set_up_tc:    pointer to the function that sets up the test case
   1.648 +  //   tear_down_tc: pointer to the function that tears down the test case
   1.649 +  //   test_info:    the TestInfo object
   1.650 +  void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
   1.651 +                   Test::TearDownTestCaseFunc tear_down_tc,
   1.652 +                   TestInfo* test_info) {
   1.653 +    // In order to support thread-safe death tests, we need to
   1.654 +    // remember the original working directory when the test program
   1.655 +    // was first invoked.  We cannot do this in RUN_ALL_TESTS(), as
   1.656 +    // the user may have changed the current directory before calling
   1.657 +    // RUN_ALL_TESTS().  Therefore we capture the current directory in
   1.658 +    // AddTestInfo(), which is called to register a TEST or TEST_F
   1.659 +    // before main() is reached.
   1.660 +    if (original_working_dir_.IsEmpty()) {
   1.661 +      original_working_dir_.Set(FilePath::GetCurrentDir());
   1.662 +      GTEST_CHECK_(!original_working_dir_.IsEmpty())
   1.663 +          << "Failed to get the current working directory.";
   1.664 +    }
   1.665 +
   1.666 +    GetTestCase(test_info->test_case_name(),
   1.667 +                test_info->type_param(),
   1.668 +                set_up_tc,
   1.669 +                tear_down_tc)->AddTestInfo(test_info);
   1.670 +  }
   1.671 +
   1.672 +#if GTEST_HAS_PARAM_TEST
   1.673 +  // Returns ParameterizedTestCaseRegistry object used to keep track of
   1.674 +  // value-parameterized tests and instantiate and register them.
   1.675 +  internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
   1.676 +    return parameterized_test_registry_;
   1.677 +  }
   1.678 +#endif  // GTEST_HAS_PARAM_TEST
   1.679 +
   1.680 +  // Sets the TestCase object for the test that's currently running.
   1.681 +  void set_current_test_case(TestCase* a_current_test_case) {
   1.682 +    current_test_case_ = a_current_test_case;
   1.683 +  }
   1.684 +
   1.685 +  // Sets the TestInfo object for the test that's currently running.  If
   1.686 +  // current_test_info is NULL, the assertion results will be stored in
   1.687 +  // ad_hoc_test_result_.
   1.688 +  void set_current_test_info(TestInfo* a_current_test_info) {
   1.689 +    current_test_info_ = a_current_test_info;
   1.690 +  }
   1.691 +
   1.692 +  // Registers all parameterized tests defined using TEST_P and
   1.693 +  // INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
   1.694 +  // combination. This method can be called more then once; it has guards
   1.695 +  // protecting from registering the tests more then once.  If
   1.696 +  // value-parameterized tests are disabled, RegisterParameterizedTests is
   1.697 +  // present but does nothing.
   1.698 +  void RegisterParameterizedTests();
   1.699 +
   1.700 +  // Runs all tests in this UnitTest object, prints the result, and
   1.701 +  // returns true if all tests are successful.  If any exception is
   1.702 +  // thrown during a test, this test is considered to be failed, but
   1.703 +  // the rest of the tests will still be run.
   1.704 +  bool RunAllTests();
   1.705 +
   1.706 +  // Clears the results of all tests, except the ad hoc tests.
   1.707 +  void ClearNonAdHocTestResult() {
   1.708 +    ForEach(test_cases_, TestCase::ClearTestCaseResult);
   1.709 +  }
   1.710 +
   1.711 +  // Clears the results of ad-hoc test assertions.
   1.712 +  void ClearAdHocTestResult() {
   1.713 +    ad_hoc_test_result_.Clear();
   1.714 +  }
   1.715 +
   1.716 +  enum ReactionToSharding {
   1.717 +    HONOR_SHARDING_PROTOCOL,
   1.718 +    IGNORE_SHARDING_PROTOCOL
   1.719 +  };
   1.720 +
   1.721 +  // Matches the full name of each test against the user-specified
   1.722 +  // filter to decide whether the test should run, then records the
   1.723 +  // result in each TestCase and TestInfo object.
   1.724 +  // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
   1.725 +  // based on sharding variables in the environment.
   1.726 +  // Returns the number of tests that should run.
   1.727 +  int FilterTests(ReactionToSharding shard_tests);
   1.728 +
   1.729 +  // Prints the names of the tests matching the user-specified filter flag.
   1.730 +  void ListTestsMatchingFilter();
   1.731 +
   1.732 +  const TestCase* current_test_case() const { return current_test_case_; }
   1.733 +  TestInfo* current_test_info() { return current_test_info_; }
   1.734 +  const TestInfo* current_test_info() const { return current_test_info_; }
   1.735 +
   1.736 +  // Returns the vector of environments that need to be set-up/torn-down
   1.737 +  // before/after the tests are run.
   1.738 +  std::vector<Environment*>& environments() { return environments_; }
   1.739 +
   1.740 +  // Getters for the per-thread Google Test trace stack.
   1.741 +  std::vector<TraceInfo>& gtest_trace_stack() {
   1.742 +    return *(gtest_trace_stack_.pointer());
   1.743 +  }
   1.744 +  const std::vector<TraceInfo>& gtest_trace_stack() const {
   1.745 +    return gtest_trace_stack_.get();
   1.746 +  }
   1.747 +
   1.748 +#if GTEST_HAS_DEATH_TEST
   1.749 +  void InitDeathTestSubprocessControlInfo() {
   1.750 +    internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
   1.751 +  }
   1.752 +  // Returns a pointer to the parsed --gtest_internal_run_death_test
   1.753 +  // flag, or NULL if that flag was not specified.
   1.754 +  // This information is useful only in a death test child process.
   1.755 +  // Must not be called before a call to InitGoogleTest.
   1.756 +  const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
   1.757 +    return internal_run_death_test_flag_.get();
   1.758 +  }
   1.759 +
   1.760 +  // Returns a pointer to the current death test factory.
   1.761 +  internal::DeathTestFactory* death_test_factory() {
   1.762 +    return death_test_factory_.get();
   1.763 +  }
   1.764 +
   1.765 +  void SuppressTestEventsIfInSubprocess();
   1.766 +
   1.767 +  friend class ReplaceDeathTestFactory;
   1.768 +#endif  // GTEST_HAS_DEATH_TEST
   1.769 +
   1.770 +  // Initializes the event listener performing XML output as specified by
   1.771 +  // UnitTestOptions. Must not be called before InitGoogleTest.
   1.772 +  void ConfigureXmlOutput();
   1.773 +
   1.774 +#if GTEST_CAN_STREAM_RESULTS_
   1.775 +  // Initializes the event listener for streaming test results to a socket.
   1.776 +  // Must not be called before InitGoogleTest.
   1.777 +  void ConfigureStreamingOutput();
   1.778 +#endif
   1.779 +
   1.780 +  // Performs initialization dependent upon flag values obtained in
   1.781 +  // ParseGoogleTestFlagsOnly.  Is called from InitGoogleTest after the call to
   1.782 +  // ParseGoogleTestFlagsOnly.  In case a user neglects to call InitGoogleTest
   1.783 +  // this function is also called from RunAllTests.  Since this function can be
   1.784 +  // called more than once, it has to be idempotent.
   1.785 +  void PostFlagParsingInit();
   1.786 +
   1.787 +  // Gets the random seed used at the start of the current test iteration.
   1.788 +  int random_seed() const { return random_seed_; }
   1.789 +
   1.790 +  // Gets the random number generator.
   1.791 +  internal::Random* random() { return &random_; }
   1.792 +
   1.793 +  // Shuffles all test cases, and the tests within each test case,
   1.794 +  // making sure that death tests are still run first.
   1.795 +  void ShuffleTests();
   1.796 +
   1.797 +  // Restores the test cases and tests to their order before the first shuffle.
   1.798 +  void UnshuffleTests();
   1.799 +
   1.800 +  // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
   1.801 +  // UnitTest::Run() starts.
   1.802 +  bool catch_exceptions() const { return catch_exceptions_; }
   1.803 +
   1.804 + private:
   1.805 +  friend class ::testing::UnitTest;
   1.806 +
   1.807 +  // Used by UnitTest::Run() to capture the state of
   1.808 +  // GTEST_FLAG(catch_exceptions) at the moment it starts.
   1.809 +  void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
   1.810 +
   1.811 +  // The UnitTest object that owns this implementation object.
   1.812 +  UnitTest* const parent_;
   1.813 +
   1.814 +  // The working directory when the first TEST() or TEST_F() was
   1.815 +  // executed.
   1.816 +  internal::FilePath original_working_dir_;
   1.817 +
   1.818 +  // The default test part result reporters.
   1.819 +  DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
   1.820 +  DefaultPerThreadTestPartResultReporter
   1.821 +      default_per_thread_test_part_result_reporter_;
   1.822 +
   1.823 +  // Points to (but doesn't own) the global test part result reporter.
   1.824 +  TestPartResultReporterInterface* global_test_part_result_repoter_;
   1.825 +
   1.826 +  // Protects read and write access to global_test_part_result_reporter_.
   1.827 +  internal::Mutex global_test_part_result_reporter_mutex_;
   1.828 +
   1.829 +  // Points to (but doesn't own) the per-thread test part result reporter.
   1.830 +  internal::ThreadLocal<TestPartResultReporterInterface*>
   1.831 +      per_thread_test_part_result_reporter_;
   1.832 +
   1.833 +  // The vector of environments that need to be set-up/torn-down
   1.834 +  // before/after the tests are run.
   1.835 +  std::vector<Environment*> environments_;
   1.836 +
   1.837 +  // The vector of TestCases in their original order.  It owns the
   1.838 +  // elements in the vector.
   1.839 +  std::vector<TestCase*> test_cases_;
   1.840 +
   1.841 +  // Provides a level of indirection for the test case list to allow
   1.842 +  // easy shuffling and restoring the test case order.  The i-th
   1.843 +  // element of this vector is the index of the i-th test case in the
   1.844 +  // shuffled order.
   1.845 +  std::vector<int> test_case_indices_;
   1.846 +
   1.847 +#if GTEST_HAS_PARAM_TEST
   1.848 +  // ParameterizedTestRegistry object used to register value-parameterized
   1.849 +  // tests.
   1.850 +  internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
   1.851 +
   1.852 +  // Indicates whether RegisterParameterizedTests() has been called already.
   1.853 +  bool parameterized_tests_registered_;
   1.854 +#endif  // GTEST_HAS_PARAM_TEST
   1.855 +
   1.856 +  // Index of the last death test case registered.  Initially -1.
   1.857 +  int last_death_test_case_;
   1.858 +
   1.859 +  // This points to the TestCase for the currently running test.  It
   1.860 +  // changes as Google Test goes through one test case after another.
   1.861 +  // When no test is running, this is set to NULL and Google Test
   1.862 +  // stores assertion results in ad_hoc_test_result_.  Initially NULL.
   1.863 +  TestCase* current_test_case_;
   1.864 +
   1.865 +  // This points to the TestInfo for the currently running test.  It
   1.866 +  // changes as Google Test goes through one test after another.  When
   1.867 +  // no test is running, this is set to NULL and Google Test stores
   1.868 +  // assertion results in ad_hoc_test_result_.  Initially NULL.
   1.869 +  TestInfo* current_test_info_;
   1.870 +
   1.871 +  // Normally, a user only writes assertions inside a TEST or TEST_F,
   1.872 +  // or inside a function called by a TEST or TEST_F.  Since Google
   1.873 +  // Test keeps track of which test is current running, it can
   1.874 +  // associate such an assertion with the test it belongs to.
   1.875 +  //
   1.876 +  // If an assertion is encountered when no TEST or TEST_F is running,
   1.877 +  // Google Test attributes the assertion result to an imaginary "ad hoc"
   1.878 +  // test, and records the result in ad_hoc_test_result_.
   1.879 +  TestResult ad_hoc_test_result_;
   1.880 +
   1.881 +  // The list of event listeners that can be used to track events inside
   1.882 +  // Google Test.
   1.883 +  TestEventListeners listeners_;
   1.884 +
   1.885 +  // The OS stack trace getter.  Will be deleted when the UnitTest
   1.886 +  // object is destructed.  By default, an OsStackTraceGetter is used,
   1.887 +  // but the user can set this field to use a custom getter if that is
   1.888 +  // desired.
   1.889 +  OsStackTraceGetterInterface* os_stack_trace_getter_;
   1.890 +
   1.891 +  // True iff PostFlagParsingInit() has been called.
   1.892 +  bool post_flag_parse_init_performed_;
   1.893 +
   1.894 +  // The random number seed used at the beginning of the test run.
   1.895 +  int random_seed_;
   1.896 +
   1.897 +  // Our random number generator.
   1.898 +  internal::Random random_;
   1.899 +
   1.900 +  // The time of the test program start, in ms from the start of the
   1.901 +  // UNIX epoch.
   1.902 +  TimeInMillis start_timestamp_;
   1.903 +
   1.904 +  // How long the test took to run, in milliseconds.
   1.905 +  TimeInMillis elapsed_time_;
   1.906 +
   1.907 +#if GTEST_HAS_DEATH_TEST
   1.908 +  // The decomposed components of the gtest_internal_run_death_test flag,
   1.909 +  // parsed when RUN_ALL_TESTS is called.
   1.910 +  internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
   1.911 +  internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
   1.912 +#endif  // GTEST_HAS_DEATH_TEST
   1.913 +
   1.914 +  // A per-thread stack of traces created by the SCOPED_TRACE() macro.
   1.915 +  internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
   1.916 +
   1.917 +  // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
   1.918 +  // starts.
   1.919 +  bool catch_exceptions_;
   1.920 +
   1.921 +  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
   1.922 +};  // class UnitTestImpl
   1.923 +
   1.924 +// Convenience function for accessing the global UnitTest
   1.925 +// implementation object.
   1.926 +inline UnitTestImpl* GetUnitTestImpl() {
   1.927 +  return UnitTest::GetInstance()->impl();
   1.928 +}
   1.929 +
   1.930 +#if GTEST_USES_SIMPLE_RE
   1.931 +
   1.932 +// Internal helper functions for implementing the simple regular
   1.933 +// expression matcher.
   1.934 +GTEST_API_ bool IsInSet(char ch, const char* str);
   1.935 +GTEST_API_ bool IsAsciiDigit(char ch);
   1.936 +GTEST_API_ bool IsAsciiPunct(char ch);
   1.937 +GTEST_API_ bool IsRepeat(char ch);
   1.938 +GTEST_API_ bool IsAsciiWhiteSpace(char ch);
   1.939 +GTEST_API_ bool IsAsciiWordChar(char ch);
   1.940 +GTEST_API_ bool IsValidEscape(char ch);
   1.941 +GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
   1.942 +GTEST_API_ bool ValidateRegex(const char* regex);
   1.943 +GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
   1.944 +GTEST_API_ bool MatchRepetitionAndRegexAtHead(
   1.945 +    bool escaped, char ch, char repeat, const char* regex, const char* str);
   1.946 +GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
   1.947 +
   1.948 +#endif  // GTEST_USES_SIMPLE_RE
   1.949 +
   1.950 +// Parses the command line for Google Test flags, without initializing
   1.951 +// other parts of Google Test.
   1.952 +GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
   1.953 +GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
   1.954 +
   1.955 +#if GTEST_HAS_DEATH_TEST
   1.956 +
   1.957 +// Returns the message describing the last system error, regardless of the
   1.958 +// platform.
   1.959 +GTEST_API_ String GetLastErrnoDescription();
   1.960 +
   1.961 +# if GTEST_OS_WINDOWS
   1.962 +// Provides leak-safe Windows kernel handle ownership.
   1.963 +class AutoHandle {
   1.964 + public:
   1.965 +  AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
   1.966 +  explicit AutoHandle(HANDLE handle) : handle_(handle) {}
   1.967 +
   1.968 +  ~AutoHandle() { Reset(); }
   1.969 +
   1.970 +  HANDLE Get() const { return handle_; }
   1.971 +  void Reset() { Reset(INVALID_HANDLE_VALUE); }
   1.972 +  void Reset(HANDLE handle) {
   1.973 +    if (handle != handle_) {
   1.974 +      if (handle_ != INVALID_HANDLE_VALUE)
   1.975 +        ::CloseHandle(handle_);
   1.976 +      handle_ = handle;
   1.977 +    }
   1.978 +  }
   1.979 +
   1.980 + private:
   1.981 +  HANDLE handle_;
   1.982 +
   1.983 +  GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
   1.984 +};
   1.985 +# endif  // GTEST_OS_WINDOWS
   1.986 +
   1.987 +// Attempts to parse a string into a positive integer pointed to by the
   1.988 +// number parameter.  Returns true if that is possible.
   1.989 +// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
   1.990 +// it here.
   1.991 +template <typename Integer>
   1.992 +bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
   1.993 +  // Fail fast if the given string does not begin with a digit;
   1.994 +  // this bypasses strtoXXX's "optional leading whitespace and plus
   1.995 +  // or minus sign" semantics, which are undesirable here.
   1.996 +  if (str.empty() || !IsDigit(str[0])) {
   1.997 +    return false;
   1.998 +  }
   1.999 +  errno = 0;
  1.1000 +
  1.1001 +  char* end;
  1.1002 +  // BiggestConvertible is the largest integer type that system-provided
  1.1003 +  // string-to-number conversion routines can return.
  1.1004 +
  1.1005 +# if GTEST_OS_WINDOWS && !defined(__GNUC__)
  1.1006 +
  1.1007 +  // MSVC and C++ Builder define __int64 instead of the standard long long.
  1.1008 +  typedef unsigned __int64 BiggestConvertible;
  1.1009 +  const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
  1.1010 +
  1.1011 +# else
  1.1012 +
  1.1013 +  typedef unsigned long long BiggestConvertible;  // NOLINT
  1.1014 +  const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
  1.1015 +
  1.1016 +# endif  // GTEST_OS_WINDOWS && !defined(__GNUC__)
  1.1017 +
  1.1018 +  const bool parse_success = *end == '\0' && errno == 0;
  1.1019 +
  1.1020 +  // TODO(vladl@google.com): Convert this to compile time assertion when it is
  1.1021 +  // available.
  1.1022 +  GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
  1.1023 +
  1.1024 +  const Integer result = static_cast<Integer>(parsed);
  1.1025 +  if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
  1.1026 +    *number = result;
  1.1027 +    return true;
  1.1028 +  }
  1.1029 +  return false;
  1.1030 +}
  1.1031 +#endif  // GTEST_HAS_DEATH_TEST
  1.1032 +
  1.1033 +// TestResult contains some private methods that should be hidden from
  1.1034 +// Google Test user but are required for testing. This class allow our tests
  1.1035 +// to access them.
  1.1036 +//
  1.1037 +// This class is supplied only for the purpose of testing Google Test's own
  1.1038 +// constructs. Do not use it in user tests, either directly or indirectly.
  1.1039 +class TestResultAccessor {
  1.1040 + public:
  1.1041 +  static void RecordProperty(TestResult* test_result,
  1.1042 +                             const TestProperty& property) {
  1.1043 +    test_result->RecordProperty(property);
  1.1044 +  }
  1.1045 +
  1.1046 +  static void ClearTestPartResults(TestResult* test_result) {
  1.1047 +    test_result->ClearTestPartResults();
  1.1048 +  }
  1.1049 +
  1.1050 +  static const std::vector<testing::TestPartResult>& test_part_results(
  1.1051 +      const TestResult& test_result) {
  1.1052 +    return test_result.test_part_results();
  1.1053 +  }
  1.1054 +};
  1.1055 +
  1.1056 +}  // namespace internal
  1.1057 +}  // namespace testing
  1.1058 +
  1.1059 +#endif  // GTEST_SRC_GTEST_INTERNAL_INL_H_

mercurial