Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012
00013 #include "perf/perf.h"
00014 #include "util/uuid.h"
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 static void
00025 doTest
00026 (
00027 IN int nUUIDs
00028 )
00029 {
00030 ASSERT(nUUIDs > 0, "bad count: %d", nUUIDs);
00031 ASSERT(nUUIDs < 1000 * 1000, "too many: %d", nUUIDs);
00032
00033 SetString seen;
00034 char buffer[eUUID_Length];
00035
00036 for (int i = 0; i < nUUIDs; ++i) {
00037 const char * val = generateUUID(buffer);
00038 ASSERT_THROW(seen.end() == seen.find(val),
00039 "generated a duplicate uuid: " << val);
00040 seen.insert(val);
00041 }
00042
00043 int nPrint = 32;
00044 DPRINTF("Printing first %d uuids...", nPrint);
00045 SetString::const_iterator i = seen.begin();
00046 while (nPrint > 0 && seen.end() != i) {
00047 const char * uuid = i->c_str();
00048 DPRINTF(" '%s'", uuid);
00049 ++i;
00050 --nPrint;
00051 }
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 int
00063 main
00064 (
00065 IN int argc,
00066 IN const char * argv[]
00067 )
00068 {
00069 int retval = 0;
00070 ASSERT(2 == argc, "Usage: util-uuid-test <nUUIDs>");
00071 int nUUIDs = atoi(argv[1]);
00072 DPRINTF("Testing generation of %d UUIDs", nUUIDs);
00073
00074 try {
00075 perf::Timer timer("overall timer");
00076
00077 doTest(nUUIDs);
00078
00079 } catch (std::exception& e) {
00080 DPRINTF("Exception: %s", e.what());
00081 retval = 1;
00082 }
00083
00084 perf::dumpTimingSummary(std::cerr);
00085
00086 return retval;
00087 }
00088