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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5934 - (show annotations) (download)
Thu Feb 16 23:58:28 2006 UTC (13 years, 9 months ago) by dworley
File MIME type: text/plain
File size: 4665 byte(s)
Start cleaning up svn:mime-type in files.

1 #include <stdlib.h>
2 #ifdef WIN32
3 #include <io.h>
4 #else
5 #include <unistd.h>
6 #endif
7 #include <cassert>
8 #include <memory>
9
10 #include "rutil/compat.hxx"
11 #include "rutil/Random.hxx"
12 #include "rutil/Coders.hxx"
13 #include <iostream>
14
15 #ifdef __FreeBSD__
16 #define NEW_THROWS 1
17 #else
18 #define NEW_THROWS 0
19 #endif
20
21 using namespace std;
22 using namespace resip;
23
24
25 Data* randomData(int size)
26 {
27 unsigned char * p = new unsigned char[size];
28
29 for(int i = 0 ; i < size; i++)
30 {
31 p[i] = static_cast<unsigned char>(Random::getRandom()&0xff);
32 }
33
34 return new Data(p,size);
35 }
36
37
38 void showData(const Data& data)
39 {
40 cout << "Data (n=" << data.size() << "): ";
41 for(Data::size_type i = 0 ; i < data.size() ; i++)
42 {
43 cout << hex << (unsigned int)(((unsigned char *)(data.data()))[i]) << ' ';
44 }
45 cout << dec << endl;
46 }
47
48 void showCoded(const Data& data)
49 {
50 showData(data);
51 }
52
53 int compareData(const Data &a, const Data& b)
54 {
55 return a == b;
56 }
57
58 int
59 main()
60 {
61 using namespace resip;
62
63 assert(sizeof(size_t) == sizeof(void*));
64
65 Data testData("The quick brown fox jumped over the lazy dog.");
66
67 Data encoded =
68 Base64Coder::encode(testData);
69
70 Data decoded = Base64Coder::decode(encoded);
71
72 cout << "encoded: '" << encoded << "'" << endl;
73 cout << "decoded: '" << decoded << "'" << endl;
74
75
76 testData = Data("1");
77
78 encoded =
79 Base64Coder::encode(testData);
80
81 decoded = Base64Coder::decode(encoded);
82
83 cout << "encoded: '" << encoded << "'" << endl;
84 cout << "decoded: '" << decoded << "'" << endl;
85
86
87 int rVal = 0; // test return val
88 for(int i=1;i<320;i++)
89 {
90 Data* originalData = randomData(i);
91
92 cout << i << "-------" << endl;
93
94
95 // encrypt this data
96
97 Data coded = Base64Coder::encode(*originalData);
98
99 showData(*originalData);
100
101 Data decoded = Base64Coder::decode(coded);
102
103 showData(decoded);
104
105 assert(originalData->size() == decoded.size());
106
107 cout << "encoded: " << coded << endl;
108
109 int b = 0;
110 if ( *originalData != decoded )
111 {
112 cout << i << ": symetry failure (encode/decode) at byte " << -b-1 << endl;
113 rVal = -1;
114 }
115 delete originalData;
116 }
117 return rVal;
118
119 }
120 // Local Variables:
121 // mode:c++
122 // c-file-style:"ellemtel"
123 // c-file-offsets:((case-label . +))
124 // indent-tabs-mode:nil
125 // End
126 /* ====================================================================
127 * The Vovida Software License, Version 1.0
128 *
129 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
130 *
131 * Redistribution and use in source and binary forms, with or without
132 * modification, are permitted provided that the following conditions
133 * are met:
134 *
135 * 1. Redistributions of source code must retain the above copyright
136 * notice, this list of conditions and the following disclaimer.
137 *
138 * 2. Redistributions in binary form must reproduce the above copyright
139 * notice, this list of conditions and the following disclaimer in
140 * the documentation and/or other materials provided with the
141 * distribution.
142 *
143 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
144 * and "Vovida Open Communication Application Library (VOCAL)" must
145 * not be used to endorse or promote products derived from this
146 * software without prior written permission. For written
147 * permission, please contact vocal@vovida.org.
148 *
149 * 4. Products derived from this software may not be called "VOCAL", nor
150 * may "VOCAL" appear in their name, without prior written
151 * permission of Vovida Networks, Inc.
152 *
153 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
154 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
155 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
156 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
157 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
158 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
159 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
160 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
161 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
162 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
163 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
164 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
165 * DAMAGE.
166 *
167 * ====================================================================
168 *
169 * This software consists of voluntary contributions made by Vovida
170 * Networks, Inc. and many individuals on behalf of Vovida Networks,
171 * Inc. For more information on Vovida Networks, Inc., please see
172 * <http://www.vovida.org/>.
173 *
174 */

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