test/fmw/gtest/googlemock/src/gmock.cc
author sgehwolf
Wed, 06 Nov 2019 18:06:36 +0100
changeset 59120 fc68b2cdfeeb
parent 55049 4853b1ceb3d6
permissions -rw-r--r--
8233712: Limit default tests jobs based on ulimit -u setting Reviewed-by: erikj, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55049
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     1
// Copyright 2008, Google Inc.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     2
// All rights reserved.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     3
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     4
// Redistribution and use in source and binary forms, with or without
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     5
// modification, are permitted provided that the following conditions are
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     6
// met:
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     7
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     8
//     * Redistributions of source code must retain the above copyright
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
     9
// notice, this list of conditions and the following disclaimer.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    10
//     * Redistributions in binary form must reproduce the above
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    11
// copyright notice, this list of conditions and the following disclaimer
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    12
// in the documentation and/or other materials provided with the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    13
// distribution.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    14
//     * Neither the name of Google Inc. nor the names of its
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    15
// contributors may be used to endorse or promote products derived from
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    16
// this software without specific prior written permission.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    17
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    19
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    20
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    21
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    22
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    23
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    24
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    25
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    29
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    30
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    31
#include "gmock/gmock.h"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    32
#include "gmock/internal/gmock-port.h"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    33
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    34
namespace testing {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    35
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    36
// FIXME: support using environment variables to
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    37
// control the flag values, like what Google Test does.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    38
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    39
GMOCK_DEFINE_bool_(catch_leaked_mocks, true,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    40
                   "true iff Google Mock should report leaked mock objects "
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    41
                   "as failures.");
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    42
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    43
GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    44
                     "Controls how verbose Google Mock's output is."
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    45
                     "  Valid values:\n"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    46
                     "  info    - prints all messages.\n"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    47
                     "  warning - prints warnings and errors.\n"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    48
                     "  error   - prints errors only.");
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    49
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    50
GMOCK_DEFINE_int32_(default_mock_behavior, 1,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    51
                    "Controls the default behavior of mocks."
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    52
                    "  Valid values:\n"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    53
                    "  0 - by default, mocks act as NiceMocks.\n"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    54
                    "  1 - by default, mocks act as NaggyMocks.\n"
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    55
                    "  2 - by default, mocks act as StrictMocks.");
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    56
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    57
namespace internal {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    58
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    59
// Parses a string as a command line flag.  The string should have the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    60
// format "--gmock_flag=value".  When def_optional is true, the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    61
// "=value" part can be omitted.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    62
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    63
// Returns the value of the flag, or NULL if the parsing failed.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    64
static const char* ParseGoogleMockFlagValue(const char* str,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    65
                                            const char* flag,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    66
                                            bool def_optional) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    67
  // str and flag must not be NULL.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    68
  if (str == NULL || flag == NULL) return NULL;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    69
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    70
  // The flag must start with "--gmock_".
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    71
  const std::string flag_str = std::string("--gmock_") + flag;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    72
  const size_t flag_len = flag_str.length();
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    73
  if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    74
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    75
  // Skips the flag name.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    76
  const char* flag_end = str + flag_len;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    77
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    78
  // When def_optional is true, it's OK to not have a "=value" part.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    79
  if (def_optional && (flag_end[0] == '\0')) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    80
    return flag_end;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    81
  }
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    82
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    83
  // If def_optional is true and there are more characters after the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    84
  // flag name, or if def_optional is false, there must be a '=' after
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    85
  // the flag name.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    86
  if (flag_end[0] != '=') return NULL;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    87
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    88
  // Returns the string after "=".
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    89
  return flag_end + 1;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    90
}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    91
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    92
// Parses a string for a Google Mock bool flag, in the form of
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    93
// "--gmock_flag=value".
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    94
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    95
// On success, stores the value of the flag in *value, and returns
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    96
// true.  On failure, returns false without changing *value.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    97
static bool ParseGoogleMockBoolFlag(const char* str, const char* flag,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    98
                                    bool* value) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
    99
  // Gets the value of the flag as a string.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   100
  const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   101
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   102
  // Aborts if the parsing failed.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   103
  if (value_str == NULL) return false;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   104
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   105
  // Converts the string value to a bool.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   106
  *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   107
  return true;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   108
}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   109
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   110
// Parses a string for a Google Mock string flag, in the form of
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   111
// "--gmock_flag=value".
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   112
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   113
// On success, stores the value of the flag in *value, and returns
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   114
// true.  On failure, returns false without changing *value.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   115
template <typename String>
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   116
static bool ParseGoogleMockStringFlag(const char* str, const char* flag,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   117
                                      String* value) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   118
  // Gets the value of the flag as a string.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   119
  const char* const value_str = ParseGoogleMockFlagValue(str, flag, false);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   120
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   121
  // Aborts if the parsing failed.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   122
  if (value_str == NULL) return false;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   123
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   124
  // Sets *value to the value of the flag.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   125
  *value = value_str;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   126
  return true;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   127
}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   128
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   129
static bool ParseGoogleMockIntFlag(const char* str, const char* flag,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   130
                                   int* value) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   131
  // Gets the value of the flag as a string.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   132
  const char* const value_str = ParseGoogleMockFlagValue(str, flag, true);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   133
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   134
  // Aborts if the parsing failed.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   135
  if (value_str == NULL) return false;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   136
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   137
  // Sets *value to the value of the flag.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   138
  return ParseInt32(Message() << "The value of flag --" << flag,
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   139
                    value_str, value);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   140
}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   141
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   142
// The internal implementation of InitGoogleMock().
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   143
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   144
// The type parameter CharType can be instantiated to either char or
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   145
// wchar_t.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   146
template <typename CharType>
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   147
void InitGoogleMockImpl(int* argc, CharType** argv) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   148
  // Makes sure Google Test is initialized.  InitGoogleTest() is
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   149
  // idempotent, so it's fine if the user has already called it.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   150
  InitGoogleTest(argc, argv);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   151
  if (*argc <= 0) return;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   152
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   153
  for (int i = 1; i != *argc; i++) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   154
    const std::string arg_string = StreamableToString(argv[i]);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   155
    const char* const arg = arg_string.c_str();
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   156
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   157
    // Do we see a Google Mock flag?
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   158
    if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks",
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   159
                                &GMOCK_FLAG(catch_leaked_mocks)) ||
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   160
        ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose)) ||
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   161
        ParseGoogleMockIntFlag(arg, "default_mock_behavior",
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   162
                               &GMOCK_FLAG(default_mock_behavior))) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   163
      // Yes.  Shift the remainder of the argv list left by one.  Note
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   164
      // that argv has (*argc + 1) elements, the last one always being
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   165
      // NULL.  The following loop moves the trailing NULL element as
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   166
      // well.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   167
      for (int j = i; j != *argc; j++) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   168
        argv[j] = argv[j + 1];
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   169
      }
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   170
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   171
      // Decrements the argument count.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   172
      (*argc)--;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   173
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   174
      // We also need to decrement the iterator as we just removed
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   175
      // an element.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   176
      i--;
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   177
    }
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   178
  }
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   179
}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   180
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   181
}  // namespace internal
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   182
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   183
// Initializes Google Mock.  This must be called before running the
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   184
// tests.  In particular, it parses a command line for the flags that
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   185
// Google Mock recognizes.  Whenever a Google Mock flag is seen, it is
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   186
// removed from argv, and *argc is decremented.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   187
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   188
// No value is returned.  Instead, the Google Mock flag variables are
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   189
// updated.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   190
//
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   191
// Since Google Test is needed for Google Mock to work, this function
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   192
// also initializes Google Test and parses its flags, if that hasn't
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   193
// been done.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   194
GTEST_API_ void InitGoogleMock(int* argc, char** argv) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   195
  internal::InitGoogleMockImpl(argc, argv);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   196
}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   197
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   198
// This overloaded version can be used in Windows programs compiled in
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   199
// UNICODE mode.
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   200
GTEST_API_ void InitGoogleMock(int* argc, wchar_t** argv) {
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   201
  internal::InitGoogleMockImpl(argc, argv);
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   202
}
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   203
4853b1ceb3d6 8222414: bring googlemock v1.8.1
iignatyev
parents:
diff changeset
   204
}  // namespace testing