summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_transport.cc
blob: 72ead1b969ea5a0d530c25a061983979ebdb57d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/tests/test_transport.h"

#include <string.h>

#include <string>

#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/dev/transport_dev.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"

REGISTER_TEST_CASE(Transport);

bool TestTransport::Init() {
  transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>(
      pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE));
  return transport_interface_ && InitTestingInterface();
}

void TestTransport::RunTest() {
  RUN_TEST(Basics);
  // TODO(juberti): more Transport tests here...
}

std::string TestTransport::TestBasics() {
  pp::Transport_Dev transport1(instance_, "test", "");
  pp::Transport_Dev transport2(instance_, "test", "");

  TestCompletionCallback connect_cb1(instance_->pp_instance());
  TestCompletionCallback connect_cb2(instance_->pp_instance());
  ASSERT_EQ(transport1.Connect(connect_cb1), PP_ERROR_WOULDBLOCK);
  ASSERT_EQ(transport2.Connect(connect_cb2), PP_ERROR_WOULDBLOCK);

  pp::Var address1;
  pp::Var address2;
  TestCompletionCallback next_address_cb1(instance_->pp_instance());
  TestCompletionCallback next_address_cb2(instance_->pp_instance());
  ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1),
            PP_ERROR_WOULDBLOCK);
  ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2),
            PP_ERROR_WOULDBLOCK);
  ASSERT_EQ(next_address_cb1.WaitForResult(), 0);
  ASSERT_EQ(next_address_cb2.WaitForResult(), 0);
  ASSERT_EQ(transport1.GetNextAddress(&address1, next_address_cb1), PP_OK);
  ASSERT_EQ(transport2.GetNextAddress(&address2, next_address_cb2), PP_OK);

  ASSERT_EQ(transport1.ReceiveRemoteAddress(address2), 0);
  ASSERT_EQ(transport2.ReceiveRemoteAddress(address1), 0);

  ASSERT_EQ(connect_cb1.WaitForResult(), 0);
  ASSERT_EQ(connect_cb2.WaitForResult(), 0);

  ASSERT_TRUE(transport1.IsWritable());
  ASSERT_TRUE(transport2.IsWritable());

  // TODO(sergeyu): Verify that data can be sent/received.

  PASS();
}