OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // Now send a well formed message to make sure the receiver wasn't | 338 // Now send a well formed message to make sure the receiver wasn't |
339 // thrown out of sync by the extra argument. | 339 // thrown out of sync by the extra argument. |
340 msg = new MsgClassIS(3, L"expect three"); | 340 msg = new MsgClassIS(3, L"expect three"); |
341 sender()->Send(msg); | 341 sender()->Send(msg); |
342 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); | 342 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); |
343 | 343 |
344 EXPECT_TRUE(WaitForClientShutdown()); | 344 EXPECT_TRUE(WaitForClientShutdown()); |
345 DestroyChannel(); | 345 DestroyChannel(); |
346 } | 346 } |
347 | 347 |
348 // This class is for testing the IPC_BEGIN_MESSAGE_MAP_EX macros. | |
349 class ServerMacroExTest { | |
350 public: | |
351 ServerMacroExTest() : unhandled_msgs_(0) { | |
352 } | |
353 | |
354 virtual ~ServerMacroExTest() { | |
355 } | |
356 | |
357 virtual bool OnMessageReceived(const IPC::Message& msg) { | |
358 bool msg_is_ok = false; | |
359 IPC_BEGIN_MESSAGE_MAP_EX(ServerMacroExTest, msg, msg_is_ok) | |
360 IPC_MESSAGE_HANDLER(MsgClassIS, OnMsgClassISMessage) | |
361 IPC_MESSAGE_HANDLER(MsgClassSI, OnMsgClassSIMessage) | |
362 IPC_MESSAGE_UNHANDLED(++unhandled_msgs_) | |
363 IPC_END_MESSAGE_MAP_EX() | |
364 return msg_is_ok; | |
365 } | |
366 | |
367 int unhandled_msgs() const { | |
368 return unhandled_msgs_; | |
369 } | |
370 | |
371 private: | |
372 void OnMsgClassISMessage(int value, const std::wstring& text) { | |
373 } | |
374 void OnMsgClassSIMessage(const std::wstring& text, int value) { | |
375 } | |
376 | |
377 int unhandled_msgs_; | |
378 | |
379 DISALLOW_COPY_AND_ASSIGN(ServerMacroExTest); | |
380 }; | |
381 | |
382 TEST_F(IPCFuzzingTest, MsgMapExMacro) { | |
383 IPC::Message* msg = NULL; | |
384 ServerMacroExTest server; | |
385 | |
386 // Test the regular messages. | |
387 msg = new MsgClassIS(3, L"text3"); | |
388 EXPECT_TRUE(server.OnMessageReceived(*msg)); | |
389 delete msg; | |
390 msg = new MsgClassSI(L"text2", 2); | |
391 EXPECT_TRUE(server.OnMessageReceived(*msg)); | |
392 delete msg; | |
393 | |
394 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | |
395 // Test a bad message. | |
396 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, | |
397 IPC::Message::PRIORITY_NORMAL); | |
398 msg->WriteInt(2); | |
399 EXPECT_FALSE(server.OnMessageReceived(*msg)); | |
400 delete msg; | |
401 | |
402 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, | |
403 IPC::Message::PRIORITY_NORMAL); | |
404 msg->WriteInt(0x64); | |
405 msg->WriteInt(0x32); | |
406 EXPECT_FALSE(server.OnMessageReceived(*msg)); | |
407 delete msg; | |
408 | |
409 EXPECT_EQ(0, server.unhandled_msgs()); | |
410 #endif | |
411 } | |
412 | |
413 } // namespace | 348 } // namespace |
OLD | NEW |