Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: ipc/ipc_fuzzing_tests.cc

Issue 2821028: Up the warnings in ipc (take 2)... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 #include <string> 6 #include <string>
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/platform_thread.h" 10 #include "base/platform_thread.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassIS::ID, value); 178 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassIS::ID, value);
179 Cleanup(); 179 Cleanup();
180 } 180 }
181 181
182 void OnMsgClassSIMessage(const std::wstring& text, int value) { 182 void OnMsgClassSIMessage(const std::wstring& text, int value) {
183 UseData(MsgClassSI::ID, value, text); 183 UseData(MsgClassSI::ID, value, text);
184 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassSI::ID, value); 184 RoundtripAckReply(FUZZER_ROUTING_ID, MsgClassSI::ID, value);
185 Cleanup(); 185 Cleanup();
186 } 186 }
187 187
188 bool RoundtripAckReply(int routing, int type_id, int reply) { 188 bool RoundtripAckReply(int routing, uint32 type_id, int reply) {
189 IPC::Message* message = new IPC::Message(routing, type_id, 189 IPC::Message* message = new IPC::Message(routing, type_id,
190 IPC::Message::PRIORITY_NORMAL); 190 IPC::Message::PRIORITY_NORMAL);
191 message->WriteInt(reply + 1); 191 message->WriteInt(reply + 1);
192 message->WriteInt(reply); 192 message->WriteInt(reply);
193 return other_->Send(message); 193 return other_->Send(message);
194 } 194 }
195 195
196 void Cleanup() { 196 void Cleanup() {
197 --message_count_; 197 --message_count_;
198 --pending_messages_; 198 --pending_messages_;
199 if (0 == message_count_) 199 if (0 == message_count_)
200 MessageLoop::current()->Quit(); 200 MessageLoop::current()->Quit();
201 } 201 }
202 202
203 void ReplyMsgNotHandled(int type_id) { 203 void ReplyMsgNotHandled(uint32 type_id) {
204 RoundtripAckReply(FUZZER_ROUTING_ID, CLIENT_UNHANDLED_IPC, type_id); 204 RoundtripAckReply(FUZZER_ROUTING_ID, CLIENT_UNHANDLED_IPC, type_id);
205 Cleanup(); 205 Cleanup();
206 } 206 }
207 207
208 void UseData(int caller, int value, const std::wstring& text) { 208 void UseData(int caller, int value, const std::wstring& text) {
209 std::wostringstream wos; 209 std::wostringstream wos;
210 wos << L"IPC fuzzer:" << caller << " [" << value << L" " << text << L"]\n"; 210 wos << L"IPC fuzzer:" << caller << " [" << value << L" " << text << L"]\n";
211 std::wstring output = wos.str(); 211 std::wstring output = wos.str();
212 LOG(WARNING) << output.c_str(); 212 LOG(WARNING) << output.c_str();
213 }; 213 };
214 214
215 int message_count_; 215 int message_count_;
216 int pending_messages_; 216 int pending_messages_;
217 }; 217 };
218 218
219 class FuzzerClientListener : public SimpleListener { 219 class FuzzerClientListener : public SimpleListener {
220 public: 220 public:
221 FuzzerClientListener() : last_msg_(NULL) { 221 FuzzerClientListener() : last_msg_(NULL) {
222 } 222 }
223 223
224 virtual void OnMessageReceived(const IPC::Message& msg) { 224 virtual void OnMessageReceived(const IPC::Message& msg) {
225 last_msg_ = new IPC::Message(msg); 225 last_msg_ = new IPC::Message(msg);
226 MessageLoop::current()->Quit(); 226 MessageLoop::current()->Quit();
227 } 227 }
228 228
229 bool ExpectMessage(int value, int type_id) { 229 bool ExpectMessage(int value, uint32 type_id) {
230 if (!MsgHandlerInternal(type_id)) 230 if (!MsgHandlerInternal(type_id))
231 return false; 231 return false;
232 int msg_value1 = 0; 232 int msg_value1 = 0;
233 int msg_value2 = 0; 233 int msg_value2 = 0;
234 void* iter = NULL; 234 void* iter = NULL;
235 if (!last_msg_->ReadInt(&iter, &msg_value1)) 235 if (!last_msg_->ReadInt(&iter, &msg_value1))
236 return false; 236 return false;
237 if (!last_msg_->ReadInt(&iter, &msg_value2)) 237 if (!last_msg_->ReadInt(&iter, &msg_value2))
238 return false; 238 return false;
239 if ((msg_value2 + 1) != msg_value1) 239 if ((msg_value2 + 1) != msg_value1)
240 return false; 240 return false;
241 if (msg_value2 != value) 241 if (msg_value2 != value)
242 return false; 242 return false;
243 243
244 delete last_msg_; 244 delete last_msg_;
245 last_msg_ = NULL; 245 last_msg_ = NULL;
246 return true; 246 return true;
247 } 247 }
248 248
249 bool ExpectMsgNotHandled(int type_id) { 249 bool ExpectMsgNotHandled(uint32 type_id) {
250 return ExpectMessage(type_id, CLIENT_UNHANDLED_IPC); 250 return ExpectMessage(type_id, CLIENT_UNHANDLED_IPC);
251 } 251 }
252 252
253 private: 253 private:
254 bool MsgHandlerInternal(int type_id) { 254 bool MsgHandlerInternal(uint32 type_id) {
255 MessageLoop::current()->Run(); 255 MessageLoop::current()->Run();
256 if (NULL == last_msg_) 256 if (NULL == last_msg_)
257 return false; 257 return false;
258 if (FUZZER_ROUTING_ID != last_msg_->routing_id()) 258 if (FUZZER_ROUTING_ID != last_msg_->routing_id())
259 return false; 259 return false;
260 return (type_id == last_msg_->type()); 260 return (type_id == last_msg_->type());
261 }; 261 };
262 262
263 IPC::Message* last_msg_; 263 IPC::Message* last_msg_;
264 }; 264 };
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, 420 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID,
421 IPC::Message::PRIORITY_NORMAL); 421 IPC::Message::PRIORITY_NORMAL);
422 msg->WriteInt(0x64); 422 msg->WriteInt(0x64);
423 msg->WriteInt(0x32); 423 msg->WriteInt(0x32);
424 EXPECT_FALSE(server.OnMessageReceived(*msg)); 424 EXPECT_FALSE(server.OnMessageReceived(*msg));
425 delete msg; 425 delete msg;
426 426
427 EXPECT_EQ(0, server.unhandled_msgs()); 427 EXPECT_EQ(0, server.unhandled_msgs());
428 #endif 428 #endif
429 } 429 }
OLDNEW
« no previous file with comments | « ipc/ipc_channel_posix.cc ('k') | ipc/ipc_logging.cc » ('j') | ipc/ipc_logging.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698