Ejemplo n.º 1
0
/**** Global functions definitions.   ****/
ErrorNumber allocLib( TA_UDBase **uDBasePtr )
{
   TA_InitializeParam initializeParam;
   TA_RetCode retCode;
   TA_UDBase *uDBase;

   /* Initialize the library. */
   memset( &initializeParam, 0, sizeof( TA_InitializeParam ) );
   initializeParam.logOutput = stdout;

   retCode = TA_Initialize( &initializeParam );
   if( retCode != TA_SUCCESS )
   {
      printf( "TA_Initialize failed [%d]\n", retCode );
      return TA_TESTUTIL_INIT_FAILED;
   }
   
   /* Install a fatal error handler. */
   retCode = TA_SetFatalErrorHandler( myFatalHandler );
   if( retCode != TA_SUCCESS )
   {
      printf( "TA_SetFatalErrorHandler failed [%d]\n", retCode );
      TA_Shutdown();
      return TA_TESTUTIL_SET_FATAL_ERROR_FAILED;
   }
      
   /* Create an unified database. */
   retCode = TA_UDBaseAlloc( &uDBase );
   if( retCode != TA_SUCCESS )
   {
      printf( "TA_UDBaseAlloc failed [%d]\n", retCode );
      TA_Shutdown();
      return TA_TESTUTIL_UDBASE_ALLOC_FAILED;
   }

   *uDBasePtr = uDBase;

   return TA_TEST_PASS;
}
Ejemplo n.º 2
0
static ErrorNumber testFatalErrors( void )
{
   TA_RetCode retCode;
   TA_UDBase *uDBase;
   ErrorNumber retValue;
   char *b;

   /* Initialize the library. */
   retValue = allocLib( &uDBase );
   if( retValue != TA_TEST_PASS )
   {
      printf( "\ntestFatalErrors Failed: Can't initialize the library\n" );
      return retValue;
   }

   TA_SetFatalErrorHandler( NULL );

   retCode = TA_RegressionTest(TA_REG_TEST_FATAL_ERROR);
   if( retCode != TA_FATAL_ERR )
      return TA_FATAL_TST_FAIL;

   /* After a function returns a TA_FATAL_ERR, further
    * information can be obtained with TA_FatalReportToBuffer()
    * and/or TA_FatalReport().
    *
    * These functions returns the info only about the LAST
    * recorded fatal error. To more easily record all the fatal
    * error, you should install a fatal error handler and call
    * the TA_FatalReportXXXX() function from the handler.
    *
    * You can monitor what is getting in the buffer by 
    * un-commenting the printf.
    *      
    */
   b = (char *)TA_Malloc(TA_FATAL_ERROR_BUF_SIZE);
   if( b )
   {
      TA_FatalReportToBuffer( b, TA_FATAL_ERROR_BUF_SIZE );
      /* printf( b ); */
   }
   TA_Free(b);

   retValue = freeLib( uDBase );
   if( retValue != TA_TEST_PASS )
      return retValue;

   retValue = allocLib( &uDBase );
   if( retValue != TA_TEST_PASS )
   {
      printf( "\ntestFatalErrors Failed: Can't initialize the library\n" );
      return retValue;
   }

   TA_SetFatalErrorHandler( NULL );

   retCode = TA_RegressionTest(TA_REG_TEST_ASSERT_FAIL);
   if( retCode != TA_FATAL_ERR )
      return TA_ASSERT_TST_FAIL;

   retValue = freeLib( uDBase );
   if( retValue != TA_TEST_PASS )
      return retValue;

   return TA_TEST_PASS; /* Success. */
}