Fabcoin Core  0.16.2
P2P Digital Currency
Common.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16  */
22 #include <random>
23 #include <boost/filesystem.hpp>
24 #include <libdevcore/CommonData.h>
25 #include <libdevcore/CommonIO.h>
26 #include <libdevcore/FileSystem.h>
27 #include "Common.h"
28 
29 using namespace std;
30 using namespace dev;
31 using namespace dev::test;
32 
33 const char* TestChannel::name() { return "TST"; }
34 
36 {
37  string testPath;
38  const char* ptestPath = getenv("ETHEREUM_TEST_PATH");
39 
40  if (ptestPath == NULL)
41  {
42  ctest << " could not find environment variable ETHEREUM_TEST_PATH \n";
43  testPath = "../../../tests";
44  }
45  else
46  testPath = ptestPath;
47 
48  return testPath;
49 }
50 
52 {
53  static std::mt19937 randomGenerator(utcTime());
54  randomGenerator.seed(std::random_device()());
55  return std::uniform_int_distribution<int>(1)(randomGenerator);
56 }
57 
58 Json::Value dev::test::loadJsonFromFile(std::string const& _path)
59 {
60  Json::Reader reader;
61  Json::Value result;
62  string s = dev::contentsString(_path);
63  if (!s.length())
64  ctest << "Contents of " + _path + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?";
65  else
66  ctest << "FIXTURE: loaded test from file: " << _path;
67 
68  reader.parse(s, result);
69  return result;
70 }
71 
72 std::string dev::test::toTestFilePath(std::string const& _filename)
73 {
74  return getTestPath() + "/" + _filename + ".json";
75 }
76 
77 std::string dev::test::getFolder(std::string const& _file)
78 {
79  return boost::filesystem::path(_file).parent_path().string();
80 }
81 
83 {
84  std::stringstream stream;
85  stream << getDataDir("EthereumTests") << "/" << randomNumber();
86  return stream.str();
87 }
88 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
Json::Value loadJsonFromFile(std::string const &_path)
Definition: Common.cpp:58
int randomNumber()
Definition: Common.cpp:51
uint64_t utcTime()
Get the current time in seconds since the epoch in UTC.
Definition: Common.cpp:64
std::hash for asio::adress
Definition: Common.h:323
std::string contentsString(std::string const &_file)
Retrieve and returns the contents of the given file as a std::string.
std::string getDataDir(std::string _prefix="ethereum")
std::string getRandomPath()
Definition: Common.cpp:82
Config::Value_type Value
const char * name
Definition: rest.cpp:36
std::string getFolder(std::string const &_file)
Definition: Common.cpp:77
#define ctest
Definition: Common.h:34
std::string getTestPath()
Definition: Common.cpp:35
std::string toTestFilePath(std::string const &_filename)
Definition: Common.cpp:72