1 // Aleth: Ethereum C++ client, tools and libraries.
2 // Copyright 2017-2019 Aleth Authors.
3 // Licensed under the GNU General Public License, Version 3.
4 
5 /// @file
6 /// Fixture class for boost output when running testeth
7 #pragma once
8 #include <test/tools/libtestutils/Common.h>
9 #include <test/tools/libtesteth/JsonSpiritHeaders.h>
10 
11 namespace dev
12 {
13 namespace test
14 {
15 
16 class TestOutputHelper
17 {
18 public:
get()19 	static TestOutputHelper& get()
20 	{
21 		static TestOutputHelper instance;
22 		return instance;
23 	}
24 	TestOutputHelper(TestOutputHelper const&) = delete;
25 	void operator=(TestOutputHelper const&) = delete;
26 
27 	void initTest(size_t _maxTests = 1);
28 	// Display percantage of completed tests to std::out. Has to be called before execution of every test.
29 	void showProgress();
30 	void finishTest();
31 
32 	//void setMaxTests(int _count) { m_maxTests = _count; }
33 	bool checkTest(std::string const& _testName);
setCurrentTestFile(boost::filesystem::path const & _name)34 	void setCurrentTestFile(boost::filesystem::path const& _name) { m_currentTestFileName = _name; }
setCurrentTestName(std::string const & _name)35 	void setCurrentTestName(std::string const& _name) { m_currentTestName = _name; }
testName()36 	std::string const& testName() { return m_currentTestName; }
caseName()37 	std::string const& caseName() { return m_currentTestCaseName; }
testFile()38 	boost::filesystem::path const& testFile() { return m_currentTestFileName; }
39 	void printTestExecStats();
40 
41     // Mark the _folderName as executed for a given _suitePath (to filler files)
42     void markTestFolderAsFinished(
43         boost::filesystem::path const& _suitePath, std::string const& _folderName);
44 
45 private:
TestOutputHelper()46 	TestOutputHelper() {}
47     void checkUnfinishedTestFolders();  // Checkup that all test folders are active during the test
48                                         // run
49     Timer m_timer;
50 	size_t m_currTest;
51 	size_t m_maxTests;
52 	std::string m_currentTestName;
53 	std::string m_currentTestCaseName;
54 	boost::filesystem::path m_currentTestFileName;
55 	typedef std::pair<double, std::string> execTimeName;
56 	std::vector<execTimeName> m_execTimeResults;
57     typedef std::set<std::string> FolderNameSet;
58     std::map<boost::filesystem::path, FolderNameSet> m_finishedTestFoldersMap;
59 };
60 
61 class TestOutputHelperFixture
62 {
63 public:
TestOutputHelperFixture()64 	TestOutputHelperFixture() { TestOutputHelper::get().initTest(); }
~TestOutputHelperFixture()65 	~TestOutputHelperFixture() { TestOutputHelper::get().finishTest(); }
66 };
67 
68 } //namespace test
69 } //namespace dev
70