core.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 core.cpp
  15. * @author Dimitry Khokhlov <winsvega@mail.ru>
  16. * @date 2014
  17. * CORE test functions.
  18. */
  19. #include <boost/test/unit_test.hpp>
  20. #include <libdevcore/CommonIO.h>
  21. #include <libdevcore/Log.h>
  22. #include <test/TestHelper.h>
  23. using namespace dev::test;
  24. BOOST_FIXTURE_TEST_SUITE(CoreLibTests, TestOutputHelper)
  25. BOOST_AUTO_TEST_CASE(byteRef)
  26. {
  27. cnote << "bytesRef copyTo and toString...";
  28. dev::bytes originalSequence = dev::fromHex("0102030405060708091011121314151617181920212223242526272829303132");
  29. dev::bytesRef out(&originalSequence.at(0), 32);
  30. dev::h256 hash32("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347");
  31. hash32.ref().copyTo(out);
  32. BOOST_CHECK_MESSAGE(out.size() == 32, "Error wrong result size when h256::ref().copyTo(dev::bytesRef out)");
  33. BOOST_CHECK_MESSAGE(out.toBytes() == originalSequence, "Error when h256::ref().copyTo(dev::bytesRef out)");
  34. }
  35. BOOST_AUTO_TEST_CASE(isHex)
  36. {
  37. BOOST_CHECK(dev::isHex("0x"));
  38. BOOST_CHECK(dev::isHex("0xA"));
  39. BOOST_CHECK(dev::isHex("0xAB"));
  40. BOOST_CHECK(dev::isHex("0x0AA"));
  41. BOOST_CHECK(!dev::isHex("0x0Ag"));
  42. BOOST_CHECK(!dev::isHex("0Ag"));
  43. BOOST_CHECK(!dev::isHex(" "));
  44. BOOST_CHECK(dev::isHex("aa"));
  45. BOOST_CHECK(dev::isHex("003"));
  46. }
  47. BOOST_AUTO_TEST_SUITE_END()