TestUtils.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file TestUtils.h
  15. * @author Marek Kotewicz <marek@ethdev.com>
  16. * @date 2015
  17. */
  18. #pragma once
  19. #include <functional>
  20. #include <string>
  21. #include <json/json.h>
  22. #include <libdevcore/TransientDirectory.h>
  23. #include <libethereum/BlockChain.h>
  24. #include <libethereum/ClientBase.h>
  25. namespace dev
  26. {
  27. namespace test
  28. {
  29. // should be used for multithread tests
  30. static SharedMutex x_boostTest;
  31. #define ETH_CHECK_EQUAL(x, y) { dev::WriteGuard(x_boostTest); BOOST_CHECK_EQUAL(x, y); }
  32. #define ETH_CHECK_EQUAL_COLLECTIONS(xb, xe, yb, ye) { dev::WriteGuard(x_boostTest); BOOST_CHECK_EQUAL_COLLECTIONS(xb, xe, yb, ye); }
  33. #define ETH_REQUIRE(x) { dev::WriteGuard(x_boostTest); BOOST_REQUIRE(x); }
  34. struct LoadTestFileFixture
  35. {
  36. LoadTestFileFixture();
  37. protected:
  38. Json::Value m_json;
  39. };
  40. struct ParallelFixture
  41. {
  42. void enumerateThreads(std::function<void()> callback) const;
  43. };
  44. struct BlockChainFixture: public LoadTestFileFixture
  45. {
  46. void enumerateBlockchains(std::function<void(Json::Value const&, dev::eth::BlockChain const&, dev::eth::State state)> callback) const;
  47. };
  48. struct ClientBaseFixture: public BlockChainFixture
  49. {
  50. void enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback) const;
  51. };
  52. // important BOOST TEST do have problems with thread safety!!!
  53. // BOOST_CHECK is not thread safe
  54. // BOOST_MESSAGE is not thread safe
  55. // http://boost.2283326.n4.nabble.com/Is-boost-test-thread-safe-td3471644.html
  56. // http://lists.boost.org/boost-users/2010/03/57691.php
  57. // worth reading
  58. // https://codecrafter.wordpress.com/2012/11/01/c-unit-test-framework-adapter-part-3/
  59. struct ParallelClientBaseFixture: public ClientBaseFixture, public ParallelFixture
  60. {
  61. void enumerateClients(std::function<void(Json::Value const&, dev::eth::ClientBase&)> callback) const;
  62. };
  63. struct JsonRpcFixture: public ClientBaseFixture
  64. {
  65. };
  66. }
  67. }