TA_RetCode TA_MINUS_DI_FramePP( TA_Libc *libHandle, TA_Integer startIdx, TA_Integer endIdx, TA_Integer *outBegIdx, TA_Integer *outNbElement, TA_ParamHolderPriv in[], TA_ParamHolderPriv optIn[], TA_ParamHolderPriv out[] ) { return TA_MINUS_DI( libHandle, startIdx, endIdx, in[0].p.in.data.inPrice.high, /* inHigh_0 */ in[0].p.in.data.inPrice.low, /* inLow_0 */ in[0].p.in.data.inPrice.close, /* inClose_0 */ optIn[0].p.optIn.data.optInInteger, /* optInTimePeriod_0 */ outBegIdx, outNbElement, out[0].p.out.data.outReal /* outReal_0 */ ); }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); setInputBuffer( 3, history->high, history->nbBars ); /* Make a simple first call. */ switch( test->id ) { case TST_MINUS_DM: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MINUS_DM, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_MINUS_DM( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_MINUS_DI: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MINUS_DI, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_MINUS_DI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_DX: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_DX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_DX( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_ADX: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_ADX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_ADX( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_PLUS_DM: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_PLUS_DM, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_PLUS_DM( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_PLUS_DI: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_PLUS_DI, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_PLUS_DI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_ADXR: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_ADX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_ADXR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_BAD_PARAM; } /* Verify that the inputs were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->id ) { case TST_MINUS_DM: retCode = TA_MINUS_DM( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_MINUS_DI: retCode = TA_MINUS_DI( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_DX: retCode = TA_DX( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_ADX: retCode = TA_ADX( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_PLUS_DM: retCode = TA_PLUS_DM( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_PLUS_DI: retCode = TA_PLUS_DI( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_ADXR: retCode = TA_ADXR( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; default: retCode = TA_BAD_PARAM; } /* Verify that the inputs were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[3].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[3].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { switch( test->id ) { case TST_MINUS_DM: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MINUS_DM, (void *)&testParam, 1, 0 ); break; case TST_MINUS_DI: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MINUS_DI, (void *)&testParam, 1, 2 ); break; case TST_DX: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_DX, (void *)&testParam, 1, 2 ); break; case TST_ADX: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_ADX, (void *)&testParam, 1, 2 ); break; case TST_PLUS_DM: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_PLUS_DM, (void *)&testParam, 1, 0 ); break; case TST_PLUS_DI: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_PLUS_DI, (void *)&testParam, 1, 2 ); break; case TST_ADXR: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_ADX, (void *)&testParam, 1, 2 ); break; } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
/**** Local functions definitions. ****/ static TA_RetCode rangeTestFunction( TA_Integer startIdx, TA_Integer endIdx, TA_Real *outputBuffer, TA_Integer *outputBufferInt, TA_Integer *outBegIdx, TA_Integer *outNbElement, TA_Integer *lookback, void *opaqueData, unsigned int outputNb, unsigned int *isOutputInteger ) { TA_RetCode retCode; TA_RangeTestParam *testParam; (void)outputNb; (void)outputBufferInt; *isOutputInteger = 0; testParam = (TA_RangeTestParam *)opaqueData; switch( testParam->test->id ) { case TST_MINUS_DM: retCode = TA_MINUS_DM( startIdx, endIdx, testParam->high, testParam->low, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_MINUS_DM_Lookback( testParam->test->optInTimePeriod ); break; case TST_MINUS_DI: retCode = TA_MINUS_DI( startIdx, endIdx, testParam->high, testParam->low, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_MINUS_DI_Lookback( testParam->test->optInTimePeriod ); break; case TST_DX: retCode = TA_DX( startIdx, endIdx, testParam->high, testParam->low, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_DX_Lookback( testParam->test->optInTimePeriod ); break; case TST_ADX: retCode = TA_ADX( startIdx, endIdx, testParam->high, testParam->low, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ADX_Lookback( testParam->test->optInTimePeriod ); break; case TST_PLUS_DM: retCode = TA_PLUS_DM( startIdx, endIdx, testParam->high, testParam->low, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_PLUS_DM_Lookback( testParam->test->optInTimePeriod ); break; case TST_PLUS_DI: retCode = TA_PLUS_DI( startIdx, endIdx, testParam->high, testParam->low, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_PLUS_DI_Lookback( testParam->test->optInTimePeriod ); break; case TST_ADXR: retCode = TA_ADXR( startIdx, endIdx, testParam->high, testParam->low, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ADXR_Lookback( testParam->test->optInTimePeriod ); break; default: retCode = TA_BAD_PARAM; } return retCode; }