OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 return ReportError("PPB_TCPSocket_Private::Connect", rv); | 68 return ReportError("PPB_TCPSocket_Private::Connect", rv); |
69 | 69 |
70 rv = tcp_socket_private_interface_->GetLocalAddress(*socket, address); | 70 rv = tcp_socket_private_interface_->GetLocalAddress(*socket, address); |
71 if (rv != PP_TRUE) | 71 if (rv != PP_TRUE) |
72 return ReportError("PPB_TCPSocket_Private::GetLocalAddress", rv); | 72 return ReportError("PPB_TCPSocket_Private::GetLocalAddress", rv); |
73 | 73 |
74 PASS(); | 74 PASS(); |
75 } | 75 } |
76 | 76 |
77 std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket( | 77 std::string TestUDPSocketPrivateShared::CreateAndBindUDPSocket( |
78 const PP_NetAddress_Private *address, | 78 PP_NetAddress_Private *address, |
79 PP_Resource *socket) { | 79 PP_Resource *socket) { |
80 *socket = udp_socket_private_interface_->Create(instance_->pp_instance()); | 80 *socket = udp_socket_private_interface_->Create(instance_->pp_instance()); |
81 if (0 == *socket) | 81 if (0 == *socket) |
82 return "PPB_UDPSocket_Private::Create failed"; | 82 return "PPB_UDPSocket_Private::Create failed"; |
83 if (!udp_socket_private_interface_->IsUDPSocket(*socket)) | 83 if (!udp_socket_private_interface_->IsUDPSocket(*socket)) |
84 return "PPB_UDPSocket_Private::IsUDPSocket failed"; | 84 return "PPB_UDPSocket_Private::IsUDPSocket failed"; |
85 | 85 |
86 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 86 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
87 int32_t rv = udp_socket_private_interface_->Bind( | 87 int32_t rv = udp_socket_private_interface_->Bind( |
88 *socket, address, | 88 *socket, address, |
89 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); | 89 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
90 | 90 |
91 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | 91 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
92 return ReportError("PPB_UDPSocket_Private::Bind force_async", rv); | 92 return ReportError("PPB_UDPSocket_Private::Bind force_async", rv); |
93 if (rv == PP_OK_COMPLETIONPENDING) | 93 if (rv == PP_OK_COMPLETIONPENDING) |
94 rv = callback.WaitForResult(); | 94 rv = callback.WaitForResult(); |
95 if (rv != PP_OK) | 95 if (rv != PP_OK) |
96 return ReportError("PPB_UDPSocket_Private::Bind", rv); | 96 return ReportError("PPB_UDPSocket_Private::Bind", rv); |
97 | 97 |
98 if (!udp_socket_private_interface_->GetBoundAddress(*socket, address)) | |
viettrungluu
2012/02/07 23:03:58
Please add tests that GetBoundAddress correctly *f
mtilburg1
2012/02/08 15:27:01
Done.
| |
99 return "PPB_UDPSocket_Private::GetBoundAddress: Failed"; | |
100 | |
98 PASS(); | 101 PASS(); |
99 } | 102 } |
100 | 103 |
101 std::string TestUDPSocketPrivateShared::TestCreate() { | 104 std::string TestUDPSocketPrivateShared::TestCreate() { |
102 PP_Resource udp_socket; | 105 PP_Resource udp_socket; |
103 std::string error_message; | 106 std::string error_message; |
104 | 107 |
105 udp_socket = udp_socket_private_interface_->Create(0); | 108 udp_socket = udp_socket_private_interface_->Create(0); |
106 if (0 != udp_socket) | 109 if (0 != udp_socket) |
107 return "PPB_UDPSocket_Private::Create returns valid socket " \ | 110 return "PPB_UDPSocket_Private::Create returns valid socket " \ |
(...skipping 10 matching lines...) Expand all Loading... | |
118 | 121 |
119 std::string TestUDPSocketPrivateShared::TestConnect() { | 122 std::string TestUDPSocketPrivateShared::TestConnect() { |
120 PP_NetAddress_Private server_address, client_address; | 123 PP_NetAddress_Private server_address, client_address; |
121 PP_Resource tcp_socket_server, tcp_socket_client; | 124 PP_Resource tcp_socket_server, tcp_socket_client; |
122 std::string error_message; | 125 std::string error_message; |
123 | 126 |
124 error_message = GenerateNetAddress(&tcp_socket_server, &server_address); | 127 error_message = GenerateNetAddress(&tcp_socket_server, &server_address); |
125 if (!error_message.empty()) | 128 if (!error_message.empty()) |
126 return error_message; | 129 return error_message; |
127 error_message = GenerateNetAddress(&tcp_socket_client, &client_address); | 130 error_message = GenerateNetAddress(&tcp_socket_client, &client_address); |
128 if (error_message.empty()) | 131 if (!error_message.empty()) |
129 return error_message; | 132 return error_message; |
130 | 133 |
131 PP_Resource socket_server, socket_client; | 134 PP_Resource socket_server, socket_client; |
132 error_message = CreateAndBindUDPSocket(&server_address, &socket_server); | 135 error_message = CreateAndBindUDPSocket(&server_address, &socket_server); |
133 if (error_message.empty()) | 136 if (!error_message.empty()) |
134 return error_message; | 137 return error_message; |
135 error_message = CreateAndBindUDPSocket(&client_address, &socket_client); | 138 error_message = CreateAndBindUDPSocket(&client_address, &socket_client); |
136 if (error_message.empty()) | 139 if (!error_message.empty()) |
137 return error_message; | 140 return error_message; |
138 | 141 |
139 static const char* const kMessage = | 142 static const char* const kMessage = |
140 "Simple message that will be sent via UDP"; | 143 "Simple message that will be sent via UDP"; |
141 static const size_t kMessageBufferSize = 1024; | 144 static const size_t kMessageBufferSize = 1024; |
142 char message_buffer[kMessageBufferSize]; | 145 char message_buffer[kMessageBufferSize]; |
143 | 146 |
144 TestCompletionCallback write_cb(instance_->pp_instance(), force_async_); | 147 TestCompletionCallback write_cb(instance_->pp_instance(), force_async_); |
145 int32_t write_rv = udp_socket_private_interface_->SendTo( | 148 int32_t write_rv = udp_socket_private_interface_->SendTo( |
146 socket_client, | 149 socket_client, |
(...skipping 26 matching lines...) Expand all Loading... | |
173 ASSERT_EQ(0, strncmp(kMessage, message_buffer, strlen(kMessage))); | 176 ASSERT_EQ(0, strncmp(kMessage, message_buffer, strlen(kMessage))); |
174 | 177 |
175 udp_socket_private_interface_->Close(socket_server); | 178 udp_socket_private_interface_->Close(socket_server); |
176 udp_socket_private_interface_->Close(socket_client); | 179 udp_socket_private_interface_->Close(socket_client); |
177 | 180 |
178 tcp_socket_private_interface_->Disconnect(tcp_socket_server); | 181 tcp_socket_private_interface_->Disconnect(tcp_socket_server); |
179 tcp_socket_private_interface_->Disconnect(tcp_socket_client); | 182 tcp_socket_private_interface_->Disconnect(tcp_socket_client); |
180 | 183 |
181 PASS(); | 184 PASS(); |
182 } | 185 } |
OLD | NEW |