diff options
author | aunsane <aunsane@gmail.com> | 2018-03-03 16:35:09 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-03-03 16:35:33 +0300 |
commit | fa58f69fe117640e29cefb1b699bede4d045bc2f (patch) | |
tree | a1bf8406d63e2b246bebdc572ceccfaabcffa359 /protocols/Tox/libtox/src/toxcore/util_test.cpp | |
parent | 0e8f5a3aa5f5e73b413c5646444751783e367f2b (diff) |
Tox:
- updated toxcore due to release v0.2
- removed message correction
- reworked nodes update
Diffstat (limited to 'protocols/Tox/libtox/src/toxcore/util_test.cpp')
-rw-r--r-- | protocols/Tox/libtox/src/toxcore/util_test.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/protocols/Tox/libtox/src/toxcore/util_test.cpp b/protocols/Tox/libtox/src/toxcore/util_test.cpp new file mode 100644 index 0000000000..8de6384848 --- /dev/null +++ b/protocols/Tox/libtox/src/toxcore/util_test.cpp @@ -0,0 +1,55 @@ +#include "util.h" + +#include "crypto_core.h" + +#include <gtest/gtest.h> + +TEST(Util, UnixTimeIncreasesOverTime) +{ + unix_time_update(); + uint64_t const start = unix_time(); + + while (start == unix_time()) { + unix_time_update(); + } + + uint64_t const end = unix_time(); + EXPECT_GT(end, start); +} + +TEST(Util, IsTimeout) +{ + uint64_t const start = unix_time(); + EXPECT_FALSE(is_timeout(start, 1)); + + while (start == unix_time()) { + unix_time_update(); + } + + EXPECT_TRUE(is_timeout(start, 1)); +} + +TEST(Util, TwoRandomIdsAreNotEqual) +{ + uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t sk1[CRYPTO_SECRET_KEY_SIZE]; + uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t sk2[CRYPTO_SECRET_KEY_SIZE]; + + crypto_new_keypair(pk1, sk1); + crypto_new_keypair(pk2, sk2); + + EXPECT_FALSE(id_equal(pk1, pk2)); +} + +TEST(Util, IdCopyMakesKeysEqual) +{ + uint8_t pk1[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t sk1[CRYPTO_SECRET_KEY_SIZE]; + uint8_t pk2[CRYPTO_PUBLIC_KEY_SIZE] = {0}; + + crypto_new_keypair(pk1, sk1); + id_copy(pk2, pk1); + + EXPECT_TRUE(id_equal(pk1, pk2)); +} |