OLD | NEW |
1 // Copyright (c) 2011 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 <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include "ppapi/cpp/module.h" | 7 #include "ppapi/cpp/module.h" |
8 #include "ppapi/tests/test_udp_socket_private_shared.h" | 8 #include "ppapi/tests/test_udp_socket_private_shared.h" |
9 #include "ppapi/tests/test_utils.h" | 9 #include "ppapi/tests/test_utils.h" |
10 #include "ppapi/tests/testing_instance.h" | 10 #include "ppapi/tests/testing_instance.h" |
11 | 11 |
(...skipping 25 matching lines...) Expand all Loading... |
37 | 37 |
38 return tcp_socket_private_interface_ && | 38 return tcp_socket_private_interface_ && |
39 udp_socket_private_interface_ && | 39 udp_socket_private_interface_ && |
40 init_host_port && | 40 init_host_port && |
41 CheckTestingInterface(); | 41 CheckTestingInterface(); |
42 } | 42 } |
43 | 43 |
44 void TestUDPSocketPrivateShared::RunTests(const std::string& filter) { | 44 void TestUDPSocketPrivateShared::RunTests(const std::string& filter) { |
45 RUN_TEST(Create, filter); | 45 RUN_TEST(Create, filter); |
46 RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter); | 46 RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter); |
| 47 RUN_TEST_FORCEASYNC_AND_NOT(ConnectFailure, filter); |
47 } | 48 } |
48 | 49 |
49 void TestUDPSocketPrivateShared::QuitMessageLoop() { | 50 void TestUDPSocketPrivateShared::QuitMessageLoop() { |
50 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 51 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
51 } | 52 } |
52 | 53 |
53 std::string TestUDPSocketPrivateShared::GenerateNetAddress( | 54 std::string TestUDPSocketPrivateShared::GenerateNetAddress( |
54 PP_Resource* socket, PP_NetAddress_Private* address) { | 55 PP_Resource* socket, PP_NetAddress_Private* address) { |
55 *socket = tcp_socket_private_interface_->Create(instance_->pp_instance()); | 56 *socket = tcp_socket_private_interface_->Create(instance_->pp_instance()); |
56 if (0 == *socket) | 57 if (0 == *socket) |
(...skipping 11 matching lines...) Expand all Loading... |
68 return ReportError("PPB_TCPSocket_Private::Connect", rv); | 69 return ReportError("PPB_TCPSocket_Private::Connect", rv); |
69 | 70 |
70 rv = tcp_socket_private_interface_->GetLocalAddress(*socket, address); | 71 rv = tcp_socket_private_interface_->GetLocalAddress(*socket, address); |
71 if (rv != PP_TRUE) | 72 if (rv != PP_TRUE) |
72 return ReportError("PPB_TCPSocket_Private::GetLocalAddress", rv); | 73 return ReportError("PPB_TCPSocket_Private::GetLocalAddress", rv); |
73 | 74 |
74 PASS(); | 75 PASS(); |
75 } | 76 } |
76 | 77 |
77 std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket( | 78 std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket( |
78 const PP_NetAddress_Private *address, | 79 PP_NetAddress_Private *address, |
79 PP_Resource *socket) { | 80 PP_Resource *socket) { |
80 *socket = udp_socket_private_interface_->Create(instance_->pp_instance()); | 81 *socket = udp_socket_private_interface_->Create(instance_->pp_instance()); |
81 if (0 == *socket) | 82 if (0 == *socket) |
82 return "PPB_UDPSocket_Private::Create failed"; | 83 return "PPB_UDPSocket_Private::Create failed"; |
83 if (!udp_socket_private_interface_->IsUDPSocket(*socket)) | 84 if (!udp_socket_private_interface_->IsUDPSocket(*socket)) |
84 return "PPB_UDPSocket_Private::IsUDPSocket failed"; | 85 return "PPB_UDPSocket_Private::IsUDPSocket failed"; |
85 | 86 |
86 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 87 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
87 int32_t rv = udp_socket_private_interface_->Bind( | 88 int32_t rv = udp_socket_private_interface_->Bind( |
88 *socket, address, | 89 *socket, address, |
89 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); | 90 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
90 | 91 |
91 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 92 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
92 return ReportError("PPB_UDPSocket_Private::Bind force_async", rv); | 93 return ReportError("PPB_UDPSocket_Private::Bind force_async", rv); |
93 if (rv == PP_OK_COMPLETIONPENDING) | 94 if (rv == PP_OK_COMPLETIONPENDING) |
94 rv = callback.WaitForResult(); | 95 rv = callback.WaitForResult(); |
95 if (rv != PP_OK) | 96 if (rv != PP_OK) |
96 return ReportError("PPB_UDPSocket_Private::Bind", rv); | 97 return ReportError("PPB_UDPSocket_Private::Bind", rv); |
97 | 98 |
| 99 if (!udp_socket_private_interface_->GetBoundAddress(*socket, address)) |
| 100 return "PPB_UDPSocket_Private::GetBoundAddress: Failed"; |
| 101 |
98 PASS(); | 102 PASS(); |
99 } | 103 } |
100 | 104 |
| 105 std::string TestUDPSocketPrivateShared::BindUDPSocketFailure( |
| 106 PP_NetAddress_Private *address, |
| 107 PP_Resource *socket) { |
| 108 *socket = udp_socket_private_interface_->Create(instance_->pp_instance()); |
| 109 if (0 == *socket) |
| 110 return "PPB_UDPSocket_Private::Create failed"; |
| 111 if (!udp_socket_private_interface_->IsUDPSocket(*socket)) |
| 112 return "PPB_UDPSocket_Private::IsUDPSocket failed"; |
| 113 |
| 114 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 115 int32_t rv = udp_socket_private_interface_->Bind( |
| 116 *socket, address, |
| 117 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
| 118 |
| 119 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 120 return ReportError("PPB_UDPSocket_Private::Bind force_async", rv); |
| 121 if (rv == PP_OK_COMPLETIONPENDING) |
| 122 rv = callback.WaitForResult(); |
| 123 if (rv == PP_OK) |
| 124 return ReportError("PPB_UDPSocket_Private::Bind", rv); |
| 125 |
| 126 if (udp_socket_private_interface_->GetBoundAddress(*socket, address)) |
| 127 return "PPB_UDPSocket_Private::GetBoundAddress: Failed"; |
| 128 |
| 129 PASS(); |
| 130 } |
| 131 |
101 std::string TestUDPSocketPrivateShared::TestCreate() { | 132 std::string TestUDPSocketPrivateShared::TestCreate() { |
102 PP_Resource udp_socket; | 133 PP_Resource udp_socket; |
103 std::string error_message; | 134 std::string error_message; |
104 | 135 |
105 udp_socket = udp_socket_private_interface_->Create(0); | 136 udp_socket = udp_socket_private_interface_->Create(0); |
106 if (0 != udp_socket) | 137 if (0 != udp_socket) |
107 return "PPB_UDPSocket_Private::Create returns valid socket " \ | 138 return "PPB_UDPSocket_Private::Create returns valid socket " \ |
108 "for invalid instance"; | 139 "for invalid instance"; |
109 | 140 |
110 udp_socket = udp_socket_private_interface_->Create(instance_->pp_instance()); | 141 udp_socket = udp_socket_private_interface_->Create(instance_->pp_instance()); |
111 if (0 == udp_socket) | 142 if (0 == udp_socket) |
112 return "PPB_UDPSocket_Private::Create failed"; | 143 return "PPB_UDPSocket_Private::Create failed"; |
113 if (!udp_socket_private_interface_->IsUDPSocket(udp_socket)) | 144 if (!udp_socket_private_interface_->IsUDPSocket(udp_socket)) |
114 return "PPB_UDPSocket_Private::IsUDPSocket failed"; | 145 return "PPB_UDPSocket_Private::IsUDPSocket failed"; |
115 | 146 |
116 PASS(); | 147 PASS(); |
117 } | 148 } |
118 | 149 |
119 std::string TestUDPSocketPrivateShared::TestConnect() { | 150 std::string TestUDPSocketPrivateShared::TestConnect() { |
120 PP_NetAddress_Private server_address, client_address; | 151 PP_NetAddress_Private server_address, client_address; |
121 PP_Resource tcp_socket_server, tcp_socket_client; | 152 PP_Resource tcp_socket_server, tcp_socket_client; |
122 std::string error_message; | 153 std::string error_message; |
123 | 154 |
124 error_message = GenerateNetAddress(&tcp_socket_server, &server_address); | 155 error_message = GenerateNetAddress(&tcp_socket_server, &server_address); |
125 if (!error_message.empty()) | 156 if (!error_message.empty()) |
126 return error_message; | 157 return error_message; |
127 error_message = GenerateNetAddress(&tcp_socket_client, &client_address); | 158 error_message = GenerateNetAddress(&tcp_socket_client, &client_address); |
128 if (error_message.empty()) | 159 if (!error_message.empty()) |
129 return error_message; | 160 return error_message; |
130 | 161 |
131 PP_Resource socket_server, socket_client; | 162 PP_Resource socket_server, socket_client; |
132 error_message = CreateAndBindUDPSocket(&server_address, &socket_server); | 163 error_message = CreateAndBindUDPSocket(&server_address, &socket_server); |
133 if (error_message.empty()) | 164 if (!error_message.empty()) |
134 return error_message; | 165 return error_message; |
135 error_message = CreateAndBindUDPSocket(&client_address, &socket_client); | 166 error_message = CreateAndBindUDPSocket(&client_address, &socket_client); |
136 if (error_message.empty()) | 167 if (!error_message.empty()) |
137 return error_message; | 168 return error_message; |
138 | 169 |
139 static const char* const kMessage = | 170 static const char* const kMessage = |
140 "Simple message that will be sent via UDP"; | 171 "Simple message that will be sent via UDP"; |
141 static const size_t kMessageBufferSize = 1024; | 172 static const size_t kMessageBufferSize = 1024; |
142 char message_buffer[kMessageBufferSize]; | 173 char message_buffer[kMessageBufferSize]; |
143 | 174 |
144 TestCompletionCallback write_cb(instance_->pp_instance(), force_async_); | 175 TestCompletionCallback write_cb(instance_->pp_instance(), force_async_); |
145 int32_t write_rv = udp_socket_private_interface_->SendTo( | 176 int32_t write_rv = udp_socket_private_interface_->SendTo( |
146 socket_client, | 177 socket_client, |
(...skipping 24 matching lines...) Expand all Loading... |
171 return ReportError("PPB_UDPSocket_Private::SendTo", write_rv); | 202 return ReportError("PPB_UDPSocket_Private::SendTo", write_rv); |
172 | 203 |
173 ASSERT_EQ(0, strncmp(kMessage, message_buffer, strlen(kMessage))); | 204 ASSERT_EQ(0, strncmp(kMessage, message_buffer, strlen(kMessage))); |
174 | 205 |
175 udp_socket_private_interface_->Close(socket_server); | 206 udp_socket_private_interface_->Close(socket_server); |
176 udp_socket_private_interface_->Close(socket_client); | 207 udp_socket_private_interface_->Close(socket_client); |
177 | 208 |
178 tcp_socket_private_interface_->Disconnect(tcp_socket_server); | 209 tcp_socket_private_interface_->Disconnect(tcp_socket_server); |
179 tcp_socket_private_interface_->Disconnect(tcp_socket_client); | 210 tcp_socket_private_interface_->Disconnect(tcp_socket_client); |
180 | 211 |
| 212 if (udp_socket_private_interface_->GetBoundAddress( |
| 213 socket_server, &server_address)) |
| 214 return "PPB_UDPSocket_Private::GetBoundAddress: expected Failure"; |
| 215 |
181 PASS(); | 216 PASS(); |
182 } | 217 } |
| 218 |
| 219 std::string TestUDPSocketPrivateShared::TestConnectFailure() { |
| 220 std::string error_message; |
| 221 PP_NetAddress_Private invalid_address = { 0 }; |
| 222 PP_Resource socket; |
| 223 |
| 224 error_message = BindUDPSocketFailure(&invalid_address, &socket); |
| 225 if (!error_message.empty()) |
| 226 return error_message; |
| 227 |
| 228 PASS(); |
| 229 } |
OLD | NEW |