webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
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>
56 
57 namespace google {
58 namespace protobuf {
59 namespace util {
60 namespace converter {
61 
62 using testing::IsEmpty;
63 using testing::NanSensitiveDoubleEq;
64 using testing::NanSensitiveFloatEq;
65 using testing::Return;
66 using testing::StrEq;
67 using testing::TypedEq;
68 
70  public:
72 
87 };
88 
90  public:
91  explicit ExpectingObjectWriter(MockObjectWriter* mock) : mock_(mock) {}
92 
94  (name.empty()
95  ? EXPECT_CALL(*mock_, StartObject(IsEmpty()))
96  : EXPECT_CALL(*mock_, StartObject(StrEq(name.ToString()))))
97  .WillOnce(Return(mock_))
98  .RetiresOnSaturation();
99  return this;
100  }
101 
102  virtual ObjectWriter* EndObject() {
103  EXPECT_CALL(*mock_, EndObject())
104  .WillOnce(Return(mock_))
105  .RetiresOnSaturation();
106  return this;
107  }
108 
110  (name.empty()
111  ? EXPECT_CALL(*mock_, StartList(IsEmpty()))
112  : EXPECT_CALL(*mock_, StartList(StrEq(name.ToString()))))
113  .WillOnce(Return(mock_))
114  .RetiresOnSaturation();
115  return this;
116  }
117 
118  virtual ObjectWriter* EndList() {
119  EXPECT_CALL(*mock_, EndList())
120  .WillOnce(Return(mock_))
121  .RetiresOnSaturation();
122  return this;
123  }
124 
126  (name.empty()
127  ? EXPECT_CALL(*mock_, RenderBool(IsEmpty(), TypedEq<bool>(value)))
128  : EXPECT_CALL(*mock_, RenderBool(StrEq(name.ToString()),
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)))
138  : EXPECT_CALL(*mock_, RenderInt32(StrEq(name.ToString()),
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)))
148  : EXPECT_CALL(*mock_, RenderUint32(StrEq(name.ToString()),
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)))
158  : EXPECT_CALL(*mock_, RenderInt64(StrEq(name.ToString()),
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)))
168  : EXPECT_CALL(*mock_, RenderUint64(StrEq(name.ToString()),
169  TypedEq<uint64>(value))))
170  .WillOnce(Return(mock_))
171  .RetiresOnSaturation();
172  return this;
173  }
174 
176  (name.empty()
177  ? EXPECT_CALL(*mock_, RenderDouble(IsEmpty(),
178  NanSensitiveDoubleEq(value)))
179  : EXPECT_CALL(*mock_, RenderDouble(StrEq(name.ToString()),
180  NanSensitiveDoubleEq(value))))
181  .WillOnce(Return(mock_))
182  .RetiresOnSaturation();
183  return this;
184  }
185 
187  (name.empty()
188  ? EXPECT_CALL(*mock_, RenderFloat(IsEmpty(),
189  NanSensitiveFloatEq(value)))
190  : EXPECT_CALL(*mock_, RenderFloat(StrEq(name.ToString()),
191  NanSensitiveFloatEq(value))))
192  .WillOnce(Return(mock_))
193  .RetiresOnSaturation();
194  return this;
195  }
196 
198  (name.empty()
199  ? EXPECT_CALL(*mock_, RenderString(IsEmpty(),
200  TypedEq<StringPiece>(value.ToString())))
201  : EXPECT_CALL(*mock_, RenderString(StrEq(name.ToString()),
202  TypedEq<StringPiece>(value.ToString()))))
203  .WillOnce(Return(mock_))
204  .RetiresOnSaturation();
205  return this;
206  }
208  (name.empty()
209  ? EXPECT_CALL(*mock_, RenderBytes(IsEmpty(), TypedEq<StringPiece>(
210  value.ToString())))
211  : EXPECT_CALL(*mock_,
212  RenderBytes(StrEq(name.ToString()),
213  TypedEq<StringPiece>(value.ToString()))))
214  .WillOnce(Return(mock_))
215  .RetiresOnSaturation();
216  return this;
217  }
218 
220  (name.empty() ? EXPECT_CALL(*mock_, RenderNull(IsEmpty()))
221  : EXPECT_CALL(*mock_, RenderNull(StrEq(name.ToString())))
222  .WillOnce(Return(mock_))
223  .RetiresOnSaturation());
224  return this;
225  }
226 
227  private:
228  MockObjectWriter* mock_;
229 
231 };
232 
233 } // namespace converter
234 } // namespace util
235 } // namespace protobuf
236 
237 } // namespace google
238 #endif // GOOGLE_PROTOBUF_UTIL_CONVERTER_EXPECTING_OBJECTWRITER_H__
virtual ObjectWriter * RenderInt32(StringPiece name, int32 value)
Definition: expecting_objectwriter.h:135
virtual ObjectWriter * RenderString(StringPiece name, StringPiece value)
Definition: expecting_objectwriter.h:197
virtual ObjectWriter * RenderUint32(StringPiece name, uint32 value)=0
virtual ObjectWriter * RenderUint64(StringPiece name, uint64 value)=0
Definition: util.py:1
Definition: expecting_objectwriter.h:69
virtual ObjectWriter * RenderUint32(StringPiece name, uint32 value)
Definition: expecting_objectwriter.h:145
virtual ObjectWriter * RenderBool(StringPiece name, bool value)=0
virtual ObjectWriter * RenderUint64(StringPiece name, uint64 value)
Definition: expecting_objectwriter.h:165
bool empty() const
Definition: stringpiece.h:256
virtual ObjectWriter * RenderInt32(StringPiece name, int32 value)=0
string ToString() const
Definition: stringpiece.h:319
virtual ObjectWriter * RenderBool(StringPiece name, bool value)
Definition: expecting_objectwriter.h:125
virtual ObjectWriter * RenderFloat(StringPiece name, float value)
Definition: expecting_objectwriter.h:186
virtual ObjectWriter * RenderFloat(StringPiece name, float value)=0
int32_t int32
Definition: port.h:130
Definition: stringpiece.h:178
#define GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition: macros.h:45
MOCK_METHOD2(RenderBool, ObjectWriter *(StringPiece, bool))
virtual ObjectWriter * RenderDouble(StringPiece name, double value)
Definition: expecting_objectwriter.h:175
virtual ObjectWriter * RenderInt64(StringPiece name, int64 value)=0
EGLAttrib * value
Definition: eglext.h:120
Definition: expecting_objectwriter.h:89
virtual ObjectWriter * StartObject(StringPiece name)
Definition: expecting_objectwriter.h:93
virtual ObjectWriter * RenderNull(StringPiece name)
Definition: expecting_objectwriter.h:219
virtual ObjectWriter * StartObject(StringPiece name)=0
uint32_t uint32
Definition: port.h:135
EGLImageKHR EGLint * name
Definition: eglext.h:851
Definition: __init__.py:1
uint64_t uint64
Definition: port.h:136
virtual ObjectWriter * RenderBytes(StringPiece name, StringPiece value)
Definition: expecting_objectwriter.h:207
virtual ObjectWriter * RenderBytes(StringPiece name, StringPiece value)=0
virtual ObjectWriter * RenderString(StringPiece name, StringPiece value)=0
int64_t int64
Definition: port.h:131
virtual ObjectWriter * EndObject()
Definition: expecting_objectwriter.h:102
virtual ObjectWriter * EndList()
Definition: expecting_objectwriter.h:118
Definition: gflags_completions.h:115
virtual ObjectWriter * StartList(StringPiece name)=0
virtual ObjectWriter * RenderNull(StringPiece name)=0
virtual ObjectWriter * StartList(StringPiece name)
Definition: expecting_objectwriter.h:109
virtual ObjectWriter * RenderDouble(StringPiece name, double value)=0
ExpectingObjectWriter(MockObjectWriter *mock)
Definition: expecting_objectwriter.h:91
MOCK_METHOD1(StartObject, ObjectWriter *(StringPiece))
MockObjectWriter()
Definition: expecting_objectwriter.h:71
virtual ObjectWriter * RenderInt64(StringPiece name, int64 value)
Definition: expecting_objectwriter.h:155