|
reSIProcate/rutil
9694
|
#include <stdlib.h>#include <unistd.h>#include <cassert>#include <memory>#include "rutil/compat.hxx"#include "rutil/Random.hxx"#include "rutil/Coders.hxx"#include <iostream>
Go to the source code of this file.
Defines | |
| #define | NEW_THROWS 0 |
Functions | |
| Data * | randomData (int size) |
| void | showData (const Data &data) |
| void | showCoded (const Data &data) |
| int | compareData (const Data &a, const Data &b) |
| int | main () |
| #define NEW_THROWS 0 |
Definition at line 18 of file testCoders.cxx.
Definition at line 53 of file testCoders.cxx.
{
return a == b;
}
| int main | ( | void | ) |
Definition at line 59 of file testCoders.cxx.
References encode(), randomData(), showData(), and resip::Data::size().
{
using namespace resip;
assert(sizeof(size_t) == sizeof(void*));
Data testData("The quick brown fox jumped over the lazy dog.");
Data encoded =
Base64Coder::encode(testData);
Data decoded = Base64Coder::decode(encoded);
cout << "encoded: '" << encoded << "'" << endl;
cout << "decoded: '" << decoded << "'" << endl;
testData = Data("1");
encoded =
Base64Coder::encode(testData);
decoded = Base64Coder::decode(encoded);
cout << "encoded: '" << encoded << "'" << endl;
cout << "decoded: '" << decoded << "'" << endl;
int rVal = 0; // test return val
for(int i=1;i<320;i++)
{
Data* originalData = randomData(i);
cout << i << "-------" << endl;
// encrypt this data
Data coded = Base64Coder::encode(*originalData);
showData(*originalData);
Data decoded = Base64Coder::decode(coded);
showData(decoded);
assert(originalData->size() == decoded.size());
cout << "encoded: " << coded << endl;
int b = 0;
if ( *originalData != decoded )
{
cout << i << ": symetry failure (encode/decode) at byte " << -b-1 << endl;
rVal = -1;
}
delete originalData;
}
return rVal;
}

| Data* randomData | ( | int | size | ) |
Definition at line 25 of file testCoders.cxx.
Referenced by main().
{
unsigned char * p = new unsigned char[size];
for(int i = 0 ; i < size; i++)
{
p[i] = static_cast<unsigned char>(Random::getRandom()&0xff);
}
return new Data(p,size);
}
| void showCoded | ( | const Data & | data | ) |
Definition at line 48 of file testCoders.cxx.
References showData().
{
showData(data);
}

| void showData | ( | const Data & | data | ) |
Definition at line 38 of file testCoders.cxx.
References resip::Data::data(), and resip::Data::size().
Referenced by main(), and showCoded().
{
cout << "Data (n=" << data.size() << "): ";
for(Data::size_type i = 0 ; i < data.size() ; i++)
{
cout << hex << (unsigned int)(((unsigned char *)(data.data()))[i]) << ' ';
}
cout << dec << endl;
}

1.7.5.1