Skip to content

Commit

Permalink
testing part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Mar 26, 2015
1 parent c24a2dc commit 17d941f
Show file tree
Hide file tree
Showing 9 changed files with 567 additions and 36 deletions.
44 changes: 20 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include_directories(${Boost_INCLUDE_DIRS})
include_directories(BEFORE ..)

find_package (Qt5WebEngine QUIET)
qt5_add_resources(UI_RESOURCES res.qrc qml.qrc)
qt5_add_resources(UI_RESOURCES res.qrc qml.qrc test.qrc)

file(GLOB HEADERS "*.h")

Expand All @@ -37,32 +37,18 @@ eth_add_executable(${EXECUTABLE}
UI_RESOURCES ${UI_RESOURCES}
)

target_link_libraries(${EXECUTABLE} Qt5::Core)
target_link_libraries(${EXECUTABLE} Qt5::Gui)
target_link_libraries(${EXECUTABLE} Qt5::Widgets)
target_link_libraries(${EXECUTABLE} Qt5::Network)
target_link_libraries(${EXECUTABLE} Qt5::Quick)
target_link_libraries(${EXECUTABLE} Qt5::Qml)
target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} ethereum)
target_link_libraries(${EXECUTABLE} evm)
target_link_libraries(${EXECUTABLE} ethcore)
target_link_libraries(${EXECUTABLE} devcrypto)
target_link_libraries(${EXECUTABLE} secp256k1)
if (NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"))
target_link_libraries(${EXECUTABLE} serpent)
endif()
target_link_libraries(${EXECUTABLE} lll)
target_link_libraries(${EXECUTABLE} solidity)
target_link_libraries(${EXECUTABLE} evmcore)
target_link_libraries(${EXECUTABLE} devcore)
target_link_libraries(${EXECUTABLE} jsqrc)
target_link_libraries(${EXECUTABLE} web3jsonrpc)
find_package(Qt5QuickTest REQUIRED)
find_package(Qt5Test REQUIRED)

set(LIBRARIES "Qt5::Core;Qt5::Gui;Qt5::Widgets;Qt5::Network;Qt5::Quick;Qt5::Qml;webthree;ethereum;evm;ethcore;devcrypto;solidity;evmcore;devcore;jsqrc;web3jsonrpc")
if (${ETH_HAVE_WEBENGINE})
add_definitions(-DETH_HAVE_WEBENGINE)
target_link_libraries(${EXECUTABLE} Qt5::WebEngine)
list(APPEND LIBRARIES "Qt5::WebEngine")
endif()
list(APPEND LIBRARIES "Qt5::QuickTest")
list(APPEND LIBRARIES "Qt5::Test")

target_link_libraries(${EXECUTABLE} ${LIBRARIES})

# eth_install_executable is defined in cmake/EthExecutableHelper.cmake
eth_install_executable(${EXECUTABLE}
Expand All @@ -71,5 +57,15 @@ eth_install_executable(${EXECUTABLE}

#add qml asnd stdc files to project tree in Qt creator
file(GLOB_RECURSE QMLFILES "qml/*.*")
file(GLOB_RECURSE TESTFILE "test/*.*")
file(GLOB_RECURSE SOLFILES "stdc/*.*")
add_custom_target(mix_qml SOURCES ${QMLFILES} ${SOLFILES})
add_custom_target(mix_qml SOURCES ${QMLFILES} ${SOLFILES} ${TESTFILES})


#test target
#set(TEST_EXECUTABLE mix_test)
#qt5_add_resources(UI_RESOURCES test.qrc)
#add_executable(${TEST_EXECUTABLE} ${UI_RESOURCES} ${SRC_LIST} ${HEADERS})



71 changes: 62 additions & 9 deletions MixApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <QQmlApplicationEngine>
#include <QUrl>
#include <QIcon>
#include <QFont>
#include <QtTest/QSignalSpy>
#include <QElapsedTimer>
#include <QtTest/QTest>
#ifdef ETH_HAVE_WEBENGINE
#include <QtWebEngine/QtWebEngine>
#endif
Expand All @@ -37,21 +41,73 @@

using namespace dev::mix;

ApplicationService::ApplicationService()
{
#ifdef ETH_HAVE_WEBENGINE
QtWebEngine::initialize();
#endif
QFont f;
m_systemPointSize = f.pointSize();
}


#include <QMetaMethod>

bool ApplicationService::waitForSignal(QObject* _item, QString _signalName, int _timeout)
{
QSignalSpy spy(_item, ("2" + _signalName.toStdString()).c_str());
QMetaObject const* mo = _item->metaObject();

QStringList methods;

for(int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
if (mo->method(i).methodType() == QMetaMethod::Signal) {
methods << QString::fromLatin1(mo->method(i).methodSignature());
}
}

QElapsedTimer timer;
timer.start();

while (!spy.size()) {
int remaining = _timeout - int(timer.elapsed());
if (remaining <= 0)
break;
QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
QTest::qSleep(10);
}

return spy.size();
}

MixApplication::MixApplication(int& _argc, char* _argv[]):
QApplication(_argc, _argv), m_engine(new QQmlApplicationEngine())
{
initialize();
//m_engine->load(QUrl("qrc:/qml/main.qml"));
m_engine->load(QUrl("qrc:/test/TestMain.qml"));


if (!m_engine->rootObjects().empty())
{
QWindow *window = qobject_cast<QWindow*>(m_engine->rootObjects().at(0));
if (window)
window->setIcon(QIcon(":/res/mix_256x256x32.png"));
}
}


void MixApplication::initialize()
{
setOrganizationName(tr("Ethereum"));
setOrganizationDomain(tr("ethereum.org"));
setApplicationName(tr("Mix"));
setApplicationVersion("0.1");
#ifdef ETH_HAVE_WEBENGINE
QtWebEngine::initialize();
#endif

QFont f;
m_engine->rootContext()->setContextProperty("systemPointSize", f.pointSize());
qmlRegisterType<CodeModel>("org.ethereum.qml.CodeModel", 1, 0, "CodeModel");
qmlRegisterType<ClientModel>("org.ethereum.qml.ClientModel", 1, 0, "ClientModel");
qmlRegisterType<ApplicationService>("org.ethereum.qml.ApplicationService", 1, 0, "ApplicationService");
qmlRegisterType<FileIo>("org.ethereum.qml.FileIo", 1, 0, "FileIo");
qmlRegisterType<QEther>("org.ethereum.qml.QEther", 1, 0, "QEther");
qmlRegisterType<QBigInt>("org.ethereum.qml.QBigInt", 1, 0, "QBigInt");
Expand All @@ -63,10 +119,7 @@ MixApplication::MixApplication(int& _argc, char* _argv[]):
qmlRegisterType<HttpServer>("HttpServer", 1, 0, "HttpServer");
qRegisterMetaType<CodeModel*>("CodeModel*");
qRegisterMetaType<ClientModel*>("ClientModel*");

m_engine->load(QUrl("qrc:/qml/main.qml"));
QWindow *window = qobject_cast<QWindow*>(m_engine->rootObjects().at(0));
window->setIcon(QIcon(":/res/mix_256x256x32.png"));
qRegisterMetaType<ClientModel*>("ClientModel*");
}

MixApplication::~MixApplication()
Expand Down
17 changes: 17 additions & 0 deletions MixApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,29 @@ namespace dev
namespace mix
{

class ApplicationService: public QObject
{
Q_OBJECT
Q_PROPERTY(int systemPointSize READ systemPointSize CONSTANT)

public:
ApplicationService();
int systemPointSize() const { return m_systemPointSize; }
public slots:
bool waitForSignal(QObject* _item, QString _signalName, int _timeout);

private:
int m_systemPointSize = 0;
};


class MixApplication: public QApplication
{
Q_OBJECT

public:
MixApplication(int& _argc, char* _argv[]);
static void initialize();
virtual ~MixApplication();
QQmlApplicationEngine* engine() { return m_engine.get(); }

Expand Down
15 changes: 13 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <stdlib.h>
#include "MixApplication.h"
#include "Exceptions.h"

#include <QtQuickTest/quicktest.h>


using namespace dev::mix;

int main(int _argc, char* _argv[])
Expand All @@ -43,8 +47,15 @@ int main(int _argc, char* _argv[])
#endif
try
{
MixApplication app(_argc, _argv);
return app.exec();

//
MixApplication::initialize();
//MixApplication app(_argc, _argv);
return quick_test_main(_argc, _argv, "mix", "/home/arkady/src/cpp-ethereum/mix/test/TestMain.qml");


//MixApplication app(_argc, _argv);
//return app.exec();
}
catch (boost::exception const& _e)
{
Expand Down
2 changes: 1 addition & 1 deletion qml.qrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file>qml/AlertMessageDialog.qml</file>
<file>qml/Application.qml</file>
<file>qml/BasicMessage.qml</file>
<file>qml/BigIntValue.qml</file>
<file>qml/CallStack.qml</file>
Expand Down Expand Up @@ -59,7 +60,6 @@
<file>qml/js/ProjectModel.js</file>
<file>qml/js/QEtherHelper.js</file>
<file>qml/js/TransactionHelper.js</file>
<file>qml/main.qml</file>
<file>qml/qmldir</file>
</qresource>
</RCC>
Loading

0 comments on commit 17d941f

Please sign in to comment.