/**** Local functions definitions. ****/ static TA_RetCode rangeTestFunction( TA_Libc *libHandle, TA_Integer startIdx, TA_Integer endIdx, TA_Real *outputBuffer, TA_Integer *outBegIdx, TA_Integer *outNbElement, TA_Integer *lookback, void *opaqueData, unsigned int outputNb ) { TA_RetCode retCode; TA_RangeTestParam *testParam; (void)outputNb; testParam = (TA_RangeTestParam *)opaqueData; if( testParam->test->theFunction == TA_MOM_TEST ) { retCode = TA_MOM( libHandle, startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod_0, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_MOM_Lookback(testParam->test->optInTimePeriod_0 ); } else if( testParam->test->theFunction == TA_ROC_TEST ) { retCode = TA_ROC( libHandle, startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod_0, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ROC_Lookback(testParam->test->optInTimePeriod_0 ); } else if( testParam->test->theFunction == TA_ROCR_TEST ) { retCode = TA_ROCR( libHandle, startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod_0, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ROCR_Lookback(testParam->test->optInTimePeriod_0 ); } else retCode = TA_UNKNOWN_ERR; return retCode; }
static ErrorNumber do_test( TA_Libc *libHandle, 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->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); CLEAR_EXPECTED_VALUE(0); /* Make a simple first call. */ if( test->theFunction == TA_MOM_TEST ) { retCode = TA_MOM( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } else if( test->theFunction == TA_ROC_TEST ) { retCode = TA_ROC( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } else if( test->theFunction == TA_ROCR_TEST ) { retCode = TA_ROCR( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } errNb = checkDataSame( gBuffer[0].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. */ CLEAR_EXPECTED_VALUE(0); if( test->theFunction == TA_MOM_TEST ) { retCode = TA_MOM( libHandle, test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[1].in ); } else if( test->theFunction == TA_ROC_TEST ) { retCode = TA_ROC( libHandle, test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[1].in ); } else if( test->theFunction == TA_ROCR_TEST ) { retCode = TA_ROCR( libHandle, test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[1].in ); } /* 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[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].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.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( libHandle, rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1 ); 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->theFunction ) { case TA_MOM_TEST: retCode = TA_MOM( startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_MOM_Lookback(testParam->test->optInTimePeriod ); break; case TA_ROC_TEST: retCode = TA_ROC( startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ROC_Lookback(testParam->test->optInTimePeriod ); break; case TA_ROCR_TEST: retCode = TA_ROCR( startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ROCR_Lookback(testParam->test->optInTimePeriod ); break; case TA_ROCR100_TEST: retCode = TA_ROCR100( startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ROCR100_Lookback(testParam->test->optInTimePeriod ); break; case TA_ROCP_TEST: retCode = TA_ROCP( startIdx, endIdx, testParam->close, testParam->test->optInTimePeriod, outBegIdx, outNbElement, outputBuffer ); *lookback = TA_ROCP_Lookback(testParam->test->optInTimePeriod ); break; default: retCode = TA_INTERNAL_ERROR(130); } return retCode; }