PLearn 0.1
assertions.cc
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <assert.h>
00003 #include <plearn/base/plerror.h>
00004 #include <assert.h> // NB: is there a reason to include assert.h at all?
00005 #include <string>
00006 
00007 // PLASSERT uses __FILE__ variable in its message, but we want the test
00008 // to have the same output, regardless of the absolute path of this file
00009 #undef __FILE__
00010 #define __FILE__ "assertions.cc"
00011 
00012 using namespace std;
00013 
00014 int main()
00015 {
00016   try {
00017     PLASSERT( 1 == 1 );
00018     PLASSERT( 3+8 == 123+46 );
00019   }
00020   catch (const PLearn::PLearnError& e)
00021   {
00022       string msg = e.message();
00023 #ifdef WIN32
00024       // This is a hack so that the test passes under Windows: the assert
00025       // code unfortunatley does not have access to the function name, and thus
00026       // displays '(null)' instead of the correct name.
00027       size_t pos = msg.find("(null)");
00028       if (pos != string::npos)
00029           msg = msg.replace(pos, 6, "int main()");
00030 
00031 #endif
00032     std::cerr << "FATAL ERROR: " << msg << std::endl;
00033   }
00034   return 0;
00035 }
00036 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines