forked from dihonglongxi/FactoryTestApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestMethodManager.h
58 lines (43 loc) · 1.67 KB
/
TestMethodManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <QDir>
#include <QSettings>
#include <QStringList>
#include <QSharedPointer>
#include <QJSEngine>
#include <QJSValue>
#include "Logger.h"
class TestMethodManager : public QObject
{
Q_OBJECT
public:
struct TestFunction
{
QString functionName;
QJSValue function;
bool isStrictlySequential;
};
struct TestMethod
{
QList<TestFunction> generalFunctionList; //All avaliable functions for this method, described in js file
};
TestMethodManager(const QSharedPointer<QSettings> &settings, QObject *parent = nullptr);
void setLogger(const QSharedPointer<Logger>& logger) {_logger = logger; _scriptEngine.globalObject().setProperty("logger", _scriptEngine.newQObject(_logger.get()));}
QJSEngine* scriptEngine() {return &_scriptEngine;}
Q_INVOKABLE void addMethod(const QString& name);
Q_INVOKABLE void addFunctionToGeneralList(const QString& name, const QJSValue& function, bool isStrictlySequential = false);
QStringList avaliableMethodsNames() const;
QStringList currentMethodGeneralFunctionNames() const;
bool isFunctionStrictlySequential(const QString& name) const;
public slots:
void setCurrentMethod(const QString& name);
void runTestFunction(const QString& name);
private:
QJSValue evaluateScriptFromFile(const QString& scriptFileName);
QList<QJSValue> evaluateScriptsFromDirectory(const QString& directoryName);
QJSValue runScript(const QString& scriptName, const QJSValueList& args);
QSharedPointer<QSettings> _settings;
QJSEngine _scriptEngine;
QSharedPointer<Logger> _logger;
QString _currentMethod;
QMap<QString, TestMethod> _methods;
};