Ocean
TestTCPClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_TEST_TESTNETWORK_TEST_TCP_CLIENT_H
9 #define META_OCEAN_TEST_TESTNETWORK_TEST_TCP_CLIENT_H
10 
12 
14 
15 namespace Ocean
16 {
17 
18 namespace Test
19 {
20 
21 namespace TestNetwork
22 {
23 
24 /**
25  * This class implements test for TCPClient.
26  * @ingroup testnetwork
27  */
28 class OCEAN_TEST_NETWORK_EXPORT TestTCPClient
29 {
30  protected:
31 
32  /**
33  * Definition of a vector holding bytes.
34  */
35  typedef std::vector<uint8_t> Buffer;
36 
37  /**
38  * This class implements a receiver.
39  */
40  class Receiver
41  {
42  public:
43 
44  /**
45  * Event function for connection requests.
46  * @param senderAddress The address of the sender
47  * @param senderPort The port of the sender
48  * @param connectionId The id of the connection
49  */
50  bool onConnectionRequest(const Network::Address4& senderAddress, const Network::Port& senderPort, const Network::TCPServer::ConnectionId connectionId);
51 
52  /**
53  * Event function for a disconnected connection.
54  * @param connectionId The id of the disconnected connection
55  */
57 
58  /**
59  * Event function for receiving data.
60  * @param connectionId The id of the connection from which the data has been received
61  * @param data The data that has been received
62  * @param size The number of bytes
63  */
64  void onReceive(const Network::TCPServer::ConnectionId connectionId, const void* data, const size_t size);
65 
66  public:
67 
68  /// The number of connection requests.
69  unsigned int numberConnectionRequests_ = 0u;
70 
71  /// The number of disconnections.
72  unsigned int numberDisconnections_ = 0u;
73 
74  /// The memory buffers.
75  std::vector<Buffer> buffers_;
76  };
77 
78  public:
79 
80  /**
81  * Tests all TCPClient functions.
82  * @param testDuration The number of seconds for each test, with range (0, infinity)
83  * @return True, if succeeded
84  */
85  static bool test(const double testDuration);
86 
87  /**
88  * Tests sending and receiving data.
89  * @param testDuration The number of seconds for each test, with range (0, infinity)
90  * @return True, if succeeded
91  */
92  static bool testSendReceive(const double testDuration);
93 };
94 
95 }
96 
97 }
98 
99 }
100 
101 #endif // META_OCEAN_TEST_TESTNETWORK_TEST_TCP_CLIENT_H
This class wraps an address number with 32 bits.
Definition: Address4.h:26
unsigned int ConnectionId
Definition of a connection id.
Definition: ConnectionOrientedServer.h:34
This class wraps a port number with 16 bits.
Definition: Port.h:26
This class implements a receiver.
Definition: TestTCPClient.h:41
void onReceive(const Network::TCPServer::ConnectionId connectionId, const void *data, const size_t size)
Event function for receiving data.
void onConnectionDisconnected(const Network::TCPServer::ConnectionId connectionId)
Event function for a disconnected connection.
std::vector< Buffer > buffers_
The memory buffers.
Definition: TestTCPClient.h:75
bool onConnectionRequest(const Network::Address4 &senderAddress, const Network::Port &senderPort, const Network::TCPServer::ConnectionId connectionId)
Event function for connection requests.
This class implements test for TCPClient.
Definition: TestTCPClient.h:29
std::vector< uint8_t > Buffer
Definition of a vector holding bytes.
Definition: TestTCPClient.h:35
static bool testSendReceive(const double testDuration)
Tests sending and receiving data.
static bool test(const double testDuration)
Tests all TCPClient functions.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15