summaryrefslogtreecommitdiff
path: root/auto_tests
diff options
context:
space:
mode:
authorendoffile78 <endoffile78@yahoo.com>2016-11-05 15:30:39 -0500
committerendoffile78 <endoffile78@yahoo.com>2016-11-06 09:14:53 -0600
commit3f53090c1d148da6ede2bbe85a58689c28289e14 (patch)
tree78bae45122f53a2de2b243e25560ba66bcfbe812 /auto_tests
parent7b6b47a610920e8911a80f4fc261c4b242279cdc (diff)
Remove assoc
Diffstat (limited to 'auto_tests')
-rw-r--r--auto_tests/Makefile.inc11
-rw-r--r--auto_tests/assoc_test.c161
2 files changed, 2 insertions, 170 deletions
diff --git a/auto_tests/Makefile.inc b/auto_tests/Makefile.inc
index 6cb9d5f1..dc1dc9f7 100644
--- a/auto_tests/Makefile.inc
+++ b/auto_tests/Makefile.inc
@@ -1,7 +1,7 @@
1if BUILD_TESTS 1if BUILD_TESTS
2 2
3TESTS = encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest 3TESTS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_test dht_autotest
4check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test dht_autotest 4check_PROGRAMS = encryptsave_test messenger_autotest crypto_test network_test onion_test TCP_test tox_test dht_autotest
5 5
6AUTOTEST_CFLAGS = \ 6AUTOTEST_CFLAGS = \
7 $(LIBSODIUM_CFLAGS) \ 7 $(LIBSODIUM_CFLAGS) \
@@ -47,13 +47,6 @@ network_test_CFLAGS = $(AUTOTEST_CFLAGS)
47network_test_LDADD = $(AUTOTEST_LDADD) 47network_test_LDADD = $(AUTOTEST_LDADD)
48 48
49 49
50assoc_test_SOURCES = ../auto_tests/assoc_test.c
51
52assoc_test_CFLAGS = $(AUTOTEST_CFLAGS)
53
54assoc_test_LDADD = $(AUTOTEST_LDADD)
55
56
57onion_test_SOURCES = ../auto_tests/onion_test.c 50onion_test_SOURCES = ../auto_tests/onion_test.c
58 51
59onion_test_CFLAGS = $(AUTOTEST_CFLAGS) 52onion_test_CFLAGS = $(AUTOTEST_CFLAGS)
diff --git a/auto_tests/assoc_test.c b/auto_tests/assoc_test.c
deleted file mode 100644
index 4814601c..00000000
--- a/auto_tests/assoc_test.c
+++ /dev/null
@@ -1,161 +0,0 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#define AUTO_TEST
6#include "../toxcore/DHT.h"
7#include "../toxcore/assoc.h"
8#include "../toxcore/util.h"
9
10#include <stdint.h>
11#include <string.h>
12#include <sys/types.h>
13
14#include <check.h>
15
16#include "helpers.h"
17
18START_TEST(test_basics)
19{
20 /* TODO(irungentoo): real test */
21 uint8_t id[crypto_box_PUBLICKEYBYTES] = {1};
22 Assoc *assoc = new_Assoc_default(NULL, id);
23 ck_assert_msg(assoc != NULL, "failed to create default assoc");
24
25 kill_Assoc(assoc);
26 assoc = new_Assoc(NULL, 17, 4, id); /* results in an assoc of 16/3 */
27 ck_assert_msg(assoc != NULL, "failed to create customized assoc");
28
29 IP_Port ipp;
30 ipp.ip.family = AF_INET;
31 ipp.ip.ip4.uint8[0] = 1;
32 ipp.port = htons(12345);
33
34 IPPTs ippts_send;
35 ippts_send.ip_port = ipp;
36 ippts_send.timestamp = unix_time();
37 IP_Port ipp_recv = ipp;
38
39 uint8_t res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0);
40 ck_assert_msg(res == 0, "stored self as entry: expected %u, got %u", 0, res);
41
42 id[0]++;
43
44 res = Assoc_add_entry(assoc, id, &ippts_send, &ipp_recv, 0);
45 ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u", 1, res);
46
47 Assoc_close_entries close_entries;
48 memset(&close_entries, 0, sizeof(close_entries));
49 close_entries.count = 4;
50 close_entries.count_good = 2;
51 close_entries.wanted_id = id;
52
53 Client_data *entries[close_entries.count];
54 close_entries.result = entries;
55
56 uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
57 ck_assert_msg(found == 1, "get_close_entries(): expected %u, got %u", 1, found);
58 kill_Assoc(assoc);
59}
60END_TEST
61
62START_TEST(test_fillup)
63{
64 /* TODO(irungentoo): real test */
65 int i, j;
66 uint8_t id[crypto_box_PUBLICKEYBYTES];
67 //uint32_t a = current_time();
68 uint32_t a = 2710106197;
69 srand(a);
70
71 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
72 id[i] = rand();
73 }
74
75 Assoc *assoc = new_Assoc(NULL, 6, 15, id);
76 ck_assert_msg(assoc != NULL, "failed to create default assoc");
77 struct entry {
78 uint8_t id[crypto_box_PUBLICKEYBYTES];
79 IPPTs ippts_send;
80 IP_Port ipp_recv;
81 };
82 struct entry entries[128];
83 struct entry closest[8];
84
85 for (j = 0; j < 128; ++j) {
86
87 for (i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
88 entries[j].id[i] = rand();
89 }
90
91 IP_Port ipp;
92 ipp.ip.family = AF_INET;
93 ipp.ip.ip4.uint32 = rand();
94 ipp.port = rand();
95 entries[j].ippts_send.ip_port = ipp;
96 entries[j].ippts_send.timestamp = unix_time();
97 ipp.ip.ip4.uint32 = rand();
98 ipp.port = rand();
99 entries[j].ipp_recv = ipp;
100
101 if (j % 16 == 0) {
102 memcpy(entries[j].id, id, crypto_box_PUBLICKEYBYTES - 30);
103 memcpy(&closest[j / 16], &entries[j], sizeof(struct entry));
104 }
105
106 uint8_t res = Assoc_add_entry(assoc, entries[j].id, &entries[j].ippts_send, &entries[j].ipp_recv, 1);
107 ck_assert_msg(res == 1, "failed to store entry: expected %u, got %u, j = %u", 1, res, j);
108 }
109
110 int good = 0;
111 Assoc_close_entries close_entries;
112 memset(&close_entries, 0, sizeof(close_entries));
113 close_entries.count = 8;
114 close_entries.count_good = 8;
115 close_entries.wanted_id = id;
116
117 Client_data *entri[close_entries.count];
118 close_entries.result = entri;
119
120 uint8_t found = Assoc_get_close_entries(assoc, &close_entries);
121 ck_assert_msg(found == 8, "get_close_entries(): expected %u, got %u", 1, found);
122
123 for (i = 0; i < 8; ++i) {
124 for (j = 0; j < 8; ++j) {
125 if (id_equal(entri[j]->public_key, closest[i].id)) {
126 ++good;
127 }
128 }
129 }
130
131 ck_assert_msg(good == 8, "Entries found were not the closest ones. Only %u/8 were.", good);
132 //printf("good: %u %u %u\n", good, a, ((uint32_t)current_time() - a));
133 kill_Assoc(assoc);
134}
135END_TEST
136
137static Suite *Assoc_suite(void)
138{
139 Suite *s = suite_create("Assoc");
140
141 DEFTESTCASE(basics);
142 DEFTESTCASE(fillup);
143 return s;
144}
145
146int main(int argc, char *argv[])
147{
148 unix_time_update();
149 Suite *Assoc = Assoc_suite();
150 SRunner *test_runner = srunner_create(Assoc);
151
152 srunner_set_fork_status(test_runner, CK_NOFORK);
153
154 srunner_run_all(test_runner, CK_NORMAL);
155
156 int number_failed = srunner_ntests_failed(test_runner);
157
158 srunner_free(test_runner);
159
160 return number_failed;
161}