/* Return 1 on success */ ErrorNumber checkSameContent( TA_Real *buffer1, TA_Real *buffer2 ) { const TA_Real *theBuffer1; const TA_Real *theBuffer2; unsigned int i; theBuffer1 = buffer1 - TA_BUF_PREFIX; theBuffer2 = buffer2 - TA_BUF_PREFIX; for( i=0; i < TA_BUF_SIZE; i++ ) { if( (!trio_isnan(theBuffer1[i])) && (!trio_isinf(theBuffer1[i])) && (theBuffer1[i] != RESV_PATTERN_SUFFIX) && (theBuffer1[i] != RESV_PATTERN_PREFIX) ) { if(!TA_REAL_EQ( theBuffer1[i], theBuffer2[i], 0.000001)) { printf( "Fail: Large difference found between two value expected identical (%f,%f,%d)\n", theBuffer1[i], theBuffer2[i], i ); return TA_TEST_TFRR_CHECK_SAME_CONTENT; } } } return TA_TEST_PASS; }
int main(void) { double my_nan; double my_pinf; double my_ninf; # if defined(TRIO_PLATFORM_UNIX) void (*signal_handler)(int); # endif my_nan = trio_nan(); my_pinf = trio_pinf(); my_ninf = trio_ninf(); printf("NaN : %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d)\n", my_nan, ((unsigned char *)&my_nan)[0], ((unsigned char *)&my_nan)[1], ((unsigned char *)&my_nan)[2], ((unsigned char *)&my_nan)[3], ((unsigned char *)&my_nan)[4], ((unsigned char *)&my_nan)[5], ((unsigned char *)&my_nan)[6], ((unsigned char *)&my_nan)[7], trio_isnan(my_nan), trio_isinf(my_nan)); printf("PInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d)\n", my_pinf, ((unsigned char *)&my_pinf)[0], ((unsigned char *)&my_pinf)[1], ((unsigned char *)&my_pinf)[2], ((unsigned char *)&my_pinf)[3], ((unsigned char *)&my_pinf)[4], ((unsigned char *)&my_pinf)[5], ((unsigned char *)&my_pinf)[6], ((unsigned char *)&my_pinf)[7], trio_isnan(my_pinf), trio_isinf(my_pinf)); printf("NInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d)\n", my_ninf, ((unsigned char *)&my_ninf)[0], ((unsigned char *)&my_ninf)[1], ((unsigned char *)&my_ninf)[2], ((unsigned char *)&my_ninf)[3], ((unsigned char *)&my_ninf)[4], ((unsigned char *)&my_ninf)[5], ((unsigned char *)&my_ninf)[6], ((unsigned char *)&my_ninf)[7], trio_isnan(my_ninf), trio_isinf(my_ninf)); # if defined(TRIO_PLATFORM_UNIX) signal_handler = signal(SIGFPE, SIG_IGN); # endif my_pinf = DBL_MAX + DBL_MAX; my_ninf = -my_pinf; my_nan = my_pinf / my_pinf; # if defined(TRIO_PLATFORM_UNIX) signal(SIGFPE, signal_handler); # endif printf("NaN : %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d)\n", my_nan, ((unsigned char *)&my_nan)[0], ((unsigned char *)&my_nan)[1], ((unsigned char *)&my_nan)[2], ((unsigned char *)&my_nan)[3], ((unsigned char *)&my_nan)[4], ((unsigned char *)&my_nan)[5], ((unsigned char *)&my_nan)[6], ((unsigned char *)&my_nan)[7], trio_isnan(my_nan), trio_isinf(my_nan)); printf("PInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d)\n", my_pinf, ((unsigned char *)&my_pinf)[0], ((unsigned char *)&my_pinf)[1], ((unsigned char *)&my_pinf)[2], ((unsigned char *)&my_pinf)[3], ((unsigned char *)&my_pinf)[4], ((unsigned char *)&my_pinf)[5], ((unsigned char *)&my_pinf)[6], ((unsigned char *)&my_pinf)[7], trio_isnan(my_pinf), trio_isinf(my_pinf)); printf("NInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d)\n", my_ninf, ((unsigned char *)&my_ninf)[0], ((unsigned char *)&my_ninf)[1], ((unsigned char *)&my_ninf)[2], ((unsigned char *)&my_ninf)[3], ((unsigned char *)&my_ninf)[4], ((unsigned char *)&my_ninf)[5], ((unsigned char *)&my_ninf)[6], ((unsigned char *)&my_ninf)[7], trio_isnan(my_ninf), trio_isinf(my_ninf)); return 0; }
static ErrorNumber callWithDefaults( const char *funcName, const double *input, const int *input_int, int size ) { TA_ParamHolder *paramHolder; const TA_FuncHandle *handle; const TA_FuncInfo *funcInfo; const TA_InputParameterInfo *inputInfo; const TA_OutputParameterInfo *outputInfo; TA_RetCode retCode; unsigned int i; int j; int outBegIdx, outNbElement, lookback; retCode = TA_GetFuncHandle( funcName, &handle ); if( retCode != TA_SUCCESS ) { printf( "Can't get the function handle [%d]\n", retCode ); return TA_ABS_TST_FAIL_GETFUNCHANDLE; } retCode = TA_ParamHolderAlloc( handle, ¶mHolder ); if( retCode != TA_SUCCESS ) { printf( "Can't allocate the param holder [%d]\n", retCode ); return TA_ABS_TST_FAIL_PARAMHOLDERALLOC; } TA_GetFuncInfo( handle, &funcInfo ); for( i=0; i < funcInfo->nbInput; i++ ) { TA_GetInputParameterInfo( handle, i, &inputInfo ); switch(inputInfo->type) { case TA_Input_Price: TA_SetInputParamPricePtr( paramHolder, i, inputInfo->flags&TA_IN_PRICE_OPEN?input:NULL, inputInfo->flags&TA_IN_PRICE_HIGH?input:NULL, inputInfo->flags&TA_IN_PRICE_LOW?input:NULL, inputInfo->flags&TA_IN_PRICE_CLOSE?input:NULL, inputInfo->flags&TA_IN_PRICE_VOLUME?input_int:NULL, NULL ); break; case TA_Input_Real: TA_SetInputParamRealPtr( paramHolder, i, input ); break; case TA_Input_Integer: TA_SetInputParamIntegerPtr( paramHolder, i, input_int ); break; } } for( i=0; i < funcInfo->nbOutput; i++ ) { TA_GetOutputParameterInfo( handle, i, &outputInfo ); switch(outputInfo->type) { case TA_Output_Real: TA_SetOutputParamRealPtr(paramHolder,i,&output[i][0]); for( j=0; j < 2000; j++ ) output[i][j] = TA_REAL_MIN; break; case TA_Output_Integer: TA_SetOutputParamIntegerPtr(paramHolder,i,&output_int[i][0]); for( j=0; j < 2000; j++ ) output_int[i][j] = TA_INTEGER_MIN; break; } } /* Do the function call. */ retCode = TA_CallFunc(paramHolder,0,size-1,&outBegIdx,&outNbElement); if( retCode != TA_SUCCESS ) { printf( "TA_CallFunc() failed zero data test [%d]\n", retCode ); TA_ParamHolderFree( paramHolder ); return TA_ABS_TST_FAIL_CALLFUNC_1; } /* Verify consistency with Lookback */ retCode = TA_GetLookback( paramHolder, &lookback ); if( retCode != TA_SUCCESS ) { printf( "TA_GetLookback() failed zero data test [%d]\n", retCode ); TA_ParamHolderFree( paramHolder ); return TA_ABS_TST_FAIL_CALLFUNC_2; } if( outBegIdx != lookback ) { printf( "TA_GetLookback() != outBegIdx [%d != %d]\n", lookback, outBegIdx ); TA_ParamHolderFree( paramHolder ); return TA_ABS_TST_FAIL_CALLFUNC_3; } for( i=0; i < funcInfo->nbOutput; i++ ) { switch(outputInfo->type) { case TA_Output_Real: for( j=0; j < outNbElement; j++ ) { if( trio_isnan(output[i][j]) || trio_isinf(output[i][j])) { printf( "Failed for output[%d][%d] = %e\n", i, j, output[i][j] ); return TA_ABS_TST_FAIL_INVALID_OUTPUT; } } break; case TA_Output_Integer: break; } } /* Do another function call where startIdx == endIdx == 0. * In that case, outBegIdx should ALWAYS be zero. */ retCode = TA_CallFunc(paramHolder,0,0,&outBegIdx,&outNbElement); if( retCode != TA_SUCCESS ) { printf( "TA_CallFunc() failed data test 4 [%d]\n", retCode ); TA_ParamHolderFree( paramHolder ); return TA_ABS_TST_FAIL_CALLFUNC_4; } if( outBegIdx != 0 ) { printf( "failed outBegIdx=%d when startIdx==endIdx==0\n", outBegIdx ); TA_ParamHolderFree( paramHolder ); return TA_ABS_TST_FAIL_STARTEND_ZERO; } retCode = TA_ParamHolderFree( paramHolder ); if( retCode != TA_SUCCESS ) { printf( "TA_ParamHolderFree failed [%d]\n", retCode ); return TA_ABS_TST_FAIL_PARAMHOLDERFREE; } return TA_TEST_PASS; }
/* Check that a buffer (within a TestBuffer) is not containing * NAN (or any reserved "impossible" value) within the specified * range (it also checks that all out-of-bound values are untouch). * * Return 1 on success. */ ErrorNumber checkForNAN( const TA_Real *buffer, unsigned int nbElement ) { unsigned int i; unsigned int idx; const TA_Real *theBuffer; theBuffer = buffer - TA_BUF_PREFIX; /* Check that the prefix are all still untouch. */ for( idx=0; idx < TA_BUF_PREFIX; idx++ ) { if( theBuffer[idx] != RESV_PATTERN_PREFIX ) { printf( "Fail: Out of range writing in prefix buffer (%d,%f)\n", idx, theBuffer[idx] ); return TA_TEST_TFRR_OVERLAP_OR_NAN_0; } } if( nbElement > MAX_NB_TEST_ELEMENT ) { printf( "Fail: outNbElement is out of range 0 (%d)\n", nbElement ); return TA_TEST_TFRR_NB_ELEMENT_OUT_OF_RANGE; } /* Check that no NAN (or reserved "impossible" value) exist * in the specified range. */ for( i=0; i < nbElement; i++,idx++ ) { if( trio_isnan(theBuffer[idx]) ) { printf( "Fail: Not a number find within the data (%d,%f)\n", i, theBuffer[idx] ); return TA_TEST_TFRR_OVERLAP_OR_NAN_1; } if( trio_isinf(theBuffer[idx]) ) { printf( "Fail: Not a number find within the data (%d,%f)\n", i, theBuffer[idx] ); return TA_TEST_TFRR_OVERLAP_OR_NAN_2; } if( theBuffer[idx] == RESV_PATTERN_PREFIX ) { printf( "Fail: Not a number find within the data (%d,%f)\n", i, theBuffer[idx] ); return TA_TEST_TFRR_OVERLAP_OR_NAN_3; } if( theBuffer[idx] == RESV_PATTERN_SUFFIX ) { printf( "Fail: Not a number find within the data (%d,%f)\n", i, theBuffer[idx] ); return TA_TEST_TFRR_OVERLAP_OR_NAN_4; } } /* Make sure that the remaining of the buffer is untouch. */ for( ; idx < TA_BUF_SIZE; idx++ ) { if( theBuffer[idx] != RESV_PATTERN_SUFFIX ) { printf( "Fail: Out of range writing in suffix buffer (%d,%f)\n", idx, theBuffer[idx] ); return TA_TEST_TFRR_OVERLAP_OR_NAN_5; } idx++; } /* Make sure the global memory guard are untouch. */ if( memoryGuard1 != RESV_PATTERN_MEMGUARD_1 ) { printf( "Fail: MemoryGuard1 have been modified (%f,%f)\n", memoryGuard1, RESV_PATTERN_MEMGUARD_1 ); return TA_TEST_TFRR_OVERLAP_OR_NAN_6; } if( memoryGuard2 != RESV_PATTERN_MEMGUARD_2 ) { printf( "Fail: MemoryGuard2 have been modified (%f,%f)\n", memoryGuard2, RESV_PATTERN_MEMGUARD_2 ); return TA_TEST_TFRR_OVERLAP_OR_NAN_7; } /* Everything looks good! */ return TA_TEST_PASS; }