File: util_test.cc

package info (click to toggle)
libtoxcore 0.2.20-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,124 kB
  • sloc: ansic: 75,034; cpp: 4,933; sh: 1,115; python: 651; makefile: 329; perl: 39
file content (48 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "util.h"

#include <gtest/gtest.h>

#include "crypto_core.h"
#include "crypto_core_test_util.hh"

namespace {

TEST(Util, TwoRandomIdsAreNotEqual)
{
    Test_Random rng;
    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(rng, pk1, sk1);
    crypto_new_keypair(rng, pk2, sk2);

    EXPECT_FALSE(pk_equal(pk1, pk2));
}

TEST(Util, IdCopyMakesKeysEqual)
{
    Test_Random rng;
    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(rng, pk1, sk1);
    pk_copy(pk2, pk1);

    EXPECT_TRUE(pk_equal(pk1, pk2));
}

TEST(Cmp, OrdersNumbersCorrectly)
{
    EXPECT_EQ(cmp_uint(1, 2), -1);
    EXPECT_EQ(cmp_uint(0, UINT32_MAX), -1);
    EXPECT_EQ(cmp_uint(UINT32_MAX, 0), 1);
    EXPECT_EQ(cmp_uint(UINT32_MAX, UINT32_MAX), 0);
    EXPECT_EQ(cmp_uint(0, UINT64_MAX), -1);
    EXPECT_EQ(cmp_uint(UINT64_MAX, 0), 1);
    EXPECT_EQ(cmp_uint(UINT64_MAX, UINT64_MAX), 0);
}

}  // namespace