1 /* TA-LIB Copyright (c) 1999-2007, Mario Fortier
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistributions in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in
13  *   the documentation and/or other materials provided with the
14  *   distribution.
15  *
16  * - Neither name of author nor the names of its contributors
17  *   may be used to endorse or promote products derived from this
18  *   software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /* List of contributors:
35  *
36  *  Initial  Name/description
37  *  -------------------------------------------------------------------
38  *  MF       Mario Fortier
39  *
40  *
41  * Change history:
42  *
43  *  MMDDYY BY   Description
44  *  -------------------------------------------------------------------
45  *  020203 MF   First version.
46  *  122506 MF   Add TA_BETA tests.
47  */
48 
49 /* Description:
50  *
51  *     Test functions which have the following characterisic:
52  *      - two inputs are needed (high and low are used here).
53  *      - has zero or one parameter being a period.
54  */
55 
56 /**** Headers ****/
57 #include <stdio.h>
58 #include <string.h>
59 
60 #include "ta_test_priv.h"
61 #include "ta_test_func.h"
62 #include "ta_utility.h"
63 #include "ta_memory.h"
64 
65 /**** External functions declarations. ****/
66 /* None */
67 
68 /**** External variables declarations. ****/
69 /* None */
70 
71 /**** Global variables definitions.    ****/
72 /* None */
73 
74 /**** Local declarations.              ****/
75 typedef enum {
76 TA_AROON_UP_TEST,
77 TA_AROON_DOWN_TEST,
78 TA_AROONOSC_TEST,
79 TA_CORREL_TEST,
80 TA_BETA_TEST
81 } TA_TestId;
82 
83 typedef struct
84 {
85    TA_Integer doRangeTestFlag;
86 
87    TA_TestId  theFunction;
88 
89    TA_Integer startIdx;
90    TA_Integer endIdx;
91    TA_Integer optInTimePeriod;
92 
93    TA_RetCode expectedRetCode;
94 
95    TA_Integer oneOfTheExpectedOutRealIndex0;
96    TA_Real    oneOfTheExpectedOutReal0;
97 
98    TA_Integer expectedBegIdx;
99    TA_Integer expectedNbElement;
100 } TA_Test;
101 
102 typedef struct
103 {
104    const TA_Test *test;
105    const TA_Real *high;
106    const TA_Real *low;
107 } TA_RangeTestParam;
108 
109 /**** Local functions declarations.    ****/
110 static ErrorNumber do_test( const TA_History *history,
111                             const TA_Test *test );
112 
113 /**** Local variables definitions.     ****/
114 
115 static TA_Test tableTest[] =
116 {
117    /*****************/
118    /* BETA TEST     */
119    /*****************/
120 
121    /* Uncomment following to enable tons of tests. Replace 999.99 with the first
122     * value you are expecting.
123     */
124 
125    { 1, TA_BETA_TEST,  0, 251, 5, TA_SUCCESS,      0, 0.62907,  5,  252-5 },
126    { 0, TA_BETA_TEST,  0, 251, 5, TA_SUCCESS,      1, 0.83604,  5,  252-5 },
127 
128    /*****************/
129    /* CORREL TEST   */
130    /*****************/
131    { 1, TA_CORREL_TEST,  0, 251, 20, TA_SUCCESS,      0, 0.9401569,  19,  252-19 }, /* First Value */
132    { 0, TA_CORREL_TEST,  0, 251, 20, TA_SUCCESS,      1, 0.9471812,  19,  252-19 },
133    { 0, TA_CORREL_TEST,  0, 251, 20, TA_SUCCESS, 252-20, 0.8866901,  19,  252-19 }, /* Last Value */
134 
135 
136    /*******************/
137    /* AROON UP TEST   */
138    /*******************/
139    { 1, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS,  0, 78.571,  14,  252-14 }, /* First Value */
140    { 0, TA_AROON_UP_TEST,  0, 251, 14, TA_SUCCESS,  1, 71.429,  14,  252-14 },
141    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS,  2, 64.2857,  14,  252-14 },
142    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS,  3, 57.143,  14,  252-14 },
143    { 0, TA_AROON_UP_TEST,  0, 251, 14, TA_SUCCESS,  4, 50.000,  14,  252-14 },
144    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS,  5, 42.857,  14,  252-14 },
145    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS,  6, 35.714,  14,  252-14 },
146    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS,  7, 28.571,  14,  252-14 },
147    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS,  8, 21.429,  14,  252-14 },
148    { 0, TA_AROON_UP_TEST,  0, 251, 14, TA_SUCCESS,  9, 14.286,  14,  252-14 },
149    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 10, 7.1429,  14,  252-14 },
150    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 11, 0.0000,  14,  252-14 },
151    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 12, 0.0000,  14,  252-14 },
152    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 13, 21.429,  14,  252-14 },
153    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 14, 14.286,  14,  252-14 },
154    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 15, 7.1429,  14,  252-14 },
155    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 16, 0.0000,  14,  252-14 },
156    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 17, 14.286,  14,  252-14 },
157    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 20, 0.00,  14,  252-14 },
158    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 21, 92.857,  14,  252-14 },
159    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 27, 50.000,  14,  252-14 },
160    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 28, 42.857,  14,  252-14 },
161    { 0, TA_AROON_UP_TEST, 13, 251, 14, TA_SUCCESS, 29,100.000,  14,  252-14 },
162    { 0, TA_AROON_UP_TEST,  1, 251, 14, TA_SUCCESS, 252-16, 0.0,  14,  252-14 },
163    { 0, TA_AROON_UP_TEST,  0, 251, 14, TA_SUCCESS, 252-15, 7.1429,  14,  252-14 }, /* Last Value */
164 
165    /*******************/
166    /* AROON DOWN TEST */
167    /*******************/
168    { 1, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS,  0, 100.0,  14,  252-14 }, /* First Value */
169    { 0, TA_AROON_DOWN_TEST,  0, 251, 14, TA_SUCCESS,  1, 92.857,  14,  252-14 },
170    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS,  2, 85.714,  14,  252-14 },
171    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS,  3, 78.571,  14,  252-14 },
172    { 0, TA_AROON_DOWN_TEST,  0, 251, 14, TA_SUCCESS,  4, 71.429,  14,  252-14 },
173    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS,  5, 64.286,  14,  252-14 },
174    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS,  6, 57.143,  14,  252-14 },
175    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS,  7,100.000,  14,  252-14 },
176    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS,  8,100.000,  14,  252-14 },
177    { 0, TA_AROON_DOWN_TEST,  0, 251, 14, TA_SUCCESS,  9,100.000,  14,  252-14 },
178    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 10,100.000,  14,  252-14 },
179    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 11,100.000,  14,  252-14 },
180    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 12, 92.857,  14,  252-14 },
181    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 13, 85.714,  14,  252-14 },
182    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 14, 78.571,  14,  252-14 },
183    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 15, 71.429,  14,  252-14 },
184    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 16, 64.286,  14,  252-14 },
185    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 17, 57.143,  14,  252-14 },
186    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 18, 50.000,  14,  252-14 },
187    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 19, 42.857,  14,  252-14 },
188    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 20, 35.714,  14,  252-14 },
189    { 0, TA_AROON_DOWN_TEST,  0, 251, 14, TA_SUCCESS, 21, 28.571,  14,  252-14 },
190    { 0, TA_AROON_DOWN_TEST,  0, 251, 14, TA_SUCCESS, 22, 21.429,  14,  252-14 },
191    { 0, TA_AROON_DOWN_TEST,  0, 251, 14, TA_SUCCESS, 23, 14.286,  14,  252-14 },
192    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 24, 7.1429,  14,  252-14 },
193    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 25, 0.0,  14,  252-14 },
194    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 26, 0.0,  14,  252-14 },
195    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 27, 92.857,  14,  252-14 },
196    { 0, TA_AROON_DOWN_TEST, 13, 251, 14, TA_SUCCESS, 28, 85.714,  14,  252-14 },
197 
198    { 0, TA_AROON_DOWN_TEST,  4, 251, 14, TA_SUCCESS, 252-16, 28.571,  14,  252-14 },
199    { 0, TA_AROON_DOWN_TEST,  0, 251, 14, TA_SUCCESS, 252-15, 21.429,  14,  252-14 }, /* Last Value */
200 
201    /******************/
202    /* AROON OSC TEST */
203    /******************/
204    { 0, TA_AROONOSC_TEST, 13, 251, 14, TA_SUCCESS,  0, -21.4285,  14,  252-14 }, /* First Value */
205    { 0, TA_AROONOSC_TEST, 13, 251, 14, TA_SUCCESS,  6, -21.4285,  14,  252-14 },
206    { 0, TA_AROONOSC_TEST, 13, 251, 14, TA_SUCCESS,  7, -71.4285,  14,  252-14 },
207    { 0, TA_AROONOSC_TEST, 0, 251, 14, TA_SUCCESS, 252-16, -28.5714,  14,  252-14 },
208    { 0, TA_AROONOSC_TEST, 0, 251, 14, TA_SUCCESS, 252-15, -14.28571,  14,  252-14 }, /* Last Value */
209 
210 };
211 
212 #define NB_TEST (sizeof(tableTest)/sizeof(TA_Test))
213 
214 /**** Global functions definitions.   ****/
test_func_per_hl(TA_History * history)215 ErrorNumber test_func_per_hl( TA_History *history )
216 {
217    unsigned int i;
218    ErrorNumber retValue;
219 
220    /* Re-initialize all the unstable period to zero. */
221    TA_SetUnstablePeriod( TA_FUNC_UNST_ALL, 0 );
222 
223    for( i=0; i < NB_TEST; i++ )
224    {
225       if( (int)tableTest[i].expectedNbElement > (int)history->nbBars )
226       {
227          printf( "Failed Bad Parameter for Test #%d (%d,%d)\n",
228                  i, tableTest[i].expectedNbElement, history->nbBars );
229          return TA_TESTUTIL_TFRR_BAD_PARAM;
230       }
231 
232       retValue = do_test( history, &tableTest[i] );
233       if( retValue != 0 )
234       {
235          printf( "Failed Test #%d (Code=%d)\n", i, retValue );
236          return retValue;
237       }
238    }
239 
240    /* Re-initialize all the unstable period to zero. */
241    TA_SetUnstablePeriod( TA_FUNC_UNST_ALL, 0 );
242 
243    /* All test succeed. */
244    return TA_TEST_PASS;
245 }
246 
247 /**** Local functions definitions.     ****/
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)248 static TA_RetCode rangeTestFunction( TA_Integer    startIdx,
249                                      TA_Integer    endIdx,
250                                      TA_Real      *outputBuffer,
251                                      TA_Integer   *outputBufferInt,
252                                      TA_Integer   *outBegIdx,
253                                      TA_Integer   *outNbElement,
254                                      TA_Integer   *lookback,
255                                      void         *opaqueData,
256                                      unsigned int  outputNb,
257                                      unsigned int *isOutputInteger )
258 {
259    TA_RetCode retCode;
260    TA_RangeTestParam *testParam;
261    double *dummyBuffer;
262 
263    (void)outputNb;
264    (void)outputBufferInt;
265 
266    *isOutputInteger = 0;
267 
268    testParam = (TA_RangeTestParam *)opaqueData;
269 
270    /* Allocate a buffer for the output who is going
271     * to be ignored (make it slightly larger to play
272     * safe)
273     */
274    dummyBuffer = TA_Malloc( sizeof(double) * (endIdx-startIdx+100) );
275    switch( testParam->test->theFunction )
276    {
277    case TA_AROON_UP_TEST:
278       retCode = TA_AROON( startIdx,
279                           endIdx,
280                           testParam->high,
281                           testParam->low,
282                           testParam->test->optInTimePeriod,
283                           outBegIdx,
284                           outNbElement,
285                           &dummyBuffer[20],
286                           outputBuffer );
287 
288       *lookback = TA_AROON_Lookback( testParam->test->optInTimePeriod );
289       break;
290    case TA_AROON_DOWN_TEST:
291       retCode = TA_AROON( startIdx,
292                           endIdx,
293                           testParam->high,
294                           testParam->low,
295                           testParam->test->optInTimePeriod,
296                           outBegIdx,
297                           outNbElement,
298                           outputBuffer,
299                           &dummyBuffer[20]
300                         );
301       *lookback = TA_AROON_Lookback( testParam->test->optInTimePeriod );
302       break;
303    case TA_AROONOSC_TEST:
304       retCode = TA_AROONOSC( startIdx,
305                              endIdx,
306                              testParam->high,
307                              testParam->low,
308                              testParam->test->optInTimePeriod,
309                              outBegIdx,
310                              outNbElement,
311                              outputBuffer );
312       *lookback = TA_AROONOSC_Lookback( testParam->test->optInTimePeriod );
313       break;
314    case TA_CORREL_TEST:
315       retCode = TA_CORREL( startIdx,
316                            endIdx,
317                            testParam->high,
318                            testParam->low,
319                            testParam->test->optInTimePeriod,
320                            outBegIdx,
321                            outNbElement,
322                            outputBuffer );
323       *lookback = TA_CORREL_Lookback( testParam->test->optInTimePeriod );
324       break;
325 
326    case TA_BETA_TEST:
327       retCode = TA_BETA( startIdx,
328                          endIdx,
329                          testParam->high,
330                          testParam->low,
331                          testParam->test->optInTimePeriod, /* time period */
332                          outBegIdx,
333                          outNbElement,
334                          outputBuffer );
335       *lookback = TA_BETA_Lookback(testParam->test->optInTimePeriod);
336       break;
337 
338    default:
339       retCode = TA_INTERNAL_ERROR(132);
340    }
341 
342    TA_Free( dummyBuffer );
343 
344    return retCode;
345 }
346 
do_test(const TA_History * history,const TA_Test * test)347 static ErrorNumber do_test( const TA_History *history,
348                             const TA_Test *test )
349 {
350    TA_RetCode retCode;
351    ErrorNumber errNb;
352    TA_Integer outBegIdx;
353    TA_Integer outNbElement;
354    TA_RangeTestParam testParam;
355 
356    /* Set to NAN all the elements of the gBuffers.  */
357    clearAllBuffers();
358 
359    /* Build the input. */
360    setInputBuffer( 0, history->high,  history->nbBars );
361    setInputBuffer( 1, history->low,   history->nbBars );
362 
363    /* Make a simple first call. */
364    switch( test->theFunction )
365    {
366    case TA_AROON_UP_TEST:
367       retCode = TA_AROON( test->startIdx,
368                           test->endIdx,
369                           gBuffer[0].in,
370                           gBuffer[1].in,
371                           test->optInTimePeriod,
372                           &outBegIdx,
373                           &outNbElement,
374                           gBuffer[1].out0,
375                           gBuffer[0].out0
376                         );
377       break;
378 
379    case TA_AROON_DOWN_TEST:
380       retCode = TA_AROON( test->startIdx,
381                           test->endIdx,
382                           gBuffer[0].in,
383                           gBuffer[1].in,
384                           test->optInTimePeriod,
385                           &outBegIdx,
386                           &outNbElement,
387                           gBuffer[0].out0,
388                           gBuffer[1].out0
389                         );
390       break;
391 
392    case TA_AROONOSC_TEST:
393       retCode = TA_AROONOSC( test->startIdx,
394                              test->endIdx,
395                              gBuffer[0].in,
396                              gBuffer[1].in,
397                              test->optInTimePeriod,
398                              &outBegIdx,
399                              &outNbElement,
400                              gBuffer[0].out0
401                            );
402       break;
403 
404    case TA_CORREL_TEST:
405       retCode = TA_CORREL( test->startIdx,
406                            test->endIdx,
407                            gBuffer[0].in,
408                            gBuffer[1].in,
409                            test->optInTimePeriod,
410                            &outBegIdx,
411                            &outNbElement,
412                            gBuffer[0].out0
413                          );
414       break;
415 
416    case TA_BETA_TEST:
417       retCode = TA_BETA( test->startIdx,
418                          test->endIdx,
419                          gBuffer[0].in,
420                          gBuffer[1].in,
421                          test->optInTimePeriod,
422                          &outBegIdx,
423                          &outNbElement,
424                          gBuffer[0].out0
425                          );
426       break;
427 
428    default:
429       retCode = TA_INTERNAL_ERROR(133);
430    }
431 
432    /* Check that the input were preserved. */
433    errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars );
434    if( errNb != TA_TEST_PASS )
435       return errNb;
436    errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars );
437    if( errNb != TA_TEST_PASS )
438       return errNb;
439 
440    CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 );
441 
442    outBegIdx = outNbElement = 0;
443 
444    /* Make another call where one of the input and one of the output
445     * are the same buffer.
446     */
447    switch( test->theFunction )
448    {
449    case TA_AROON_UP_TEST:
450       retCode = TA_AROON( test->startIdx,
451                           test->endIdx,
452                           gBuffer[0].in,
453                           gBuffer[1].in,
454                           test->optInTimePeriod,
455                           &outBegIdx,
456                           &outNbElement,
457                           gBuffer[1].out1,
458                           gBuffer[0].in
459                         );
460       break;
461 
462    case TA_AROON_DOWN_TEST:
463       retCode = TA_AROON( test->startIdx,
464                           test->endIdx,
465                           gBuffer[0].in,
466                           gBuffer[1].in,
467                           test->optInTimePeriod,
468                           &outBegIdx,
469                           &outNbElement,
470                           gBuffer[0].in,
471                           gBuffer[1].out1
472                         );
473       break;
474 
475    case TA_AROONOSC_TEST:
476       retCode = TA_AROONOSC( test->startIdx,
477                              test->endIdx,
478                              gBuffer[0].in,
479                              gBuffer[1].in,
480                              test->optInTimePeriod,
481                              &outBegIdx,
482                              &outNbElement,
483                              gBuffer[0].in
484                            );
485       break;
486 
487    case TA_CORREL_TEST:
488       retCode = TA_CORREL( test->startIdx,
489                            test->endIdx,
490                            gBuffer[0].in,
491                            gBuffer[1].in,
492                            test->optInTimePeriod,
493                            &outBegIdx,
494                            &outNbElement,
495                            gBuffer[0].in
496                          );
497       break;
498 
499    case TA_BETA_TEST:
500       retCode = TA_BETA( test->startIdx,
501                          test->endIdx,
502                          gBuffer[0].in,
503                          gBuffer[1].in,
504                          test->optInTimePeriod,
505                          &outBegIdx,
506                          &outNbElement,
507                          gBuffer[0].in
508                          );
509       break;
510 
511    default:
512       retCode = TA_INTERNAL_ERROR(134);
513    }
514 
515    /* Check that the other input was preserved. */
516    errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars );
517    if( errNb != TA_TEST_PASS )
518       return errNb;
519 
520    /* The previous call should have the same output
521     * as this call.
522     *
523     * checkSameContent verify that all value different than NAN in
524     * the first parameter is identical in the second parameter.
525     */
526    errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in );
527    if( errNb != TA_TEST_PASS )
528       return errNb;
529    errNb = checkSameContent( gBuffer[1].out1, gBuffer[1].out0 );
530    if( errNb != TA_TEST_PASS )
531       return errNb;
532 
533    CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 );
534    setInputBuffer( 0, history->high,  history->nbBars );
535    setInputBuffer( 1, history->low,   history->nbBars );
536 
537    /* Make another call where the input and the output are the
538     * same buffer.
539     */
540    switch( test->theFunction )
541    {
542    case TA_AROON_UP_TEST:
543       retCode = TA_AROON( test->startIdx,
544                           test->endIdx,
545                           gBuffer[0].in,
546                           gBuffer[1].in,
547                           test->optInTimePeriod,
548                           &outBegIdx,
549                           &outNbElement,
550                           gBuffer[1].out2,
551                           gBuffer[1].in
552                         );
553       break;
554 
555    case TA_AROON_DOWN_TEST:
556       retCode = TA_AROON( test->startIdx,
557                           test->endIdx,
558                           gBuffer[0].in,
559                           gBuffer[1].in,
560                           test->optInTimePeriod,
561                           &outBegIdx,
562                           &outNbElement,
563                           gBuffer[1].in,
564                           gBuffer[1].out2
565                         );
566       break;
567 
568    case TA_AROONOSC_TEST:
569       retCode = TA_AROONOSC( test->startIdx,
570                              test->endIdx,
571                              gBuffer[0].in,
572                              gBuffer[1].in,
573                              test->optInTimePeriod,
574                              &outBegIdx,
575                              &outNbElement,
576                              gBuffer[1].in
577                            );
578       break;
579 
580    case TA_CORREL_TEST:
581       retCode = TA_CORREL( test->startIdx,
582                            test->endIdx,
583                            gBuffer[0].in,
584                            gBuffer[1].in,
585                            test->optInTimePeriod,
586                            &outBegIdx,
587                            &outNbElement,
588                            gBuffer[1].in
589                          );
590       break;
591 
592    case TA_BETA_TEST:
593       retCode = TA_BETA( test->startIdx,
594                          test->endIdx,
595                          gBuffer[0].in,
596                          gBuffer[1].in,
597                          test->optInTimePeriod,
598                          &outBegIdx,
599                          &outNbElement,
600                          gBuffer[1].in
601                          );
602       break;
603 
604    default:
605       retCode = TA_INTERNAL_ERROR(135);
606    }
607 
608    /* Check that the other input were preserved. */
609    errNb = checkDataSame( gBuffer[0].in, history->high, history->nbBars );
610    if( errNb != TA_TEST_PASS )
611       return errNb;
612 
613    /* The previous call should have the same output as this call.
614     *
615     * checkSameContent verify that all value different than NAN in
616     * the first parameter is identical in the second parameter.
617     */
618    errNb = checkSameContent(  gBuffer[0].out0, gBuffer[1].in );
619    if( errNb != TA_TEST_PASS )
620       return errNb;
621 
622    /* Do a systematic test of most of the
623     * possible startIdx/endIdx range.
624     */
625    testParam.test  = test;
626    testParam.high  = history->high;
627    testParam.low   = history->low;
628 
629    if( test->doRangeTestFlag )
630    {
631       errNb = doRangeTest( rangeTestFunction,
632                            TA_FUNC_UNST_NONE,
633                            (void *)&testParam, 1, 0 );
634       if( errNb != TA_TEST_PASS )
635          return errNb;
636    }
637 
638    return TA_TEST_PASS;
639 }
640 
641