OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/sync_socket.h" | 6 #include "base/sync_socket.h" |
7 #include "base/threading/simple_thread.h" | 7 #include "base/threading/simple_thread.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 DISALLOW_COPY_AND_ASSIGN(HangingReceiveThread); | 43 DISALLOW_COPY_AND_ASSIGN(HangingReceiveThread); |
44 }; | 44 }; |
45 | 45 |
46 // Tests sending data between two SyncSockets. Uses ASSERT() and thus will exit | 46 // Tests sending data between two SyncSockets. Uses ASSERT() and thus will exit |
47 // early upon failure. Callers should use ASSERT_NO_FATAL_FAILURE() if testing | 47 // early upon failure. Callers should use ASSERT_NO_FATAL_FAILURE() if testing |
48 // continues after return. | 48 // continues after return. |
49 void SendReceivePeek(base::SyncSocket* socket_a, base::SyncSocket* socket_b) { | 49 void SendReceivePeek(base::SyncSocket* socket_a, base::SyncSocket* socket_b) { |
50 int received = 0; | 50 int received = 0; |
51 const int kSending = 123; | 51 const int kSending = 123; |
52 COMPILE_ASSERT(sizeof(kSending) == sizeof(received), Invalid_Data_Size); | 52 static_assert(sizeof(kSending) == sizeof(received), "invalid data size"); |
53 | 53 |
54 ASSERT_EQ(0u, socket_a->Peek()); | 54 ASSERT_EQ(0u, socket_a->Peek()); |
55 ASSERT_EQ(0u, socket_b->Peek()); | 55 ASSERT_EQ(0u, socket_b->Peek()); |
56 | 56 |
57 // Verify |socket_a| can send to |socket_a| and |socket_a| can Receive from | 57 // Verify |socket_a| can send to |socket_a| and |socket_a| can Receive from |
58 // |socket_a|. | 58 // |socket_a|. |
59 ASSERT_EQ(sizeof(kSending), socket_a->Send(&kSending, sizeof(kSending))); | 59 ASSERT_EQ(sizeof(kSending), socket_a->Send(&kSending, sizeof(kSending))); |
60 ASSERT_EQ(sizeof(kSending), socket_b->Peek()); | 60 ASSERT_EQ(sizeof(kSending), socket_b->Peek()); |
61 ASSERT_EQ(sizeof(kSending), socket_b->Receive(&received, sizeof(kSending))); | 61 ASSERT_EQ(sizeof(kSending), socket_b->Receive(&received, sizeof(kSending))); |
62 ASSERT_EQ(kSending, received); | 62 ASSERT_EQ(kSending, received); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 ASSERT_TRUE(socket_b.Shutdown()); | 122 ASSERT_TRUE(socket_b.Shutdown()); |
123 thread.Stop(); | 123 thread.Stop(); |
124 | 124 |
125 // Ensure the receive didn't just timeout. | 125 // Ensure the receive didn't just timeout. |
126 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(), | 126 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(), |
127 kReceiveTimeoutInMilliseconds); | 127 kReceiveTimeoutInMilliseconds); |
128 | 128 |
129 ASSERT_TRUE(socket_a.Close()); | 129 ASSERT_TRUE(socket_a.Close()); |
130 ASSERT_TRUE(socket_b.Close()); | 130 ASSERT_TRUE(socket_b.Close()); |
131 } | 131 } |
OLD | NEW |