OLD | NEW |
1 // Copyright (c) 2010 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 "ppapi/tests/test_transport.h" | 5 #include "ppapi/tests/test_transport.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "ppapi/c/dev/ppb_testing_dev.h" | 11 #include "ppapi/c/dev/ppb_testing_dev.h" |
12 #include "ppapi/c/dev/ppb_transport_dev.h" | |
13 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
14 #include "ppapi/cpp/completion_callback.h" | 13 #include "ppapi/cpp/completion_callback.h" |
15 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
16 #include "ppapi/cpp/module.h" | 15 #include "ppapi/cpp/module.h" |
| 16 #include "ppapi/cpp/dev/transport_dev.h" |
17 #include "ppapi/tests/test_utils.h" | 17 #include "ppapi/tests/test_utils.h" |
18 #include "ppapi/tests/testing_instance.h" | 18 #include "ppapi/tests/testing_instance.h" |
19 | 19 |
20 REGISTER_TEST_CASE(Transport); | 20 REGISTER_TEST_CASE(Transport); |
21 | 21 |
22 bool TestTransport::Init() { | 22 bool TestTransport::Init() { |
23 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>( | 23 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>( |
24 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE)); | 24 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE)); |
25 return transport_interface_ && InitTestingInterface(); | 25 return transport_interface_ && InitTestingInterface(); |
26 } | 26 } |
27 | 27 |
28 void TestTransport::RunTest() { | 28 void TestTransport::RunTest() { |
29 RUN_TEST(FirstTransport); | 29 RUN_TEST(Basics); |
30 // TODO(juberti): more Transport tests here... | 30 // TODO(juberti): more Transport tests here... |
31 } | 31 } |
32 | 32 |
33 std::string TestTransport::TestFirstTransport() { | 33 std::string TestTransport::TestBasics() { |
34 // TODO(juberti): actual test | 34 pp::Transport_Dev transport1(instance_, "test", ""); |
| 35 pp::Transport_Dev transport2(instance_, "test", ""); |
| 36 |
| 37 TestCompletionCallback connect_cb1; |
| 38 TestCompletionCallback connect_cb2; |
| 39 ASSERT_EQ(transport1.Connect(connect_cb1), PP_ERROR_WOULDBLOCK); |
| 40 ASSERT_EQ(transport2.Connect(connect_cb2), PP_ERROR_WOULDBLOCK); |
| 41 |
| 42 PP_Var address1; |
| 43 PP_Var address2; |
| 44 TestCompletionCallback next_address_cb1; |
| 45 TestCompletionCallback next_address_cb2; |
| 46 ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1), |
| 47 PP_ERROR_WOULDBLOCK); |
| 48 ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2), |
| 49 PP_ERROR_WOULDBLOCK); |
| 50 ASSERT_EQ(next_address_cb1.WaitForResult(), 0); |
| 51 ASSERT_EQ(next_address_cb2.WaitForResult(), 0); |
| 52 ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1), PP_OK); |
| 53 ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2), PP_OK); |
| 54 |
| 55 ASSERT_EQ(transport1.ReceiveRemoteAddress(address2), 0); |
| 56 ASSERT_EQ(transport2.ReceiveRemoteAddress(address1), 0); |
| 57 |
| 58 ASSERT_EQ(connect_cb1.WaitForResult(), 0); |
| 59 ASSERT_EQ(connect_cb2.WaitForResult(), 0); |
| 60 |
| 61 ASSERT_TRUE(transport1.IsWritable()); |
| 62 ASSERT_TRUE(transport2.IsWritable()); |
| 63 |
| 64 // TODO(sergeyu): Verify that data can be sent/received. |
| 65 |
35 PASS(); | 66 PASS(); |
36 } | 67 } |
OLD | NEW |