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

src/cdebug.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 <stdio.h>
00018 
00019 #if defined(_WIN32) || defined(_WIN64)
00020 #include <spl/configwin32.h>
00021 #else
00022 #include <spl/autoconf/config.h>
00023 #endif
00024 
00025 #include <spl/Debug.h>
00026 #include <spl/Exception.h>
00027 #include <spl/Log.h>
00028 #include <spl/String.h>
00029 
00030 #if defined(DEBUG)
00031 
00032 void *operator new(size_t size)
00033 {
00034         return malloc( (int)size );
00035 }
00036 
00037 void operator delete(void *vp)
00038 {
00039         free( vp );
00040 }
00041 
00042 void *operator new[](size_t size)
00043 {
00044         void *mem = _debugMalloc( (int)size, __FILE__, __LINE__, true );
00045         return mem;
00046 }
00047 
00048 void operator delete[](void *vp)
00049 {
00050         free( vp );
00051 }
00052 
00053 void debugAssertCPP(const int cond, const char *file, const int line)
00054 {
00055         if ( !cond )
00056         {
00057                 char buf[1024];
00058                 sprintf(buf, "Assertion failed in %s on line %d", file, line);
00059                 throw new AssertionFailedException(buf);
00060         }
00061 }
00062 
00063 void _unitAssert( const char *msg, const int cond, const char *filename, const int lineno )
00064 {
00065         if ( cond == 0 )
00066         {
00067                 char buf[256];
00068                 sprintf(buf, "ASSERTION FAILED in %s, on line %d\n%s\n", filename, lineno, msg);
00069 
00070                 Log::SWriteError( buf );
00071 #ifdef __TANDEM
00072                 exit(20);
00073 #endif
00074         }
00075 }
00076 
00077 
00078 void _unitTest( const char *msg, const int cond)
00079 {
00080         Log::SWriteInfo(String::Format("%s ..... %s\n", msg, ((cond != 0) ? "ok" : "FAIL")));
00081 }
00082 
00083 #endif