proxygen
gmock_test.cc File Reference
#include "gmock/gmock.h"
#include <string>
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

template<typename Char , int M, int N>
void TestInitGoogleMock (const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
 
 TEST (InitGoogleMockTest, ParsesInvalidCommandLine)
 
 TEST (InitGoogleMockTest, ParsesEmptyCommandLine)
 
 TEST (InitGoogleMockTest, ParsesSingleFlag)
 
 TEST (InitGoogleMockTest, ParsesUnrecognizedFlag)
 
 TEST (InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag)
 
 TEST (WideInitGoogleMockTest, ParsesInvalidCommandLine)
 
 TEST (WideInitGoogleMockTest, ParsesEmptyCommandLine)
 
 TEST (WideInitGoogleMockTest, ParsesSingleFlag)
 
 TEST (WideInitGoogleMockTest, ParsesUnrecognizedFlag)
 
 TEST (WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag)
 
 TEST (FlagTest, IsAccessibleInCode)
 

Function Documentation

TEST ( InitGoogleMockTest  ,
ParsesInvalidCommandLine   
)

Definition at line 65 of file gmock_test.cc.

References argv, GMOCK_FLAG, and TestInitGoogleMock().

65  {
66  const char* argv[] = {
67  NULL
68  };
69 
70  const char* new_argv[] = {
71  NULL
72  };
73 
74  TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
75 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
TEST ( InitGoogleMockTest  ,
ParsesEmptyCommandLine   
)

Definition at line 77 of file gmock_test.cc.

References argv, GMOCK_FLAG, and TestInitGoogleMock().

77  {
78  const char* argv[] = {
79  "foo.exe",
80  NULL
81  };
82 
83  const char* new_argv[] = {
84  "foo.exe",
85  NULL
86  };
87 
88  TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
89 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
TEST ( InitGoogleMockTest  ,
ParsesSingleFlag   
)

Definition at line 91 of file gmock_test.cc.

References argv, and TestInitGoogleMock().

91  {
92  const char* argv[] = {
93  "foo.exe",
94  "--gmock_verbose=info",
95  NULL
96  };
97 
98  const char* new_argv[] = {
99  "foo.exe",
100  NULL
101  };
102 
103  TestInitGoogleMock(argv, new_argv, "info");
104 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
TEST ( InitGoogleMockTest  ,
ParsesUnrecognizedFlag   
)

Definition at line 106 of file gmock_test.cc.

References argv, GMOCK_FLAG, and TestInitGoogleMock().

106  {
107  const char* argv[] = {
108  "foo.exe",
109  "--non_gmock_flag=blah",
110  NULL
111  };
112 
113  const char* new_argv[] = {
114  "foo.exe",
115  "--non_gmock_flag=blah",
116  NULL
117  };
118 
119  TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
120 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
TEST ( InitGoogleMockTest  ,
ParsesGoogleMockFlagAndUnrecognizedFlag   
)

Definition at line 122 of file gmock_test.cc.

References argv, and TestInitGoogleMock().

122  {
123  const char* argv[] = {
124  "foo.exe",
125  "--non_gmock_flag=blah",
126  "--gmock_verbose=error",
127  NULL
128  };
129 
130  const char* new_argv[] = {
131  "foo.exe",
132  "--non_gmock_flag=blah",
133  NULL
134  };
135 
136  TestInitGoogleMock(argv, new_argv, "error");
137 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
TEST ( WideInitGoogleMockTest  ,
ParsesInvalidCommandLine   
)

Definition at line 139 of file gmock_test.cc.

References argv, GMOCK_FLAG, and TestInitGoogleMock().

139  {
140  const wchar_t* argv[] = {
141  NULL
142  };
143 
144  const wchar_t* new_argv[] = {
145  NULL
146  };
147 
148  TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
149 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
TEST ( WideInitGoogleMockTest  ,
ParsesEmptyCommandLine   
)

Definition at line 151 of file gmock_test.cc.

References argv, GMOCK_FLAG, and TestInitGoogleMock().

151  {
152  const wchar_t* argv[] = {
153  L"foo.exe",
154  NULL
155  };
156 
157  const wchar_t* new_argv[] = {
158  L"foo.exe",
159  NULL
160  };
161 
162  TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
163 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
TEST ( WideInitGoogleMockTest  ,
ParsesSingleFlag   
)

Definition at line 165 of file gmock_test.cc.

References argv, and TestInitGoogleMock().

165  {
166  const wchar_t* argv[] = {
167  L"foo.exe",
168  L"--gmock_verbose=info",
169  NULL
170  };
171 
172  const wchar_t* new_argv[] = {
173  L"foo.exe",
174  NULL
175  };
176 
177  TestInitGoogleMock(argv, new_argv, "info");
178 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
TEST ( WideInitGoogleMockTest  ,
ParsesUnrecognizedFlag   
)

Definition at line 180 of file gmock_test.cc.

References argv, GMOCK_FLAG, and TestInitGoogleMock().

180  {
181  const wchar_t* argv[] = {
182  L"foo.exe",
183  L"--non_gmock_flag=blah",
184  NULL
185  };
186 
187  const wchar_t* new_argv[] = {
188  L"foo.exe",
189  L"--non_gmock_flag=blah",
190  NULL
191  };
192 
193  TestInitGoogleMock(argv, new_argv, GMOCK_FLAG(verbose));
194 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
TEST ( WideInitGoogleMockTest  ,
ParsesGoogleMockFlagAndUnrecognizedFlag   
)

Definition at line 196 of file gmock_test.cc.

References argv, and TestInitGoogleMock().

196  {
197  const wchar_t* argv[] = {
198  L"foo.exe",
199  L"--non_gmock_flag=blah",
200  L"--gmock_verbose=error",
201  NULL
202  };
203 
204  const wchar_t* new_argv[] = {
205  L"foo.exe",
206  L"--non_gmock_flag=blah",
207  NULL
208  };
209 
210  TestInitGoogleMock(argv, new_argv, "error");
211 }
void TestInitGoogleMock(const Char *(&argv)[M], const Char *(&new_argv)[N], const ::std::string &expected_gmock_verbose)
Definition: gmock_test.cc:49
char ** argv
TEST ( FlagTest  ,
IsAccessibleInCode   
)

Definition at line 216 of file gmock_test.cc.

References dummy(), and GMOCK_FLAG.

216  {
217  bool dummy = testing::GMOCK_FLAG(catch_leaked_mocks) &&
218  testing::GMOCK_FLAG(verbose) == "";
219  (void)dummy; // Avoids the "unused local variable" warning.
220 }
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
void dummy()
template<typename Char , int M, int N>
void TestInitGoogleMock ( const Char *(&)  argv[M],
const Char *(&)  new_argv[N],
const ::std::string expected_gmock_verbose 
)

Definition at line 49 of file gmock_test.cc.

References argv, ASSERT_EQ, EXPECT_EQ, EXPECT_STREQ, GMOCK_FLAG, i, testing::InitGoogleMock(), M, and string.

50  {
51  const ::std::string old_verbose = GMOCK_FLAG(verbose);
52 
53  int argc = M;
54  InitGoogleMock(&argc, const_cast<Char**>(argv));
55  ASSERT_EQ(N, argc) << "The new argv has wrong number of elements.";
56 
57  for (int i = 0; i < N; i++) {
58  EXPECT_STREQ(new_argv[i], argv[i]);
59  }
60 
61  EXPECT_EQ(expected_gmock_verbose, GMOCK_FLAG(verbose).c_str());
62  GMOCK_FLAG(verbose) = old_verbose; // Restores the gmock_verbose flag.
63 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
Definition: gmock.cc:173
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_STREQ(s1, s2)
Definition: gtest.h:1995
char ** argv
#define GMOCK_FLAG(name)
Definition: gmock-port.h:70
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
const char * string
Definition: Conv.cpp:212