expecting_objectwriter.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_UTIL_CONVERTER_EXPECTING_OBJECTWRITER_H__
32 #define GOOGLE_PROTOBUF_UTIL_CONVERTER_EXPECTING_OBJECTWRITER_H__
33 
34 // An implementation of ObjectWriter that automatically sets the
35 // gmock expectations for the response to a method. Every method
36 // returns the object itself for chaining.
37 //
38 // Usage:
39 // // Setup
40 // MockObjectWriter mock;
41 // ExpectingObjectWriter ow(&mock);
42 //
43 // // Set expectation
44 // ow.StartObject("")
45 // ->RenderString("key", "value")
46 // ->EndObject();
47 //
48 // // Actual testing
49 // mock.StartObject(StringPiece())
50 // ->RenderString("key", "value")
51 // ->EndObject();
52 
55 #include <gmock/gmock.h>
57 
58 namespace google {
59 namespace protobuf {
60 namespace util {
61 namespace converter {
62 
63 using testing::IsEmpty;
64 using testing::NanSensitiveDoubleEq;
65 using testing::NanSensitiveFloatEq;
66 using testing::Return;
67 using testing::StrEq;
68 using testing::TypedEq;
69 
71  public:
73 
89 };
90 
92  public:
93  explicit ExpectingObjectWriter(MockObjectWriter* mock) : mock_(mock) {}
94 
96  (name.empty() ? EXPECT_CALL(*mock_, StartObject(IsEmpty()))
98  .WillOnce(Return(mock_))
99  .RetiresOnSaturation();
100  return this;
101  }
102 
103  virtual ObjectWriter* EndObject() {
105  .WillOnce(Return(mock_))
106  .RetiresOnSaturation();
107  return this;
108  }
109 
111  (name.empty() ? EXPECT_CALL(*mock_, StartList(IsEmpty()))
113  .WillOnce(Return(mock_))
114  .RetiresOnSaturation();
115  return this;
116  }
117 
118  virtual ObjectWriter* EndList() {
120  .WillOnce(Return(mock_))
121  .RetiresOnSaturation();
122  return this;
123  }
124 
126  (name.empty()
127  ? EXPECT_CALL(*mock_, RenderBool(IsEmpty(), TypedEq<bool>(value)))
129  TypedEq<bool>(value))))
130  .WillOnce(Return(mock_))
131  .RetiresOnSaturation();
132  return this;
133  }
134 
136  (name.empty()
137  ? EXPECT_CALL(*mock_, RenderInt32(IsEmpty(), TypedEq<int32>(value)))
139  TypedEq<int32>(value))))
140  .WillOnce(Return(mock_))
141  .RetiresOnSaturation();
142  return this;
143  }
144 
146  (name.empty()
147  ? EXPECT_CALL(*mock_, RenderUint32(IsEmpty(), TypedEq<uint32>(value)))
149  TypedEq<uint32>(value))))
150  .WillOnce(Return(mock_))
151  .RetiresOnSaturation();
152  return this;
153  }
154 
156  (name.empty()
157  ? EXPECT_CALL(*mock_, RenderInt64(IsEmpty(), TypedEq<int64>(value)))
159  TypedEq<int64>(value))))
160  .WillOnce(Return(mock_))
161  .RetiresOnSaturation();
162  return this;
163  }
164 
166  (name.empty()
167  ? EXPECT_CALL(*mock_, RenderUint64(IsEmpty(), TypedEq<uint64>(value)))
169  TypedEq<uint64>(value))))
170  .WillOnce(Return(mock_))
171  .RetiresOnSaturation();
172  return this;
173  }
174 
176  (name.empty()
177  ? EXPECT_CALL(*mock_,
178  RenderDouble(IsEmpty(), NanSensitiveDoubleEq(value)))
180  NanSensitiveDoubleEq(value))))
181  .WillOnce(Return(mock_))
182  .RetiresOnSaturation();
183  return this;
184  }
185 
187  (name.empty()
188  ? EXPECT_CALL(*mock_,
189  RenderFloat(IsEmpty(), NanSensitiveFloatEq(value)))
191  NanSensitiveFloatEq(value))))
192  .WillOnce(Return(mock_))
193  .RetiresOnSaturation();
194  return this;
195  }
196 
198  StringPiece value) {
199  (name.empty() ? EXPECT_CALL(*mock_, RenderString(IsEmpty(),
200  TypedEq<StringPiece>(
201  std::string(value))))
203  TypedEq<StringPiece>(
204  std::string(value)))))
205  .WillOnce(Return(mock_))
206  .RetiresOnSaturation();
207  return this;
208  }
210  (name.empty()
211  ? EXPECT_CALL(*mock_, RenderBytes(IsEmpty(), TypedEq<StringPiece>(
212  value.ToString())))
213  : EXPECT_CALL(*mock_,
214  RenderBytes(StrEq(name.ToString()),
215  TypedEq<StringPiece>(value.ToString()))))
216  .WillOnce(Return(mock_))
217  .RetiresOnSaturation();
218  return this;
219  }
220 
222  (name.empty() ? EXPECT_CALL(*mock_, RenderNull(IsEmpty()))
224  .WillOnce(Return(mock_))
225  .RetiresOnSaturation());
226  return this;
227  }
228 
229  private:
231 
233 };
234 
235 } // namespace converter
236 } // namespace util
237 } // namespace protobuf
238 } // namespace google
239 
240 #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_EXPECTING_OBJECTWRITER_H__
google::protobuf::util::converter::ExpectingObjectWriter::ExpectingObjectWriter
ExpectingObjectWriter(MockObjectWriter *mock)
Definition: expecting_objectwriter.h:93
name
GLuint const GLchar * name
Definition: glcorearb.h:3055
google::protobuf::util::converter::ExpectingObjectWriter::mock_
MockObjectWriter * mock_
Definition: expecting_objectwriter.h:230
google::protobuf::util::converter::ObjectWriter::StartList
virtual ObjectWriter * StartList(StringPiece name)=0
google::protobuf::int64
int64_t int64
Definition: protobuf/src/google/protobuf/stubs/port.h:151
google::protobuf::util::converter::ExpectingObjectWriter::RenderNull
virtual ObjectWriter * RenderNull(StringPiece name)
Definition: expecting_objectwriter.h:221
google::protobuf::util::converter::ObjectWriter::RenderUint64
virtual ObjectWriter * RenderUint64(StringPiece name, uint64 value)=0
google::protobuf::uint32
uint32_t uint32
Definition: protobuf/src/google/protobuf/stubs/port.h:155
google::protobuf::util::converter::ObjectWriter
Definition: object_writer.h:60
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::util::converter::ExpectingObjectWriter
Definition: expecting_objectwriter.h:91
gmock.h
google::protobuf::util::converter::MockObjectWriter
Definition: expecting_objectwriter.h:70
google::protobuf::util::converter::ObjectWriter::RenderDouble
virtual ObjectWriter * RenderDouble(StringPiece name, double value)=0
google::protobuf::util::converter::MockObjectWriter::MOCK_METHOD1
MOCK_METHOD1(StartObject, ObjectWriter *(StringPiece))
google::protobuf::util::converter::ExpectingObjectWriter::RenderBytes
virtual ObjectWriter * RenderBytes(StringPiece name, StringPiece value)
Definition: expecting_objectwriter.h:209
google::protobuf::util::converter::ExpectingObjectWriter::RenderInt64
virtual ObjectWriter * RenderInt64(StringPiece name, int64 value)
Definition: expecting_objectwriter.h:155
google::protobuf::util::converter::ObjectWriter::RenderBool
virtual ObjectWriter * RenderBool(StringPiece name, bool value)=0
google::protobuf::util::converter::ExpectingObjectWriter::RenderFloat
virtual ObjectWriter * RenderFloat(StringPiece name, float value)
Definition: expecting_objectwriter.h:186
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
google::protobuf::util::converter::ObjectWriter::RenderInt32
virtual ObjectWriter * RenderInt32(StringPiece name, int32 value)=0
google::protobuf::util::converter::MockObjectWriter::MOCK_METHOD2
MOCK_METHOD2(RenderBool, ObjectWriter *(StringPiece, bool))
strutil.h
google::protobuf::util::converter::ObjectWriter::StartObject
virtual ObjectWriter * StartObject(StringPiece name)=0
google::protobuf::util::converter::ExpectingObjectWriter::GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS
GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ExpectingObjectWriter)
google::protobuf::StringPiece
Definition: stringpiece.h:180
google::protobuf::util::converter::ExpectingObjectWriter::RenderDouble
virtual ObjectWriter * RenderDouble(StringPiece name, double value)
Definition: expecting_objectwriter.h:175
google::protobuf::util::converter::MockObjectWriter::MockObjectWriter
MockObjectWriter()
Definition: expecting_objectwriter.h:72
google::protobuf::util::converter::ObjectWriter::EndList
virtual ObjectWriter * EndList()=0
google::protobuf::uint64
uint64_t uint64
Definition: protobuf/src/google/protobuf/stubs/port.h:156
google::protobuf::util::converter::ExpectingObjectWriter::StartList
virtual ObjectWriter * StartList(StringPiece name)
Definition: expecting_objectwriter.h:110
google::protobuf::util::converter::ObjectWriter::RenderBytes
virtual ObjectWriter * RenderBytes(StringPiece name, StringPiece value)=0
google::protobuf::util::converter::ExpectingObjectWriter::RenderBool
virtual ObjectWriter * RenderBool(StringPiece name, bool value)
Definition: expecting_objectwriter.h:125
google::protobuf::util::converter::ExpectingObjectWriter::StartObject
virtual ObjectWriter * StartObject(StringPiece name)
Definition: expecting_objectwriter.h:95
google::protobuf::util::converter::ObjectWriter::RenderNull
virtual ObjectWriter * RenderNull(StringPiece name)=0
google::protobuf::util::converter::ObjectWriter::RenderString
virtual ObjectWriter * RenderString(StringPiece name, StringPiece value)=0
common.h
google::protobuf::util::converter::ExpectingObjectWriter::EndObject
virtual ObjectWriter * EndObject()
Definition: expecting_objectwriter.h:103
object_writer.h
google::protobuf::util::converter::ExpectingObjectWriter::RenderUint64
virtual ObjectWriter * RenderUint64(StringPiece name, uint64 value)
Definition: expecting_objectwriter.h:165
EXPECT_CALL
#define EXPECT_CALL(obj, call)
google::protobuf::util::converter::ExpectingObjectWriter::EndList
virtual ObjectWriter * EndList()
Definition: expecting_objectwriter.h:118
google::protobuf::util::converter::ExpectingObjectWriter::RenderString
virtual ObjectWriter * RenderString(StringPiece name, StringPiece value)
Definition: expecting_objectwriter.h:197
google::protobuf::util::converter::ExpectingObjectWriter::RenderInt32
virtual ObjectWriter * RenderInt32(StringPiece name, int32 value)
Definition: expecting_objectwriter.h:135
google::protobuf::util::converter::ObjectWriter::RenderUint32
virtual ObjectWriter * RenderUint32(StringPiece name, uint32 value)=0
testing::Return
internal::ReturnAction< R > Return(R value)
Definition: gmock-actions.h:1041
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
google
Definition: data_proto2_to_proto3_util.h:11
google::protobuf::util::converter::ExpectingObjectWriter::RenderUint32
virtual ObjectWriter * RenderUint32(StringPiece name, uint32 value)
Definition: expecting_objectwriter.h:145
google::protobuf::util::converter::MockObjectWriter::MOCK_METHOD0
MOCK_METHOD0(EndObject, ObjectWriter *())
google::protobuf::util::converter::ObjectWriter::RenderFloat
virtual ObjectWriter * RenderFloat(StringPiece name, float value)=0
google::protobuf::util::converter::ObjectWriter::EndObject
virtual ObjectWriter * EndObject()=0
google::protobuf::util::converter::ObjectWriter::RenderInt64
virtual ObjectWriter * RenderInt64(StringPiece name, int64 value)=0


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:51