forked from qt-creator/qt-creator
Android: Move tests from sdkmanager class to test class
Change-Id: I2e7be8f33b40d7c67e72efa88ca5528deb046ade Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -58,5 +58,6 @@ add_qtc_plugin(Android
|
|||||||
extend_qtc_plugin(Android
|
extend_qtc_plugin(Android
|
||||||
CONDITION WITH_TESTS
|
CONDITION WITH_TESTS
|
||||||
SOURCES
|
SOURCES
|
||||||
|
androidsdkmanager_test.cpp androidsdkmanager_test.h
|
||||||
android_tst.qrc
|
android_tst.qrc
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ Project {
|
|||||||
condition: qtc.testsEnabled
|
condition: qtc.testsEnabled
|
||||||
files: [
|
files: [
|
||||||
"android_tst.qrc",
|
"android_tst.qrc",
|
||||||
|
"androidsdkmanager_test.cpp",
|
||||||
|
"androidsdkmanager_test.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,11 @@
|
|||||||
#include "androidqtversion.h"
|
#include "androidqtversion.h"
|
||||||
#include "androidrunconfiguration.h"
|
#include "androidrunconfiguration.h"
|
||||||
#include "androidruncontrol.h"
|
#include "androidruncontrol.h"
|
||||||
|
#include "androidsdkmanager_test.h"
|
||||||
#include "androidsettingswidget.h"
|
#include "androidsettingswidget.h"
|
||||||
#include "androidtoolchain.h"
|
#include "androidtoolchain.h"
|
||||||
#include "androidtr.h"
|
#include "androidtr.h"
|
||||||
|
|
||||||
#include "javaeditor.h"
|
#include "javaeditor.h"
|
||||||
#include "javalanguageserver.h"
|
#include "javalanguageserver.h"
|
||||||
|
|
||||||
@@ -33,9 +35,9 @@
|
|||||||
|
|
||||||
#include <languageclient/languageclientsettings.h>
|
#include <languageclient/languageclientsettings.h>
|
||||||
|
|
||||||
#include <projectexplorer/devicesupport/devicemanager.h>
|
|
||||||
#include <projectexplorer/buildconfiguration.h>
|
#include <projectexplorer/buildconfiguration.h>
|
||||||
#include <projectexplorer/deployconfiguration.h>
|
#include <projectexplorer/deployconfiguration.h>
|
||||||
|
#include <projectexplorer/devicesupport/devicemanager.h>
|
||||||
#include <projectexplorer/kitinformation.h>
|
#include <projectexplorer/kitinformation.h>
|
||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
@@ -113,6 +115,10 @@ void AndroidPlugin::initialize()
|
|||||||
{Android::Constants::JLS_SETTINGS_ID,
|
{Android::Constants::JLS_SETTINGS_ID,
|
||||||
Tr::tr("Java Language Server"),
|
Tr::tr("Java Language Server"),
|
||||||
[] { return new JLSSettings; }});
|
[] { return new JLSSettings; }});
|
||||||
|
|
||||||
|
#ifdef WITH_TESTS
|
||||||
|
addTest<AndroidSdkManagerTest>();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidPlugin::kitsRestored()
|
void AndroidPlugin::kitsRestored()
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ class AndroidPlugin final : public ExtensionSystem::IPlugin
|
|||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
private slots:
|
private slots:
|
||||||
void testAndroidSdkManagerProgressParser_data();
|
|
||||||
void testAndroidSdkManagerProgressParser();
|
|
||||||
void testAndroidConfigAvailableNdkPlatforms_data();
|
void testAndroidConfigAvailableNdkPlatforms_data();
|
||||||
void testAndroidConfigAvailableNdkPlatforms();
|
void testAndroidConfigAvailableNdkPlatforms();
|
||||||
void testAndroidQtVersionParseBuiltWith_data();
|
void testAndroidQtVersionParseBuiltWith_data();
|
||||||
|
|||||||
@@ -20,18 +20,13 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
|
||||||
# include <QTest>
|
|
||||||
# include "androidplugin.h"
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
|
|
||||||
using namespace Utils;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Q_LOGGING_CATEGORY(sdkManagerLog, "qtc.android.sdkManager", QtWarningMsg)
|
Q_LOGGING_CATEGORY(sdkManagerLog, "qtc.android.sdkManager", QtWarningMsg)
|
||||||
const char commonArgsKey[] = "Common Arguments:";
|
const char commonArgsKey[] = "Common Arguments:";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Android {
|
namespace Android {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -652,54 +647,5 @@ void AndroidSdkManagerPrivate::clearPackages()
|
|||||||
m_allPackages.clear();
|
m_allPackages.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
|
||||||
void AndroidPlugin::testAndroidSdkManagerProgressParser_data()
|
|
||||||
{
|
|
||||||
QTest::addColumn<QString>("output");
|
|
||||||
QTest::addColumn<int>("progress");
|
|
||||||
QTest::addColumn<bool>("foundAssertion");
|
|
||||||
|
|
||||||
// Output of "sdkmanager --licenses", Android SDK Tools version 4.0
|
|
||||||
QTest::newRow("Loading local repository")
|
|
||||||
<< "Loading local repository... \r"
|
|
||||||
<< -1
|
|
||||||
<< false;
|
|
||||||
|
|
||||||
QTest::newRow("Fetch progress (single line)")
|
|
||||||
<< "[============= ] 34% Fetch remote repository... \r"
|
|
||||||
<< 34
|
|
||||||
<< false;
|
|
||||||
|
|
||||||
QTest::newRow("Fetch progress (multi line)")
|
|
||||||
<< "[============================= ] 73% Fetch remote repository... \r"
|
|
||||||
"[============================= ] 75% Fetch remote repository... \r"
|
|
||||||
<< 75
|
|
||||||
<< false;
|
|
||||||
|
|
||||||
QTest::newRow("Some SDK package licenses not accepted")
|
|
||||||
<< "7 of 7 SDK package licenses not accepted.\n"
|
|
||||||
<< -1
|
|
||||||
<< false;
|
|
||||||
|
|
||||||
QTest::newRow("Unaccepted licenses assertion")
|
|
||||||
<< "\nReview licenses that have not been accepted (y/N)? "
|
|
||||||
<< -1
|
|
||||||
<< true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AndroidPlugin::testAndroidSdkManagerProgressParser()
|
|
||||||
{
|
|
||||||
QFETCH(QString, output);
|
|
||||||
QFETCH(int, progress);
|
|
||||||
QFETCH(bool, foundAssertion);
|
|
||||||
|
|
||||||
bool actualFoundAssertion = false;
|
|
||||||
const int actualProgress = parseProgress(output, actualFoundAssertion);
|
|
||||||
|
|
||||||
QCOMPARE(progress, actualProgress);
|
|
||||||
QCOMPARE(foundAssertion, actualFoundAssertion);
|
|
||||||
}
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Android
|
} // namespace Android
|
||||||
|
|||||||
@@ -81,5 +81,7 @@ private:
|
|||||||
std::unique_ptr<AndroidSdkManagerPrivate> m_d;
|
std::unique_ptr<AndroidSdkManagerPrivate> m_d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int parseProgress(const QString &out, bool &foundAssertion);
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Android
|
} // namespace Android
|
||||||
|
|||||||
66
src/plugins/android/androidsdkmanager_test.cpp
Normal file
66
src/plugins/android/androidsdkmanager_test.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
|
||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "androidsdkmanager_test.h"
|
||||||
|
#include "androidsdkmanager.h"
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
namespace Android::Internal {
|
||||||
|
|
||||||
|
AndroidSdkManagerTest::AndroidSdkManagerTest(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
AndroidSdkManagerTest::~AndroidSdkManagerTest() = default;
|
||||||
|
|
||||||
|
void AndroidSdkManagerTest::testAndroidSdkManagerProgressParser_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QString>("output");
|
||||||
|
QTest::addColumn<int>("progress");
|
||||||
|
QTest::addColumn<bool>("foundAssertion");
|
||||||
|
|
||||||
|
// Output of "sdkmanager --licenses", Android SDK Tools version 4.0
|
||||||
|
QTest::newRow("Loading local repository")
|
||||||
|
<< "Loading local repository... \r"
|
||||||
|
<< -1
|
||||||
|
<< false;
|
||||||
|
|
||||||
|
QTest::newRow("Fetch progress (single line)")
|
||||||
|
<< "[============= ] 34% Fetch remote repository... \r"
|
||||||
|
<< 34
|
||||||
|
<< false;
|
||||||
|
|
||||||
|
QTest::newRow("Fetch progress (multi line)")
|
||||||
|
<< "[============================= ] 73% Fetch remote repository... \r"
|
||||||
|
"[============================= ] 75% Fetch remote repository... \r"
|
||||||
|
<< 75
|
||||||
|
<< false;
|
||||||
|
|
||||||
|
QTest::newRow("Some SDK package licenses not accepted")
|
||||||
|
<< "7 of 7 SDK package licenses not accepted.\n"
|
||||||
|
<< -1
|
||||||
|
<< false;
|
||||||
|
|
||||||
|
QTest::newRow("Unaccepted licenses assertion")
|
||||||
|
<< "\nReview licenses that have not been accepted (y/N)? "
|
||||||
|
<< -1
|
||||||
|
<< true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AndroidSdkManagerTest::testAndroidSdkManagerProgressParser()
|
||||||
|
{
|
||||||
|
QFETCH(QString, output);
|
||||||
|
QFETCH(int, progress);
|
||||||
|
QFETCH(bool, foundAssertion);
|
||||||
|
|
||||||
|
bool actualFoundAssertion = false;
|
||||||
|
const int actualProgress = parseProgress(output, actualFoundAssertion);
|
||||||
|
|
||||||
|
QCOMPARE(progress, actualProgress);
|
||||||
|
QCOMPARE(foundAssertion, actualFoundAssertion);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
27
src/plugins/android/androidsdkmanager_test.h
Normal file
27
src/plugins/android/androidsdkmanager_test.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (C) 2022 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QString;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class AndroidSdkManagerTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
AndroidSdkManagerTest(QObject *parent = nullptr);
|
||||||
|
~AndroidSdkManagerTest();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void testAndroidSdkManagerProgressParser_data();
|
||||||
|
void testAndroidSdkManagerProgressParser();
|
||||||
|
};
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Android
|
||||||
Reference in New Issue
Block a user