00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }