Ocean
Loading...
Searching...
No Matches
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
16
17namespace Ocean
18{
19
20namespace Test
21{
22
23namespace TestNetwork
24{
25
26/**
27 * This class implements test for TCPClient.
28 * @ingroup testnetwork
29 */
30class OCEAN_TEST_NETWORK_EXPORT TestTCPClient
31{
32 protected:
33
34 /**
35 * Definition of a vector holding bytes.
36 */
37 using Buffer = std::vector<uint8_t>;
38
39 /**
40 * This class implements a receiver.
41 */
43 {
44 public:
45
46 /**
47 * Event function for connection requests.
48 * @param senderAddress The address of the sender
49 * @param senderPort The port of the sender
50 * @param connectionId The id of the connection
51 */
52 bool onConnectionRequest(const Network::Address4& senderAddress, const Network::Port& senderPort, const Network::TCPServer::ConnectionId connectionId);
53
54 /**
55 * Event function for a disconnected connection.
56 * @param connectionId The id of the disconnected connection
57 */
59
60 /**
61 * Event function for receiving data.
62 * @param connectionId The id of the connection from which the data has been received
63 * @param data The data that has been received
64 * @param size The number of bytes
65 */
66 void onReceive(const Network::TCPServer::ConnectionId connectionId, const void* data, const size_t size);
67
68 public:
69
70 /// The number of connection requests.
71 unsigned int numberConnectionRequests_ = 0u;
72
73 /// The number of disconnections.
74 unsigned int numberDisconnections_ = 0u;
75
76 /// The memory buffers.
77 std::vector<Buffer> buffers_;
78 };
79
80 public:
81
82 /**
83 * Tests all TCPClient functions.
84 * @param testDuration The number of seconds for each test, with range (0, infinity)
85 * @param selector The selector defining which tests to run
86 * @return True, if succeeded
87 */
88 static bool test(const double testDuration, const TestSelector& selector);
89
90 /**
91 * Tests sending and receiving data.
92 * @param testDuration The number of seconds for each test, with range (0, infinity)
93 * @return True, if succeeded
94 */
95 static bool testSendReceive(const double testDuration);
96};
97
98}
99
100}
101
102}
103
104#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:43
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:77
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:31
static bool test(const double testDuration, const TestSelector &selector)
Tests all TCPClient functions.
std::vector< uint8_t > Buffer
Definition of a vector holding bytes.
Definition TestTCPClient.h:37
static bool testSendReceive(const double testDuration)
Tests sending and receiving data.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
The namespace covering the entire Ocean framework.
Definition Accessor.h:15