diff options
author | Lee Clagett <code@leeclagett.com> | 2017-02-12 17:53:13 -0500 |
---|---|---|
committer | Lee Clagett <code@leeclagett.com> | 2017-02-16 20:10:23 -0500 |
commit | 2cde2c02ca0e2bf1dc6f8fa78cd830f5989f9cea (patch) | |
tree | e0fb13b6e69c139e0cdf4557bc9fa99b7d492d81 /tests/libwallet_api_tests | |
parent | Merge pull request #1719 (diff) | |
download | monero-2cde2c02ca0e2bf1dc6f8fa78cd830f5989f9cea.tar.xz |
switch to boost::thread for mingw build
Diffstat (limited to 'tests/libwallet_api_tests')
-rw-r--r-- | tests/libwallet_api_tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/libwallet_api_tests/main.cpp | 59 |
2 files changed, 32 insertions, 29 deletions
diff --git a/tests/libwallet_api_tests/CMakeLists.txt b/tests/libwallet_api_tests/CMakeLists.txt index 9be97ec7c..3a9501cdd 100644 --- a/tests/libwallet_api_tests/CMakeLists.txt +++ b/tests/libwallet_api_tests/CMakeLists.txt @@ -41,8 +41,10 @@ target_link_libraries(libwallet_api_tests PRIVATE wallet epee + ${Boost_CHRONO_LIBRARY} ${Boost_SERIALIZATION_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} + ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp index cb1169df3..f33f41fa4 100644 --- a/tests/libwallet_api_tests/main.cpp +++ b/tests/libwallet_api_tests/main.cpp @@ -34,18 +34,19 @@ #include "wallet/wallet2.h" #include "include_base_utils.h" +#include <boost/chrono/chrono.hpp> #include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/thread/condition_variable.hpp> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> #include <iostream> #include <vector> -#include <mutex> -#include <thread> #include <atomic> #include <functional> -#include <condition_variable> using namespace std; @@ -254,15 +255,15 @@ TEST_F(WalletManagerTest, WalletAmountFromString) } -void open_wallet_helper(Monero::WalletManager *wmgr, Monero::Wallet **wallet, const std::string &pass, std::mutex *mutex) +void open_wallet_helper(Monero::WalletManager *wmgr, Monero::Wallet **wallet, const std::string &pass, boost::mutex *mutex) { if (mutex) mutex->lock(); - LOG_PRINT_L3("opening wallet in thread: " << std::this_thread::get_id()); + LOG_PRINT_L3("opening wallet in thread: " << boost::this_thread::get_id()); *wallet = wmgr->openWallet(WALLET_NAME, pass, true); LOG_PRINT_L3("wallet address: " << (*wallet)->address()); LOG_PRINT_L3("wallet status: " << (*wallet)->status()); - LOG_PRINT_L3("closing wallet in thread: " << std::this_thread::get_id()); + LOG_PRINT_L3("closing wallet in thread: " << boost::this_thread::get_id()); if (mutex) mutex->unlock(); } @@ -307,7 +308,7 @@ TEST_F(WalletManagerTest, WalletManagerOpensWalletWithPasswordAndReopen) Monero::Wallet *wallet2 = nullptr; Monero::Wallet *wallet3 = nullptr; - std::mutex mutex; + boost::mutex mutex; open_wallet_helper(wmgr, &wallet2, wrong_wallet_pass, nullptr); ASSERT_TRUE(wallet2 != nullptr); @@ -785,12 +786,12 @@ struct MyWalletListener : public Monero::WalletListener Monero::Wallet * wallet; uint64_t total_tx; uint64_t total_rx; - std::mutex mutex; - std::condition_variable cv_send; - std::condition_variable cv_receive; - std::condition_variable cv_update; - std::condition_variable cv_refresh; - std::condition_variable cv_newblock; + boost::mutex mutex; + boost::condition_variable cv_send; + boost::condition_variable cv_receive; + boost::condition_variable cv_update; + boost::condition_variable cv_refresh; + boost::condition_variable cv_newblock; bool send_triggered; bool receive_triggered; bool newblock_triggered; @@ -880,8 +881,8 @@ TEST_F(WalletTest2, WalletCallBackRefreshedSync) ASSERT_TRUE(wallet_src->init(TESTNET_DAEMON_ADDRESS, 0)); ASSERT_TRUE(wallet_src_listener->refresh_triggered); ASSERT_TRUE(wallet_src->connected()); - std::chrono::seconds wait_for = std::chrono::seconds(60*3); - std::unique_lock<std::mutex> lock (wallet_src_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(60*3); + boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex); wallet_src_listener->cv_refresh.wait_for(lock, wait_for); wmgr->closeWallet(wallet_src); } @@ -895,8 +896,8 @@ TEST_F(WalletTest2, WalletCallBackRefreshedAsync) Monero::Wallet * wallet_src = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true); MyWalletListener * wallet_src_listener = new MyWalletListener(wallet_src); - std::chrono::seconds wait_for = std::chrono::seconds(20); - std::unique_lock<std::mutex> lock (wallet_src_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(20); + boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex); wallet_src->init(MAINNET_DAEMON_ADDRESS, 0); wallet_src->startRefresh(); std::cerr << "TEST: waiting on refresh lock...\n"; @@ -936,8 +937,8 @@ TEST_F(WalletTest2, WalletCallbackSent) ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok); ASSERT_TRUE(tx->commit()); - std::chrono::seconds wait_for = std::chrono::seconds(60*3); - std::unique_lock<std::mutex> lock (wallet_src_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(60*3); + boost::unique_lock<boost::mutex> lock (wallet_src_listener->mutex); std::cerr << "TEST: waiting on send lock...\n"; wallet_src_listener->cv_send.wait_for(lock, wait_for); std::cerr << "TEST: send lock acquired...\n"; @@ -978,8 +979,8 @@ TEST_F(WalletTest2, WalletCallbackReceived) ASSERT_TRUE(tx->status() == Monero::PendingTransaction::Status_Ok); ASSERT_TRUE(tx->commit()); - std::chrono::seconds wait_for = std::chrono::seconds(60*4); - std::unique_lock<std::mutex> lock (wallet_dst_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(60*4); + boost::unique_lock<boost::mutex> lock (wallet_dst_listener->mutex); std::cerr << "TEST: waiting on receive lock...\n"; wallet_dst_listener->cv_receive.wait_for(lock, wait_for); std::cerr << "TEST: receive lock acquired...\n"; @@ -1011,8 +1012,8 @@ TEST_F(WalletTest2, WalletCallbackNewBlock) std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet_src)); // wait max 4 min for new block - std::chrono::seconds wait_for = std::chrono::seconds(60*4); - std::unique_lock<std::mutex> lock (wallet_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(60*4); + boost::unique_lock<boost::mutex> lock (wallet_listener->mutex); std::cerr << "TEST: waiting on newblock lock...\n"; wallet_listener->cv_newblock.wait_for(lock, wait_for); std::cerr << "TEST: newblock lock acquired...\n"; @@ -1049,8 +1050,8 @@ TEST_F(WalletManagerMainnetTest, CreateAndRefreshWalletMainNetAsync) Monero::Wallet * wallet = wmgr->createWallet(WALLET_NAME_MAINNET, "", WALLET_LANG); std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet)); - std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH); - std::unique_lock<std::mutex> lock (wallet_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH); + boost::unique_lock<boost::mutex> lock (wallet_listener->mutex); wallet->init(MAINNET_DAEMON_ADDRESS, 0); wallet->startRefresh(); std::cerr << "TEST: waiting on refresh lock...\n"; @@ -1075,8 +1076,8 @@ TEST_F(WalletManagerMainnetTest, OpenAndRefreshWalletMainNetAsync) std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet)); - std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH); - std::unique_lock<std::mutex> lock (wallet_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH); + boost::unique_lock<boost::mutex> lock (wallet_listener->mutex); wallet->init(MAINNET_DAEMON_ADDRESS, 0); wallet->startRefresh(); std::cerr << "TEST: waiting on refresh lock...\n"; @@ -1109,8 +1110,8 @@ TEST_F(WalletManagerMainnetTest, RecoverAndRefreshWalletMainNetAsync) ASSERT_TRUE(wallet->status() == Monero::Wallet::Status_Ok); ASSERT_TRUE(wallet->address() == address); std::unique_ptr<MyWalletListener> wallet_listener (new MyWalletListener(wallet)); - std::chrono::seconds wait_for = std::chrono::seconds(SECONDS_TO_REFRESH); - std::unique_lock<std::mutex> lock (wallet_listener->mutex); + boost::chrono::seconds wait_for = boost::chrono::seconds(SECONDS_TO_REFRESH); + boost::unique_lock<boost::mutex> lock (wallet_listener->mutex); wallet->init(MAINNET_DAEMON_ADDRESS, 0); wallet->startRefresh(); std::cerr << "TEST: waiting on refresh lock...\n"; |