summaryrefslogtreecommitdiff
path: root/auto_tests/invalid_udp_proxy_test.c
diff options
context:
space:
mode:
authorhugbubby <hugbubby@protonmail.com>2018-07-25 16:19:05 -0700
committeriphydf <iphydf@users.noreply.github.com>2018-07-28 16:14:06 +0000
commit051eb1d5a78ac196362fde9b917641ddb4e59c4f (patch)
tree8ae556512375faf11069173d4fd3865d42be0597 /auto_tests/invalid_udp_proxy_test.c
parentc4d58403f966328fb26e062b71adf05842ff3039 (diff)
auto_test fixture and filenames
Renamed a poorly named test, fixed up a few printf statements, substituted some unsigned integers with fixed size counterparts, and implemmented the auto_run_test.h fixture for the lossy and lossless packet tests.
Diffstat (limited to 'auto_tests/invalid_udp_proxy_test.c')
-rw-r--r--auto_tests/invalid_udp_proxy_test.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/auto_tests/invalid_udp_proxy_test.c b/auto_tests/invalid_udp_proxy_test.c
new file mode 100644
index 00000000..96c8197b
--- /dev/null
+++ b/auto_tests/invalid_udp_proxy_test.c
@@ -0,0 +1,51 @@
1// Test that if UDP is enabled, and a proxy is provided that does not support
2// UDP proxying, we disable UDP.
3
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#endif
7
8#include <stdio.h>
9
10#include "../testing/misc_tools.h"
11#include "check_compat.h"
12
13static uint8_t const key[] = {
14 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD,
15 0xDF, 0x0E, 0xBA, 0x05, 0x7D, 0xAB, 0xB4, 0x9F,
16 0xE1, 0x5F, 0x38, 0x03, 0xB1, 0xBF, 0xF0, 0x65,
17 0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E,
18};
19
20// Try to bootstrap for 30 seconds.
21#define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0))
22
23int main(void)
24{
25 setvbuf(stdout, nullptr, _IONBF, 0);
26
27 struct Tox_Options *opts = tox_options_new(nullptr);
28 tox_options_set_udp_enabled(opts, true);
29 tox_options_set_proxy_type(opts, TOX_PROXY_TYPE_SOCKS5);
30 tox_options_set_proxy_host(opts, "localhost");
31 tox_options_set_proxy_port(opts, 51724);
32 Tox *tox = tox_new_log(opts, nullptr, nullptr);
33 tox_options_free(opts);
34
35 tox_add_tcp_relay(tox, "tox.ngc.zone", 33445, key, nullptr);
36 tox_bootstrap(tox, "tox.ngc.zone", 33445, key, nullptr);
37
38 printf("Waiting for connection...");
39
40 for (uint16_t i = 0; i < NUM_ITERATIONS; i++) {
41 tox_iterate(tox, nullptr);
42 c_sleep(ITERATION_INTERVAL);
43 // None of the iterations should have a connection.
44 const TOX_CONNECTION status = tox_self_get_connection_status(tox);
45 ck_assert_msg(status == TOX_CONNECTION_NONE,
46 "unexpectedly got a connection (%d)", status);
47 }
48
49 tox_kill(tox);
50 return 0;
51}