• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test/TestDesStream.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
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