File indexing completed on 2025-08-06 08:19:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include "gmock/gmock.h"
0037
0038 #include <string>
0039 #include "gtest/gtest.h"
0040
0041 #if !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
0042
0043 using testing::GMOCK_FLAG(verbose);
0044 using testing::InitGoogleMock;
0045
0046
0047
0048 template <typename Char, int M, int N>
0049 void TestInitGoogleMock(const Char* (&argv)[M], const Char* (&new_argv)[N],
0050 const ::std::string& expected_gmock_verbose) {
0051 const ::std::string old_verbose = GMOCK_FLAG(verbose);
0052
0053 int argc = M;
0054 InitGoogleMock(&argc, const_cast<Char**>(argv));
0055 ASSERT_EQ(N, argc) << "The new argv has wrong number of elements.";
0056
0057 for (int i = 0; i < N; i++) {
0058 EXPECT_STREQ(new_argv[i], argv[i]);
0059 }
0060
0061 EXPECT_EQ(expected_gmock_verbose, GMOCK_FLAG(verbose).c_str());
0062 GMOCK_FLAG(verbose) = old_verbose;
0063 }
0064
0065 TEST(InitGoogleMockTest, ParsesInvalidCommandLine) {
0066 const char* argv[] = {
0067 NULL
0068 };
0069
0070 const char* new_argv[] = {
0071 NULL
0072 };
0073
0074 TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
0075 }
0076
0077 TEST(InitGoogleMockTest, ParsesEmptyCommandLine) {
0078 const char* argv[] = {
0079 "foo.exe",
0080 NULL
0081 };
0082
0083 const char* new_argv[] = {
0084 "foo.exe",
0085 NULL
0086 };
0087
0088 TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
0089 }
0090
0091 TEST(InitGoogleMockTest, ParsesSingleFlag) {
0092 const char* argv[] = {
0093 "foo.exe",
0094 "--gmock_verbose=info",
0095 NULL
0096 };
0097
0098 const char* new_argv[] = {
0099 "foo.exe",
0100 NULL
0101 };
0102
0103 TestInitGoogleMock(argv, new_argv, "info");
0104 }
0105
0106 TEST(InitGoogleMockTest, ParsesUnrecognizedFlag) {
0107 const char* argv[] = {
0108 "foo.exe",
0109 "--non_gmock_flag=blah",
0110 NULL
0111 };
0112
0113 const char* new_argv[] = {
0114 "foo.exe",
0115 "--non_gmock_flag=blah",
0116 NULL
0117 };
0118
0119 TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
0120 }
0121
0122 TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
0123 const char* argv[] = {
0124 "foo.exe",
0125 "--non_gmock_flag=blah",
0126 "--gmock_verbose=error",
0127 NULL
0128 };
0129
0130 const char* new_argv[] = {
0131 "foo.exe",
0132 "--non_gmock_flag=blah",
0133 NULL
0134 };
0135
0136 TestInitGoogleMock(argv, new_argv, "error");
0137 }
0138
0139 TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) {
0140 const wchar_t* argv[] = {
0141 NULL
0142 };
0143
0144 const wchar_t* new_argv[] = {
0145 NULL
0146 };
0147
0148 TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
0149 }
0150
0151 TEST(WideInitGoogleMockTest, ParsesEmptyCommandLine) {
0152 const wchar_t* argv[] = {
0153 L"foo.exe",
0154 NULL
0155 };
0156
0157 const wchar_t* new_argv[] = {
0158 L"foo.exe",
0159 NULL
0160 };
0161
0162 TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
0163 }
0164
0165 TEST(WideInitGoogleMockTest, ParsesSingleFlag) {
0166 const wchar_t* argv[] = {
0167 L"foo.exe",
0168 L"--gmock_verbose=info",
0169 NULL
0170 };
0171
0172 const wchar_t* new_argv[] = {
0173 L"foo.exe",
0174 NULL
0175 };
0176
0177 TestInitGoogleMock(argv, new_argv, "info");
0178 }
0179
0180 TEST(WideInitGoogleMockTest, ParsesUnrecognizedFlag) {
0181 const wchar_t* argv[] = {
0182 L"foo.exe",
0183 L"--non_gmock_flag=blah",
0184 NULL
0185 };
0186
0187 const wchar_t* new_argv[] = {
0188 L"foo.exe",
0189 L"--non_gmock_flag=blah",
0190 NULL
0191 };
0192
0193 TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
0194 }
0195
0196 TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
0197 const wchar_t* argv[] = {
0198 L"foo.exe",
0199 L"--non_gmock_flag=blah",
0200 L"--gmock_verbose=error",
0201 NULL
0202 };
0203
0204 const wchar_t* new_argv[] = {
0205 L"foo.exe",
0206 L"--non_gmock_flag=blah",
0207 NULL
0208 };
0209
0210 TestInitGoogleMock(argv, new_argv, "error");
0211 }
0212
0213 #endif
0214
0215
0216 TEST(FlagTest, IsAccessibleInCode) {
0217 bool dummy = testing::GMOCK_FLAG(catch_leaked_mocks) &&
0218 testing::GMOCK_FLAG(verbose) == "";
0219 (void)dummy;
0220 }