/[resiprocate]/main/rutil/test/testRandomHex.cxx
ViewVC logotype

Contents of /main/rutil/test/testRandomHex.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8409 - (show annotations) (download)
Wed Jan 28 23:32:08 2009 UTC (10 years, 11 months ago) by adam
File MIME type: text/plain
File size: 3832 byte(s)
Checking in Gregor Jasny's proposed changes to use tr1 hash implementation with gcc >= 4.3

1 #include <cstdlib>
2 #include <iostream>
3 #include <set>
4
5 #include "rutil/Data.hxx"
6 #include "rutil/Random.hxx"
7
8 using namespace std;
9 using namespace resip;
10
11 int main(int argc, char** argv)
12 {
13 int runs = 1000;
14 int length = 8;
15
16 if(argc == 3)
17 {
18 runs = atoi(argv[1]);
19 length = atoi(argv[2]);
20 }
21
22 //Random::initialize();
23
24 if (runs <= 0 || length <= 0)
25 {
26 cerr << "usage: testRandomHex number_of_tries string_length" << endl
27 << "number_of_tries and string_length must be a positive integers." << endl;
28 exit(-1);
29 }
30
31 cerr << "Generating " << runs << " random " << length << " byte strings and checking for uniqueness." << endl;
32
33 set<Data> randomDatas;
34
35 for (int i = 0; i < runs; i++)
36 {
37 Data foo = Random::getRandomHex(length/2);
38 cerr << foo << endl;
39 if (randomDatas.insert(foo).second == false)
40 {
41 cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl;
42 exit(-1);
43 }
44 }
45
46 cerr << endl << "Now doing crypto random" << endl;
47
48 for (int i = 0; i < runs; i++)
49 {
50 Data foo = Random::getCryptoRandomHex(length/2);
51 cerr << foo << endl;
52 if (randomDatas.insert(foo).second == false)
53 {
54 cerr << "RandomHex produced a duplicate" << length << "byte string after " << i << " runs. " << endl;
55 exit(-1);
56 }
57 }
58
59 cerr << "Success." << endl;
60 return 0;
61 }
62
63
64 /* ====================================================================
65 * The Vovida Software License, Version 1.0
66 *
67 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
68 *
69 * Redistribution and use in source and binary forms, with or without
70 * modification, are permitted provided that the following conditions
71 * are met:
72 *
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 *
76 * 2. Redistributions in binary form must reproduce the above copyright
77 * notice, this list of conditions and the following disclaimer in
78 * the documentation and/or other materials provided with the
79 * distribution.
80 *
81 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
82 * and "Vovida Open Communication Application Library (VOCAL)" must
83 * not be used to endorse or promote products derived from this
84 * software without prior written permission. For written
85 * permission, please contact vocal@vovida.org.
86 *
87 * 4. Products derived from this software may not be called "VOCAL", nor
88 * may "VOCAL" appear in their name, without prior written
89 * permission of Vovida Networks, Inc.
90 *
91 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
92 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
93 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
94 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
95 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
96 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
97 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
98 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
99 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
100 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
102 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
103 * DAMAGE.
104 *
105 * ====================================================================
106 *
107 * This software consists of voluntary contributions made by Vovida
108 * Networks, Inc. and many individuals on behalf of Vovida Networks,
109 * Inc. For more information on Vovida Networks, Inc., please see
110 * <http://www.vovida.org/>.
111 *
112 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27