• R/O
  • SSH
  • HTTPS

eirsamples: Commit


Commit MetaInfo

Revision9 (tree)
Time2018-05-03 06:28:02
Authorquiret

Log Message

- moved the network unittest into its own project at TidesNet repository
- readjusted the TidesNet checkout URL
- added dependency on libparse project (I will add JSON parsing to it)

Change Summary

Incremental Difference

--- marketstatcollect/src/network_tests.cpp (revision 8)
+++ marketstatcollect/src/network_tests.cpp (nonexistent)
@@ -1,219 +0,0 @@
1-// For now I am putting all the network tests here.
2-// Should be moved into it's own project eventually.
3-
4-#include <tidesnet/tidesnet.h>
5-#include <sdk/OSUtils.memheap.h>
6-
7-#include <stdio.h>
8-#include <assert.h>
9-
10-static void LOCAL_NETWORK_TEST( TidesNetwork::TidesNet *netMan )
11-{
12- using namespace TidesNetwork;
13-
14- printf( "testing local hostname resolution..." );
15- {
16- // Test IPV4.
17- {
18- ipdescIPV4 resolved;
19-
20- assert( netMan->ResolveHostnameIPV4( "127.0.0.1", resolved ) == true );
21- assert( netMan->ResolveHostnameIPV4( "localhost", resolved ) == true );
22- }
23- // Test IPV6.
24- {
25- ipdescIPV6 resolved;
26-
27- assert( netMan->ResolveHostnameIPV6( "localhost", resolved ) == true );
28- assert( netMan->ResolveHostnameIPV6( "::1", resolved ) == true );
29- }
30- }
31- printf( "ok.\n" );
32-
33- printf( "testing IPV6 TCP connect to localhost..." );
34- {
35- // First get the IP.
36- ipdescIPV6 resolved;
37-
38- assert( netMan->ResolveHostnameIPV6( "localhost", resolved ) == true );
39-
40- // Next open a listener socket.
41- connRecvInst listener = netMan->CreateNetListener( 7733, eConnFamily::IPV6, eConnProtocol::TCP );
42-
43- assert( listener.is_good() );
44-
45- // Then connect to it with a new socket.
46- netSocketInst localConn = netMan->ConnectRemoteIPV6( resolved, 7733, eConnProtocol::TCP );
47-
48- assert( localConn.is_good() );
49-
50- // Accept with our listener.
51- netSocketInst remoteConn = listener->Accept();
52-
53- assert( remoteConn != nullptr );
54- }
55- printf( "ok.\n" );
56-
57- printf( "testing IPV4 TCP connect to localhost..." );
58- {
59- // First get the IP.
60- ipdescIPV4 resolved;
61-
62- assert( netMan->ResolveHostnameIPV4( "localhost", resolved ) == true );
63-
64- // Next open a listener socket.
65- connRecvInst listener = netMan->CreateNetListener( 4422, eConnFamily::IPV4, eConnProtocol::TCP );
66-
67- assert( listener.is_good() );
68-
69- // Then connect to it with a new socket.
70- netSocketInst localConn = netMan->ConnectRemoteIPV4( resolved, 4422, eConnProtocol::TCP );
71-
72- assert( localConn.is_good() );
73-
74- // Accept with our listener.
75- netSocketInst remoteConn = listener->Accept();
76-
77- assert( remoteConn.is_good() );
78- }
79- printf( "ok.\n" );
80-
81- printf( "testing local TCP IPV6 small send-and-receive..." );
82- {
83- static const char sample_data[] = "my meow is a great one.";
84-
85- ipdescIPV6 localhost;
86-
87- bool gotToResolve = netMan->ResolveHostnameIPV6( "localhost", localhost );
88-
89- assert( gotToResolve == true );
90-
91- connRecvInst serverSocket = netMan->CreateNetListener( 6336, eConnFamily::IPV6, eConnProtocol::TCP );
92-
93- assert( serverSocket.is_good() );
94-
95- netSocketInst clientSocket = netMan->ConnectRemoteIPV6( localhost, 6336, eConnProtocol::TCP );
96-
97- assert( clientSocket.is_good() );
98-
99- netSocketInst serverSendSocket = serverSocket->Accept();
100-
101- assert( serverSendSocket.is_good() );
102-
103- // Helpers.
104- auto send_and_receive = [&]( NetSocket *sender, NetSocket *receiver )
105- {
106- // We assume that the small size that we sent fits 100% into the buffer.
107- {
108- size_t writeCount = sender->Write( sample_data, sizeof(sample_data) );
109-
110- assert( writeCount == sizeof(sample_data) );
111- }
112-
113- // Receive and validate.
114- {
115- char wanted_data[ sizeof(sample_data) * 2 ];
116-
117- size_t readCount = receiver->Read( wanted_data, sizeof(wanted_data) );
118-
119- assert( readCount == sizeof(sample_data) );
120-
121- for ( size_t n = 0; n < sizeof(sample_data); n++ )
122- {
123- assert( wanted_data[n] == sample_data[n] );
124- }
125- }
126- };
127-
128- // Send from client to server.
129- send_and_receive( clientSocket, serverSendSocket );
130-
131- // Also test the other way round.
132- send_and_receive( serverSendSocket, clientSocket );
133- }
134- printf( "ok.\n" );
135-
136- printf( "testing local IPV6 TCP big data transfer..." );
137- {
138- // We want to use an incremental row of (d/q)words and transfer it to the client, as one big chunk.
139- static constexpr size_t NUM_COUNT = 1000;
140-
141- size_t *number_array = new size_t[ NUM_COUNT ];
142-
143- for ( size_t n = 0; n < NUM_COUNT; n++ )
144- {
145- number_array[ n ] = n;
146- }
147-
148- ipdescIPV6 localhost;
149-
150- bool gotToResolve = netMan->ResolveHostnameIPV6( "localhost", localhost );
151-
152- // Create the network architecture.
153- connRecvInst listener = netMan->CreateNetListener( 1298, eConnFamily::IPV6, eConnProtocol::TCP );
154-
155- assert( listener.is_good() );
156-
157- netSocketInst senderSocket = netMan->ConnectRemoteIPV6( localhost, 1298, eConnProtocol::TCP );
158-
159- assert( senderSocket.is_good() );
160-
161- netSocketInst receiverSocket = listener->Accept();
162-
163- assert( receiverSocket.is_good() );
164-
165- // Send the big data.
166- size_t big_tx_size = ( sizeof(size_t) * NUM_COUNT );
167-
168- netMan->SocketTransferBuffer( senderSocket, number_array, big_tx_size );
169-
170- // Clear the buffer.
171- memset( number_array, 0, big_tx_size );
172-
173- // Receive the big data again.
174- netMan->SocketReceiveBuffer( receiverSocket, number_array, big_tx_size );
175-
176- // Verify the received data.
177- for ( size_t n = 0; n < NUM_COUNT; n++ )
178- {
179- assert( number_array[n] == n );
180- }
181- }
182- printf( "ok.\n" );
183-}
184-
185-static void REMOTE_NETWORK_TEST( TidesNetwork::TidesNet *netMan )
186-{
187- using namespace TidesNetwork;
188-
189- printf( "testing remote hostname resolution..." );
190- {
191- // Test IPV4.
192- {
193- ipdescIPV4 resolved;
194-
195- assert( netMan->ResolveHostnameIPV4( "microsoft.com", resolved ) == true );
196- }
197- // Test IPV6.
198- {
199- // Not many hosts actually have IPV6 even today (first of May 2018) so it was actually
200- // difficult to find one.
201- // WARNING: not all networks seem to support IPV6 anyway.
202- ipdescIPV6 resolved;
203-
204- assert( netMan->ResolveHostnameIPV6( "mtasa.com", resolved ) == true );
205- }
206- }
207- printf( "ok.\n" );
208-}
209-
210-void DO_NETWORK_TEST( void )
211-{
212- using namespace TidesNetwork;
213-
214- // Smart capsules take care of the annoying stuff.
215- netManInst netMan;
216-
217- LOCAL_NETWORK_TEST( netMan );
218- REMOTE_NETWORK_TEST( netMan );
219-}
\ No newline at end of file
--- marketstatcollect/src/main.cpp (revision 8)
+++ marketstatcollect/src/main.cpp (revision 9)
@@ -5,13 +5,8 @@
55
66 #include <iostream>
77
8-// Temporary tests.
9-extern void DO_NETWORK_TEST( void );
10-
118 int main( int argc, char *argv )
129 {
13- DO_NETWORK_TEST();
14-
1510 std::cout <<
1611 "Marketing Data Collector by (c)Martin Turski, turningtides@outlook.de" << std::endl <<
1712 "put config.ini and sites.txt files into the application folder and run this tool" << std::endl <<
Show on old repository browser