Ocean
Loading...
Searching...
No Matches
TestPackagedTCPClient.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_PACKAGED_TCP_CLIENT_H
9#define META_OCEAN_TEST_TESTNETWORK_TEST_PACKAGED_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 PackagedTCPClient.
28 * @ingroup testnetwork
29 */
30class OCEAN_TEST_NETWORK_EXPORT TestPackagedTCPClient
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 for clients.
41 */
42 class OCEAN_TEST_NETWORK_EXPORT ClientReceiver
43 {
44 public:
45
46 /**
47 * Event function for receiving data.
48 * @param data The data that has been received
49 * @param size The number of bytes
50 */
51 void onReceive(const void* data, const size_t size);
52
53 public:
54
55 /// The memory buffers.
56 std::vector<Buffer> buffers_;
57 };
58
59 /**
60 * This class implements a receiver for servers.
61 */
62 class OCEAN_TEST_NETWORK_EXPORT ServerReceiver
63 {
64 public:
65
66 /**
67 * Event function for connection requests.
68 * @param senderAddress The address of the sender
69 * @param senderPort The port of the sender
70 * @param connectionId The id of the connection
71 */
72 bool onConnectionRequest(const Network::Address4& senderAddress, const Network::Port& senderPort, const Network::PackagedTCPServer::ConnectionId connectionId);
73
74 /**
75 * Event function for a disconnected connection.
76 * @param connectionId The id of the disconnected connection
77 */
79
80 /**
81 * Event function for receiving data.
82 * @param connectionId The id of the connection from which the data has been received
83 * @param data The data that has been received
84 * @param size The number of bytes
85 */
86 void onReceive(const Network::PackagedTCPServer::ConnectionId connectionId, const void* data, const size_t size);
87
88 public:
89
90 /// The id of the latest connection request.
91 Network::PackagedTCPServer::ConnectionId connectionId_ = Network::PackagedTCPServer::invalidConnectionId();
92
93 /// The number of connection requests.
94 unsigned int numberConnectionRequests_ = 0u;
95
96 /// The number of disconnections.
97 unsigned int numberDisconnections_ = 0u;
98
99 /// The memory buffers.
100 std::vector<Buffer> buffers_;
101 };
102
103 public:
104
105 /**
106 * Tests all PackagedTCPClient functions.
107 * @param testDuration The number of seconds for each test, with range (0, infinity)
108 * @param selector The selector defining which tests to run
109 * @return True, if succeeded
110 */
111 static bool test(const double testDuration, const TestSelector& selector);
112
113 /**
114 * Tests sending and receiving data.
115 * @param testDuration The number of seconds for each test, with range (0, infinity)
116 * @return True, if succeeded
117 */
118 static bool testSendReceive(const double testDuration);
119};
120
121}
122
123}
124
125}
126
127#endif // META_OCEAN_TEST_TESTNETWORK_TEST_PACKAGED_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 for clients.
Definition TestPackagedTCPClient.h:43
std::vector< Buffer > buffers_
The memory buffers.
Definition TestPackagedTCPClient.h:56
void onReceive(const void *data, const size_t size)
Event function for receiving data.
This class implements a receiver for servers.
Definition TestPackagedTCPClient.h:63
bool onConnectionRequest(const Network::Address4 &senderAddress, const Network::Port &senderPort, const Network::PackagedTCPServer::ConnectionId connectionId)
Event function for connection requests.
std::vector< Buffer > buffers_
The memory buffers.
Definition TestPackagedTCPClient.h:100
void onReceive(const Network::PackagedTCPServer::ConnectionId connectionId, const void *data, const size_t size)
Event function for receiving data.
void onConnectionDisconnected(const Network::PackagedTCPServer::ConnectionId connectionId)
Event function for a disconnected connection.
This class implements test for PackagedTCPClient.
Definition TestPackagedTCPClient.h:31
std::vector< uint8_t > Buffer
Definition of a vector holding bytes.
Definition TestPackagedTCPClient.h:37
static bool testSendReceive(const double testDuration)
Tests sending and receiving data.
static bool test(const double testDuration, const TestSelector &selector)
Tests all PackagedTCPClient functions.
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