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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27