/**** Global functions definitions. ****/ ErrorNumber test_yahoo( void ) { ErrorNumber retValue; TA_UDBase *udb; TA_Libc *libHandle; printf( "Testing Yahoo! data source\n" ); retValue = allocLib( &libHandle, &udb ); if( retValue != TA_TEST_PASS ) return retValue; retValue = test_index( libHandle, udb ); if( retValue != TA_TEST_PASS ) { printf( "Note: Yahoo! data source tests requires \n" ); printf( " an internet connection.\n" ); printf( "\nTest failed with value %d\n", retValue ); return retValue; } retValue = freeLib( libHandle, udb ); if( retValue != TA_TEST_PASS ) return retValue; return TA_TEST_PASS; }
LibCurses::LibCurses(int y, int x) { int sx; int sy; _mapX = x; _mapY = y; initscr(); keypad(stdscr, TRUE); curs_set(0); timeout(0); getmaxyx(stdscr, sy, sx); if (sx < x || sy < y) { freeLib(); throw errGraphic("Window too small!"); return ; } start_color(); init_pair(1, COLOR_BLUE, COLOR_BLUE); init_pair(2, COLOR_GREEN, COLOR_GREEN); init_pair(3, COLOR_BLACK, COLOR_GREEN); init_pair(4, COLOR_MAGENTA, COLOR_MAGENTA); init_pair(5, COLOR_RED, COLOR_GREEN); erase(); }
/**** Global functions definitions. ****/ ErrorNumber test_yahoo( void ) { ErrorNumber retValue; TA_UDBase *udb; printf( "Testing Yahoo! data source\n" ); /* Test the TA_YAHOO_ONE_SYMBOL data source. */ retValue = allocLib( &udb ); if( retValue != TA_TEST_PASS ) return retValue; retValue = test_one_symbol( udb ); if( retValue != TA_TEST_PASS ) { printf( "Error #%d TA_YAHOO_ONE_SYMBOL:\n", retValue ); printf( "Note: If you do not care about Yahoo! data source\n" ); printf( " you can ignore the previous error messages.\n" ); } retValue = freeLib( udb ); if( retValue != TA_TEST_PASS ) return retValue; /* Test the TA_YAHOO_WEB data source. */ retValue = allocLib( &udb ); if( retValue != TA_TEST_PASS ) return retValue; retValue = test_web( udb ); if( retValue != TA_TEST_PASS ) { printf( "Error #%d TA_YAHOO_WEB:\n", retValue ); printf( "Note: If you do not care about Yahoo! data source\n" ); printf( " you can ignore the previous error messages.\n" ); } retValue = freeLib( udb ); if( retValue != TA_TEST_PASS ) return retValue; return TA_TEST_PASS; }
/**** Local functions definitions. ****/ static ErrorNumber test_with_simulator( void ) { ErrorNumber retValue; /* Initialize the library. */ retValue = allocLib(); if( retValue != TA_TEST_PASS ) return retValue; /* Perform testing of each of the TA Functions. */ retValue = testTAFunction_ALL(); if( retValue != TA_TEST_PASS ) { return retValue; } /* Clean-up and exit. */ retValue = freeLib( ); if( retValue != TA_TEST_PASS ) return retValue; return TA_TEST_PASS; /* All test succeed. */ }
static ErrorNumber testCircularBuffer( void ) { TA_RetCode retCode; int i; int buffer[20]; TA_UDBase *uDBase; ErrorNumber retValue; /* Initialize the library. */ retValue = allocLib( &uDBase ); if( retValue != TA_TEST_PASS ) { printf( "\nFailed: Can't initialize the library\n" ); return retValue; } /* The following function is supose to fill * the buffer with the value 0 to 8 sequentialy, * if somehow it is not 0 to 8, there is a bug! */ memset( buffer, 0xFF, sizeof(buffer) ); retCode = circBufferFillFrom0ToSize( 1, buffer ); if( retCode != TA_SUCCESS ) { printf( "\nFailed circular buffer test RetCode = %d\n", retCode ); return TA_CIRC_BUFF_FAIL_0; } for( i=0; i < (1+3); i++ ) { if( buffer[i] != i ) { printf( "\nFailed circular buffer test (%d != %d)\n", buffer[i], i ); return TA_CIRC_BUFF_FAIL_1; } } memset( buffer, 0xFF, sizeof(buffer) ); retCode = circBufferFillFrom0ToSize( 2, buffer ); if( retCode != TA_SUCCESS ) { printf( "\nFailed circular buffer test RetCode = %d\n", retCode ); return TA_CIRC_BUFF_FAIL_0; } for( i=0; i < (2+3); i++ ) { if( buffer[i] != i ) { printf( "\nFailed circular buffer test (%d != %d)\n", buffer[i], i ); return TA_CIRC_BUFF_FAIL_2; } } memset( buffer, 0xFF, sizeof(buffer) ); retCode = circBufferFillFrom0ToSize( 3, buffer ); if( retCode != TA_SUCCESS ) { printf( "\nFailed circular buffer test RetCode = %d\n", retCode ); return TA_CIRC_BUFF_FAIL_0; } for( i=0; i < (3+3); i++ ) { if( buffer[i] != i ) { printf( "\nFailed circular buffer test (%d != %d)\n", buffer[i], i ); return TA_CIRC_BUFF_FAIL_3; } } memset( buffer, 0xFF, sizeof(buffer) ); retCode = circBufferFillFrom0ToSize( 4, buffer ); if( retCode != TA_SUCCESS ) { printf( "\nFailed circular buffer test RetCode = %d\n", retCode ); return TA_CIRC_BUFF_FAIL_0; } for( i=0; i < (4+3); i++ ) { if( buffer[i] != i ) { printf( "\nFailed circular buffer test (%d != %d)\n", buffer[i], i ); return TA_CIRC_BUFF_FAIL_4; } } memset( buffer, 0xFF, sizeof(buffer) ); retCode = circBufferFillFrom0ToSize( 5, buffer ); if( retCode != TA_SUCCESS ) { printf( "\nFailed circular buffer test RetCode = %d\n", retCode ); return TA_CIRC_BUFF_FAIL_0; } for( i=0; i < (5+3); i++ ) { if( buffer[i] != i ) { printf( "\nFailed circular buffer test (%d != %d)\n", buffer[i], i ); return TA_CIRC_BUFF_FAIL_5; } } memset( buffer, 0xFF, sizeof(buffer) ); retCode = circBufferFillFrom0ToSize( 6, buffer ); if( retCode != TA_SUCCESS ) { printf( "\nFailed circular buffer test RetCode = %d\n", retCode ); return TA_CIRC_BUFF_FAIL_0; } for( i=0; i < (6+3); i++ ) { if( buffer[i] != i ) { printf( "\nFailed circular buffer test (%d != %d)\n", buffer[i], i ); return TA_CIRC_BUFF_FAIL_6; } } retValue = freeLib( uDBase ); if( retValue != TA_TEST_PASS ) return retValue; return TA_TEST_PASS; /* Success. */ }
/**** Global functions definitions. ****/ ErrorNumber test_abstract( void ) { ErrorNumber retValue; TA_RetCode retCode; TA_ParamHolder *paramHolder; const TA_FuncHandle *handle; printf( "Testing Abstract interface\n" ); retValue = allocLib(); if( retValue != TA_TEST_PASS ) return retValue; /* Verify TA_GetLookback. */ retCode = TA_GetFuncHandle( "STOCH", &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; } retValue = testLookback(paramHolder); if( retValue != TA_SUCCESS ) { printf( "testLookback() failed [%d]\n", retValue ); TA_ParamHolderFree( paramHolder ); return retValue; } retCode = TA_ParamHolderFree( paramHolder ); if( retCode != TA_SUCCESS ) { printf( "TA_ParamHolderFree failed [%d]\n", retCode ); return TA_ABS_TST_FAIL_PARAMHOLDERFREE; } retValue = freeLib(); if( retValue != TA_TEST_PASS ) return retValue; /* Call all the TA functions through the abstract interface. */ retValue = allocLib(); if( retValue != TA_TEST_PASS ) return retValue; retValue = test_default_calls(); if( retValue != TA_TEST_PASS ) { printf( "TA-Abstract default call failed\n" ); return retValue; } retValue = freeLib(); if( retValue != TA_TEST_PASS ) return retValue; return TA_TEST_PASS; /* Succcess. */ }
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. */ }
/**** Global functions definitions. ****/ ErrorNumber test_pm( void ) { ErrorNumber errorNumber; TA_UDBase *udb; unsigned int i, j; printf( "Testing Performance Measurement\n" ); /* Side Note: * Why all these allocLib/freeLib in this function? * Each time freeLib is being called, it is verified * that all ressource has been freed. So that's a good * way to verify for any potential memory leak. */ /* Initialize some globals used throughout these tests. */ TA_SetTimeNow( ×tampNow ); TA_SetDateNow( ×tampNow ); TA_NextWeekday( ×tampNow ); TA_TimestampCopy( ×tampNowPlusOneYear, ×tampNow ); TA_NextYear( ×tampNowPlusOneYear ); TA_PrevDay( ×tampNowPlusOneYear ); /* Using a user defined kkey */ TA_InstrumentInitWithUserKey( &id1_1, 12 ); TA_InstrumentInitWithUserKey( &id1_2, 9 ); /* Using a category / symbol strings. */ TA_InstrumentInit( &id2_1, "AB", "CD" ); TA_InstrumentInit( &id2_1, "AB", "CE" ); /* Using a category only. */ TA_InstrumentInit( &id3_1, "ABCD", NULL ); TA_InstrumentInit( &id3_2, "EFGH", NULL ); /* Using only a symbol string */ TA_InstrumentInit( &id4_1, NULL, "A" ); TA_InstrumentInit( &id4_2, NULL, "B" ); /* Test limit cases with empty TA_TradeLog */ errorNumber = allocLib( &udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = test_emptytradelog(); if( errorNumber != TA_TEST_PASS ) { printf( "Failed: Empty trade log cases\n" ); return errorNumber; } errorNumber = freeLib( udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Test with only one TA_Transaction. * Repeat all tests for each possible * TA_Instrument key type. */ for( i=0; i < NB_TA_KEY_TYPE; i++ ) { errorNumber = allocLib( &udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = test_onetransaction_only( (TA_KEY_TYPE)i ); if( errorNumber != TA_TEST_PASS ) { printf( "Failed: one transaction cases (key=%d,errorNumber=%d)\n", (TA_KEY_TYPE)i, errorNumber ); return errorNumber; } errorNumber = freeLib( udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; } /* Tests with two TA_Transaction for the * same given TA_Instrument. * * Repeat the test for each combination * of: * - TA_Instrument key type * - long and short trade. * - winning and losing trade */ for( i=0; i <= 1; i++ ) { /* 0 = test a loosing trade * 1 = test a winning trade */ for( j=0; j < NB_TA_KEY_TYPE; j++ ) { /* Test Long */ errorNumber = allocLib( &udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = test_onetrade_only( (TA_KEY_TYPE)j, TA_LONG_ENTRY, i ); if( errorNumber != TA_TEST_PASS ) { printf( "Failed: one trade only (key=%d,type=%d,winning=%d)\n", (TA_KEY_TYPE)j, TA_LONG_ENTRY, i ); return errorNumber; } errorNumber = freeLib( udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Test Short */ errorNumber = allocLib( &udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = test_onetrade_only( (TA_KEY_TYPE)j, TA_SHORT_ENTRY, i ); if( errorNumber != TA_TEST_PASS ) { printf( "Failed: one trade only (key=%d,type=%d,winning=%d)\n", (TA_KEY_TYPE)j, TA_SHORT_ENTRY, i ); return errorNumber; } errorNumber = freeLib( udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; } } /* Test TA_PMValueId using a list of tests * defined in static variables. */ for( i=0; i < NB_PMVALUEID_TEST; i++ ) { errorNumber = allocLib( &udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = test_valueId( &pmValueIdTests[i] ); if( errorNumber != TA_TEST_PASS ) { printf( "Failed: test_valueId #%d\n", i); return errorNumber; } errorNumber = freeLib( udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; } /* Test TA_PMArrayId using a list of tests * defined in static variables. */ for( i=0; i < NB_PMARRAYID_TEST; i++ ) { errorNumber = allocLib( &udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = test_arrayId( &pmArrayIdTests[i] ); if( errorNumber != TA_TEST_PASS ) { printf( "Failed: test_arrayId #%d\n", i); return errorNumber; } errorNumber = freeLib( udb ); if( errorNumber != TA_TEST_PASS ) return errorNumber; } return TA_TEST_PASS; }
/**** Local functions definitions. ****/ static ErrorNumber test_with_simulator( void ) { TA_UDBase *uDBase; TA_History *history; TA_AddDataSourceParam param; TA_RetCode retCode; ErrorNumber retValue; TA_HistoryAllocParam histParam; /* Initialize the library. */ retValue = allocLib( &uDBase ); if( retValue != TA_TEST_PASS ) return retValue; /* Add a datasource using pre-defined data. * This data is embedded in the library and does * not required any external data provider. * The test functions may assume that this data will * be unmodified forever by TA-LIB. */ memset( ¶m, 0, sizeof( TA_AddDataSourceParam ) ); param.id = TA_SIMULATOR; retCode = TA_AddDataSource( uDBase, ¶m ); if( retCode != TA_SUCCESS ) { printf( "TA_AddDataSource failed [%d]\n", retCode ); freeLib( uDBase ); return TA_REGTEST_ADDDATASOURCE_FAILED; } /* Regression testing of the functionality provided * by ta_period.c */ retValue = test_period( uDBase ); if( retValue != TA_TEST_PASS ) { freeLib( uDBase ); return retValue; } /* Allocate the reference historical data. */ memset( &histParam, 0, sizeof( TA_HistoryAllocParam ) ); histParam.category = "TA_SIM_REF"; histParam.symbol = "DAILY_REF_0"; histParam.field = TA_ALL; histParam.period = TA_DAILY; retCode = TA_HistoryAlloc( uDBase, &histParam, &history ); if( retCode != TA_SUCCESS ) { printf( "TA_HistoryAlloc failed [%d]\n", retCode ); freeLib( uDBase ); return TA_REGTEST_HISTORYALLOC_FAILED; } /* Perform testing of each of the TA Functions. */ retValue = testTAFunction_ALL( history ); if( retValue != TA_TEST_PASS ) { TA_HistoryFree( history ); freeLib( uDBase ); return retValue; } /* Clean-up and exit. */ retCode = TA_HistoryFree( history ); if( retCode != TA_SUCCESS ) { printf( "TA_HistoryFree failed [%d]\n", retCode ); freeLib( uDBase ); return TA_REGTEST_HISTORYFREE_FAILED; } retValue = freeLib( uDBase ); if( retValue != TA_TEST_PASS ) return retValue; return TA_TEST_PASS; /* All test succeed. */ }