1 // Copyright (C) 2011-2021 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 /// \brief Test of QidGenerator
8 ///
9 
10 #include <config.h>
11 
12 #include <gtest/gtest.h>
13 
14 #include <dns/qid_gen.h>
15 
16 using namespace isc::dns;
17 
18 // Tests the operation of the Qid generator
19 
20 // Check that getInstance returns a singleton
TEST(QidGenerator,singleton)21 TEST(QidGenerator, singleton) {
22     QidGenerator& g1 = QidGenerator::getInstance();
23     QidGenerator& g2 = QidGenerator::getInstance();
24 
25     EXPECT_TRUE(&g1 == &g2);
26 }
27 
TEST(QidGenerator,generate)28 TEST(QidGenerator, generate) {
29     // We'll assume that cryptolink's generator is 'good enough', and won't
30     // do full statistical checking here. Let's just call it the xkcd
31     // test (http://xkcd.com/221/), and check if three consecutive
32     // generates are not all the same.
33     uint16_t one, two, three;
34     QidGenerator& gen = QidGenerator::getInstance();
35     one = gen.generateQid();
36     two = gen.generateQid();
37     three = gen.generateQid();
38     ASSERT_FALSE((one == two) && (one == three));
39 }
40