summaryrefslogtreecommitdiffstats
path: root/src/lib/dns/tests/qid_gen_unittest.cc
blob: 20a2dfa13118ec7dfed6a8afe442582d17099667 (plain)
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
// Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

/// \brief Test of QidGenerator
///

#include <config.h>

#include <gtest/gtest.h>

#include <dns/qid_gen.h>

using namespace isc::dns;

// Tests the operation of the Qid generator

// Check that getInstance returns a singleton
TEST(QidGenerator, singleton) {
    QidGenerator& g1 = QidGenerator::getInstance();
    QidGenerator& g2 = QidGenerator::getInstance();

    EXPECT_TRUE(&g1 == &g2);
}

TEST(QidGenerator, generate) {
    // We'll assume that cryptolink's generator is 'good enough', and won't
    // do full statistical checking here. Let's just call it the xkcd
    // test (http://xkcd.com/221/), and check if three consecutive
    // generates are not all the same.
    uint16_t one, two, three;
    QidGenerator& gen = QidGenerator::getInstance();
    one = gen.generateQid();
    two = gen.generateQid();
    three = gen.generateQid();
    ASSERT_FALSE((one == two) && (one == three));
}