aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDmitry K <winsvega@mail.ru>2016-08-03 00:32:03 +0800
committerDmitry K <winsvega@mail.ru>2016-08-03 00:32:03 +0800
commit5925ae0c6a32517f3b19b095e3ed8518d021f2e7 (patch)
tree117140938964c4b555856ae340d907e917e4efbb /test
parenta10b6f92f97bf2eacc80534f6640e08f0b26e95d (diff)
downloaddexon-solidity-5925ae0c6a32517f3b19b095e3ed8518d021f2e7.tar.gz
dexon-solidity-5925ae0c6a32517f3b19b095e3ed8518d021f2e7.tar.zst
dexon-solidity-5925ae0c6a32517f3b19b095e3ed8518d021f2e7.zip
Windows pipe for soltest
Diffstat (limited to 'test')
-rw-r--r--test/RPCSession.cpp46
-rw-r--r--test/RPCSession.h17
-rw-r--r--test/TestHelper.cpp51
-rw-r--r--test/TestHelper.h15
-rw-r--r--test/boostTest.cpp65
-rw-r--r--test/libsolidity/SolidityExecutionFramework.cpp17
6 files changed, 176 insertions, 35 deletions
diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp
index 124ee789..c510a028 100644
--- a/test/RPCSession.cpp
+++ b/test/RPCSession.cpp
@@ -13,6 +13,8 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
+
+ The Implementation originally from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365592(v=vs.85).aspx
*/
/** @file RPCSession.cpp
* @author Dimtiry Khokhlov <dimitry@ethdev.com>
@@ -32,6 +34,19 @@ using namespace dev;
IPCSocket::IPCSocket(string const& _path): m_path(_path)
{
+ m_socket = CreateFile(
+ m_path.c_str(), // pipe name
+ GENERIC_READ | // read and write access
+ GENERIC_WRITE,
+ 0, // no sharing
+ NULL, // default security attribute
+ OPEN_EXISTING, // opens existing pipe
+ 0, // default attributes
+ NULL); // no template file
+
+ if (m_socket == INVALID_HANDLE_VALUE)
+ BOOST_FAIL("Error creating IPC socket object");
+
#if defined(_WIN32)
#else
if (_path.length() >= sizeof(sockaddr_un::sun_path))
@@ -66,7 +81,36 @@ IPCSocket::IPCSocket(string const& _path): m_path(_path)
string IPCSocket::sendRequest(string const& _req)
{
#if defined(_WIN32)
- return "";
+ string returnStr;
+ DWORD cbWritten;
+ BOOL fSuccess = WriteFile(
+ m_socket, // pipe handle
+ _req.c_str(), // message
+ _req.size(), // message length
+ &cbWritten, // bytes written
+ NULL); // not overlapped
+
+ if (!fSuccess)
+ BOOST_FAIL("WriteFile to pipe failed");
+
+ DWORD cbRead;
+ TCHAR chBuf[c_buffsize];
+
+ // Read from the pipe.
+ fSuccess = ReadFile(
+ m_socket, // pipe handle
+ chBuf, // buffer to receive reply
+ c_buffsize,// size of buffer
+ &cbRead, // number of bytes read
+ NULL); // not overlapped
+
+ returnStr += chBuf;
+
+ if (!fSuccess)
+ BOOST_FAIL("ReadFile from pipe failed");
+
+ cerr << "."; //Output for log activity
+ return returnStr;
#else
send(m_socket, _req.c_str(), _req.length(), 0);
diff --git a/test/RPCSession.h b/test/RPCSession.h
index fd77ceca..9b7009bf 100644
--- a/test/RPCSession.h
+++ b/test/RPCSession.h
@@ -19,33 +19,35 @@
* @date 2016
*/
-#include <string>
-#include <stdio.h>
-#include <map>
#if defined(_WIN32)
+#include <windows.h>
+#include "libdevcore/UndefMacros.h"
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#endif
+
+#include <string>
+#include <stdio.h>
+#include <map>
#include <json/value.h>
#include <boost/test/unit_test.hpp>
#if defined(_WIN32)
+const int c_buffsize = 5120000; //because windows pipe is broken and wont work as in examples. use larger buffer limit to receive whole package in one call
class IPCSocket : public boost::noncopyable
{
public:
IPCSocket(std::string const& _path);
std::string sendRequest(std::string const& _req);
- ~IPCSocket() { fclose(m_fp); }
+ ~IPCSocket() { CloseHandle(m_socket); }
std::string const& path() const { return m_path; }
private:
- FILE *m_fp;
std::string m_path;
- int m_socket;
-
+ HANDLE m_socket;
};
#else
class IPCSocket: public boost::noncopyable
@@ -61,7 +63,6 @@ private:
FILE *m_fp;
std::string m_path;
int m_socket;
-
};
#endif
diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp
new file mode 100644
index 00000000..e85ace36
--- /dev/null
+++ b/test/TestHelper.cpp
@@ -0,0 +1,51 @@
+/*
+ This file is part of cpp-ethereum.
+
+ cpp-ethereum is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ cpp-ethereum is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
+*/
+/** @file TestHelper.h
+* @author Marko Simovic <markobarko@gmail.com>
+* @date 2014
+*/
+
+#include <boost/test/framework.hpp>
+#include "TestHelper.h"
+using namespace std;
+using namespace dev::test;
+
+Options::Options(int argc, char** argv)
+{
+ tArgc = 0;
+ tArgv = new char*[argc];
+ for (size_t i = 0; i < argc; i++)
+ {
+ string arg = argv[i];
+ if (arg == "--ipc" && i + 1 < argc)
+ {
+ ipcPath = argv[i + 1];
+ i++;
+ }
+ else
+ {
+ tArgv[i] = argv[i];
+ tArgc++;
+ }
+ }
+}
+
+Options const& Options::get(int argc, char** argv)
+{
+ static Options instance(argc, argv);
+ return instance;
+} \ No newline at end of file
diff --git a/test/TestHelper.h b/test/TestHelper.h
index 2d08d62c..49931614 100644
--- a/test/TestHelper.h
+++ b/test/TestHelper.h
@@ -102,5 +102,20 @@ namespace test
} \
while (0)
+
+ class Options
+ {
+ public:
+ std::string ipcPath;
+ int tArgc;
+ char **tArgv;
+ /// Get reference to options
+ /// The first time used, options are parsed with argc, argv
+ static Options const& get(int argc = 0, char** argv = 0);
+
+ private:
+ Options(int argc, char** argv = 0);
+ Options(Options const&) = delete;
+ };
}
}
diff --git a/test/boostTest.cpp b/test/boostTest.cpp
index a2cfa5ee..7ed2a6cd 100644
--- a/test/boostTest.cpp
+++ b/test/boostTest.cpp
@@ -25,17 +25,60 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
-#if defined(_MSC_VER)
-#pragma warning(push)
-#pragma warning(disable:4535) // calling _set_se_translator requires /EHa
-#endif
-#include <boost/test/included/unit_test.hpp>
-#if defined(_MSC_VER)
-#pragma warning(pop)
-#endif
-#pragma GCC diagnostic pop
+ #define BOOST_TEST_NO_MAIN
+ #if defined(_MSC_VER)
+ #pragma warning(push)
+ #pragma warning(disable:4535) // calling _set_se_translator requires /EHa
+ #endif
+ #include <boost/test/included/unit_test.hpp>
+ #if defined(_MSC_VER)
+ #pragma warning(pop)
+ #endif
-#include <test/TestHelper.h>
-using namespace boost::unit_test;
+ #pragma GCC diagnostic pop
+ #include <stdlib.h>
+ #include <boost/version.hpp>
+ #include "TestHelper.h"
+
+ using namespace boost::unit_test;
+
+ std::vector<char*> parameters;
+ static std::ostringstream strCout;
+ std::streambuf* oldCoutStreamBuf;
+ std::streambuf* oldCerrStreamBuf;
+
+ //Custom Boost Initialization
+ test_suite* fake_init_func(int argc, char* argv[])
+ {
+ //Required for boost. -nowarning
+ (void)argc;
+ (void)argv;
+ return 0;
+ }
+
+ //Custom Boost Unit Test Main
+ int main(int argc, char* argv[])
+ {
+ //Initialize options before boost reads it
+ dev::test::Options const& opt = dev::test::Options::get(argc, argv);
+ return unit_test_main(fake_init_func, opt.tArgc, opt.tArgv);
+ }
+
+ /*
+#else
+ #if defined(_MSC_VER)
+ #pragma warning(push)
+ #pragma warning(disable:4535) // calling _set_se_translator requires /EHa
+ #endif
+ #include <boost/test/included/unit_test.hpp>
+ #if defined(_MSC_VER)
+ #pragma warning(pop)
+ #endif
+
+ #pragma GCC diagnostic pop
+
+ #include <test/TestHelper.h>
+ using namespace boost::unit_test;
+#endif*/ \ No newline at end of file
diff --git a/test/libsolidity/SolidityExecutionFramework.cpp b/test/libsolidity/SolidityExecutionFramework.cpp
index a33f4caf..921fd056 100644
--- a/test/libsolidity/SolidityExecutionFramework.cpp
+++ b/test/libsolidity/SolidityExecutionFramework.cpp
@@ -25,8 +25,6 @@
#include <libdevcore/CommonIO.h>
#include <test/libsolidity/SolidityExecutionFramework.h>
-
-
using namespace std;
using namespace dev;
using namespace dev::solidity;
@@ -39,24 +37,13 @@ namespace // anonymous
string getIPCSocketPath()
{
- string ipcPath;
-
- size_t argc = boost::unit_test::framework::master_test_suite().argc;
- char** argv = boost::unit_test::framework::master_test_suite().argv;
- for (size_t i = 0; i < argc; i++)
- {
- string arg = argv[i];
- if (arg == "--ipc" && i + 1 < argc)
- {
- ipcPath = argv[i + 1];
- i++;
- }
- }
+ string ipcPath = dev::test::Options::get().ipcPath;
if (ipcPath.empty())
if (auto path = getenv("ETH_TEST_IPC"))
ipcPath = path;
if (ipcPath.empty())
BOOST_FAIL("ERROR: ipcPath not set! (use --ipc <path> or the environment variable ETH_TEST_IPC)");
+
return ipcPath;
}