iOS: Add some autotests for devicectl error parsing

Change-Id: I641f0c86b30a11ca6321db88afbf2969b4863972
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Eike Ziller
2024-01-23 14:44:49 +01:00
parent 7e8aac5f3c
commit a9a5972a9f
6 changed files with 174 additions and 1 deletions

View File

@@ -25,7 +25,8 @@ Utils::expected_str<QJsonValue> Ios::Internal::parseDevicectlResult(const QByteA
if (!errorValue.isUndefined()) {
// error
QString error
= Tr::tr("Operation failed: %1.")
//: The error message (%1) can contain a full stop, so do not add it here
= Tr::tr("Operation failed: %1")
.arg(errorValue["userInfo"]["NSLocalizedDescription"]["string"].toString());
const QJsonValue userInfo
= errorValue["userInfo"]["NSUnderlyingError"]["error"]["userInfo"];

View File

@@ -11,6 +11,7 @@ add_subdirectory(extensionsystem)
add_subdirectory(externaltool)
add_subdirectory(filesearch)
add_subdirectory(haskell)
add_subdirectory(ios)
add_subdirectory(json)
add_subdirectory(languageserverprotocol)
add_subdirectory(pointeralgorithm)

View File

@@ -0,0 +1 @@
add_subdirectory(devicectlutils)

View File

@@ -0,0 +1,7 @@
add_qtc_test(tst_devicectlutils
DEPENDS Utils
SOURCES
../../../../src/plugins/ios/devicectlutils.cpp
../../../../src/plugins/ios/devicectlutils.h
tst_devicectlutils.cpp
)

View File

@@ -0,0 +1,6 @@
import qbs
QtcAutotest {
name: "devicectlutils autotest"
files: "tst_aggregate.cpp"
}

View File

@@ -0,0 +1,157 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "../../../../src/plugins/ios/devicectlutils.h"
#include <QtTest>
using namespace Ios::Internal;
class tst_Devicectlutils : public QObject
{
Q_OBJECT
private slots:
void parseError_data();
void parseError();
};
void tst_Devicectlutils::parseError_data()
{
QTest::addColumn<QByteArray>("data");
QTest::addColumn<QString>("error");
QTest::addRow("deploy-missing-plist") << QByteArray(R"raw(
{
"error" : {
"code" : 3002,
"domain" : "com.apple.dt.CoreDeviceError",
"userInfo" : {
"NSLocalizedDescription" : {
"string" : "Failed to install the app on the device."
},
"NSUnderlyingError" : {
"error" : {
"code" : 3000,
"domain" : "com.apple.dt.CoreDeviceError",
"userInfo" : {
"NSLocalizedDescription" : {
"string" : "The item at cmake_widgets.app is not a valid bundle."
},
"NSLocalizedFailureReason" : {
"string" : "Failed to get the identifier for the app to be installed."
},
"NSLocalizedRecoverySuggestion" : {
"string" : "Ensure that your bundle's Info.plist contains a value for the CFBundleIdentifier key."
},
"NSURL" : {
"url" : "file:///Users/user/temp/build/build-cmake_widgets-Qt_6_6_1_for_iOS/Debug-iphoneos/cmake_widgets.app/"
}
}
}
},
"NSURL" : {
"url" : "file:///Users/user/temp/build/build-cmake_widgets-Qt_6_6_1_for_iOS/Debug-iphoneos/cmake_widgets.app/"
}
}
},
"info" : {
"arguments" : [
"devicectl",
"device",
"install",
"app",
"--device",
"00000000-0000000000000000",
"--quiet",
"--json-output",
"-",
"/Users/user/temp/build/build-cmake_widgets-Qt_6_6_1_for_iOS/Debug-iphoneos/cmake_widgets.app"
],
"commandType" : "devicectl.device.install.app",
"environment" : {
"TERM" : "xterm-256color"
},
"jsonVersion" : 2,
"outcome" : "failed",
"version" : "355.7.7"
}
}
)raw") << QString(R"raw(Operation failed: Failed to install the app on the device.
The item at cmake_widgets.app is not a valid bundle.
Failed to get the identifier for the app to be installed.
Ensure that your bundle's Info.plist contains a value for the CFBundleIdentifier key.)raw");
QTest::addRow("deploy-device-gone") << QByteArray(R"raw(
{
"error" : {
"code" : 1,
"domain" : "com.apple.CoreDevice.ControlChannelConnectionError",
"userInfo" : {
"NSLocalizedDescription" : {
"string" : "Internal logic error: Connection was invalidated"
},
"NSUnderlyingError" : {
"error" : {
"code" : 0,
"domain" : "com.apple.CoreDevice.ControlChannelConnectionError",
"userInfo" : {
"NSLocalizedDescription" : {
"string" : "Transport error"
},
"NSUnderlyingError" : {
"error" : {
"code" : 60,
"domain" : "Network.NWError",
"userInfo" : {
"NSDescription" : {
"string" : "Operation timed out"
}
}
}
}
}
}
}
}
},
"info" : {
"arguments" : [
"devicectl",
"device",
"install",
"app",
"--device",
"00000000-0000000000000000",
"--quiet",
"--json-output",
"-",
"/Users/user/temp/build/build-cmake_widgets-Qt_6_6_1_for_iOS/Debug-iphoneos/cmake_widgets.app"
],
"commandType" : "devicectl.device.install.app",
"environment" : {
"TERM" : "xterm-256color"
},
"jsonVersion" : 2,
"outcome" : "failed",
"version" : "355.7.7"
}
}
)raw") << QString(R"raw(Operation failed: Internal logic error: Connection was invalidated
Transport error)raw");
}
void tst_Devicectlutils::parseError()
{
QFETCH(QByteArray, data);
QFETCH(QString, error);
const Utils::expected_str<QJsonValue> result = parseDevicectlResult(data);
if (error.isEmpty()) {
QVERIFY(result);
} else {
QVERIFY(!result);
QCOMPARE(result.error(), error);
}
}
QTEST_GUILESS_MAIN(tst_Devicectlutils)
#include "tst_devicectlutils.moc"