qid_gen_unittest.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  15. //
  16. // Permission to use, copy, modify, and/or distribute this software for any
  17. // purpose with or without fee is hereby granted, provided that the above
  18. // copyright notice and this permission notice appear in all copies.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  21. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  22. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  23. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  25. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  26. // PERFORMANCE OF THIS SOFTWARE.
  27. /// \brief Test of QidGenerator
  28. ///
  29. #include <gtest/gtest.h>
  30. #include <util/random/qid_gen.h>
  31. using namespace isc::util::random;
  32. // Tests the operation of the Qid generator
  33. // Check that getInstance returns a singleton
  34. TEST(QidGenerator, singleton) {
  35. QidGenerator& g1 = QidGenerator::getInstance();
  36. QidGenerator& g2 = QidGenerator::getInstance();
  37. EXPECT_TRUE(&g1 == &g2);
  38. }
  39. TEST(QidGenerator, generate) {
  40. // We'll assume that boost's generator is 'good enough', and won't
  41. // do full statistical checking here. Let's just call it the xkcd
  42. // test (http://xkcd.com/221/), and check if three consecutive
  43. // generates are not all the same.
  44. uint16_t one, two, three;
  45. QidGenerator& gen = QidGenerator::getInstance();
  46. one = gen.generateQid();
  47. two = gen.generateQid();
  48. three = gen.generateQid();
  49. ASSERT_FALSE((one == two) && (one == three));
  50. }