diff options
Diffstat (limited to 'toxrtp/tests/test_bidirect.c')
-rw-r--r-- | toxrtp/tests/test_bidirect.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/toxrtp/tests/test_bidirect.c b/toxrtp/tests/test_bidirect.c new file mode 100644 index 00000000..b5a0899e --- /dev/null +++ b/toxrtp/tests/test_bidirect.c | |||
@@ -0,0 +1,109 @@ | |||
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 | |||
16 | int _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 | |||
33 | int 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 */ | ||