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

test/TestException.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 #include <spl/Exception.h>
00019 #include <spl/Log.h>
00020 
00021 #ifdef _WINDOWS
00022 #include <spl/configwin32.h>
00023 #else
00024 #include <spl/autoconf/config.h>
00025 #endif
00026 
00027 #ifdef DEBUG
00028 
00029 void static _ExceptionTest1()
00030 {
00031         try
00032         {
00033                 throw new Exception("hi");
00034                 UNIT_ASSERT("Exception not thrown", false);
00035         }
00036         catch ( Exception )
00037         {
00038                 UNIT_ASSERT("Execption", false);
00039         }
00040         catch ( Exception *ex )
00041         {
00042                 delete ex;
00043                 return;
00044         }
00045         UNIT_TEST("Exception catch", false);
00046 }
00047 
00048 void static _ExceptionTest2()
00049 {
00050         try
00051         {
00052                 throw new InvalidArgumentException("hi");
00053                 UNIT_ASSERT("Exception not thrown", false);
00054         }
00055         catch ( Exception )
00056         {
00057                 UNIT_ASSERT("Execption", false);
00058         }
00059         catch ( Exception *ex )
00060         {
00061                 delete ex;
00062                 return;
00063         }
00064         UNIT_ASSERT("Exception not catched", false);
00065 }
00066 
00067 void static _ExceptionTest3()
00068 {
00069         try
00070         {
00071                 throw new SocketException("hi");
00072                 UNIT_ASSERT("Exception not thrown", false);
00073         }
00074         catch ( Exception )
00075         {
00076                 UNIT_ASSERT("Execption", false);
00077         }
00078         catch ( Exception *ex )
00079         {
00080                 delete ex;
00081                 return;
00082         }
00083         UNIT_ASSERT("Exception not catched", false);
00084 }
00085 
00086 void _ExceptionTestHarness()
00087 {
00088         _ExceptionTest1();
00089         Log::SWriteOkFail( "Exception 1" );
00090         DEBUG_CLEAR_MEM_CHECK_POINTS();
00091         DEBUG_DUMP_MEM_LEAKS();
00092         UNIT_ASSERT_MEM_NOTED("Exception Test 1");
00093 
00094         _ExceptionTest2();
00095         Log::SWriteOkFail( "Exception 2" );
00096         DEBUG_CLEAR_MEM_CHECK_POINTS();
00097         DEBUG_DUMP_MEM_LEAKS();
00098         UNIT_ASSERT_MEM_NOTED("Exception Test 2");
00099 
00100         _ExceptionTest3();
00101         Log::SWriteOkFail( "Exception 3" );
00102         DEBUG_CLEAR_MEM_CHECK_POINTS();
00103         DEBUG_DUMP_MEM_LEAKS();
00104         UNIT_ASSERT_MEM_NOTED("Exception Test 2");
00105 }
00106 
00107 #endif