diff options
Diffstat (limited to 'src/lib/dns/tests/qid_gen_unittest.cc')
-rw-r--r-- | src/lib/dns/tests/qid_gen_unittest.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lib/dns/tests/qid_gen_unittest.cc b/src/lib/dns/tests/qid_gen_unittest.cc new file mode 100644 index 0000000..20a2dfa --- /dev/null +++ b/src/lib/dns/tests/qid_gen_unittest.cc @@ -0,0 +1,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)); +} |