mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fixes for test/TestUtils.h
This commit is contained in:
parent
ac558b0377
commit
9a032ef39f
@ -19,8 +19,6 @@
|
||||
* @date 2015
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
#include <random>
|
||||
#include <thread>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
@ -28,10 +26,6 @@
|
||||
#include <libtestutils/FixedClient.h>
|
||||
#include "TestUtils.h"
|
||||
|
||||
// used methods from TestHelper:
|
||||
// getTestPath
|
||||
#include "TestHelper.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::eth;
|
||||
@ -73,19 +67,12 @@ std::string dev::test::getCommandLineArgument(string const& _name, bool _require
|
||||
return "";
|
||||
}
|
||||
|
||||
bool LoadTestFileFixture::m_loaded = false;
|
||||
Json::Value LoadTestFileFixture::m_json;
|
||||
|
||||
LoadTestFileFixture::LoadTestFileFixture()
|
||||
{
|
||||
if (!m_loaded)
|
||||
{
|
||||
m_json = loadJsonFromFile(toTestFilePath(getCommandLineArgument("--eth_testfile")));
|
||||
m_loaded = true;
|
||||
}
|
||||
m_json = loadJsonFromFile(toTestFilePath(getCommandLineArgument("--eth_testfile")));
|
||||
}
|
||||
|
||||
void ParallelFixture::enumerateThreads(std::function<void()> callback)
|
||||
void ParallelFixture::enumerateThreads(std::function<void()> callback) const
|
||||
{
|
||||
size_t threadsCount = std::stoul(getCommandLineArgument("--eth_threads"), nullptr, 10);
|
||||
|
||||
@ -99,7 +86,7 @@ void ParallelFixture::enumerateThreads(std::function<void()> callback)
|
||||
});
|
||||
}
|
||||
|
||||
void BlockChainFixture::enumerateBlockchains(std::function<void(Json::Value const&, dev::eth::BlockChain&, State state)> callback)
|
||||
void BlockChainFixture::enumerateBlockchains(std::function<void(Json::Value const&, dev::eth::BlockChain const&, State state)> callback) const
|
||||
{
|
||||
for (string const& name: m_json.getMemberNames())
|
||||
{
|
||||
@ -108,16 +95,16 @@ void BlockChainFixture::enumerateBlockchains(std::function<void(Json::Value cons
|
||||
}
|
||||
}
|
||||
|
||||
void ClientBaseFixture::enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback)
|
||||
void ClientBaseFixture::enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback) const
|
||||
{
|
||||
enumerateBlockchains([&callback](Json::Value const& _json, BlockChain& _bc, State _state) -> void
|
||||
enumerateBlockchains([&callback](Json::Value const& _json, BlockChain const& _bc, State _state) -> void
|
||||
{
|
||||
FixedClient client(_bc, _state);
|
||||
callback(_json, client);
|
||||
});
|
||||
}
|
||||
|
||||
void ParallelClientBaseFixture::enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback)
|
||||
void ParallelClientBaseFixture::enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback) const
|
||||
{
|
||||
ClientBaseFixture::enumerateClients([this, &callback](Json::Value const& _json, dev::eth::ClientBase& _client) -> void
|
||||
{
|
||||
|
14
TestUtils.h
14
TestUtils.h
@ -41,24 +41,24 @@ static SharedMutex x_boostTest;
|
||||
struct LoadTestFileFixture
|
||||
{
|
||||
LoadTestFileFixture();
|
||||
|
||||
static bool m_loaded;
|
||||
static Json::Value m_json;
|
||||
|
||||
protected:
|
||||
Json::Value m_json;
|
||||
};
|
||||
|
||||
struct ParallelFixture
|
||||
{
|
||||
void enumerateThreads(std::function<void()> callback);
|
||||
void enumerateThreads(std::function<void()> callback) const;
|
||||
};
|
||||
|
||||
struct BlockChainFixture: public LoadTestFileFixture
|
||||
{
|
||||
void enumerateBlockchains(std::function<void(Json::Value const&, dev::eth::BlockChain&, dev::eth::State state)> callback);
|
||||
void enumerateBlockchains(std::function<void(Json::Value const&, dev::eth::BlockChain const&, dev::eth::State state)> callback) const;
|
||||
};
|
||||
|
||||
struct ClientBaseFixture: public BlockChainFixture
|
||||
{
|
||||
void enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback);
|
||||
void enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback) const;
|
||||
};
|
||||
|
||||
// important BOOST TEST do have problems with thread safety!!!
|
||||
@ -70,7 +70,7 @@ struct ClientBaseFixture: public BlockChainFixture
|
||||
// https://codecrafter.wordpress.com/2012/11/01/c-unit-test-framework-adapter-part-3/
|
||||
struct ParallelClientBaseFixture: public ClientBaseFixture, public ParallelFixture
|
||||
{
|
||||
void enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback);
|
||||
void enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback) const;
|
||||
};
|
||||
|
||||
struct JsonRpcFixture: public ClientBaseFixture
|
||||
|
Loading…
Reference in New Issue
Block a user