mirror of
https://github.com/TokTok/c-toxcore
synced 2026-04-25 19:52:17 +00:00
* Use-after-free because we free network before dht in one case. * Various unchecked allocs in tests (not so important). * We used to not check whether ping arrays were actually allocated in DHT. * `ping_kill` and `ping_array_kill` used to crash when passing NULL. Also: * Added an assert in all public API functions to ensure tox isn't NULL. The error message you get from that is a bit nicer than "Segmentation fault" when clients (or our tests) do things wrong. * Decreased the sleep time in iterate_all_wait from 20ms to 5ms. Everything seems to still work with 5ms, and this greatly decreases the amount of time spent per test run, making oomer run much faster.
33 lines
650 B
C++
33 lines
650 B
C++
#include "util.h"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "crypto_core.h"
|
|
|
|
namespace {
|
|
|
|
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));
|
|
}
|
|
|
|
} // namespace
|