|
1 |
| -/* Copyright (C) 2015 |
| 1 | +/* Copyright (C) 2015-2016 |
2 | 2 | * Parts derived from Firebird by Fabian Vogt
|
3 | 3 | *
|
4 | 4 | * This program is free software: you can redistribute it and/or modify
|
|
26 | 26 | #include <QtGui/QPixmap>
|
27 | 27 |
|
28 | 28 | #include <fstream>
|
| 29 | +#include <unistd.h> |
29 | 30 |
|
30 | 31 | #include "mainwindow.h"
|
31 | 32 | #include "ui_mainwindow.h"
|
|
46 | 47 | #include "../../core/link.h"
|
47 | 48 | #include "../../core/os/os.h"
|
48 | 49 |
|
| 50 | +#include "../../tests/autotester/autotester.h" |
| 51 | +#include "autotesterthread.h" |
| 52 | + |
| 53 | + |
49 | 54 | static const constexpr int WindowStateVersion = 0;
|
50 | 55 |
|
51 | 56 | MainWindow::MainWindow(QWidget *p) : QMainWindow(p), ui(new Ui::MainWindow) {
|
@@ -124,6 +129,12 @@ MainWindow::MainWindow(QWidget *p) : QMainWindow(p), ui(new Ui::MainWindow) {
|
124 | 129 | connect(this, &MainWindow::setReceiveState, &emu, &EmuThread::setReceiveState);
|
125 | 130 | connect(ui->buttonReceiveFiles, &QPushButton::clicked, this, &MainWindow::saveSelected);
|
126 | 131 |
|
| 132 | + // Autotester |
| 133 | + connect(&tester, &AutotesterThread::testError, this, &MainWindow::dispAutotesterError, Qt::QueuedConnection); |
| 134 | + connect(ui->buttonOpenJSONconfig, &QPushButton::clicked, this, &MainWindow::prepareAndOpenJSONConfig); |
| 135 | + connect(ui->buttonReloadJSONconfig, &QPushButton::clicked, this, &MainWindow::reloadJSONConfig); |
| 136 | + connect(ui->buttonLaunchTest, &QPushButton::clicked, this, &MainWindow::launchTest); |
| 137 | + |
127 | 138 | // Toolbar Actions
|
128 | 139 | connect(ui->actionSetup, &QAction::triggered, this, &MainWindow::runSetup);
|
129 | 140 | connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
|
@@ -224,6 +235,8 @@ MainWindow::MainWindow(QWidget *p) : QMainWindow(p), ui(new Ui::MainWindow) {
|
224 | 235 | setAcceptDrops(true);
|
225 | 236 | debuggerOn = false;
|
226 | 237 |
|
| 238 | + autotester::stepCallback = []() { QApplication::processEvents(); }; |
| 239 | + |
227 | 240 | settings = new QSettings(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/CEmu/cemu_config.ini"), QSettings::IniFormat);
|
228 | 241 |
|
229 | 242 | #ifdef _WIN32
|
@@ -1064,6 +1077,105 @@ void MainWindow::saveSelected() {
|
1064 | 1077 | }
|
1065 | 1078 | }
|
1066 | 1079 |
|
| 1080 | +/* ================================================ */ |
| 1081 | +/* Autotester Things */ |
| 1082 | +/* ================================================ */ |
| 1083 | + |
| 1084 | +void MainWindow::dispAutotesterError(int errCode) { |
| 1085 | + QString errMsg; |
| 1086 | + switch (errCode) { |
| 1087 | + case -1: |
| 1088 | + errMsg = tr("Error. No config loaded"); |
| 1089 | + break; |
| 1090 | + case 1: |
| 1091 | + errMsg = tr("Error. Couldn't follow the test sequence defined in the configuration"); |
| 1092 | + break; |
| 1093 | + default: |
| 1094 | + errMsg = tr("Error. Unknown one - wat?"); |
| 1095 | + break; |
| 1096 | + } |
| 1097 | + QMessageBox::warning(this, tr("Autotester error"), errMsg); |
| 1098 | +} |
| 1099 | + |
| 1100 | + |
| 1101 | +void MainWindow::openJSONConfig(const QString& jsonPath) { |
| 1102 | + std::string jsonContents; |
| 1103 | + std::ifstream ifs(jsonPath.toStdString()); |
| 1104 | + if (ifs.good()) |
| 1105 | + { |
| 1106 | + ui->buttonReloadJSONconfig->setEnabled(true); |
| 1107 | + chdir(QDir::toNativeSeparators(QFileInfo(jsonPath).absoluteDir().path()).toStdString().c_str()); |
| 1108 | + std::getline(ifs, jsonContents, '\0'); |
| 1109 | + if (!ifs.eof()) { |
| 1110 | + QMessageBox::warning(this, tr("File error"), tr("Couldn't read JSON file.")); |
| 1111 | + return; |
| 1112 | + } |
| 1113 | + } else { |
| 1114 | + ui->buttonReloadJSONconfig->setEnabled(false); |
| 1115 | + QMessageBox::warning(this, tr("Opening error"), tr("Unable to open the file.")); |
| 1116 | + return; |
| 1117 | + } |
| 1118 | + |
| 1119 | + if (autotester::loadJSONConfig(jsonContents)) |
| 1120 | + { |
| 1121 | + ui->JSONconfigPath->setText(jsonPath); |
| 1122 | + ui->buttonLaunchTest->setEnabled(true); |
| 1123 | + std::cout << "[OK] Test config loaded and verified. " << autotester::config.hashes.size() << " unique tests found." << std::endl; |
| 1124 | + } else { |
| 1125 | + QMessageBox::warning(this, tr("JSON format error"), tr("Error. See the test config file format and make sure values are correct and referenced files are there.")); |
| 1126 | + return; |
| 1127 | + } |
| 1128 | +} |
| 1129 | + |
| 1130 | +void MainWindow::prepareAndOpenJSONConfig() { |
| 1131 | + QFileDialog dialog(this); |
| 1132 | + |
| 1133 | + ui->buttonLaunchTest->setEnabled(false); |
| 1134 | + |
| 1135 | + dialog.setDirectory(QDir::homePath()); |
| 1136 | + dialog.setFileMode(QFileDialog::ExistingFile); |
| 1137 | + dialog.setNameFilter(QStringLiteral("JSON config (*.json)")); |
| 1138 | + if (!dialog.exec()) { |
| 1139 | + return; |
| 1140 | + } |
| 1141 | + |
| 1142 | + openJSONConfig(dialog.selectedFiles().at(0)); |
| 1143 | +} |
| 1144 | + |
| 1145 | +void MainWindow::reloadJSONConfig() { |
| 1146 | + openJSONConfig(ui->JSONconfigPath->text()); |
| 1147 | +} |
| 1148 | + |
| 1149 | +void MainWindow::launchTest() { |
| 1150 | + if (!autotester::configLoaded) { |
| 1151 | + dispAutotesterError(-1); |
| 1152 | + return; |
| 1153 | + } |
| 1154 | + |
| 1155 | + if (ui->checkBoxTestReset->isChecked()) { |
| 1156 | + resetCalculator(); |
| 1157 | + QThread::msleep(1000); |
| 1158 | + } |
| 1159 | + |
| 1160 | + if (ui->checkBoxTestClear->isChecked()) { |
| 1161 | + // Clear home screen |
| 1162 | + autotester::sendKey(0x09); |
| 1163 | + } |
| 1164 | + |
| 1165 | + QStringList filesList; |
| 1166 | + for (const auto& file : autotester::config.transfer_files) { |
| 1167 | + filesList << QString::fromStdString(file); |
| 1168 | + } |
| 1169 | + sendFiles(filesList); |
| 1170 | + QThread::msleep(200); |
| 1171 | + |
| 1172 | + autotester_thread->launchActualTest(); |
| 1173 | +} |
| 1174 | + |
| 1175 | +/* ================================================ */ |
| 1176 | +/* Debugger Things */ |
| 1177 | +/* ================================================ */ |
| 1178 | + |
1067 | 1179 | void MainWindow::setFont(int fontSize) {
|
1068 | 1180 | ui->textSizeSlider->setValue(fontSize);
|
1069 | 1181 | settings->setValue(QStringLiteral("textSize"), ui->textSizeSlider->value());
|
@@ -1100,10 +1212,6 @@ void MainWindow::setFont(int fontSize) {
|
1100 | 1212 | ui->lcdcurrView->setFont(monospace);
|
1101 | 1213 | }
|
1102 | 1214 |
|
1103 |
| -/* ================================================ */ |
1104 |
| -/* Debugger Things */ |
1105 |
| -/* ================================================ */ |
1106 |
| - |
1107 | 1215 | static int hex2int(QString str) {
|
1108 | 1216 | return std::stoi(str.toStdString(), nullptr, 16);
|
1109 | 1217 | }
|
|
0 commit comments