File: test_tcp_socket.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (107 lines) | stat: -rw-r--r-- 3,964 bytes parent folder | download | duplicates (7)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_TESTS_TEST_TCP_SOCKET_H_
#define PPAPI_TESTS_TEST_TCP_SOCKET_H_

#include <stddef.h>

#include <string>

#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/ppb_tcp_socket.h"
#include "ppapi/cpp/net_address.h"
#include "ppapi/tests/test_case.h"

namespace pp {
class TCPSocket;
}

class TestTCPSocket: public TestCase {
 public:
  explicit TestTCPSocket(TestingInstance* instance);

  // TestCase implementation.
  virtual bool Init();
  virtual void RunTests(const std::string& filter);

 private:
  std::string TestConnect();
  std::string TestReadWrite();
  std::string TestSetOption();
  std::string TestListen();
  std::string TestBacklog();
  std::string TestInterface_1_0();
  std::string TestUnexpectedCalls();

  // The higher level test fixture is responsible for making socket methods
  // behave in the expected manner.  The *Fails tests expect the specified even
  // to fail with PP_ERROR_FAILED, and the *Hangs test expect the specified
  // operation to never complete, at least until teardown starts.
  std::string TestConnectFails();
  std::string TestConnectHangs();
  std::string TestWriteFails();
  std::string TestReadFails();
  std::string TestSetSendBufferSizeFails();
  std::string TestSetReceiveBufferSizeFails();
  std::string TestSetNoDelayFails();
  // When a bind call fails, normally the socket is reuseable.
  std::string TestBindFailsConnectSucceeds();
  // This is needed in addition to the above test in the case where a bind
  // failure is simulated in a way that also closes the NetworkContext pipe.
  std::string TestBindFails();
  std::string TestBindHangs();
  std::string TestListenFails();
  std::string TestListenHangs();
  std::string TestAcceptFails();
  std::string TestAcceptHangs();
  std::string TestAcceptedSocketWriteFails();
  std::string TestAcceptedSocketReadFails();
  std::string TestBindConnectFails();
  std::string TestBindConnectHangs();

  std::string ReadFirstLineFromSocket(pp::TCPSocket* socket, std::string* s);
  std::string ReadFirstLineFromSocket_1_0(PP_Resource socket,
                                          std::string* s);
  // Expects to read exactly |num_bytes| from the socket. Stops once exactly
  // |num_bytes| have been read.
  std::string ReadFromSocket(pp::TCPSocket* socket,
                             char* buffer,
                             size_t num_bytes);
  // Reads from |socket| until a read error occurs, and sets |read_data| and
  // |error| accordingly. Only fails if a Read() call returns more data than the
  // buffer that was passed in to it.
  std::string ReadFromSocketUntilError(pp::TCPSocket* socket,
                                       std::string* read_data,
                                       int* error);
  std::string WriteToSocket(pp::TCPSocket* socket, const std::string& s);
  std::string WriteToSocket_1_0(PP_Resource socket, const std::string& s);

  // Sets |address| to an address usable for Bind(). Returned address uses the
  // IP address used to talk to |test_server_addr_| and a port of 0, so Bind()
  // calls to it should succeed.
  std::string GetAddressToBind(pp::NetAddress* address);

  std::string StartListen(pp::TCPSocket* socket, int32_t backlog);

  enum Command {
    kBind = 0x1,
    kListen = 0x2,
    kAccept = 0x4,
    kConnect = 0x8,
    kReadWrite = 0x10,
    kAllCommands = -1,
  };
  // Runs |commands|, consisting of one or more Command values on |socket|,
  // expecting all of them to fail with PP_ERROR_FAILED. Useful for testing
  // invalid state transitions.
  std::string RunCommandsExpendingFailures(pp::TCPSocket* socket, int commands);

  // Address of the EmbeddedTestServer set up by the browser test fixture.
  pp::NetAddress test_server_addr_;

  const PPB_TCPSocket_1_0* socket_interface_1_0_;
};

#endif  // PPAPI_TESTS_TEST_TCP_SOCKET_H_