summaryrefslogtreecommitdiff
path: root/toxcore/util_test.cpp
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-03 15:44:43 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-02-08 12:54:39 +0000
commit3fcc9a3c83c807792846ae2c9f98aeb447e62805 (patch)
tree757f7e6a50b32534dcf0fa38007dbf0265eeb7ef /toxcore/util_test.cpp
parentdcd439a5c3d80cd89c493a900c78e2a398f65248 (diff)
Add some unit tests for util.h.
Diffstat (limited to 'toxcore/util_test.cpp')
-rw-r--r--toxcore/util_test.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/toxcore/util_test.cpp b/toxcore/util_test.cpp
new file mode 100644
index 00000000..8de63848
--- /dev/null
+++ b/toxcore/util_test.cpp
@@ -0,0 +1,55 @@
1#include "util.h"
2
3#include "crypto_core.h"
4
5#include <gtest/gtest.h>
6
7TEST(Util, UnixTimeIncreasesOverTime)
8{
9 unix_time_update();
10 uint64_t const start = unix_time();
11
12 while (start == unix_time()) {
13 unix_time_update();
14 }
15
16 uint64_t const end = unix_time();
17 EXPECT_GT(end, start);
18}
19
20TEST(Util, IsTimeout)
21{
22 uint64_t const start = unix_time();
23 EXPECT_FALSE(is_timeout(start, 1));
24
25 while (start == unix_time()) {
26 unix_time_update();
27 }
28
29 EXPECT_TRUE(is_timeout(start, 1));
30}
31
32TEST(Util, TwoRandomIdsAreNotEqual)
33{
34 uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE];
35 uint8_t sk1[CRYPTO_SECRET_KEY_SIZE];
36 uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE];
37 uint8_t sk2[CRYPTO_SECRET_KEY_SIZE];
38
39 crypto_new_keypair(pk1, sk1);
40 crypto_new_keypair(pk2, sk2);
41
42 EXPECT_FALSE(id_equal(pk1, pk2));
43}
44
45TEST(Util, IdCopyMakesKeysEqual)
46{
47 uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE];
48 uint8_t sk1[CRYPTO_SECRET_KEY_SIZE];
49 uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE] = {0};
50
51 crypto_new_keypair(pk1, sk1);
52 id_copy(pk2, pk1);
53
54 EXPECT_TRUE(id_equal(pk1, pk2));
55}