summaryrefslogtreecommitdiff
path: root/toxrtp/tests
diff options
context:
space:
mode:
Diffstat (limited to 'toxrtp/tests')
-rw-r--r--toxrtp/tests/Makefile.inc1
-rw-r--r--toxrtp/tests/test_bidirect.c109
-rw-r--r--toxrtp/tests/test_headers.c316
-rw-r--r--toxrtp/tests/test_helper.c83
-rw-r--r--toxrtp/tests/test_helper.h61
5 files changed, 0 insertions, 570 deletions
diff --git a/toxrtp/tests/Makefile.inc b/toxrtp/tests/Makefile.inc
deleted file mode 100644
index 8d1c8b69..00000000
--- a/toxrtp/tests/Makefile.inc
+++ /dev/null
@@ -1 +0,0 @@
1
diff --git a/toxrtp/tests/test_bidirect.c b/toxrtp/tests/test_bidirect.c
deleted file mode 100644
index b5a0899e..00000000
--- a/toxrtp/tests/test_bidirect.c
+++ /dev/null
@@ -1,109 +0,0 @@
1#define _BSD_SOURCE
2
3#include "../toxrtp.h"
4#include "../toxrtp_message.h"
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <utime.h>
9#include <assert.h>
10
11#include "test_helper.h"
12#include "../../toxcore/tox.h"
13
14#ifdef _CT_BIDIRECT
15
16int _print_help( const char* name )
17{
18 char* _help = malloc( 300 );
19 memset(_help, '\0', 300);
20
21 strcat(_help, " Usage: ");
22 strcat(_help, name);
23 strcat(_help, "\n -d IP ( destination )\n"
24 " -p PORT ( dest Port )\n"
25 " -l PORT ( listen Port ) \n");
26
27 puts ( _help );
28
29 free(_help);
30 return FAILURE;
31}
32
33int main( int argc, char* argv[] )
34{
35 int status;
36 tox_IP_Port Ip_port;
37 const char* ip, *psend, *plisten;
38 uint16_t port_send, port_listen;
39 const uint8_t* test_bytes = "0123456789012345678901234567890123456789012345678901234567890123456789"
40 "0123456789012345678901234567890123456789012345678901234567890123456789"
41 "0123456789012345678901234567890123456789012345678901234567890123456789"
42 "0123456789012345678901234567890123456789012345678901234567890123456789";
43
44
45 rtp_session_t* _m_session;
46 rtp_msg_t *_m_msg_R, *_m_msg_S;
47 arg_t* _list = parse_args ( argc, argv );
48
49 ip = find_arg_duble(_list, "-d");
50 psend = find_arg_duble(_list, "-p");
51 plisten = find_arg_duble(_list, "-l");
52
53 if ( !ip || !plisten || !psend )
54 return _print_help(argv[0]);
55
56 port_send = atoi(psend);
57 port_listen = atoi(plisten);
58
59 IP_Port local, remote;
60
61 /*
62 * This is the Local ip. We initiate networking on
63 * this value for it's the local one. To make stuff simpler we receive over this value
64 * and send on the other one ( see remote )
65 */
66 local.ip.i = htonl(INADDR_ANY);
67 local.port = port_listen;
68 Networking_Core* _networking = new_networking(local.ip, port_listen);
69
70 if ( !_networking )
71 return FAILURE;
72
73 int _socket = _networking->sock;
74 /*
75 * Now this is the remote. It's used by rtp_session_t to determine the receivers ip etc.
76 */
77 t_setipport ( ip, port_send, &remote );
78 _m_session = rtp_init_session(-1, -1);
79 rtp_add_receiver( _m_session, &remote );
80
81 /* Now let's start our main loop in both recv and send mode */
82
83 for ( ;; )
84 {
85 /*
86 * This part checks for received messages and if gotten one
87 * display 'Received msg!' indicator and free message
88 */
89 _m_msg_R = rtp_recv_msg ( _m_session );
90
91 if ( _m_msg_R ) {
92 puts ( "Received msg!" );
93 rtp_free_msg(_m_session, _m_msg_R);
94 }
95 /* -------------------- */
96
97 /*
98 * This one makes a test msg and sends that message to the 'remote'
99 */
100 _m_msg_S = rtp_msg_new ( _m_session, test_bytes, 280 ) ;
101 rtp_send_msg ( _m_session, _m_msg_S, _socket );
102 usleep ( 10000 );
103 /* -------------------- */
104 }
105
106 return SUCCESS;
107}
108
109#endif /* _CT_BIDIRECT */
diff --git a/toxrtp/tests/test_headers.c b/toxrtp/tests/test_headers.c
deleted file mode 100644
index be3f1375..00000000
--- a/toxrtp/tests/test_headers.c
+++ /dev/null
@@ -1,316 +0,0 @@
1/* test_headers.c
2 *
3 * Tests header parsing. You probably won't need this. !Red!
4 *
5 *
6 * Copyright (C) 2013 Tox project All Rights Reserved.
7 *
8 * This file is part of Tox.
9 *
10 * Tox is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Tox is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#include "test_helper.h"
26#include "../toxrtp.h"
27#include "../toxrtp_message.h"
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <utime.h>
33#include <assert.h>
34#include "../toxrtp_error_id.h"
35
36#define _CT_HEADERS_
37
38#ifdef _CT_HEADERS
39
40int _socket;
41pthread_mutex_t _mutex;
42
43int print_help()
44{
45 puts (
46 " Usage: Tuxrtp [-s (send mode) -d IP ( destination ) -p PORT ( dest Port )] \n"
47 " [-r ( recv mode ) ]"
48 );
49 return FAILURE;
50}
51
52void print_session_stats ( rtp_session_t* _m_session )
53{
54 printf
55 (
56 "Session test:\n"
57 "\tPackets sent:%d\n"
58 "\tPackets recv:%d\n\n"
59 "\tBytes sent:%d\n"
60 "\tBytes recv:%d\n\n"
61 "\tHeader CCSRs:%d\n"
62 ,
63 _m_session->_packets_sent,
64 _m_session->_packets_recv,
65 _m_session->_bytes_sent,
66 _m_session->_bytes_recv,
67 _m_session->_cc
68 );
69
70 uint8_t i;
71 for ( i = 0; i < _m_session->_cc; i++ ) {
72 printf (
73 "\t%d > :%d\n", i, _m_session->_csrc[i]
74 );
75 }
76}
77
78void print_header_info ( rtp_header_t* _header )
79{
80 printf
81 (
82 "Header info:\n"
83 "\tVersion :%d\n"
84 "\tPadding :%d\n"
85 "\tExtension :%d\n"
86 "\tCSRC count :%d\n"
87 "\tPayload type :%d\n"
88 "\tMarker :%d\n\n"
89
90 "\tSSrc :%d\n"
91 "\tSequence num :%d\n"
92 "\tLenght: :%d\n"
93 "\tCSRC's:\n"
94 ,
95 rtp_header_get_flag_version ( _header ),
96 rtp_header_get_flag_padding ( _header ),
97 rtp_header_get_flag_extension ( _header ),
98 rtp_header_get_flag_CSRC_count ( _header ),
99 rtp_header_get_setting_payload_type ( _header ),
100 rtp_header_get_setting_marker ( _header ),
101
102 _header->_ssrc,
103 _header->_sequence_number,
104 _header->_length
105 );
106
107
108 uint8_t i;
109 for ( i = 0; i < rtp_header_get_flag_CSRC_count ( _header ); i++ ) {
110 printf (
111 "\t%d > :%d\n", i, _header->_csrc[i]
112 );
113 }
114
115 puts ( "\n" );
116}
117
118void print_ext_header_info(rtp_ext_header_t* _ext_header)
119{
120 printf
121 (
122 "External Header info: \n"
123 "\tLenght :%d\n"
124 "\tID :%d\n"
125 "\tValue H :%d\n"
126 "\tValue W :%d\n\n",
127 _ext_header->_ext_len,
128 _ext_header->_ext_type,
129 rtp_get_resolution_marking_height(_ext_header, 0),
130 rtp_get_resolution_marking_width(_ext_header, 0)
131 );
132}
133
134int rtp_handlepacket ( rtp_session_t* _session, rtp_msg_t* _msg )
135{
136 if ( !_msg )
137 return FAILURE;
138
139 if ( rtp_check_late_message(_session, _msg) < 0 ) {
140 rtp_register_msg(_session, _msg);
141 }
142
143 if ( _session->_last_msg ) {
144 _session->_last_msg->_next = _msg;
145 _session->_last_msg = _msg;
146 } else {
147 _session->_last_msg = _session->_oldest_msg = _msg;
148 }
149
150
151 return SUCCESS;
152}
153
154void* receivepacket_callback(void* _p_session)
155{
156 rtp_msg_t* _msg;
157 rtp_session_t* _session = _p_session;
158
159 uint32_t _bytes;
160 tox_IP_Port _from;
161 uint8_t _socket_data[MAX_UDP_PACKET_SIZE];
162
163 int _m_socket = _socket;
164
165 while ( 1 )
166 {
167 int _status = receivepacket ( _m_socket, &_from, _socket_data, &_bytes );
168
169 if ( _status == FAILURE ) { /* nothing recved */
170 usleep(1000);
171 continue;
172 }
173
174 pthread_mutex_lock ( &_mutex );
175
176 _msg = rtp_msg_parse ( NULL, _socket_data, _bytes );
177 rtp_handlepacket(_session, _msg);
178
179 pthread_mutex_unlock ( &_mutex );
180 }
181
182 pthread_exit(NULL);
183}
184
185int main ( int argc, char* argv[] )
186{
187 arg_t* _list = parse_args ( argc, argv );
188
189 if ( _list == NULL ) { /* failed */
190 return print_help();
191 }
192
193 pthread_mutex_init ( &_mutex, NULL );
194
195 int status;
196 IP_Port Ip_port;
197 const char* ip;
198 uint16_t port;
199
200
201 const uint8_t* test_bytes [300];
202 memset(test_bytes, 'a', 300);
203
204 rtp_session_t* _m_session;
205 rtp_msg_t* _m_msg;
206
207 if ( find_arg_simple ( _list, "-r" ) != FAILURE ) { /* Server mode */
208
209 IP_Port LOCAL_IP; /* since you need at least 1 recv-er */
210 LOCAL_IP.ip.i = htonl(INADDR_ANY);
211 LOCAL_IP.port = RTP_PORT;
212 LOCAL_IP.padding = -1;
213
214 _m_session = rtp_init_session ( -1, -1 );
215 Networking_Core* _networking = new_networking(LOCAL_IP.ip, RTP_PORT_LISTEN);
216 _socket = _networking->sock;
217
218
219 if ( !_networking ){
220 pthread_mutex_destroy ( &_mutex );
221 return FAILURE;
222 }
223
224 int _socket = _networking->sock;
225
226 if ( status < 0 ) {
227 pthread_mutex_destroy ( &_mutex );
228 return FAILURE;
229 }
230 /* -- start in recv mode, get 1 message and then analyze it -- */
231 pthread_t _tid;
232 RUN_IN_THREAD(receivepacket_callback, _tid, _m_session)
233
234 for ( ; ; ) { /* Recv for x seconds */
235 _m_msg = rtp_recv_msg ( _m_session );
236
237 /* _m_msg = rtp_session_get_message_queded ( _m_session ); DEPRECATED */
238 if ( _m_msg ) {
239 /*rtp_free_msg(_m_session, _m_msg);
240 _m_msg = NULL;*/
241 printf("Timestamp: %d\n", _m_msg->_header->_timestamp);
242 }
243
244 usleep ( 10000 );
245 }
246
247 if ( _m_msg->_header ) {
248 rtp_header_print ( _m_msg->_header );
249 }
250 if ( _m_msg->_ext_header ){
251 print_ext_header_info(_m_msg->_ext_header);
252 }
253
254 //print_session_stats ( _m_session );
255
256
257 //printf ( "Payload: ( %d ) \n%s\n", _m_msg->_length, _m_msg->_data );
258
259
260 } else if ( find_arg_simple ( _list, "-s" ) != FAILURE ) {
261 ip = find_arg_duble ( _list, "-d" );
262
263 if ( ip == NULL ) {
264 pthread_mutex_destroy ( &_mutex );
265 return FAILURE;
266 }
267
268 const char* _port = find_arg_duble ( _list, "-p" );
269
270 if ( _port != NULL ) {
271 port = atoi ( _port );
272 }
273
274 t_setipport ( ip, port, &Ip_port );
275 printf ( "Remote: %s:%d\n", ip, port );
276
277 Networking_Core* _networking = new_networking(Ip_port.ip, RTP_PORT);
278
279 if ( !_networking ){
280 pthread_mutex_destroy ( &_mutex );
281 return FAILURE;
282 }
283
284 int _socket = _networking->sock;
285
286 _m_session = rtp_init_session ( -1, -1 );
287 rtp_add_receiver( _m_session, &Ip_port );
288 //rtp_add_resolution_marking(_m_session, 1920, 1080);
289 //rtp_add_framerate_marking(_m_session, 1000);
290
291 puts ( "Now sending payload!\n" );
292 uint16_t _first_sequ = _m_session->_sequence_number;
293
294 /* use already defined buffer lenght */
295 while ( 1 ){
296 _m_msg = rtp_msg_new ( _m_session, test_bytes, 300 );
297 rtp_send_msg ( _m_session, _m_msg, _socket );
298 usleep(10000);
299 }
300
301 if ( _m_session->_last_error ) {
302 puts ( _m_session->_last_error );
303 }
304
305 return rtp_terminate_session(_m_session);
306
307 } else {
308 pthread_mutex_destroy ( &_mutex );
309 return FAILURE;
310 }
311 pthread_mutex_destroy ( &_mutex );
312
313 return SUCCESS;
314}
315
316#endif /* _CT_HEADERS */
diff --git a/toxrtp/tests/test_helper.c b/toxrtp/tests/test_helper.c
deleted file mode 100644
index 526b6b38..00000000
--- a/toxrtp/tests/test_helper.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* test_helper.c
2 *
3 * Tests support. !Red!
4 *
5 *
6 * Copyright (C) 2013 Tox project All Rights Reserved.
7 *
8 * This file is part of Tox.
9 *
10 * Tox is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Tox is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#include "test_helper.h"
26
27#include <string.h>
28#include <stdlib.h>
29
30arg_t* parse_args ( int argc, char* argv[] )
31{
32 arg_t* _list = calloc(sizeof(arg_t), 1);
33 _list->next = _list->prev = NULL;
34
35 arg_t* it = _list;
36
37 size_t val;
38 for ( val = 0; val < argc; val ++ ) {
39 it->value = argv[val];
40
41 if ( val < argc - 1 ) { /* just about to end */
42 it->next = calloc(sizeof(arg_t), 1);
43 it->next->prev = it;
44 it = it->next;
45 it->next = NULL;
46 }
47 }
48
49 return _list;
50}
51
52int find_arg_simple ( arg_t* _head, const char* _id )
53{
54 arg_t* it = _head;
55
56 int i;
57 for ( i = 1; it != NULL; it = it->next ) {
58 if ( strcmp ( _id, it->value ) == 0 ) {
59 return i;
60 }
61
62 i++;
63 }
64
65 return FAILURE;
66}
67
68const char* find_arg_duble ( arg_t* _head, const char* _id )
69{
70 arg_t* _it;
71 for ( _it = _head; _it != NULL; _it = _it->next ) {
72 if ( strcmp ( _id, _it->value ) == 0 ) {
73 if ( _it->next && _it->next->value[0] != '-' ) { /* exclude option */
74 return _it->next->value;
75 } else {
76 return NULL;
77 }
78 }
79 }
80
81 return NULL;
82}
83
diff --git a/toxrtp/tests/test_helper.h b/toxrtp/tests/test_helper.h
deleted file mode 100644
index de654743..00000000
--- a/toxrtp/tests/test_helper.h
+++ /dev/null
@@ -1,61 +0,0 @@
1/* test_helper.h
2 *
3 * Tests support. !Red!
4 *
5 *
6 * Copyright (C) 2013 Tox project All Rights Reserved.
7 *
8 * This file is part of Tox.
9 *
10 * Tox is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Tox is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#ifndef _TEST__HELPER_
26#define _TEST__HELPER_
27
28#include "../toxrtp_helper.h"
29
30#define RTP_PORT 31003
31#define RTP_PORT_LISTEN 31001
32
33#define _SLEEP_INTERVAL 1000
34
35typedef struct arg_s {
36 const char* value;
37 struct arg_s* next;
38 struct arg_s* prev;
39
40} arg_t;
41
42
43
44/* Parses arguments into d-list arg_t */
45arg_t* parse_args ( int argc, char* argv[] );
46
47/* Get a single argument ( i.e. ./test -s |find if has 's' >> | find_arg_simple(_t, "-s") )
48 * A little error checking, of course, returns FAILURE if not found and if found returns position
49 * where it's found.
50 */
51int find_arg_simple ( arg_t* _head, const char* _id );
52
53/* Get a single argument ( i.e. ./test -d 127.0.0.1 |get 'd' value >> | find_arg_duble(_t, "-d") )
54 * A little error checking, of course, returns NULL if not found and if found returns value
55 * of that argument ( i.e. '127.0.0.1').
56 */
57const char* find_arg_duble ( arg_t* _head, const char* _id );
58
59#endif /* _TEST__HELPER_ */
60
61