diff options
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/unit_tests/ban.cpp | 2 | ||||
-rw-r--r-- | tests/unit_tests/blockchain_db.cpp | 2 | ||||
-rw-r--r-- | tests/unit_tests/epee_boosted_tcp_server.cpp | 21 | ||||
-rw-r--r-- | tests/unit_tests/epee_levin_protocol_handler_async.cpp | 26 | ||||
-rw-r--r-- | tests/unit_tests/hardfork.cpp | 4 | ||||
-rw-r--r-- | tests/unit_tests/vercmp.cpp | 43 |
7 files changed, 75 insertions, 28 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index e70ed1a24..d8763df1d 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -58,7 +58,8 @@ set(unit_tests_sources uri.cpp varint.cpp ringct.cpp - output_selection.cpp) + output_selection.cpp + vercmp.cpp) set(unit_tests_headers unit_tests_utils.h) @@ -75,6 +76,8 @@ target_link_libraries(unit_tests wallet p2p epee + ${Boost_CHRONO_LIBRARY} + ${Boost_THREAD_LIBRARY} ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_LIBRARIES}) diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp index 88bbf7eec..f859c6f10 100644 --- a/tests/unit_tests/ban.cpp +++ b/tests/unit_tests/ban.cpp @@ -66,7 +66,7 @@ public: virtual void on_transaction_relayed(const cryptonote::blobdata& tx) {} bool get_testnet() const { return false; } bool get_pool_transaction(const crypto::hash& id, cryptonote::transaction& tx) const { return false; } - bool get_blocks(uint64_t start_offset, size_t count, std::list<cryptonote::block>& blocks, std::list<cryptonote::transaction>& txs) const { return false; } + bool get_blocks(uint64_t start_offset, size_t count, std::list<std::pair<cryptonote::blobdata, cryptonote::block>>& blocks, std::list<cryptonote::blobdata>& txs) const { return false; } bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<cryptonote::transaction>& txs, std::list<crypto::hash>& missed_txs) const { return false; } bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; } }; diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp index 8fc10be10..faf4c776f 100644 --- a/tests/unit_tests/blockchain_db.cpp +++ b/tests/unit_tests/blockchain_db.cpp @@ -288,7 +288,7 @@ TYPED_TEST(BlockchainDBTest, AddBlock) ASSERT_TRUE(compare_blocks(this->m_blocks[0], b)); // assert that we can't add the same block twice - ASSERT_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]), BLOCK_EXISTS); + ASSERT_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]), TX_EXISTS); for (auto& h : this->m_blocks[0].tx_hashes) { diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp index 946db292d..261d81f84 100644 --- a/tests/unit_tests/epee_boosted_tcp_server.cpp +++ b/tests/unit_tests/epee_boosted_tcp_server.cpp @@ -28,10 +28,9 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers -#include <condition_variable> -#include <chrono> -#include <mutex> -#include <thread> +#include <boost/chrono/chrono.hpp> +#include <boost/thread/condition_variable.hpp> +#include <boost/thread/mutex.hpp> #include "gtest/gtest.h" @@ -88,13 +87,13 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant) test_tcp_server srv(epee::net_utils::e_connection_type_RPC); // RPC disables network limit for unit tests ASSERT_TRUE(srv.init_server(test_server_port, test_server_host)); - std::mutex mtx; - std::condition_variable cond; + boost::mutex mtx; + boost::condition_variable cond; int counter = 0; auto counter_incrementer = [&counter, &cond, &mtx]() { - std::unique_lock<std::mutex> lock(mtx); + boost::unique_lock<boost::mutex> lock(mtx); ++counter; if (4 <= counter) { @@ -110,8 +109,8 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant) ASSERT_TRUE(srv.async_call([&counter_incrementer]() { counter_incrementer(); throw 4; })); { - std::unique_lock<std::mutex> lock(mtx); - ASSERT_NE(std::cv_status::timeout, cond.wait_for(lock, std::chrono::seconds(5))); + boost::unique_lock<boost::mutex> lock(mtx); + ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5))); ASSERT_EQ(4, counter); } @@ -124,8 +123,8 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant) ASSERT_TRUE(srv.async_call(counter_incrementer)); { - std::unique_lock<std::mutex> lock(mtx); - ASSERT_NE(std::cv_status::timeout, cond.wait_for(lock, std::chrono::seconds(5))); + boost::unique_lock<boost::mutex> lock(mtx); + ASSERT_NE(boost::cv_status::timeout, cond.wait_for(lock, boost::chrono::seconds(5))); ASSERT_EQ(4, counter); } diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp index 2dd3ffe29..e1ce50e2f 100644 --- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp +++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp @@ -28,8 +28,8 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers -#include <mutex> -#include <thread> +#include <boost/thread/mutex.hpp> +#include <boost/thread/thread.hpp> #include "gtest/gtest.h" @@ -59,7 +59,7 @@ namespace virtual int invoke(int command, const std::string& in_buff, std::string& buff_out, test_levin_connection_context& context) { m_invoke_counter.inc(); - std::unique_lock<std::mutex> lock(m_mutex); + boost::unique_lock<boost::mutex> lock(m_mutex); m_last_command = command; m_last_in_buf = in_buff; buff_out = m_invoke_out_buf; @@ -69,7 +69,7 @@ namespace virtual int notify(int command, const std::string& in_buff, test_levin_connection_context& context) { m_notify_counter.inc(); - std::unique_lock<std::mutex> lock(m_mutex); + boost::unique_lock<boost::mutex> lock(m_mutex); m_last_command = command; m_last_in_buf = in_buff; return m_return_code; @@ -115,7 +115,7 @@ namespace unit_test::call_counter m_new_connection_counter; unit_test::call_counter m_close_connection_counter; - std::mutex m_mutex; + boost::mutex m_mutex; int m_return_code; std::string m_invoke_out_buf; @@ -144,7 +144,7 @@ namespace { //std::cout << "test_connection::do_send()" << std::endl; m_send_counter.inc(); - std::unique_lock<std::mutex> lock(m_mutex); + boost::unique_lock<boost::mutex> lock(m_mutex); m_last_send_data.append(reinterpret_cast<const char*>(ptr), cb); return m_send_return; } @@ -159,7 +159,7 @@ namespace size_t send_counter() const { return m_send_counter.get(); } const std::string& last_send_data() const { return m_last_send_data; } - void reset_last_send_data() { std::unique_lock<std::mutex> lock(m_mutex); m_last_send_data.clear(); } + void reset_last_send_data() { boost::unique_lock<boost::mutex> lock(m_mutex); m_last_send_data.clear(); } bool send_return() const { return m_send_return; } void send_return(bool v) { m_send_return = v; } @@ -172,7 +172,7 @@ namespace test_levin_connection_context m_context; unit_test::call_counter m_send_counter; - std::mutex m_mutex; + boost::mutex m_mutex; std::string m_last_send_data; @@ -305,14 +305,14 @@ TEST_F(positive_test_connection_to_levin_protocol_handler_calls, concurent_handl } }; - const size_t thread_count = std::thread::hardware_concurrency(); - std::vector<std::thread> threads(thread_count); - for (std::thread& th : threads) + const size_t thread_count = boost::thread::hardware_concurrency(); + std::vector<boost::thread> threads(thread_count); + for (boost::thread& th : threads) { - th = std::thread(create_and_destroy_connections); + th = boost::thread(create_and_destroy_connections); } - for (std::thread& th : threads) + for (boost::thread& th : threads) { th.join(); } diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index 81cf32c8b..7ca5ad09d 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -59,7 +59,9 @@ public: virtual void block_txn_abort() {} virtual void drop_hard_fork_info() {} virtual bool block_exists(const crypto::hash& h, uint64_t *height) const { return false; } - virtual block get_block(const crypto::hash& h) const { return block(); } + virtual blobdata get_block_blob_from_height(const uint64_t& height) const { return blobdata(); } + virtual blobdata get_block_blob(const crypto::hash& h) const { return blobdata(); } + virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const { return false; } virtual uint64_t get_block_height(const crypto::hash& h) const { return 0; } virtual block_header get_block_header(const crypto::hash& h) const { return block_header(); } virtual uint64_t get_block_timestamp(const uint64_t& height) const { return 0; } diff --git a/tests/unit_tests/vercmp.cpp b/tests/unit_tests/vercmp.cpp new file mode 100644 index 000000000..d48dfdf7c --- /dev/null +++ b/tests/unit_tests/vercmp.cpp @@ -0,0 +1,43 @@ +// Copyright (c) 2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "gtest/gtest.h" + +#include "common/util.h" + +TEST(vercmp, empty) { ASSERT_TRUE(tools::vercmp("", "") == 0); } +TEST(vercmp, empty0) { ASSERT_TRUE(tools::vercmp("", "0") == 0); } +TEST(vercmp, empty1) { ASSERT_TRUE(tools::vercmp("0", "") == 0); } +TEST(vercmp, zero_zero) { ASSERT_TRUE(tools::vercmp("0", "0") == 0); } +TEST(vercmp, one_one) { ASSERT_TRUE(tools::vercmp("1", "1") == 0); } +TEST(vercmp, one_two) { ASSERT_TRUE(tools::vercmp("1", "2") < 0); } +TEST(vercmp, two_one) { ASSERT_TRUE(tools::vercmp("2", "1") > 0); } +TEST(vercmp, ten_nine) { ASSERT_TRUE(tools::vercmp("10", "9") > 0); } +TEST(vercmp, one_dot_ten_one_dot_nine) { ASSERT_TRUE(tools::vercmp("1.10", "1.9") > 0); } +TEST(vercmp, one_one_dot_nine) { ASSERT_TRUE(tools::vercmp("1", "1.9") < 0); } + |