34 #include <google/protobuf/stubs/callback.h>
35 #include <google/protobuf/stubs/casts.h>
36 #include <google/protobuf/stubs/common.h>
37 #include <google/protobuf/stubs/logging.h>
38 #include <google/protobuf/stubs/strutil.h>
39 #include <google/protobuf/stubs/substitute.h>
41 #include <google/protobuf/testing/googletest.h>
42 #include <gtest/gtest.h>
50 #ifdef PACKAGE_VERSION // only defined when using automake, not MSVC
52 TEST(VersionTest, VersionMatchesConfig) {
67 #endif // PACKAGE_VERSION
80 std::vector<std::string> captured_messages_;
84 captured_messages_.push_back(
89 TEST(LoggingTest, DefaultLogging) {
98 "[libprotobuf INFO " __FILE__
":" +
SimpleItoa(
line + 1) +
"] A message.\n"
99 "[libprotobuf WARNING " __FILE__
":" +
SimpleItoa(
line + 2) +
"] A warning.\n"
100 "[libprotobuf ERROR " __FILE__
":" +
SimpleItoa(
line + 3) +
"] An error.\n",
104 TEST(LoggingTest, NullLogging) {
118 TEST(LoggingTest, CaptureLogging) {
119 captured_messages_.clear();
123 int start_line = __LINE__;
131 "2 " __FILE__
":" +
SimpleItoa(start_line + 1) +
": An error.",
132 captured_messages_[0]);
134 "1 " __FILE__
":" +
SimpleItoa(start_line + 2) +
": A warning.",
135 captured_messages_[1]);
138 TEST(LoggingTest, SilenceLogging) {
139 captured_messages_.clear();
144 LogSilencer* silencer1 =
new LogSilencer;
146 LogSilencer* silencer2 =
new LogSilencer;
157 "0 " __FILE__
":" +
SimpleItoa(line1) +
": Visible1",
158 captured_messages_[0]);
160 "0 " __FILE__
":" +
SimpleItoa(line2) +
": Visible2",
161 captured_messages_[1]);
166 void SetA123Method() {
a_ = 123; }
169 void SetAMethod(
int a) {
a_ =
a; }
175 void SetABMethod(
int a,
const char*
b) {
a_ =
a;
b_ =
b; }
176 static void SetABFunction(
int a,
const char*
b) {
181 virtual void SetUp() {
189 void DeleteClosureInCallback() {
203 TEST_F(ClosureTest, TestClosureFunction0) {
210 TEST_F(ClosureTest, TestClosureMethod0) {
212 &ClosureTest::SetA123Method);
218 TEST_F(ClosureTest, TestClosureFunction1) {
225 TEST_F(ClosureTest, TestClosureMethod1) {
227 &ClosureTest::SetAMethod, 456);
233 TEST_F(ClosureTest, TestClosureFunction1String) {
240 TEST_F(ClosureTest, TestClosureMethod1String) {
248 TEST_F(ClosureTest, TestClosureFunction2) {
249 const char* cstr =
"hello";
258 TEST_F(ClosureTest, TestClosureMethod2) {
259 const char* cstr =
"hello";
261 &ClosureTest::SetABMethod, 789, cstr);
271 TEST_F(ClosureTest, TestPermanentClosureFunction0) {
282 TEST_F(ClosureTest, TestPermanentClosureMethod0) {
284 &ClosureTest::SetA123Method);
294 TEST_F(ClosureTest, TestPermanentClosureFunction1) {
305 TEST_F(ClosureTest, TestPermanentClosureMethod1) {
307 &ClosureTest::SetAMethod, 456);
317 TEST_F(ClosureTest, TestPermanentClosureFunction2) {
318 const char* cstr =
"hello";
333 TEST_F(ClosureTest, TestPermanentClosureMethod2) {
334 const char* cstr =
"hello";
336 &ClosureTest::SetABMethod, 789, cstr);
350 TEST_F(ClosureTest, TestPermanentClosureDeleteInCallback) {
352 &ClosureTest::DeleteClosureInCallback);