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