Advertisement
Guest User

Greg Christopher

a guest
May 19th, 2009
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. // breakboost.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6.  
  7. #define BOOST_TEST_MODULE SVGADTCT_TEST
  8. #define BOOST_TEST_NO_MAIN
  9. #ifdef BOOST_TEST_MODULE
  10. #include <boost/test/included/unit_test.hpp>
  11. using namespace boost::unit_test;
  12.  
  13. //BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE);
  14. //BOOST_AUTO_TEST_SUITE_END()
  15.  
  16. int TestMain(); // In this situation there is a separate TestMain() from WinMain()
  17.  
  18. bool TestInit(); // Create stub initialization function for Boost.
  19. bool TestInit()
  20. {
  21.         //- Register test
  22.  
  23.     framework::master_test_suite().add( BOOST_TEST_CASE(TestMain) );
  24.  
  25.     return true;
  26. };
  27.  
  28. #endif
  29.  
  30. /*
  31.  * Prototypes --
  32.  */
  33.  
  34. static void Log(const char *fmt, ...);
  35.  
  36.  
  37. int _tmain(int argc, _TCHAR* argv[])
  38. {
  39. #ifdef BOOST_TEST_MODULE
  40.  
  41.         //- Call test framework
  42.  
  43.     ::boost::unit_test::unit_test_main( (boost::unit_test::init_unit_test_func) TestInit , __argc, __argv );
  44.  
  45.     return 0;
  46. } // _tmain
  47.  
  48. int TestMain()
  49. {
  50. #endif //BOOST_TEST_MODULE
  51.  
  52.  
  53.    Log("INFO, starting. \n");
  54.  
  55.  
  56.    Log("INFO, exit.\n");
  57.  
  58.    return 0;
  59. } //TestMain()
  60.  
  61. void
  62. Log(const char *fmt, ...)
  63. {
  64.    time_t timet;
  65.    struct tm stime;
  66.    char buffer[32];
  67.    va_list args;
  68.    static FILE *logFile = NULL;
  69.  
  70.    if (!logFile) {
  71.       fopen_s(&logFile, "svgadtct.log", "w");
  72.    }
  73.  
  74.    time(&timet);
  75.    localtime_s(&stime, &timet);
  76.    asctime_s(buffer, &stime);
  77.    buffer[24] = 0; // clobber the newline at the end of the date
  78.    fprintf(logFile, "%s: TEST| ", buffer);
  79.  
  80.  
  81.    va_start(args, fmt);
  82.    vfprintf(logFile, fmt, args);
  83.    char myOutputBuffer[1000] = {0};
  84.    _snprintf_s(myOutputBuffer,(size_t) 999, fmt, args);
  85.    if ( strstr(myOutputBuffer, "WARN") )
  86.    {
  87.        BOOST_WARN_MESSAGE(1, myOutputBuffer);
  88.    }
  89.    else if ( strstr(myOutputBuffer, "FAIL") )
  90.    {
  91.        BOOST_CHECK_MESSAGE(1, myOutputBuffer);
  92.    }
  93.    else //Everything else Plus ERROR
  94.    {
  95.        //-- Normally for ERROR would ask BOOST to abort by failing REQUIRE().
  96.        // Will let program handle control flow change since all ERROR conditions
  97.        // are properly handled by this framework.
  98.        BOOST_WARN_MESSAGE(1, myOutputBuffer);
  99.    }
  100.    va_end(args);
  101.  
  102.    fflush(logFile);
  103. } // Log()
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement