From a63b35fbc08ad27353bd569b985e1c5606a0d84e Mon Sep 17 00:00:00 2001 From: fasiondog Date: Sat, 6 Apr 2019 21:47:00 +0800 Subject: [PATCH] fix getHistoryFinanceInfo on Linux,sizeof(unsigned long) is 8 not 4 --- .../data_driver/HistoryFinanceReader.cpp | 13 ++++++----- .../libs/hikyuu/hikyuu/test_Stock.cpp | 22 +++++++++++++++++++ .../libs/hikyuu/hikyuu/test_temp.cpp | 16 +------------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/hikyuu_cpp/hikyuu/data_driver/HistoryFinanceReader.cpp b/hikyuu_cpp/hikyuu/data_driver/HistoryFinanceReader.cpp index cf56a43db..d0e45894d 100644 --- a/hikyuu_cpp/hikyuu/data_driver/HistoryFinanceReader.cpp +++ b/hikyuu_cpp/hikyuu/data_driver/HistoryFinanceReader.cpp @@ -52,14 +52,14 @@ ::getHistoryFinanceInfo(Datetime date, memcpy(&report_size, header_buf + 12, 4); char stock_code[7]; - unsigned long address = 0; + hku_uint32 address = 0; for (int i = 0; i < max_count; i++) { if (!fread(stock_code, 1, 7, fp)) { HKU_ERROR("read stock_code failed! " << filename << funcname); return result; } - if (!fread(&address, sizeof(unsigned long), 1, fp)) { + if (!fread(&address, 4, 1, fp)) { HKU_ERROR("read stock_item address failed! " << filename << funcname); return result; } @@ -75,14 +75,14 @@ ::getHistoryFinanceInfo(Datetime date, if (address != 0) { int report_fields_count = int(report_size / 4); if (report_fields_count >= MAX_COL_NUM) { - HKU_WARN("Over MAX_COL_NUM! [HistoryFinanceReader::getHistoryFinanceInfo]"); + HKU_WARN("Over MAX_COL_NUM! " << filename << funcname); report_fields_count = MAX_COL_NUM; } fseek(fp, address, SEEK_SET); - if (!fread((char *)result_buffer, sizeof(float), report_fields_count, fp)) { - HKU_ERROR("read col data failed!" << filename << funcname); + if (!fread(result_buffer, 4, report_fields_count, fp)) { + HKU_ERROR("read col data failed! " << filename << funcname); return result; } @@ -95,6 +95,9 @@ ::getHistoryFinanceInfo(Datetime date, result.push_back(result_buffer[i]); } } + + } else { + HKU_ERROR("Invalid address(0)! " << filename << funcname); } fclose(fp); diff --git a/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_Stock.cpp b/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_Stock.cpp index 893de86e8..fb60baf99 100644 --- a/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_Stock.cpp +++ b/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_Stock.cpp @@ -1928,4 +1928,26 @@ BOOST_AUTO_TEST_CASE( test_Stock_id_map ) { MEMORY_CHECK; } + +/** @par 检测点 */ +BOOST_AUTO_TEST_CASE( test_Stock_getHistoryFinanceInfo ) { + StockManager& sm = StockManager::instance(); + Stock stk = getStock("sh600000"); + PriceList result = stk.getHistoryFinanceInfo(Datetime(201109300000)); + BOOST_CHECK(result.size() == 286); + BOOST_CHECK_CLOSE(result[0], 1.067, 0.00001); + BOOST_CHECK_CLOSE(result[1], 1.061, 0.00001); + BOOST_CHECK_CLOSE(result[2], 1.360, 0.00001); + BOOST_CHECK_CLOSE(result[3], 7.482, 0.00001); + BOOST_CHECK_CLOSE(result[9], 0.0, 0.00001); + BOOST_CHECK_CLOSE(result[14], 7.87818e+09, 0.00001); + BOOST_CHECK_CLOSE(result[282], 6.327156e+06, 0.00001); + BOOST_CHECK_CLOSE(result[285], 0.0, 0.00001); + //for (int i = 0; i < 286; i++) { + // std::cout << result[i] << std::endl; + //} + + MEMORY_CHECK; +} + /** @} */ diff --git a/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_temp.cpp b/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_temp.cpp index 281a45f22..4c6e85ad0 100644 --- a/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_temp.cpp +++ b/hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_temp.cpp @@ -11,19 +11,5 @@ using namespace hku; BOOST_AUTO_TEST_CASE( test_temp ) { - StockManager& sm = StockManager::instance(); - Stock stk = getStock("sh600000"); - PriceList result = stk.getHistoryFinanceInfo(Datetime(201109300000)); - BOOST_CHECK(result.size() == 286); - BOOST_CHECK_CLOSE(result[0], 1.067, 0.00001); - BOOST_CHECK_CLOSE(result[1], 1.061, 0.00001); - BOOST_CHECK_CLOSE(result[2], 1.360, 0.00001); - BOOST_CHECK_CLOSE(result[3], 7.482, 0.00001); - BOOST_CHECK_CLOSE(result[9], 0.0, 0.00001); - BOOST_CHECK_CLOSE(result[14], 7.87818e+09, 0.00001); - BOOST_CHECK_CLOSE(result[282], 6.327156e+06, 0.00001); - BOOST_CHECK_CLOSE(result[285], 0.0, 0.00001); - //for (int i = 0; i < 286; i++) { - // std::cout << result[i] << std::endl; - //} + }