streamencoding.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.org
00003      Copyright (C) 1994-2010  Martin Bickel
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 #include "streamencoding.h"
00022 #include "basestrm.h"
00023             
00024 
00025 void testStreamEncoding1()
00026 {
00027    const int maxsize = 100000;
00028    char buffer[maxsize];
00029 
00030    int size;
00031 
00032    {
00033       tnfilestream stream ( "asc2_dlg.zip", tnstream::reading );
00034       size = stream.readdata(buffer, maxsize, false );
00035    }
00036 
00037    ASCString encodedData;
00038 
00039    {
00040       ASCIIEncodingStream stream;
00041       stream.writedata(buffer, size);
00042       encodedData = stream.getResult();
00043    }
00044 
00045    {
00046       char buffer2[maxsize];
00047 
00048       ASCIIDecodingStream stream ( encodedData );
00049 
00050       int size2 = stream.readdata( buffer2, size, true);
00051       assertOrThrow( size2 == size );
00052 
00053       for ( int i = 0; i < size; ++i )
00054          if ( buffer[i] != buffer2[i] )
00055             throw ASCmsgException( "ASCII Encoding/Decoding failed at offset " + ASCString::toString(i));
00056    }
00057 }
00058 
00059 void testStreamEncoding2()
00060 {
00061    const int maxsize = 100000;
00062    char buffer[maxsize];
00063 
00064    int size;
00065 
00066    {
00067       tnfilestream stream ( "asc2_dlg.zip", tnstream::reading );
00068       size = stream.readdata(buffer, maxsize, false );
00069    }
00070 
00071    ASCString encodedData;
00072 
00073    {
00074       ASCIIEncodingStream outerStream;
00075       StreamCompressionFilter stream( &outerStream );
00076       stream.writedata(buffer, size);
00077       stream.close();
00078 
00079       encodedData = outerStream.getResult();
00080    }
00081 
00082    {
00083       char buffer2[maxsize];
00084 
00085       ASCIIDecodingStream outerStream ( encodedData );
00086       StreamDecompressionFilter stream( &outerStream );
00087 
00088       int size2 = stream.readdata( buffer2, size, true);
00089       assertOrThrow( size2 == size );
00090 
00091       for ( int i = 0; i < size; ++i )
00092          if ( buffer[i] != buffer2[i] )
00093             throw ASCmsgException( "ASCII Encoding/Decoding failed at offset " + ASCString::toString(i));
00094    }
00095 
00096 }
00097 
00098 void testStreamEncoding()
00099 {
00100    testStreamEncoding1();
00101    testStreamEncoding2();
00102 }

Generated on Mon May 21 01:26:37 2012 for Advanced Strategic Command by  doxygen 1.5.1