1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*=========================================================================
Program: Image Guided Surgery Software Toolkit
Module: $RCSfile: igstkBinaryDataTest.cxx,v $
Language: C++
Date: $Date: 2008-07-14 16:11:45 $
Version: $Revision: 1.11 $
Copyright (c) ISC Insight Software Consortium. All rights reserved.
See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
// Warning about: identifier was truncated to '255' characters
// in the debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "igstkBinaryData.h"
#include "igstkRealTimeClock.h"
int igstkBinaryDataTest( int, char * [] )
{
igstk::RealTimeClock::Initialize();
try
{
std::cout << "Testing igstk::BinaryData" << std::endl;
/* creating binary data objects */
igstk::BinaryData data;
igstk::BinaryData data2;
igstk::BinaryData data3;
std::string encoded;
/* creating an array */
unsigned char buffer[201];
/* allocating memory and assigning data */
data.SetSize(11);
data2.SetSize(201);
unsigned int i;
for( i = 0; i < 10; ++i )
{
data[i] = (unsigned char)i + '0';
}
data[10] = 0;
for( i = 0; i < 200; ++i )
{
data2[i] = (unsigned char)i + 1;
}
data2[200] = 0;
/* copy data into an array */
data2.CopyTo(buffer);
/* print objects out */
std::cout << "data: " << data << std::endl;
std::cout << "data2: " << data2 << std::endl;
std::cout << "buffer: " << buffer << std::endl;
/* copy data from an array */
data3.CopyFrom(buffer, data2.GetSize());
std::cout << "data3: " << data3 << std::endl;
encoded = data3;
std::cout << "encoded: " << encoded << std::endl;
igstk::BinaryData data4(encoded);
std::cout << "data4: " << data4 << std::endl;
igstk::BinaryData data5("\\\\abc\\x37");
std::cout << "data5: " << data5 << std::endl;
unsigned char array[] = "124897as";
data5.Append(array, strlen((const char*)array));
std::cout << "data5: " << data5 << std::endl;
/* get container objects */
const igstk::BinaryData::ContainerType& obj = data.GetData();
igstk::BinaryData::ContainerType& obj2 = data.GetData();
/* Compare the containers sizes.*/
if( obj.size() != obj2.size() )
{
std::cerr << "GetData() const and non-const methods are not consistent"
<< std::endl;
return EXIT_FAILURE;
}
/* comparison operator tests */
if( data == data2 )
{
std::cerr << "operator== failed !!" << std::endl;
return EXIT_FAILURE;
}
if( data != data2 )
{
}
else
{
std::cerr << "operator!= failed !!" << std::endl;
return EXIT_FAILURE;
}
if( data < data2 )
{
std::cerr << "operator< failed !!" << std::endl;
return EXIT_FAILURE;
}
else
{
}
data.SetSize(2);
data2.SetSize(3);
data[0] = '\\';
data[1] = 0;
data2[0] = '\\';
data2[1] = 0;
data2[2] = 0;
std::cout << data << std::endl;
bool less = (data < data2);
if( !less )
{
std::cerr << "operator< failed !!" << std::endl;
return EXIT_FAILURE;
}
}
catch(...)
{
std::cerr << "Exception catched !!" << std::endl;
return EXIT_FAILURE;
}
std::cout << "[PASSED]" << std::endl;
return EXIT_SUCCESS;
}
|