-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
75 lines (61 loc) · 1.83 KB
/
main.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <QCoreApplication>
#include <QFileInfo>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include "testclient.h"
#include "testserver.h"
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
const auto args = app.arguments();
if (args.count() != 2)
{
qDebug() << "Please enter config file path.";
qDebug() << QString(QFileInfo(app.applicationFilePath()).fileName() + " /path/to/config.json").toStdString().c_str();
return 0;
}
QFile f(args.at(1));
if (!f.open(QFile::ReadOnly))
{
qDebug() << "Could not open config file:" << f.errorString().toStdString().c_str();
return 1;
}
const auto json = QJsonDocument::fromJson(f.readAll());
f.close();
if (json.isNull() || !json.isObject())
{
qDebug() << "Invalid json.";
return 2;
}
const auto root = json.object();
const auto instances = root.value("instances");
if (!instances.isArray())
{
qDebug() << "Invalid json's test property.";
return 3;
}
QSet<QSharedPointer<AbstractTest>> testsList;
for (const auto &item: instances.toArray())
{
if (!item.isObject())
continue;
AbstractTestPtr t;
const auto testConfigs = item.toObject();
const auto type = testConfigs.value(QStringLiteral("type")).toString();
if (type == QStringLiteral("client"))
t = AbstractTestPtr(new TestClient(testConfigs));
else if (type == QStringLiteral("server"))
t = AbstractTestPtr(new TestServer(testConfigs));
else
continue;
t->start();
testsList.insert(t);
}
const auto retCode = app.exec();
for (const auto &t: testsList)
t->stop();
return retCode;
}