diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-11 20:56:22 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-11 20:56:22 +0000 |
commit | 2a3aa7b56211437d70787ebe9da514d288957d5f (patch) | |
tree | ec5e0b87cf79507a409b81064c59d7a3ef2f74ba | |
parent | 307f7bdd33cf295aac89b436982d40d8ba63fc6a (diff) | |
download | chromium_src-2a3aa7b56211437d70787ebe9da514d288957d5f.zip chromium_src-2a3aa7b56211437d70787ebe9da514d288957d5f.tar.gz chromium_src-2a3aa7b56211437d70787ebe9da514d288957d5f.tar.bz2 |
Move IPC tests into anonymous namespaces.
This reduces chances of (very confusing) name collisions between different
tests.
Review URL: https://codereview.chromium.org/11865015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176430 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ipc/ipc_channel_posix_unittest.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_channel_unittest.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_fuzzing_tests.cc | 8 | ||||
-rw-r--r-- | ipc/ipc_message_unittest.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_message_utils_unittest.cc | 6 | ||||
-rw-r--r-- | ipc/ipc_perftests.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_send_fds_test.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_sync_channel_unittest.cc | 113 | ||||
-rw-r--r-- | ipc/ipc_sync_message_unittest.cc | 4 | ||||
-rw-r--r-- | ipc/sync_socket_unittest.cc | 8 |
10 files changed, 54 insertions, 105 deletions
diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc index 0484f07..56549f1 100644 --- a/ipc/ipc_channel_posix_unittest.cc +++ b/ipc/ipc_channel_posix_unittest.cc @@ -92,8 +92,6 @@ class IPCChannelPosixTestListener : public IPC::Listener { bool quit_only_on_message_; }; -} // namespace - class IPCChannelPosixTest : public base::MultiProcessTest { public: static void SetUpSocket(IPC::ChannelHandle *handle, @@ -425,3 +423,5 @@ MULTIPROCESS_TEST_MAIN(IPCChannelPosixFailConnectionProc) { } return 0; } + +} // namespace diff --git a/ipc/ipc_channel_unittest.cc b/ipc/ipc_channel_unittest.cc index 6b63ae0..bb7403f 100644 --- a/ipc/ipc_channel_unittest.cc +++ b/ipc/ipc_channel_unittest.cc @@ -34,6 +34,8 @@ #include "ipc/ipc_test_base.h" #include "testing/multiprocess_func_list.h" +namespace { + const size_t kLongMessageStringNumBytes = 50000; class IPCChannelTest : public IPCTestBase { @@ -334,3 +336,5 @@ MULTIPROCESS_IPC_TEST_MAIN(RunTestClient) { MessageLoop::current()->Run(); return 0; } + +} // namespace diff --git a/ipc/ipc_fuzzing_tests.cc b/ipc/ipc_fuzzing_tests.cc index 82ac37f..f501449 100644 --- a/ipc/ipc_fuzzing_tests.cc +++ b/ipc/ipc_fuzzing_tests.cc @@ -16,7 +16,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/multiprocess_func_list.h" -// IPC messages for testing --------------------------------------------------- +// IPC messages for testing ---------------------------------------------------- #define IPC_MESSAGE_IMPL #include "ipc/ipc_message_macros.h" @@ -35,7 +35,9 @@ IPC_MESSAGE_CONTROL2(MsgDoMutex, std::wstring, int) // Used to generate an ID for a message that should not exist. IPC_MESSAGE_CONTROL0(MsgUnhandled) -// ---------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- + +namespace { TEST(IPCMessageIntegrity, ReadBeyondBufferStr) { //This was BUG 984408. @@ -418,3 +420,5 @@ TEST_F(IPCFuzzingTest, MsgMapExMacro) { EXPECT_EQ(0, server.unhandled_msgs()); #endif } + +} // namespace diff --git a/ipc/ipc_message_unittest.cc b/ipc/ipc_message_unittest.cc index 2f50ee3..4c0d514f 100644 --- a/ipc/ipc_message_unittest.cc +++ b/ipc/ipc_message_unittest.cc @@ -11,6 +11,8 @@ #include "ipc/ipc_message_utils.h" #include "testing/gtest/include/gtest/gtest.h" +namespace { + TEST(IPCMessageTest, ListValue) { ListValue input; input.Set(0, Value::CreateDoubleValue(42.42)); @@ -67,3 +69,5 @@ TEST(IPCMessageTest, DictionaryValue) { iter = PickleIterator(bad_msg); EXPECT_FALSE(IPC::ReadParam(&bad_msg, &iter, &output)); } + +} // namespace diff --git a/ipc/ipc_message_utils_unittest.cc b/ipc/ipc_message_utils_unittest.cc index fe2c4e3..2a49b9a 100644 --- a/ipc/ipc_message_utils_unittest.cc +++ b/ipc/ipc_message_utils_unittest.cc @@ -7,7 +7,9 @@ #include "ipc/ipc_message_utils.h" #include "testing/gtest/include/gtest/gtest.h" -namespace IPC { +using namespace IPC; + +namespace { // Tests nesting of messages as parameters to other messages. TEST(IPCMessageUtilsTest, NestedMessages) { @@ -66,4 +68,4 @@ TEST(IPCMessageUtilsTest, ParameterValidation) { ASSERT_FALSE(ParamTraits<FilePath>::Read(&message, &iter, &badPath)); } -} // namespace IPC +} // namespace diff --git a/ipc/ipc_perftests.cc b/ipc/ipc_perftests.cc index b290c16..5b563d1 100644 --- a/ipc/ipc_perftests.cc +++ b/ipc/ipc_perftests.cc @@ -34,6 +34,8 @@ #include "ipc/ipc_switches.h" #include "testing/multiprocess_func_list.h" +namespace { + // This test times the roundtrip IPC message cycle. It is enabled with a // special preprocessor define to enable it instead of the standard IPC // unit tests. This works around some funny termination conditions in the @@ -203,3 +205,5 @@ MULTIPROCESS_IPC_TEST_MAIN(RunReflector) { MessageLoop::current()->Run(); return 0; } + +} // namespace diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc index 06a4660..68b22326 100644 --- a/ipc/ipc_send_fds_test.cc +++ b/ipc/ipc_send_fds_test.cc @@ -129,8 +129,6 @@ int TestDescriptorClient(ino_t expected_inode_num) { return 0; } -} // namespace - class IPCSendFdsTest : public IPCTestBase { }; @@ -203,4 +201,6 @@ TEST_F(IPCSendFdsTest, DescriptorTest) { TestDescriptorServer(chan, process_handle); } +} // namespace + #endif // defined(OS_POSIX) diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc index a4e9bd8..b1d2401 100644 --- a/ipc/ipc_sync_channel_unittest.cc +++ b/ipc/ipc_sync_channel_unittest.cc @@ -27,8 +27,7 @@ #include "testing/gtest/include/gtest/gtest.h" using base::WaitableEvent; - -namespace IPC { +using namespace IPC; namespace { @@ -266,16 +265,12 @@ void RunTest(std::vector<Worker*> workers) { } } -} // namespace - class IPCSyncChannelTest : public testing::Test { private: MessageLoop message_loop_; }; -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class SimpleServer : public Worker { public: @@ -307,17 +302,13 @@ void Simple(bool pump_during_send) { RunTest(workers); } -} // namespace - // Tests basic synchronous call TEST_F(IPCSyncChannelTest, Simple) { Simple(false); Simple(true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ // Worker classes which override how the sync channel is created to use the // two-step initialization (calling the lightweight constructor and then @@ -371,8 +362,6 @@ void TwoStep(bool create_server_pipe_now, bool create_client_pipe_now) { RunTest(workers); } -} // namespace - // Tests basic two-step initialization, where you call the lightweight // constructor then Init. TEST_F(IPCSyncChannelTest, TwoStepInitialization) { @@ -382,10 +371,7 @@ TEST_F(IPCSyncChannelTest, TwoStepInitialization) { TwoStep(true, true); } - -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class DelayClient : public Worker { public: @@ -405,17 +391,13 @@ void DelayReply(bool pump_during_send) { RunTest(workers); } -} // namespace - // Tests that asynchronous replies work TEST_F(IPCSyncChannelTest, DelayReply) { DelayReply(false); DelayReply(true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class NoHangServer : public Worker { public: @@ -462,17 +444,13 @@ void NoHang(bool pump_during_send) { RunTest(workers); } -} // namespace - // Tests that caller doesn't hang if receiver dies TEST_F(IPCSyncChannelTest, NoHang) { NoHang(false); NoHang(true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class UnblockServer : public Worker { public: @@ -528,8 +506,6 @@ void Unblock(bool server_pump, bool client_pump, bool delete_during_send) { RunTest(workers); } -} // namespace - // Tests that the caller unblocks to answer a sync message from the receiver. TEST_F(IPCSyncChannelTest, Unblock) { Unblock(false, false, false); @@ -538,7 +514,7 @@ TEST_F(IPCSyncChannelTest, Unblock) { Unblock(true, true, false); } -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // Tests that the the SyncChannel object can be deleted during a Send. TEST_F(IPCSyncChannelTest, ChannelDeleteDuringSend) { @@ -548,9 +524,7 @@ TEST_F(IPCSyncChannelTest, ChannelDeleteDuringSend) { Unblock(true, true, true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class RecursiveServer : public Worker { public: @@ -610,8 +584,6 @@ void Recursive( RunTest(workers); } -} // namespace - // Tests a server calling Send while another Send is pending. TEST_F(IPCSyncChannelTest, Recursive) { Recursive(false, false, false); @@ -624,9 +596,7 @@ TEST_F(IPCSyncChannelTest, Recursive) { Recursive(true, true, true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ void RecursiveNoHang( bool server_pump_first, bool server_pump_second, bool client_pump) { @@ -637,8 +607,6 @@ void RecursiveNoHang( RunTest(workers); } -} // namespace - // Tests that if a caller makes a sync call during an existing sync call and // the receiver dies, neither of the Send() calls hang. TEST_F(IPCSyncChannelTest, RecursiveNoHang) { @@ -652,9 +620,7 @@ TEST_F(IPCSyncChannelTest, RecursiveNoHang) { RecursiveNoHang(true, true, true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class MultipleServer1 : public Worker { public: @@ -755,8 +721,6 @@ void Multiple(bool server_pump, bool client_pump) { RunTest(workers); } -} // namespace - // Tests that multiple SyncObjects on the same listener thread can unblock each // other. TEST_F(IPCSyncChannelTest, Multiple) { @@ -766,9 +730,7 @@ TEST_F(IPCSyncChannelTest, Multiple) { Multiple(true, true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ // This class provides server side functionality to test the case where // multiple sync channels are in use on the same thread on the client and @@ -867,8 +829,6 @@ void QueuedReply(bool client_pump) { RunTest(workers); } -} // namespace - // While a blocking send is in progress, the listener thread might answer other // synchronous messages. This tests that if during the response to another // message the reply to the original messages comes, it is queued up correctly @@ -880,9 +840,7 @@ TEST_F(IPCSyncChannelTest, QueuedReply) { QueuedReply(true); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class ChattyClient : public Worker { public: @@ -909,8 +867,6 @@ void ChattyServer(bool pump_during_send) { RunTest(workers); } -} // namespace - // Tests http://b/1093251 - that sending lots of sync messages while // the receiver is waiting for a sync reply does not overflow the PostMessage // queue. @@ -921,8 +877,6 @@ TEST_F(IPCSyncChannelTest, ChattyServer) { //------------------------------------------------------------------------------ -namespace { - class TimeoutServer : public Worker { public: TimeoutServer(int timeout_ms, @@ -1009,8 +963,6 @@ void SendWithTimeoutMixedOKAndTimeout(bool pump_during_send) { RunTest(workers); } -} // namespace - // Tests that SendWithTimeout does not time-out if the response comes back fast // enough. TEST_F(IPCSyncChannelTest, SendWithTimeoutOK) { @@ -1033,8 +985,6 @@ TEST_F(IPCSyncChannelTest, DISABLED_SendWithTimeoutMixedOKAndTimeout) { //------------------------------------------------------------------------------ -namespace { - void NestedCallback(Worker* server) { // Sleep a bit so that we wake up after the reply has been received. base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(250)); @@ -1069,8 +1019,6 @@ class DoneEventRaceServer : public Worker { } }; -} // namespace - // Tests http://b/1474092 - that if after the done_event is set but before // OnObjectSignaled is called another message is sent out, then after its // reply comes back OnObjectSignaled will be called for the first message. @@ -1081,9 +1029,7 @@ TEST_F(IPCSyncChannelTest, DoneEventRace) { RunTest(workers); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class TestSyncMessageFilter : public SyncMessageFilter { public: @@ -1173,8 +1119,6 @@ class ServerSendAfterClose : public Worker { bool send_result_; }; -} // namespace - // Tests basic synchronous call TEST_F(IPCSyncChannelTest, SyncMessageFilter) { std::vector<Worker*> workers; @@ -1199,9 +1143,7 @@ TEST_F(IPCSyncChannelTest, SendAfterClose) { server.Shutdown(); } -//----------------------------------------------------------------------------- - -namespace { +//------------------------------------------------------------------------------ class RestrictedDispatchServer : public Worker { public: @@ -1376,8 +1318,6 @@ class RestrictedDispatchClient : public Worker { scoped_ptr<SyncChannel> non_restricted_channel_; }; -} // namespace - TEST_F(IPCSyncChannelTest, RestrictedDispatch) { WaitableEvent sent_ping_event(false, false); WaitableEvent wait_event(false, false); @@ -1396,7 +1336,7 @@ TEST_F(IPCSyncChannelTest, RestrictedDispatch) { EXPECT_EQ(4, success); } -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // This test case inspired by crbug.com/108491 // We create two servers that use the same ListenerThread but have @@ -1425,8 +1365,6 @@ TEST_F(IPCSyncChannelTest, RestrictedDispatch) { // event 2: indicate to server1 that client2 listener is in OnDoClient2Task // event 3: indicate to client2 that server listener is in OnDoServerTask -namespace { - class RestrictedDispatchDeadlockServer : public Worker { public: RestrictedDispatchDeadlockServer(int server_num, @@ -1606,8 +1544,6 @@ class RestrictedDispatchDeadlockClient1 : public Worker { bool done_issued_; }; -} // namespace - TEST_F(IPCSyncChannelTest, RestrictedDispatchDeadlock) { std::vector<Worker*> workers; @@ -1650,14 +1586,13 @@ TEST_F(IPCSyncChannelTest, RestrictedDispatchDeadlock) { RunTest(workers); } -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // This test case inspired by crbug.com/120530 // We create 4 workers that pipe to each other W1->W2->W3->W4->W1 then we send a // message that recurses through 3, 4 or 5 steps to make sure, say, W1 can // re-enter when called from W4 while it's sending a message to W2. // The first worker drives the whole test so it must be treated specially. -namespace { class RestrictedDispatchPipeWorker : public Worker { public: @@ -1737,8 +1672,6 @@ class RestrictedDispatchPipeWorker : public Worker { int* success_; }; -} // namespace - TEST_F(IPCSyncChannelTest, RestrictedDispatch4WayDeadlock) { int success = 0; std::vector<Worker*> workers; @@ -1758,9 +1691,8 @@ TEST_F(IPCSyncChannelTest, RestrictedDispatch4WayDeadlock) { EXPECT_EQ(3, success); } +//------------------------------------------------------------------------------ -//----------------------------------------------------------------------------- -// // This test case inspired by crbug.com/122443 // We want to make sure a reply message with the unblock flag set correctly // behaves as a reply, not a regular message. @@ -1769,8 +1701,6 @@ TEST_F(IPCSyncChannelTest, RestrictedDispatch4WayDeadlock) { // it will send another message to Server2. While sending that second message it // will receive a reply from Server1 with the unblock flag. -namespace { - class ReentrantReplyServer1 : public Worker { public: ReentrantReplyServer1(WaitableEvent* server_ready) @@ -1861,8 +1791,6 @@ class ReentrantReplyClient : public Worker { WaitableEvent* server_ready_; }; -} // namespace - TEST_F(IPCSyncChannelTest, ReentrantReply) { std::vector<Worker*> workers; WaitableEvent server_ready(false, false); @@ -1872,10 +1800,9 @@ TEST_F(IPCSyncChannelTest, ReentrantReply) { RunTest(workers); } -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------------ // Generate a validated channel ID using Channel::GenerateVerifiedChannelID(). -namespace { class VerifiedServer : public Worker { public: @@ -1957,12 +1884,10 @@ void Verified() { #endif } -} // namespace - // Windows needs to send an out-of-band secret to verify the client end of the // channel. Test that we still connect correctly in that case. TEST_F(IPCSyncChannelTest, Verified) { Verified(); } -} // namespace IPC +} // namespace diff --git a/ipc/ipc_sync_message_unittest.cc b/ipc/ipc_sync_message_unittest.cc index 7b513f7..d170b7f 100644 --- a/ipc/ipc_sync_message_unittest.cc +++ b/ipc/ipc_sync_message_unittest.cc @@ -17,6 +17,8 @@ #define IPC_MESSAGE_IMPL #include "ipc/ipc_sync_message_unittest.h" +namespace { + static IPC::Message* g_reply; class TestMessageReceiver { @@ -301,3 +303,5 @@ TEST(IPCSyncMessageTest, Main) { DCHECK_EQ(33, int1); DCHECK(!bool1); } + +} // namespace diff --git a/ipc/sync_socket_unittest.cc b/ipc/sync_socket_unittest.cc index a5cfc6b..b1e91c8 100644 --- a/ipc/sync_socket_unittest.cc +++ b/ipc/sync_socket_unittest.cc @@ -22,7 +22,7 @@ #include "base/file_descriptor_posix.h" #endif -// IPC messages for testing --------------------------------------------------- +// IPC messages for testing ---------------------------------------------------- #define IPC_MESSAGE_IMPL #include "ipc/ipc_message_macros.h" @@ -44,12 +44,12 @@ IPC_MESSAGE_CONTROL1(MsgClassResponse, std::string) // Message class to tell the server to shut down. IPC_MESSAGE_CONTROL0(MsgClassShutdown) -// ---------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- namespace { + const char kHelloString[] = "Hello, SyncSocket Client"; const size_t kHelloStringLength = arraysize(kHelloString); -} // namespace // The SyncSocket server listener class processes two sorts of // messages from the client. @@ -308,3 +308,5 @@ TEST_F(SyncSocketTest, NonBlockingWriteTest) { // Should be able to write more data to the buffer now. EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); } + +} // namespace |