test/fmw/gtest/src/gtest-internal-inl.h
author lana
Thu, 06 Apr 2017 17:01:01 +0000
changeset 44485 944ceffabd2f
parent 37967 8dd54c3bf02a
child 54913 9cfbe22bcdf8
permissions -rw-r--r--
Added tag jdk-9+164 for changeset 3e8038219df3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37967
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     1
// Copyright 2005, Google Inc.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     2
// All rights reserved.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     3
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     4
// Redistribution and use in source and binary forms, with or without
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     5
// modification, are permitted provided that the following conditions are
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     6
// met:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     7
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     8
//     * Redistributions of source code must retain the above copyright
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     9
// notice, this list of conditions and the following disclaimer.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    10
//     * Redistributions in binary form must reproduce the above
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    11
// copyright notice, this list of conditions and the following disclaimer
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    12
// in the documentation and/or other materials provided with the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    13
// distribution.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    14
//     * Neither the name of Google Inc. nor the names of its
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    15
// contributors may be used to endorse or promote products derived from
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    16
// this software without specific prior written permission.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    17
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    29
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    30
// Utility functions and classes used by the Google C++ testing framework.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    31
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    32
// Author: wan@google.com (Zhanyong Wan)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    33
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    34
// This file contains purely Google Test's internal implementation.  Please
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    35
// DO NOT #INCLUDE IT IN A USER PROGRAM.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    36
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    37
#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    38
#define GTEST_SRC_GTEST_INTERNAL_INL_H_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    39
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    40
// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    41
// part of Google Test's implementation; otherwise it's undefined.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    42
#if !GTEST_IMPLEMENTATION_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    43
// A user is trying to include this from his code - just say no.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    44
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    45
# error "It must not be included except by Google Test itself."
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    46
#endif  // GTEST_IMPLEMENTATION_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    47
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    48
#ifndef _WIN32_WCE
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    49
# include <errno.h>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    50
#endif  // !_WIN32_WCE
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    51
#include <stddef.h>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    52
#include <stdlib.h>  // For strtoll/_strtoul64/malloc/free.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    53
#include <string.h>  // For memmove.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    54
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    55
#include <algorithm>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    56
#include <string>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    57
#include <vector>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    58
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    59
#include "gtest/internal/gtest-port.h"
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    60
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    61
#if GTEST_CAN_STREAM_RESULTS_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    62
# include <arpa/inet.h>  // NOLINT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    63
# include <netdb.h>  // NOLINT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    64
#endif
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    65
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    66
#if GTEST_OS_WINDOWS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    67
# include <windows.h>  // NOLINT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    68
#endif  // GTEST_OS_WINDOWS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    69
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    70
#include "gtest/gtest.h"  // NOLINT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    71
#include "gtest/gtest-spi.h"
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    72
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    73
namespace testing {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    74
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    75
// Declares the flags.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    76
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    77
// We don't want the users to modify this flag in the code, but want
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    78
// Google Test's own unit tests to be able to access it. Therefore we
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    79
// declare it here as opposed to in gtest.h.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    80
GTEST_DECLARE_bool_(death_test_use_fork);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    81
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    82
namespace internal {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    83
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    84
// The value of GetTestTypeId() as seen from within the Google Test
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    85
// library.  This is solely for testing GetTestTypeId().
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    86
GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    87
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    88
// Names of the flags (needed for parsing Google Test flags).
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    89
const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    90
const char kBreakOnFailureFlag[] = "break_on_failure";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    91
const char kCatchExceptionsFlag[] = "catch_exceptions";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    92
const char kColorFlag[] = "color";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    93
const char kFilterFlag[] = "filter";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    94
const char kListTestsFlag[] = "list_tests";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    95
const char kOutputFlag[] = "output";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    96
const char kPrintTimeFlag[] = "print_time";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    97
const char kRandomSeedFlag[] = "random_seed";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    98
const char kRepeatFlag[] = "repeat";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    99
const char kShuffleFlag[] = "shuffle";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   100
const char kStackTraceDepthFlag[] = "stack_trace_depth";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   101
const char kStreamResultToFlag[] = "stream_result_to";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   102
const char kThrowOnFailureFlag[] = "throw_on_failure";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   103
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   104
// A valid random seed must be in [1, kMaxRandomSeed].
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   105
const int kMaxRandomSeed = 99999;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   106
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   107
// g_help_flag is true iff the --help flag or an equivalent form is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   108
// specified on the command line.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   109
GTEST_API_ extern bool g_help_flag;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   110
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   111
// Returns the current time in milliseconds.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   112
GTEST_API_ TimeInMillis GetTimeInMillis();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   113
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   114
// Returns true iff Google Test should use colors in the output.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   115
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   116
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   117
// Formats the given time in milliseconds as seconds.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   118
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   119
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   120
// Converts the given time in milliseconds to a date string in the ISO 8601
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   121
// format, without the timezone information.  N.B.: due to the use the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   122
// non-reentrant localtime() function, this function is not thread safe.  Do
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   123
// not use it in any code that can be called from multiple threads.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   124
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   125
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   126
// Parses a string for an Int32 flag, in the form of "--flag=value".
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   127
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   128
// On success, stores the value of the flag in *value, and returns
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   129
// true.  On failure, returns false without changing *value.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   130
GTEST_API_ bool ParseInt32Flag(
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   131
    const char* str, const char* flag, Int32* value);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   132
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   133
// Returns a random seed in range [1, kMaxRandomSeed] based on the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   134
// given --gtest_random_seed flag value.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   135
inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   136
  const unsigned int raw_seed = (random_seed_flag == 0) ?
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   137
      static_cast<unsigned int>(GetTimeInMillis()) :
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   138
      static_cast<unsigned int>(random_seed_flag);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   139
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   140
  // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   141
  // it's easy to type.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   142
  const int normalized_seed =
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   143
      static_cast<int>((raw_seed - 1U) %
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   144
                       static_cast<unsigned int>(kMaxRandomSeed)) + 1;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   145
  return normalized_seed;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   146
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   147
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   148
// Returns the first valid random seed after 'seed'.  The behavior is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   149
// undefined if 'seed' is invalid.  The seed after kMaxRandomSeed is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   150
// considered to be 1.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   151
inline int GetNextRandomSeed(int seed) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   152
  GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   153
      << "Invalid random seed " << seed << " - must be in [1, "
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   154
      << kMaxRandomSeed << "].";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   155
  const int next_seed = seed + 1;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   156
  return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   157
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   158
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   159
// This class saves the values of all Google Test flags in its c'tor, and
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   160
// restores them in its d'tor.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   161
class GTestFlagSaver {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   162
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   163
  // The c'tor.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   164
  GTestFlagSaver() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   165
    also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   166
    break_on_failure_ = GTEST_FLAG(break_on_failure);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   167
    catch_exceptions_ = GTEST_FLAG(catch_exceptions);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   168
    color_ = GTEST_FLAG(color);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   169
    death_test_style_ = GTEST_FLAG(death_test_style);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   170
    death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   171
    filter_ = GTEST_FLAG(filter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   172
    internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   173
    list_tests_ = GTEST_FLAG(list_tests);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   174
    output_ = GTEST_FLAG(output);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   175
    print_time_ = GTEST_FLAG(print_time);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   176
    random_seed_ = GTEST_FLAG(random_seed);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   177
    repeat_ = GTEST_FLAG(repeat);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   178
    shuffle_ = GTEST_FLAG(shuffle);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   179
    stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   180
    stream_result_to_ = GTEST_FLAG(stream_result_to);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   181
    throw_on_failure_ = GTEST_FLAG(throw_on_failure);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   182
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   183
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   184
  // The d'tor is not virtual.  DO NOT INHERIT FROM THIS CLASS.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   185
  ~GTestFlagSaver() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   186
    GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   187
    GTEST_FLAG(break_on_failure) = break_on_failure_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   188
    GTEST_FLAG(catch_exceptions) = catch_exceptions_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   189
    GTEST_FLAG(color) = color_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   190
    GTEST_FLAG(death_test_style) = death_test_style_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   191
    GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   192
    GTEST_FLAG(filter) = filter_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   193
    GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   194
    GTEST_FLAG(list_tests) = list_tests_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   195
    GTEST_FLAG(output) = output_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   196
    GTEST_FLAG(print_time) = print_time_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   197
    GTEST_FLAG(random_seed) = random_seed_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   198
    GTEST_FLAG(repeat) = repeat_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   199
    GTEST_FLAG(shuffle) = shuffle_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   200
    GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   201
    GTEST_FLAG(stream_result_to) = stream_result_to_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   202
    GTEST_FLAG(throw_on_failure) = throw_on_failure_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   203
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   204
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   205
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   206
  // Fields for saving the original values of flags.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   207
  bool also_run_disabled_tests_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   208
  bool break_on_failure_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   209
  bool catch_exceptions_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   210
  std::string color_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   211
  std::string death_test_style_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   212
  bool death_test_use_fork_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   213
  std::string filter_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   214
  std::string internal_run_death_test_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   215
  bool list_tests_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   216
  std::string output_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   217
  bool print_time_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   218
  internal::Int32 random_seed_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   219
  internal::Int32 repeat_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   220
  bool shuffle_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   221
  internal::Int32 stack_trace_depth_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   222
  std::string stream_result_to_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   223
  bool throw_on_failure_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   224
} GTEST_ATTRIBUTE_UNUSED_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   225
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   226
// Converts a Unicode code point to a narrow string in UTF-8 encoding.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   227
// code_point parameter is of type UInt32 because wchar_t may not be
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   228
// wide enough to contain a code point.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   229
// If the code_point is not a valid Unicode code point
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   230
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   231
// to "(Invalid Unicode 0xXXXXXXXX)".
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   232
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   233
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   234
// Converts a wide string to a narrow string in UTF-8 encoding.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   235
// The wide string is assumed to have the following encoding:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   236
//   UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   237
//   UTF-32 if sizeof(wchar_t) == 4 (on Linux)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   238
// Parameter str points to a null-terminated wide string.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   239
// Parameter num_chars may additionally limit the number
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   240
// of wchar_t characters processed. -1 is used when the entire string
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   241
// should be processed.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   242
// If the string contains code points that are not valid Unicode code points
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   243
// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   244
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   245
// and contains invalid UTF-16 surrogate pairs, values in those pairs
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   246
// will be encoded as individual Unicode characters from Basic Normal Plane.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   247
GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   248
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   249
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   250
// if the variable is present. If a file already exists at this location, this
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   251
// function will write over it. If the variable is present, but the file cannot
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   252
// be created, prints an error and exits.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   253
void WriteToShardStatusFileIfNeeded();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   254
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   255
// Checks whether sharding is enabled by examining the relevant
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   256
// environment variable values. If the variables are present,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   257
// but inconsistent (e.g., shard_index >= total_shards), prints
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   258
// an error and exits. If in_subprocess_for_death_test, sharding is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   259
// disabled because it must only be applied to the original test
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   260
// process. Otherwise, we could filter out death tests we intended to execute.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   261
GTEST_API_ bool ShouldShard(const char* total_shards_str,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   262
                            const char* shard_index_str,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   263
                            bool in_subprocess_for_death_test);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   264
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   265
// Parses the environment variable var as an Int32. If it is unset,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   266
// returns default_val. If it is not an Int32, prints an error and
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   267
// and aborts.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   268
GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   269
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   270
// Given the total number of shards, the shard index, and the test id,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   271
// returns true iff the test should be run on this shard. The test id is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   272
// some arbitrary but unique non-negative integer assigned to each test
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   273
// method. Assumes that 0 <= shard_index < total_shards.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   274
GTEST_API_ bool ShouldRunTestOnShard(
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   275
    int total_shards, int shard_index, int test_id);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   276
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   277
// STL container utilities.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   278
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   279
// Returns the number of elements in the given container that satisfy
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   280
// the given predicate.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   281
template <class Container, typename Predicate>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   282
inline int CountIf(const Container& c, Predicate predicate) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   283
  // Implemented as an explicit loop since std::count_if() in libCstd on
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   284
  // Solaris has a non-standard signature.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   285
  int count = 0;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   286
  for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   287
    if (predicate(*it))
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   288
      ++count;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   289
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   290
  return count;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   291
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   292
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   293
// Applies a function/functor to each element in the container.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   294
template <class Container, typename Functor>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   295
void ForEach(const Container& c, Functor functor) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   296
  std::for_each(c.begin(), c.end(), functor);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   297
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   298
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   299
// Returns the i-th element of the vector, or default_value if i is not
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   300
// in range [0, v.size()).
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   301
template <typename E>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   302
inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   303
  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   304
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   305
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   306
// Performs an in-place shuffle of a range of the vector's elements.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   307
// 'begin' and 'end' are element indices as an STL-style range;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   308
// i.e. [begin, end) are shuffled, where 'end' == size() means to
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   309
// shuffle to the end of the vector.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   310
template <typename E>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   311
void ShuffleRange(internal::Random* random, int begin, int end,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   312
                  std::vector<E>* v) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   313
  const int size = static_cast<int>(v->size());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   314
  GTEST_CHECK_(0 <= begin && begin <= size)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   315
      << "Invalid shuffle range start " << begin << ": must be in range [0, "
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   316
      << size << "].";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   317
  GTEST_CHECK_(begin <= end && end <= size)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   318
      << "Invalid shuffle range finish " << end << ": must be in range ["
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   319
      << begin << ", " << size << "].";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   320
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   321
  // Fisher-Yates shuffle, from
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   322
  // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   323
  for (int range_width = end - begin; range_width >= 2; range_width--) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   324
    const int last_in_range = begin + range_width - 1;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   325
    const int selected = begin + random->Generate(range_width);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   326
    std::swap((*v)[selected], (*v)[last_in_range]);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   327
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   328
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   329
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   330
// Performs an in-place shuffle of the vector's elements.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   331
template <typename E>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   332
inline void Shuffle(internal::Random* random, std::vector<E>* v) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   333
  ShuffleRange(random, 0, static_cast<int>(v->size()), v);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   334
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   335
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   336
// A function for deleting an object.  Handy for being used as a
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   337
// functor.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   338
template <typename T>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   339
static void Delete(T* x) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   340
  delete x;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   341
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   342
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   343
// A predicate that checks the key of a TestProperty against a known key.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   344
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   345
// TestPropertyKeyIs is copyable.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   346
class TestPropertyKeyIs {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   347
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   348
  // Constructor.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   349
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   350
  // TestPropertyKeyIs has NO default constructor.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   351
  explicit TestPropertyKeyIs(const std::string& key) : key_(key) {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   352
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   353
  // Returns true iff the test name of test property matches on key_.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   354
  bool operator()(const TestProperty& test_property) const {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   355
    return test_property.key() == key_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   356
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   357
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   358
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   359
  std::string key_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   360
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   361
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   362
// Class UnitTestOptions.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   363
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   364
// This class contains functions for processing options the user
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   365
// specifies when running the tests.  It has only static members.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   366
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   367
// In most cases, the user can specify an option using either an
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   368
// environment variable or a command line flag.  E.g. you can set the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   369
// test filter using either GTEST_FILTER or --gtest_filter.  If both
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   370
// the variable and the flag are present, the latter overrides the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   371
// former.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   372
class GTEST_API_ UnitTestOptions {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   373
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   374
  // Functions for processing the gtest_output flag.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   375
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   376
  // Returns the output format, or "" for normal printed output.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   377
  static std::string GetOutputFormat();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   378
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   379
  // Returns the absolute path of the requested output file, or the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   380
  // default (test_detail.xml in the original working directory) if
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   381
  // none was explicitly specified.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   382
  static std::string GetAbsolutePathToOutputFile();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   383
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   384
  // Functions for processing the gtest_filter flag.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   385
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   386
  // Returns true iff the wildcard pattern matches the string.  The
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   387
  // first ':' or '\0' character in pattern marks the end of it.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   388
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   389
  // This recursive algorithm isn't very efficient, but is clear and
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   390
  // works well enough for matching test names, which are short.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   391
  static bool PatternMatchesString(const char *pattern, const char *str);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   392
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   393
  // Returns true iff the user-specified filter matches the test case
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   394
  // name and the test name.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   395
  static bool FilterMatchesTest(const std::string &test_case_name,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   396
                                const std::string &test_name);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   397
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   398
#if GTEST_OS_WINDOWS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   399
  // Function for supporting the gtest_catch_exception flag.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   400
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   401
  // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   402
  // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   403
  // This function is useful as an __except condition.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   404
  static int GTestShouldProcessSEH(DWORD exception_code);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   405
#endif  // GTEST_OS_WINDOWS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   406
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   407
  // Returns true if "name" matches the ':' separated list of glob-style
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   408
  // filters in "filter".
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   409
  static bool MatchesFilter(const std::string& name, const char* filter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   410
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   411
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   412
// Returns the current application's name, removing directory path if that
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   413
// is present.  Used by UnitTestOptions::GetOutputFile.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   414
GTEST_API_ FilePath GetCurrentExecutableName();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   415
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   416
// The role interface for getting the OS stack trace as a string.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   417
class OsStackTraceGetterInterface {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   418
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   419
  OsStackTraceGetterInterface() {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   420
  virtual ~OsStackTraceGetterInterface() {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   421
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   422
  // Returns the current OS stack trace as an std::string.  Parameters:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   423
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   424
  //   max_depth  - the maximum number of stack frames to be included
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   425
  //                in the trace.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   426
  //   skip_count - the number of top frames to be skipped; doesn't count
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   427
  //                against max_depth.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   428
  virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   429
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   430
  // UponLeavingGTest() should be called immediately before Google Test calls
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   431
  // user code. It saves some information about the current stack that
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   432
  // CurrentStackTrace() will use to find and hide Google Test stack frames.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   433
  virtual void UponLeavingGTest() = 0;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   434
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   435
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   436
  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   437
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   438
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   439
// A working implementation of the OsStackTraceGetterInterface interface.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   440
class OsStackTraceGetter : public OsStackTraceGetterInterface {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   441
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   442
  OsStackTraceGetter() : caller_frame_(NULL) {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   443
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   444
  virtual string CurrentStackTrace(int max_depth, int skip_count)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   445
      GTEST_LOCK_EXCLUDED_(mutex_);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   446
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   447
  virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   448
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   449
  // This string is inserted in place of stack frames that are part of
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   450
  // Google Test's implementation.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   451
  static const char* const kElidedFramesMarker;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   452
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   453
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   454
  Mutex mutex_;  // protects all internal state
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   455
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   456
  // We save the stack frame below the frame that calls user code.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   457
  // We do this because the address of the frame immediately below
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   458
  // the user code changes between the call to UponLeavingGTest()
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   459
  // and any calls to CurrentStackTrace() from within the user code.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   460
  void* caller_frame_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   461
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   462
  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   463
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   464
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   465
// Information about a Google Test trace point.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   466
struct TraceInfo {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   467
  const char* file;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   468
  int line;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   469
  std::string message;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   470
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   471
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   472
// This is the default global test part result reporter used in UnitTestImpl.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   473
// This class should only be used by UnitTestImpl.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   474
class DefaultGlobalTestPartResultReporter
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   475
  : public TestPartResultReporterInterface {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   476
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   477
  explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   478
  // Implements the TestPartResultReporterInterface. Reports the test part
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   479
  // result in the current test.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   480
  virtual void ReportTestPartResult(const TestPartResult& result);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   481
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   482
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   483
  UnitTestImpl* const unit_test_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   484
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   485
  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   486
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   487
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   488
// This is the default per thread test part result reporter used in
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   489
// UnitTestImpl. This class should only be used by UnitTestImpl.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   490
class DefaultPerThreadTestPartResultReporter
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   491
    : public TestPartResultReporterInterface {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   492
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   493
  explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   494
  // Implements the TestPartResultReporterInterface. The implementation just
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   495
  // delegates to the current global test part result reporter of *unit_test_.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   496
  virtual void ReportTestPartResult(const TestPartResult& result);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   497
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   498
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   499
  UnitTestImpl* const unit_test_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   500
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   501
  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   502
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   503
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   504
// The private implementation of the UnitTest class.  We don't protect
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   505
// the methods under a mutex, as this class is not accessible by a
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   506
// user and the UnitTest class that delegates work to this class does
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   507
// proper locking.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   508
class GTEST_API_ UnitTestImpl {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   509
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   510
  explicit UnitTestImpl(UnitTest* parent);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   511
  virtual ~UnitTestImpl();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   512
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   513
  // There are two different ways to register your own TestPartResultReporter.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   514
  // You can register your own repoter to listen either only for test results
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   515
  // from the current thread or for results from all threads.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   516
  // By default, each per-thread test result repoter just passes a new
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   517
  // TestPartResult to the global test result reporter, which registers the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   518
  // test part result for the currently running test.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   519
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   520
  // Returns the global test part result reporter.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   521
  TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   522
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   523
  // Sets the global test part result reporter.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   524
  void SetGlobalTestPartResultReporter(
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   525
      TestPartResultReporterInterface* reporter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   526
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   527
  // Returns the test part result reporter for the current thread.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   528
  TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   529
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   530
  // Sets the test part result reporter for the current thread.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   531
  void SetTestPartResultReporterForCurrentThread(
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   532
      TestPartResultReporterInterface* reporter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   533
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   534
  // Gets the number of successful test cases.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   535
  int successful_test_case_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   536
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   537
  // Gets the number of failed test cases.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   538
  int failed_test_case_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   539
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   540
  // Gets the number of all test cases.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   541
  int total_test_case_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   542
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   543
  // Gets the number of all test cases that contain at least one test
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   544
  // that should run.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   545
  int test_case_to_run_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   546
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   547
  // Gets the number of successful tests.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   548
  int successful_test_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   549
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   550
  // Gets the number of failed tests.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   551
  int failed_test_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   552
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   553
  // Gets the number of disabled tests that will be reported in the XML report.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   554
  int reportable_disabled_test_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   555
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   556
  // Gets the number of disabled tests.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   557
  int disabled_test_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   558
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   559
  // Gets the number of tests to be printed in the XML report.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   560
  int reportable_test_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   561
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   562
  // Gets the number of all tests.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   563
  int total_test_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   564
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   565
  // Gets the number of tests that should run.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   566
  int test_to_run_count() const;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   567
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   568
  // Gets the time of the test program start, in ms from the start of the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   569
  // UNIX epoch.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   570
  TimeInMillis start_timestamp() const { return start_timestamp_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   571
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   572
  // Gets the elapsed time, in milliseconds.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   573
  TimeInMillis elapsed_time() const { return elapsed_time_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   574
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   575
  // Returns true iff the unit test passed (i.e. all test cases passed).
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   576
  bool Passed() const { return !Failed(); }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   577
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   578
  // Returns true iff the unit test failed (i.e. some test case failed
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   579
  // or something outside of all tests failed).
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   580
  bool Failed() const {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   581
    return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   582
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   583
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   584
  // Gets the i-th test case among all the test cases. i can range from 0 to
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   585
  // total_test_case_count() - 1. If i is not in that range, returns NULL.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   586
  const TestCase* GetTestCase(int i) const {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   587
    const int index = GetElementOr(test_case_indices_, i, -1);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   588
    return index < 0 ? NULL : test_cases_[i];
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   589
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   590
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   591
  // Gets the i-th test case among all the test cases. i can range from 0 to
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   592
  // total_test_case_count() - 1. If i is not in that range, returns NULL.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   593
  TestCase* GetMutableTestCase(int i) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   594
    const int index = GetElementOr(test_case_indices_, i, -1);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   595
    return index < 0 ? NULL : test_cases_[index];
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   596
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   597
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   598
  // Provides access to the event listener list.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   599
  TestEventListeners* listeners() { return &listeners_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   600
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   601
  // Returns the TestResult for the test that's currently running, or
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   602
  // the TestResult for the ad hoc test if no test is running.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   603
  TestResult* current_test_result();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   604
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   605
  // Returns the TestResult for the ad hoc test.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   606
  const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   607
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   608
  // Sets the OS stack trace getter.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   609
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   610
  // Does nothing if the input and the current OS stack trace getter
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   611
  // are the same; otherwise, deletes the old getter and makes the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   612
  // input the current getter.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   613
  void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   614
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   615
  // Returns the current OS stack trace getter if it is not NULL;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   616
  // otherwise, creates an OsStackTraceGetter, makes it the current
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   617
  // getter, and returns it.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   618
  OsStackTraceGetterInterface* os_stack_trace_getter();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   619
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   620
  // Returns the current OS stack trace as an std::string.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   621
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   622
  // The maximum number of stack frames to be included is specified by
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   623
  // the gtest_stack_trace_depth flag.  The skip_count parameter
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   624
  // specifies the number of top frames to be skipped, which doesn't
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   625
  // count against the number of frames to be included.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   626
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   627
  // For example, if Foo() calls Bar(), which in turn calls
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   628
  // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   629
  // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   630
  std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   631
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   632
  // Finds and returns a TestCase with the given name.  If one doesn't
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   633
  // exist, creates one and returns it.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   634
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   635
  // Arguments:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   636
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   637
  //   test_case_name: name of the test case
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   638
  //   type_param:     the name of the test's type parameter, or NULL if
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   639
  //                   this is not a typed or a type-parameterized test.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   640
  //   set_up_tc:      pointer to the function that sets up the test case
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   641
  //   tear_down_tc:   pointer to the function that tears down the test case
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   642
  TestCase* GetTestCase(const char* test_case_name,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   643
                        const char* type_param,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   644
                        Test::SetUpTestCaseFunc set_up_tc,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   645
                        Test::TearDownTestCaseFunc tear_down_tc);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   646
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   647
  // Adds a TestInfo to the unit test.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   648
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   649
  // Arguments:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   650
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   651
  //   set_up_tc:    pointer to the function that sets up the test case
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   652
  //   tear_down_tc: pointer to the function that tears down the test case
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   653
  //   test_info:    the TestInfo object
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   654
  void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   655
                   Test::TearDownTestCaseFunc tear_down_tc,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   656
                   TestInfo* test_info) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   657
    // In order to support thread-safe death tests, we need to
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   658
    // remember the original working directory when the test program
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   659
    // was first invoked.  We cannot do this in RUN_ALL_TESTS(), as
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   660
    // the user may have changed the current directory before calling
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   661
    // RUN_ALL_TESTS().  Therefore we capture the current directory in
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   662
    // AddTestInfo(), which is called to register a TEST or TEST_F
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   663
    // before main() is reached.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   664
    if (original_working_dir_.IsEmpty()) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   665
      original_working_dir_.Set(FilePath::GetCurrentDir());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   666
      GTEST_CHECK_(!original_working_dir_.IsEmpty())
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   667
          << "Failed to get the current working directory.";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   668
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   669
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   670
    GetTestCase(test_info->test_case_name(),
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   671
                test_info->type_param(),
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   672
                set_up_tc,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   673
                tear_down_tc)->AddTestInfo(test_info);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   674
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   675
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   676
#if GTEST_HAS_PARAM_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   677
  // Returns ParameterizedTestCaseRegistry object used to keep track of
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   678
  // value-parameterized tests and instantiate and register them.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   679
  internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   680
    return parameterized_test_registry_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   681
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   682
#endif  // GTEST_HAS_PARAM_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   683
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   684
  // Sets the TestCase object for the test that's currently running.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   685
  void set_current_test_case(TestCase* a_current_test_case) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   686
    current_test_case_ = a_current_test_case;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   687
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   688
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   689
  // Sets the TestInfo object for the test that's currently running.  If
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   690
  // current_test_info is NULL, the assertion results will be stored in
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   691
  // ad_hoc_test_result_.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   692
  void set_current_test_info(TestInfo* a_current_test_info) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   693
    current_test_info_ = a_current_test_info;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   694
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   695
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   696
  // Registers all parameterized tests defined using TEST_P and
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   697
  // INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   698
  // combination. This method can be called more then once; it has guards
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   699
  // protecting from registering the tests more then once.  If
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   700
  // value-parameterized tests are disabled, RegisterParameterizedTests is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   701
  // present but does nothing.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   702
  void RegisterParameterizedTests();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   703
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   704
  // Runs all tests in this UnitTest object, prints the result, and
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   705
  // returns true if all tests are successful.  If any exception is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   706
  // thrown during a test, this test is considered to be failed, but
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   707
  // the rest of the tests will still be run.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   708
  bool RunAllTests();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   709
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   710
  // Clears the results of all tests, except the ad hoc tests.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   711
  void ClearNonAdHocTestResult() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   712
    ForEach(test_cases_, TestCase::ClearTestCaseResult);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   713
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   714
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   715
  // Clears the results of ad-hoc test assertions.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   716
  void ClearAdHocTestResult() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   717
    ad_hoc_test_result_.Clear();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   718
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   719
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   720
  // Adds a TestProperty to the current TestResult object when invoked in a
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   721
  // context of a test or a test case, or to the global property set. If the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   722
  // result already contains a property with the same key, the value will be
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   723
  // updated.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   724
  void RecordProperty(const TestProperty& test_property);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   725
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   726
  enum ReactionToSharding {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   727
    HONOR_SHARDING_PROTOCOL,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   728
    IGNORE_SHARDING_PROTOCOL
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   729
  };
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   730
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   731
  // Matches the full name of each test against the user-specified
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   732
  // filter to decide whether the test should run, then records the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   733
  // result in each TestCase and TestInfo object.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   734
  // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   735
  // based on sharding variables in the environment.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   736
  // Returns the number of tests that should run.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   737
  int FilterTests(ReactionToSharding shard_tests);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   738
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   739
  // Prints the names of the tests matching the user-specified filter flag.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   740
  void ListTestsMatchingFilter();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   741
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   742
  const TestCase* current_test_case() const { return current_test_case_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   743
  TestInfo* current_test_info() { return current_test_info_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   744
  const TestInfo* current_test_info() const { return current_test_info_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   745
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   746
  // Returns the vector of environments that need to be set-up/torn-down
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   747
  // before/after the tests are run.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   748
  std::vector<Environment*>& environments() { return environments_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   749
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   750
  // Getters for the per-thread Google Test trace stack.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   751
  std::vector<TraceInfo>& gtest_trace_stack() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   752
    return *(gtest_trace_stack_.pointer());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   753
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   754
  const std::vector<TraceInfo>& gtest_trace_stack() const {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   755
    return gtest_trace_stack_.get();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   756
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   757
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   758
#if GTEST_HAS_DEATH_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   759
  void InitDeathTestSubprocessControlInfo() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   760
    internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   761
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   762
  // Returns a pointer to the parsed --gtest_internal_run_death_test
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   763
  // flag, or NULL if that flag was not specified.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   764
  // This information is useful only in a death test child process.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   765
  // Must not be called before a call to InitGoogleTest.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   766
  const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   767
    return internal_run_death_test_flag_.get();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   768
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   769
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   770
  // Returns a pointer to the current death test factory.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   771
  internal::DeathTestFactory* death_test_factory() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   772
    return death_test_factory_.get();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   773
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   774
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   775
  void SuppressTestEventsIfInSubprocess();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   776
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   777
  friend class ReplaceDeathTestFactory;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   778
#endif  // GTEST_HAS_DEATH_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   779
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   780
  // Initializes the event listener performing XML output as specified by
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   781
  // UnitTestOptions. Must not be called before InitGoogleTest.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   782
  void ConfigureXmlOutput();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   783
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   784
#if GTEST_CAN_STREAM_RESULTS_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   785
  // Initializes the event listener for streaming test results to a socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   786
  // Must not be called before InitGoogleTest.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   787
  void ConfigureStreamingOutput();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   788
#endif
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   789
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   790
  // Performs initialization dependent upon flag values obtained in
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   791
  // ParseGoogleTestFlagsOnly.  Is called from InitGoogleTest after the call to
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   792
  // ParseGoogleTestFlagsOnly.  In case a user neglects to call InitGoogleTest
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   793
  // this function is also called from RunAllTests.  Since this function can be
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   794
  // called more than once, it has to be idempotent.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   795
  void PostFlagParsingInit();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   796
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   797
  // Gets the random seed used at the start of the current test iteration.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   798
  int random_seed() const { return random_seed_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   799
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   800
  // Gets the random number generator.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   801
  internal::Random* random() { return &random_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   802
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   803
  // Shuffles all test cases, and the tests within each test case,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   804
  // making sure that death tests are still run first.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   805
  void ShuffleTests();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   806
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   807
  // Restores the test cases and tests to their order before the first shuffle.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   808
  void UnshuffleTests();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   809
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   810
  // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   811
  // UnitTest::Run() starts.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   812
  bool catch_exceptions() const { return catch_exceptions_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   813
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   814
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   815
  friend class ::testing::UnitTest;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   816
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   817
  // Used by UnitTest::Run() to capture the state of
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   818
  // GTEST_FLAG(catch_exceptions) at the moment it starts.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   819
  void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   820
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   821
  // The UnitTest object that owns this implementation object.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   822
  UnitTest* const parent_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   823
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   824
  // The working directory when the first TEST() or TEST_F() was
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   825
  // executed.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   826
  internal::FilePath original_working_dir_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   827
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   828
  // The default test part result reporters.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   829
  DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   830
  DefaultPerThreadTestPartResultReporter
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   831
      default_per_thread_test_part_result_reporter_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   832
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   833
  // Points to (but doesn't own) the global test part result reporter.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   834
  TestPartResultReporterInterface* global_test_part_result_repoter_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   835
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   836
  // Protects read and write access to global_test_part_result_reporter_.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   837
  internal::Mutex global_test_part_result_reporter_mutex_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   838
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   839
  // Points to (but doesn't own) the per-thread test part result reporter.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   840
  internal::ThreadLocal<TestPartResultReporterInterface*>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   841
      per_thread_test_part_result_reporter_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   842
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   843
  // The vector of environments that need to be set-up/torn-down
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   844
  // before/after the tests are run.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   845
  std::vector<Environment*> environments_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   846
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   847
  // The vector of TestCases in their original order.  It owns the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   848
  // elements in the vector.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   849
  std::vector<TestCase*> test_cases_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   850
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   851
  // Provides a level of indirection for the test case list to allow
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   852
  // easy shuffling and restoring the test case order.  The i-th
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   853
  // element of this vector is the index of the i-th test case in the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   854
  // shuffled order.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   855
  std::vector<int> test_case_indices_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   856
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   857
#if GTEST_HAS_PARAM_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   858
  // ParameterizedTestRegistry object used to register value-parameterized
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   859
  // tests.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   860
  internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   861
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   862
  // Indicates whether RegisterParameterizedTests() has been called already.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   863
  bool parameterized_tests_registered_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   864
#endif  // GTEST_HAS_PARAM_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   865
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   866
  // Index of the last death test case registered.  Initially -1.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   867
  int last_death_test_case_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   868
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   869
  // This points to the TestCase for the currently running test.  It
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   870
  // changes as Google Test goes through one test case after another.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   871
  // When no test is running, this is set to NULL and Google Test
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   872
  // stores assertion results in ad_hoc_test_result_.  Initially NULL.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   873
  TestCase* current_test_case_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   874
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   875
  // This points to the TestInfo for the currently running test.  It
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   876
  // changes as Google Test goes through one test after another.  When
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   877
  // no test is running, this is set to NULL and Google Test stores
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   878
  // assertion results in ad_hoc_test_result_.  Initially NULL.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   879
  TestInfo* current_test_info_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   880
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   881
  // Normally, a user only writes assertions inside a TEST or TEST_F,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   882
  // or inside a function called by a TEST or TEST_F.  Since Google
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   883
  // Test keeps track of which test is current running, it can
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   884
  // associate such an assertion with the test it belongs to.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   885
  //
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   886
  // If an assertion is encountered when no TEST or TEST_F is running,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   887
  // Google Test attributes the assertion result to an imaginary "ad hoc"
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   888
  // test, and records the result in ad_hoc_test_result_.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   889
  TestResult ad_hoc_test_result_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   890
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   891
  // The list of event listeners that can be used to track events inside
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   892
  // Google Test.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   893
  TestEventListeners listeners_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   894
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   895
  // The OS stack trace getter.  Will be deleted when the UnitTest
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   896
  // object is destructed.  By default, an OsStackTraceGetter is used,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   897
  // but the user can set this field to use a custom getter if that is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   898
  // desired.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   899
  OsStackTraceGetterInterface* os_stack_trace_getter_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   900
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   901
  // True iff PostFlagParsingInit() has been called.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   902
  bool post_flag_parse_init_performed_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   903
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   904
  // The random number seed used at the beginning of the test run.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   905
  int random_seed_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   906
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   907
  // Our random number generator.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   908
  internal::Random random_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   909
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   910
  // The time of the test program start, in ms from the start of the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   911
  // UNIX epoch.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   912
  TimeInMillis start_timestamp_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   913
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   914
  // How long the test took to run, in milliseconds.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   915
  TimeInMillis elapsed_time_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   916
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   917
#if GTEST_HAS_DEATH_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   918
  // The decomposed components of the gtest_internal_run_death_test flag,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   919
  // parsed when RUN_ALL_TESTS is called.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   920
  internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   921
  internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   922
#endif  // GTEST_HAS_DEATH_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   923
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   924
  // A per-thread stack of traces created by the SCOPED_TRACE() macro.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   925
  internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   926
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   927
  // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   928
  // starts.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   929
  bool catch_exceptions_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   930
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   931
  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   932
};  // class UnitTestImpl
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   933
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   934
// Convenience function for accessing the global UnitTest
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   935
// implementation object.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   936
inline UnitTestImpl* GetUnitTestImpl() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   937
  return UnitTest::GetInstance()->impl();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   938
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   939
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   940
#if GTEST_USES_SIMPLE_RE
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   941
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   942
// Internal helper functions for implementing the simple regular
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   943
// expression matcher.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   944
GTEST_API_ bool IsInSet(char ch, const char* str);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   945
GTEST_API_ bool IsAsciiDigit(char ch);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   946
GTEST_API_ bool IsAsciiPunct(char ch);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   947
GTEST_API_ bool IsRepeat(char ch);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   948
GTEST_API_ bool IsAsciiWhiteSpace(char ch);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   949
GTEST_API_ bool IsAsciiWordChar(char ch);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   950
GTEST_API_ bool IsValidEscape(char ch);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   951
GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   952
GTEST_API_ bool ValidateRegex(const char* regex);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   953
GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   954
GTEST_API_ bool MatchRepetitionAndRegexAtHead(
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   955
    bool escaped, char ch, char repeat, const char* regex, const char* str);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   956
GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   957
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   958
#endif  // GTEST_USES_SIMPLE_RE
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   959
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   960
// Parses the command line for Google Test flags, without initializing
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   961
// other parts of Google Test.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   962
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   963
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   964
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   965
#if GTEST_HAS_DEATH_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   966
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   967
// Returns the message describing the last system error, regardless of the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   968
// platform.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   969
GTEST_API_ std::string GetLastErrnoDescription();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   970
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   971
# if GTEST_OS_WINDOWS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   972
// Provides leak-safe Windows kernel handle ownership.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   973
class AutoHandle {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   974
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   975
  AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   976
  explicit AutoHandle(HANDLE handle) : handle_(handle) {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   977
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   978
  ~AutoHandle() { Reset(); }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   979
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   980
  HANDLE Get() const { return handle_; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   981
  void Reset() { Reset(INVALID_HANDLE_VALUE); }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   982
  void Reset(HANDLE handle) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   983
    if (handle != handle_) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   984
      if (handle_ != INVALID_HANDLE_VALUE)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   985
        ::CloseHandle(handle_);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   986
      handle_ = handle;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   987
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   988
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   989
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   990
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   991
  HANDLE handle_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   992
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   993
  GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   994
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   995
# endif  // GTEST_OS_WINDOWS
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   996
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   997
// Attempts to parse a string into a positive integer pointed to by the
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   998
// number parameter.  Returns true if that is possible.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   999
// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1000
// it here.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1001
template <typename Integer>
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1002
bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1003
  // Fail fast if the given string does not begin with a digit;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1004
  // this bypasses strtoXXX's "optional leading whitespace and plus
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1005
  // or minus sign" semantics, which are undesirable here.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1006
  if (str.empty() || !IsDigit(str[0])) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1007
    return false;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1008
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1009
  errno = 0;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1010
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1011
  char* end;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1012
  // BiggestConvertible is the largest integer type that system-provided
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1013
  // string-to-number conversion routines can return.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1014
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1015
# if GTEST_OS_WINDOWS && !defined(__GNUC__)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1016
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1017
  // MSVC and C++ Builder define __int64 instead of the standard long long.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1018
  typedef unsigned __int64 BiggestConvertible;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1019
  const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1020
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1021
# else
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1022
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1023
  typedef unsigned long long BiggestConvertible;  // NOLINT
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1024
  const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1025
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1026
# endif  // GTEST_OS_WINDOWS && !defined(__GNUC__)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1027
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1028
  const bool parse_success = *end == '\0' && errno == 0;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1029
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1030
  // TODO(vladl@google.com): Convert this to compile time assertion when it is
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1031
  // available.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1032
  GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1033
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1034
  const Integer result = static_cast<Integer>(parsed);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1035
  if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1036
    *number = result;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1037
    return true;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1038
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1039
  return false;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1040
}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1041
#endif  // GTEST_HAS_DEATH_TEST
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1042
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1043
// TestResult contains some private methods that should be hidden from
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1044
// Google Test user but are required for testing. This class allow our tests
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1045
// to access them.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1046
//
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1047
// This class is supplied only for the purpose of testing Google Test's own
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1048
// constructs. Do not use it in user tests, either directly or indirectly.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1049
class TestResultAccessor {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1050
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1051
  static void RecordProperty(TestResult* test_result,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1052
                             const std::string& xml_element,
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1053
                             const TestProperty& property) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1054
    test_result->RecordProperty(xml_element, property);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1055
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1056
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1057
  static void ClearTestPartResults(TestResult* test_result) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1058
    test_result->ClearTestPartResults();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1059
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1060
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1061
  static const std::vector<testing::TestPartResult>& test_part_results(
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1062
      const TestResult& test_result) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1063
    return test_result.test_part_results();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1064
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1065
};
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1066
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1067
#if GTEST_CAN_STREAM_RESULTS_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1068
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1069
// Streams test results to the given port on the given host machine.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1070
class StreamingListener : public EmptyTestEventListener {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1071
 public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1072
  // Abstract base class for writing strings to a socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1073
  class AbstractSocketWriter {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1074
   public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1075
    virtual ~AbstractSocketWriter() {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1076
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1077
    // Sends a string to the socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1078
    virtual void Send(const string& message) = 0;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1079
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1080
    // Closes the socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1081
    virtual void CloseConnection() {}
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1082
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1083
    // Sends a string and a newline to the socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1084
    void SendLn(const string& message) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1085
      Send(message + "\n");
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1086
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1087
  };
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1088
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1089
  // Concrete class for actually writing strings to a socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1090
  class SocketWriter : public AbstractSocketWriter {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1091
   public:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1092
    SocketWriter(const string& host, const string& port)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1093
        : sockfd_(-1), host_name_(host), port_num_(port) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1094
      MakeConnection();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1095
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1096
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1097
    virtual ~SocketWriter() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1098
      if (sockfd_ != -1)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1099
        CloseConnection();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1100
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1101
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1102
    // Sends a string to the socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1103
    virtual void Send(const string& message) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1104
      GTEST_CHECK_(sockfd_ != -1)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1105
          << "Send() can be called only when there is a connection.";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1106
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1107
      const int len = static_cast<int>(message.length());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1108
      if (write(sockfd_, message.c_str(), len) != len) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1109
        GTEST_LOG_(WARNING)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1110
            << "stream_result_to: failed to stream to "
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1111
            << host_name_ << ":" << port_num_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1112
      }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1113
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1114
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1115
   private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1116
    // Creates a client socket and connects to the server.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1117
    void MakeConnection();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1118
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1119
    // Closes the socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1120
    void CloseConnection() {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1121
      GTEST_CHECK_(sockfd_ != -1)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1122
          << "CloseConnection() can be called only when there is a connection.";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1123
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1124
      close(sockfd_);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1125
      sockfd_ = -1;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1126
    }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1127
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1128
    int sockfd_;  // socket file descriptor
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1129
    const string host_name_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1130
    const string port_num_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1131
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1132
    GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1133
  };  // class SocketWriter
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1134
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1135
  // Escapes '=', '&', '%', and '\n' characters in str as "%xx".
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1136
  static string UrlEncode(const char* str);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1137
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1138
  StreamingListener(const string& host, const string& port)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1139
      : socket_writer_(new SocketWriter(host, port)) { Start(); }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1140
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1141
  explicit StreamingListener(AbstractSocketWriter* socket_writer)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1142
      : socket_writer_(socket_writer) { Start(); }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1143
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1144
  void OnTestProgramStart(const UnitTest& /* unit_test */) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1145
    SendLn("event=TestProgramStart");
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1146
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1147
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1148
  void OnTestProgramEnd(const UnitTest& unit_test) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1149
    // Note that Google Test current only report elapsed time for each
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1150
    // test iteration, not for the entire test program.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1151
    SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1152
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1153
    // Notify the streaming server to stop.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1154
    socket_writer_->CloseConnection();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1155
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1156
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1157
  void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1158
    SendLn("event=TestIterationStart&iteration=" +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1159
           StreamableToString(iteration));
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1160
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1161
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1162
  void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1163
    SendLn("event=TestIterationEnd&passed=" +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1164
           FormatBool(unit_test.Passed()) + "&elapsed_time=" +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1165
           StreamableToString(unit_test.elapsed_time()) + "ms");
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1166
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1167
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1168
  void OnTestCaseStart(const TestCase& test_case) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1169
    SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1170
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1171
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1172
  void OnTestCaseEnd(const TestCase& test_case) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1173
    SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1174
           + "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1175
           + "ms");
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1176
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1177
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1178
  void OnTestStart(const TestInfo& test_info) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1179
    SendLn(std::string("event=TestStart&name=") + test_info.name());
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1180
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1181
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1182
  void OnTestEnd(const TestInfo& test_info) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1183
    SendLn("event=TestEnd&passed=" +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1184
           FormatBool((test_info.result())->Passed()) +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1185
           "&elapsed_time=" +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1186
           StreamableToString((test_info.result())->elapsed_time()) + "ms");
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1187
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1188
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1189
  void OnTestPartResult(const TestPartResult& test_part_result) {
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1190
    const char* file_name = test_part_result.file_name();
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1191
    if (file_name == NULL)
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1192
      file_name = "";
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1193
    SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1194
           "&line=" + StreamableToString(test_part_result.line_number()) +
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1195
           "&message=" + UrlEncode(test_part_result.message()));
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1196
  }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1197
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1198
 private:
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1199
  // Sends the given message and a newline to the socket.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1200
  void SendLn(const string& message) { socket_writer_->SendLn(message); }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1201
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1202
  // Called at the start of streaming to notify the receiver what
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1203
  // protocol we are using.
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1204
  void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1205
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1206
  string FormatBool(bool value) { return value ? "1" : "0"; }
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1207
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1208
  const scoped_ptr<AbstractSocketWriter> socket_writer_;
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1209
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1210
  GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1211
};  // class StreamingListener
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1212
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1213
#endif  // GTEST_CAN_STREAM_RESULTS_
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1214
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1215
}  // namespace internal
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1216
}  // namespace testing
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1217
8dd54c3bf02a 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
  1218
#endif  // GTEST_SRC_GTEST_INTERNAL_INL_H_