Skip to content

Commit

Permalink
fix getHistoryFinanceInfo on Linux,sizeof(unsigned long) is 8 not 4
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Apr 6, 2019
1 parent b864bed commit a63b35f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
13 changes: 8 additions & 5 deletions hikyuu_cpp/hikyuu/data_driver/HistoryFinanceReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -95,6 +95,9 @@ ::getHistoryFinanceInfo(Datetime date,
result.push_back(result_buffer[i]);
}
}

} else {
HKU_ERROR("Invalid address(0)! " << filename << funcname);
}

fclose(fp);
Expand Down
22 changes: 22 additions & 0 deletions hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_Stock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/** @} */
16 changes: 1 addition & 15 deletions hikyuu_cpp/unit_test/libs/hikyuu/hikyuu/test_temp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
//}

}

0 comments on commit a63b35f

Please sign in to comment.