00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018 #ifdef DEBUG
00019
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 #include <spl/io/DesStream.h>
00023 #include <spl/Log.h>
00024 #include <spl/io/Stream.h>
00025 #include <spl/io/MemoryStream.h>
00026
00027 static void _TestDesStream1()
00028 {
00029 MemoryStreamPtr ms = MemoryStreamPtr(new MemoryStream());
00030 DesStream ds("the password", ms);
00031
00032 DEBUG_CLEAR_MEM_CHECK_POINTS();
00033 ds.CheckMem();
00034 DEBUG_DUMP_MEM_LEAKS();
00035 UNIT_ASSERT_MEM_NOTED("DesStream test 1.1");
00036
00037 const byte *txt = (const byte *)"the time has come, said the walrus.....";
00038 Array<byte> txta(txt, (int)strlen((const char *)txt)+1);
00039 UNIT_ASSERT("txt should be 40 chars", strlen((const char *)txt) == 39);
00040
00041 ds.Write(txta, 0, 40);
00042 DEBUG_CLEAR_MEM_CHECK_POINTS();
00043 ds.CheckMem();
00044 txta.CheckMem();
00045 DEBUG_DUMP_MEM_LEAKS();
00046 UNIT_ASSERT_MEM_NOTED("DesStream test 1.2");
00047
00048 Array<byte> buf(41);
00049 ds.Read(buf, 0, 40);
00050 UNIT_ASSERT("decryption failed", strcmp((char *)buf.Data(), (const char *)txt) == 0);
00051
00052 DEBUG_CLEAR_MEM_CHECK_POINTS();
00053 ds.CheckMem();
00054 txta.CheckMem();
00055 buf.CheckMem();
00056 DEBUG_DUMP_MEM_LEAKS();
00057 UNIT_ASSERT_MEM_NOTED("DesStream test 1.3");
00058
00059 Log::SWriteOkFail( "DesStream test 1" );
00060 }
00061
00062 void _TestDesStream()
00063 {
00064 _TestDesStream1();
00065 DEBUG_CLEAR_MEM_CHECK_POINTS();
00066 DEBUG_DUMP_MEM_LEAKS();
00067 }
00068
00069 #endif