Browse Source

continue work on tests

cl-refactor
arkpar 10 years ago
parent
commit
b1a51ebd46
  1. 1
      mix/qml/CodeEditorView.qml
  2. 1
      mix/qml/MainContent.qml
  3. 21
      mix/qml/WebCodeEditor.qml
  4. 1
      mix/qml/WebPreview.qml
  5. 19
      mix/test/TestService.cpp
  6. 6
      mix/test/TestService.h
  7. 107
      mix/test/qml/TestMain.qml

1
mix/qml/CodeEditorView.qml

@ -203,7 +203,6 @@ Item {
id: editors
model: editorListModel
onItemRemoved: {
console.log("unloaded");
item.item.unloaded = true;
}
delegate: Loader {

1
mix/qml/MainContent.qml

@ -22,6 +22,7 @@ Rectangle {
property alias rightViewVisible: rightView.visible
property alias webViewVisible: webPreview.visible
property alias webView: webPreview
property alias projectViewVisible: projectList.visible
property alias runOnProjectLoad: mainSettings.runOnProjectLoad
property alias rightPane: rightView

21
mix/qml/WebCodeEditor.qml

@ -19,10 +19,11 @@ Item {
function setText(text, mode) {
currentText = text;
currentMode = mode;
if(mode !== undefined)
currentMode = mode;
if (initialized) {
editorBrowser.runJavaScript("setTextBase64(\"" + Qt.btoa(text) + "\")");
editorBrowser.runJavaScript("setMode(\"" + mode + "\")");
editorBrowser.runJavaScript("setMode(\"" + currentMode + "\")");
}
setFocus();
}
@ -94,15 +95,19 @@ Item {
if (currentMode === "solidity")
{
codeModel.onCompilationComplete.connect(function(){
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
if (editorBrowser)
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
});
codeModel.onCompilationError.connect(function(error){
var errorInfo = ErrorLocationFormater.extractErrorInfo(error, false);
if (errorInfo.line && errorInfo.column)
editorBrowser.runJavaScript("compilationError('" + errorInfo.line + "', '" + errorInfo.column + "', '" + errorInfo.errorDetail + "')", function(result) { });
else
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
if (editorBrowser)
{
var errorInfo = ErrorLocationFormater.extractErrorInfo(error, false);
if (errorInfo.line && errorInfo.column)
editorBrowser.runJavaScript("compilationError('" + errorInfo.line + "', '" + errorInfo.column + "', '" + errorInfo.errorDetail + "')", function(result) { });
else
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
}
});
}
parent.changeGeneration();

1
mix/qml/WebPreview.qml

@ -12,6 +12,7 @@ Item {
id: webPreview
property string pendingPageUrl: ""
property bool initialized: false
property alias urlInput: urlInput
signal javaScriptMessage(var _level, string _sourceId, var _lineNb, string _content)
function setPreviewUrl(url) {

19
mix/test/TestService.cpp

@ -23,6 +23,8 @@
#include "TestService.h"
#include <QtTest/QSignalSpy>
#include <QElapsedTimer>
#include <QQuickItem>
#include <QQuickWindow>
#include <QtTest/QTest>
#include <QtTest/qtestkeyboard.h>
@ -104,8 +106,25 @@ bool TestService::keyClickChar(QString const& _character, int _modifiers, int _d
return true;
}
void TestService::setTargetWindow(QObject* _window)
{
QQuickWindow* window = qobject_cast<QQuickWindow*>(_window);
if (window)
m_targetWindow = window;
window->requestActivate();
}
QWindow* TestService::eventWindow()
{
QQuickWindow* window = qobject_cast<QQuickWindow*>(m_targetWindow);
if (window)
{
window->requestActivate();
return window;
}
QQuickItem* item = qobject_cast<QQuickItem*>(m_targetWindow);
if (item)
return item->window();
return 0;
}

6
mix/test/TestService.h

@ -34,6 +34,11 @@ namespace mix
class TestService: public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* targetWindow READ targetWindow WRITE setTargetWindow)
public:
QObject* targetWindow() const { return m_targetWindow; }
void setTargetWindow(QObject* _window);
public slots:
bool waitForSignal(QObject* _item, QString _signalName, int _timeout);
@ -46,6 +51,7 @@ public slots:
private:
QWindow* eventWindow();
QObject* m_targetWindow;
};
}

107
mix/test/qml/TestMain.qml

@ -3,50 +3,85 @@ import QtTest 1.1
import org.ethereum.qml.TestService 1.0
import "../../qml"
TestCase
{
id: tc
TestService
{
id: ts
function typeString(str)
TestService
{
for (var c in str)
ts.keyClickChar(c, Qt.NoModifier, 20);
id: ts
targetWindow: mainApplication
function typeString(str)
{
for (var c in str)
{
ts.keyPressChar(str[c], Qt.NoModifier, 0);
ts.keyReleaseChar(str[c], Qt.NoModifier, 0);
}
}
}
}
function newProject()
{
waitForRendering(mainApplication.mainContent, 10000);
mainApplication.projectModel.createProject();
var projectDlg = mainApplication.projectModel.newProjectDialog;
//if (ts.waitForSignal(projectDlg, "visibleChanged", 1000))
projectDlg.projectTitle = "TestProject";
projectDlg.pathFieldText = "/tmp/MixTest"; //TODO: get platform temp path
projectDlg.acceptAndClose();
ts.waitForSignal(mainApplication.mainContent.codeEditor, "loadComplete()", 5000)
wait(300);
}
function test_t1()
{
waitForRendering(mainApplication.mainContent, 10000);
mainApplication.projectModel.createProject();
var projectDlg = mainApplication.projectModel.newProjectDialog;
projectDlg.projectTitle = "TestProject";
projectDlg.pathFieldText = "/tmp/MixTest"; //TODO: get platform temp path
projectDlg.acceptAndClose();
ts.waitForSignal(mainApplication.mainContent.codeEditor, "loadComplete()", 5000)
ts.keyClickChar("A", Qt.ControlModifier, 20);
ts.typeString("CCC");
if (ts.waitForSignal(mainApplication.codeModel, "compilationComplete()", 5000))
console.log("compiled");
ts.waitForSignal(mainApplication.codeModel, "compilationComplete()", 5000);
}
function test_defaultTransactionSequence()
{
newProject();
mainApplication.mainContent.codeEditor.getEditor("contract.sol").setText(
//ts.typeString(
"contract Contract {\r" +
" function Contract() {\r" +
" uint x = 69;\r" +
" uint y = 5;\r" +
" for (uint i = 0; i < y; ++i) {\r" +
" x += 42;\r" +
" z += x;\r" +
" }\r" +
" }\r" +
" uint z;\r" +
"}\r"
);
ts.keyPressChar("S", Qt.ControlModifier, 200); //Ctrl+S
if (!ts.waitForSignal(mainApplication.codeModel, "compilationComplete()", 5000))
fail("not compiled");
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel, "count", 3);
}
function runTest()
{
waitForRendering(mainApplication.mainContent, 10000);
console.log("runtest");
mousePress(mainApplication, 10, 10);
}
function test_ConstructorParameters()
{
newProject();
mainApplication.mainContent.codeEditor.getEditor("contract.sol").setText(
//ts.typeString(
"contract Contract {\r" +
" function Contract(uint256 x) {\r" +
" z = x;\r" +
" }\r" +
" }\r" +
" function getZ() returns(uint256) {\r" +
" return z;\r" +
" }\r" +
" }\r" +
" uint z;\r" +
"}\r"
);
ts.keyPressChar("S", Qt.ControlModifier, 200); //Ctrl+S
if (!ts.waitForSignal(mainApplication.codeModel, "compilationComplete()", 5000))
fail("not compiled");
tryCompare(mainApplication.mainContent.rightPane.transactionLog.transactionModel, "count", 3);
}
Application
{
id: mainApplication
}
Application
{
id: mainApplication
}
}

Loading…
Cancel
Save