diff --git a/tools/nitpick/src/Nitpick.cpp b/tools/nitpick/src/Nitpick.cpp index 63afbf3947..36de8c4799 100644 --- a/tools/nitpick/src/Nitpick.cpp +++ b/tools/nitpick/src/Nitpick.cpp @@ -93,7 +93,7 @@ void Nitpick::setup() { if (_testRunnerMobile) { delete _testRunnerMobile; } - _testRunnerMobile = new TestRunnerMobile(_ui.workingFolderRunOnMobileLabel, _ui.readDeviceButton); + _testRunnerMobile = new TestRunnerMobile(_ui.workingFolderRunOnMobileLabel, _ui.connectDeviceButton, _ui.pullFolderButton, _ui.detectedDeviceLabel); } void Nitpick::startTestsEvaluation(const bool isRunningFromCommandLine, @@ -327,6 +327,10 @@ void Nitpick::on_setWorkingFolderRunOnMobileButton_clicked() { _testRunnerMobile->setWorkingFolderAndEnableControls(); } -void Nitpick::on_readDeviceButton_clicked() { - _testRunnerMobile->readDevice(); +void Nitpick::on_connectDeviceButton_clicked() { + _testRunnerMobile->connectDevice(); +} + +void Nitpick::on_pullFolderButton_clicked() { + _testRunnerMobile->pullFolder(); } diff --git a/tools/nitpick/src/Nitpick.h b/tools/nitpick/src/Nitpick.h index e64cb2f015..571687a72b 100644 --- a/tools/nitpick/src/Nitpick.h +++ b/tools/nitpick/src/Nitpick.h @@ -96,7 +96,8 @@ private slots: void content(); void on_setWorkingFolderRunOnMobileButton_clicked(); - void on_readDeviceButton_clicked(); + void on_connectDeviceButton_clicked(); + void on_pullFolderButton_clicked(); private: Ui::NitpickClass _ui; diff --git a/tools/nitpick/src/PythonInterface.cpp b/tools/nitpick/src/PythonInterface.cpp index 820f2931b5..9e2fec005f 100644 --- a/tools/nitpick/src/PythonInterface.cpp +++ b/tools/nitpick/src/PythonInterface.cpp @@ -31,7 +31,7 @@ PythonInterface::PythonInterface() { #elif defined Q_OS_MAC _pythonCommand = "/usr/local/bin/python3"; if (!QFile::exists(_pythonCommand)) { - QMessageBox::critical(0, "PYTHON_PATH not defined", + QMessageBox::critical(0, "python not found", "python3 not found at " + _pythonCommand); exit(-1); } diff --git a/tools/nitpick/src/TestRunner.cpp b/tools/nitpick/src/TestRunner.cpp index 1f4b3f847d..491e211e2c 100644 --- a/tools/nitpick/src/TestRunner.cpp +++ b/tools/nitpick/src/TestRunner.cpp @@ -30,3 +30,14 @@ void TestRunner::setWorkingFolder(QLabel* workingFolderLabel) { workingFolderLabel->setText(QDir::toNativeSeparators(_workingFolder)); } + +void Worker::setCommandLine(const QString& commandLine) { + _commandLine = commandLine; +} + +int Worker::runCommand() { + int result = system(_commandLine.toStdString().c_str()); + emit commandComplete(); + return result; +} + diff --git a/tools/nitpick/src/TestRunnerDesktop.cpp b/tools/nitpick/src/TestRunnerDesktop.cpp index f8e69650e0..f0147f200d 100644 --- a/tools/nitpick/src/TestRunnerDesktop.cpp +++ b/tools/nitpick/src/TestRunnerDesktop.cpp @@ -803,13 +803,3 @@ void TestRunnerDesktop::parseBuildInformation() { exit(-1); } } - -void Worker::setCommandLine(const QString& commandLine) { - _commandLine = commandLine; -} - -int Worker::runCommand() { - int result = system(_commandLine.toStdString().c_str()); - emit commandComplete(); - return result; -} diff --git a/tools/nitpick/src/TestRunnerMobile.cpp b/tools/nitpick/src/TestRunnerMobile.cpp index 384314903d..5c1f907e34 100644 --- a/tools/nitpick/src/TestRunnerMobile.cpp +++ b/tools/nitpick/src/TestRunnerMobile.cpp @@ -16,9 +16,13 @@ #include "Nitpick.h" extern Nitpick* nitpick; -TestRunnerMobile::TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *readDeviceButton, QObject* parent) : QObject(parent) { +TestRunnerMobile::TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *conectDeviceButton, QPushButton *pullFolderButton, QLabel* detectedDeviceLabel, QObject* parent) + : QObject(parent) +{ _workingFolderLabel = workingFolderLabel; - _readDeviceButton = readDeviceButton; + _connectDeviceButton = conectDeviceButton; + _pullFolderButton = pullFolderButton; + _detectedDeviceLabel = detectedDeviceLabel; } TestRunnerMobile::~TestRunnerMobile() { @@ -27,9 +31,63 @@ TestRunnerMobile::~TestRunnerMobile() { void TestRunnerMobile::setWorkingFolderAndEnableControls() { setWorkingFolder(_workingFolderLabel); - _readDeviceButton->setEnabled(true); + _connectDeviceButton->setEnabled(true); + + // Find ADB (Android Debugging Bridge) before continuing +#ifdef Q_OS_WIN + if (QProcessEnvironment::systemEnvironment().contains("ADB_PATH")) { + QString adbExePath = QProcessEnvironment::systemEnvironment().value("ADB_PATH") + "/platform-tools"; + if (!QFile::exists(adbExePath + "/" + _adbExe)) { + QMessageBox::critical(0, _adbExe, QString("Python executable not found in ") + adbExePath); + exit(-1); + } + + _adbCommand = adbExePath + "/" + _adbExe; + } else { + QMessageBox::critical(0, "PYTHON_PATH not defined", + "Please set PYTHON_PATH to directory containing the Python executable"); + exit(-1); + } +#elif defined Q_OS_MAC + _adbCommand = "/usr/local/bin/adb"; + if (!QFile::exists(_adbCommand)) { + QMessageBox::critical(0, "adb not found", + "python3 not found at " + _adbCommand); + exit(-1); + } +#endif } -void TestRunnerMobile::readDevice() { +void TestRunnerMobile::connectDevice() { + QString devicesFullFilename{ _workingFolder + "/devices.txt" }; + QString command = _adbCommand + " devices > " + devicesFullFilename; + int result = system(command.toStdString().c_str()); + if (!QFile::exists(devicesFullFilename)) { + QMessageBox::critical(0, "Internal error", "devicesFullFilename not found"); + exit (-1); + } + + // Device should be in second line + QFile devicesFile(devicesFullFilename); + devicesFile.open(QIODevice::ReadOnly | QIODevice::Text); + QString line1 = devicesFile.readLine(); + QString line2 = devicesFile.readLine(); + + const QString DEVICE{ "device" }; + if (line2.contains(DEVICE)) { + // Make sure only 1 device + QString line3 = devicesFile.readLine(); + if (line3.contains(DEVICE)) { + QMessageBox::critical(0, "Too many devices detected", "Tests will run only if a single device is attached"); + + } else { + _pullFolderButton->setEnabled(true); + _detectedDeviceLabel->setText(line2.remove(DEVICE)); + } + } +} + +void TestRunnerMobile::pullFolder() { + QString command = _adbCommand + " devices > " + _workingFolder + "/devices.txt"; } diff --git a/tools/nitpick/src/TestRunnerMobile.h b/tools/nitpick/src/TestRunnerMobile.h index 7279e1276e..84531b5b64 100644 --- a/tools/nitpick/src/TestRunnerMobile.h +++ b/tools/nitpick/src/TestRunnerMobile.h @@ -20,15 +20,27 @@ class TestRunnerMobile : public QObject, public TestRunner { Q_OBJECT public: - explicit TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *readDeviceButton, QObject* parent = 0); + explicit TestRunnerMobile(QLabel* workingFolderLabel, QPushButton *connectDeviceButton, QPushButton *pullFolderButton, QLabel* detectedDeviceLabel, QObject* parent = 0); ~TestRunnerMobile(); void setWorkingFolderAndEnableControls(); - void readDevice(); + void connectDevice(); + void pullFolder(); private: QLabel* _workingFolderLabel; - QString _workingFolder; - QPushButton* _readDeviceButton; + QPushButton* _connectDeviceButton; + QPushButton* _pullFolderButton; + QLabel* _detectedDeviceLabel; + +#ifdef Q_OS_WIN + const QString _adbExe{ "adb.exe" }; +#else + // Both Mac and Linux use "adb" + const QString _adbExe{ "adb" }; +#endif + + QString _adbCommand; + }; #endif diff --git a/tools/nitpick/ui/Nitpick.ui b/tools/nitpick/ui/Nitpick.ui index fbf3a587c7..139d4ced56 100644 --- a/tools/nitpick/ui/Nitpick.ui +++ b/tools/nitpick/ui/Nitpick.ui @@ -187,7 +187,7 @@ - Run on Desktop + Test on Desktop @@ -549,31 +549,31 @@ - Run on Device + Test on Device - + false 10 - 100 + 90 160 30 - Read Device + Connect Device - + 190 - 100 - 230 - 20 + 96 + 320 + 30 @@ -606,6 +606,32 @@ (not set...) + + + false + + + + 200 + 170 + 160 + 30 + + + + Pull folder + + + + + + 10 + 170 + 161 + 31 + + +