diff options
author | Samuel Ghinet <samuel.ghinet@qt.io> | 2022-01-10 15:48:29 +0200 |
---|---|---|
committer | Samuel Ghinet <samuel.ghinet@qt.io> | 2022-01-17 08:59:09 +0000 |
commit | c1c147a9dc99cba08582e83ef00883ece87d9e4f (patch) | |
tree | 4517ff5021d04e1ccc66f0e9eb6284a66bbb4e6e /tests | |
parent | fc605c8c6f9009f0ff9326562b86bf0469e8e32e (diff) | |
download | qt-creator-c1c147a9dc99cba08582e83ef00883ece87d9e4f.tar.gz |
QDS-5691 Create a tab for Recent choices
The Recents should store presets, rather than normal project items,
while the rest of tabs are to store normal project (i.e. wizard) items
but with the default screen size written under the wizard name.
In this patch I also did a few renames: e.g. the Presets view now uses a
PresetModel rather than ProjectModel, because we now store presets. A
Preset is a higher level concept than Project / Wizard item: it can be a
project/wizard item with pre-defined configurations; and now we can have
multiple presets using the same Wizard factory. Renamed struct
ProjectCategory to WizardCategory, because the items are grouped by the
category of the wizard (i.e. the "category" property of IWizardFactory)
I extracted a class, PresetData, to hold the data that is being shared
by the PresetModel (items in the view) and the PresetCategoryModel
(header/tab items). It stored both information on normal presets and on
recent presets.
Made changes to JsonWizardFactory so that I could extract the list of
screen sizes without requiring to build a wizard object first. This is
important, because multiple JsonWizard objects cannot be created at the
same time and I need to show the screen sizes of multiple presets /
wizards as the Presets view is opened. This also required class
WizardFactories to use JsonWizardFactory instead of Core::IWizardFactory
-- since "screen sizes" are a particularity of the json wizards, not of
all kinds of wizards.
Also, fixed a TODO in WizardHandler::reset() method.
Also, added a few utilities I had need of, in algorithm.h.
Change-Id: Ifd986e2def19b2e112f0aa1ab3db63d522736321
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'tests')
6 files changed, 624 insertions, 44 deletions
diff --git a/tests/auto/qml/qmldesigner/wizard/CMakeLists.txt b/tests/auto/qml/qmldesigner/wizard/CMakeLists.txt index ca3a0ac7ec..de84a6e931 100644 --- a/tests/auto/qml/qmldesigner/wizard/CMakeLists.txt +++ b/tests/auto/qml/qmldesigner/wizard/CMakeLists.txt @@ -5,7 +5,7 @@ set(WITH_TESTS ON) find_package(Googletest MODULE) add_qtc_test(tst_qml_wizard - DEPENDS Core Utils StudioWelcome QmlDesigner Googletest + DEPENDS Core Utils StudioWelcome ProjectExplorer QmlDesigner Googletest DEFINES QT_CREATOR QMLDESIGNER_TEST @@ -17,8 +17,13 @@ add_qtc_test(tst_qml_wizard SOURCES wizardfactories-test.cpp stylemodel-test.cpp + recentpresets-test.cpp + presetmodel-test.cpp test-utilities.h + test-main.cpp "${StudioWelcomeDir}/wizardfactories.cpp" "${StudioWelcomeDir}/stylemodel.cpp" + "${StudioWelcomeDir}/recentpresets.cpp" + "${StudioWelcomeDir}/presetmodel.cpp" ) diff --git a/tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp b/tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp new file mode 100644 index 0000000000..dc855b67a3 --- /dev/null +++ b/tests/auto/qml/qmldesigner/wizard/presetmodel-test.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "test-utilities.h" + +#include "presetmodel.h" + +using namespace StudioWelcome; +using ::testing::ElementsAre; +using ::testing::ElementsAreArray; +using ::testing::PrintToString; + +namespace StudioWelcome { +void PrintTo(const PresetItem &item, std::ostream *os) +{ + *os << "{categId: " << item.categoryId << ", " + << "name: " << item.name; + + if (!item.screenSizeName.isEmpty()) + *os << ", size: " << item.screenSizeName; + + *os << "}"; +} + +} // namespace StudioWelcome + +namespace { +std::pair<QString, WizardCategory> aCategory(const QString &categId, + const QString &categName, + const std::vector<QString> &names) +{ + std::vector<PresetItem> items = Utils::transform(names, [&categId](const QString &name) { + return PresetItem{name, categId}; + }); + return std::make_pair(categId, WizardCategory{categId, categName, items}); +} + +MATCHER_P2(PresetIs, category, name, PrintToString(PresetItem{name, category})) +{ + return arg.categoryId == category && arg.name == name; +} + +MATCHER_P3(PresetIs, category, name, size, PrintToString(PresetItem{name, category, size})) +{ + return arg.categoryId == category && arg.name == name && size == arg.screenSizeName; +} + +} // namespace + +/******************* TESTS *******************/ + +TEST(QdsPresetModel, whenHaveNoPresetsNoRecentsReturnEmpty) +{ + PresetData data; + + ASSERT_THAT(data.presets(), SizeIs(0)); + ASSERT_THAT(data.categories(), SizeIs(0)); +} + +TEST(QdsPresetModel, haveSameArraySizeForPresetsAndCategories) +{ + PresetData data; + + data.setData( + { + aCategory("A.categ", "A", {"item a", "item b"}), + aCategory("B.categ", "B", {"item c", "item d"}), + }, + {/*recents*/}); + + ASSERT_THAT(data.presets(), SizeIs(2)); + ASSERT_THAT(data.categories(), SizeIs(2)); +} + +TEST(QdsPresetModel, haveWizardPresetsNoRecents) +{ + // Given + PresetData data; + + // When + data.setData( + { + aCategory("A.categ", "A", {"item a", "item b"}), + aCategory("B.categ", "B", {"item c", "item d"}), + }, + {/*recents*/}); + + // Then + ASSERT_THAT(data.categories(), ElementsAre("A", "B")); + ASSERT_THAT(data.presets()[0], + ElementsAre(PresetIs("A.categ", "item a"), PresetIs("A.categ", "item b"))); + ASSERT_THAT(data.presets()[1], + ElementsAre(PresetIs("B.categ", "item c"), PresetIs("B.categ", "item d"))); +} + +TEST(QdsPresetModel, haveRecentsNoWizardPresets) +{ + PresetData data; + + data.setData({/*wizardPresets*/}, + { + {"A.categ", "Desktop", "640 x 480"}, + {"B.categ", "Mobile", "800 x 600"}, + }); + + ASSERT_THAT(data.categories(), IsEmpty()); + ASSERT_THAT(data.presets(), IsEmpty()); +} + +TEST(QdsPresetModel, recentsAddedBeforeWizardPresets) +{ + // Given + PresetData data; + + // When + data.setData( + /*wizard presets*/ + { + aCategory("A.categ", "A", {"Desktop", "item b"}), + aCategory("B.categ", "B", {"item c", "Mobile"}), + }, + /*recents*/ + { + {"A.categ", "Desktop", "800 x 600"}, + {"B.categ", "Mobile", "640 x 480"}, + }); + + // Then + ASSERT_THAT(data.categories(), ElementsAre("Recents", "A", "B")); + + ASSERT_THAT(data.presets(), + ElementsAreArray( + {ElementsAre(PresetIs("A.categ", "Desktop"), PresetIs("B.categ", "Mobile")), + + ElementsAre(PresetIs("A.categ", "Desktop"), PresetIs("A.categ", "item b")), + ElementsAre(PresetIs("B.categ", "item c"), PresetIs("B.categ", "Mobile"))})); +} + +TEST(QdsPresetModel, recentsShouldNotSorted) +{ + // Given + PresetData data; + + // When + data.setData( + /*wizard presets*/ + { + aCategory("A.categ", "A", {"Desktop", "item b"}), + aCategory("B.categ", "B", {"item c", "Mobile"}), + aCategory("Z.categ", "Z", {"Z.desktop"}), + }, + /*recents*/ + { + {"Z.categ", "Z.desktop", "200 x 300"}, + {"B.categ", "Mobile", "200 x 300"}, + {"A.categ", "Desktop", "200 x 300"}, + }); + + // Then + ASSERT_THAT(data.presets()[0], + ElementsAre(PresetIs("Z.categ", "Z.desktop"), + PresetIs("B.categ", "Mobile"), + PresetIs("A.categ", "Desktop"))); +} + +TEST(QdsPresetModel, recentsOfSameWizardProjectButDifferentSizesAreRecognizedAsDifferentPresets) +{ + // Given + PresetData data; + + // When + data.setData( + /*wizard presets*/ + { + aCategory("A.categ", "A", {"Desktop"}), + aCategory("B.categ", "B", {"Mobile"}), + }, + /*recents*/ + { + {"B.categ", "Mobile", "400 x 400"}, + {"B.categ", "Mobile", "200 x 300"}, + {"A.categ", "Desktop", "640 x 480"}, + }); + + // Then + ASSERT_THAT(data.presets()[0], + ElementsAre(PresetIs("B.categ", "Mobile", "400 x 400"), + PresetIs("B.categ", "Mobile", "200 x 300"), + PresetIs("A.categ", "Desktop", "640 x 480"))); +} + +TEST(QdsPresetModel, outdatedRecentsAreNotShown) +{ + // Given + PresetData data; + + // When + data.setData( + /*wizard presets*/ + { + aCategory("A.categ", "A", {"Desktop"}), + aCategory("B.categ", "B", {"Mobile"}), + }, + /*recents*/ + { + {"B.categ", "NoLongerExists", "400 x 400"}, + {"A.categ", "Desktop", "640 x 480"}, + }); + + // Then + ASSERT_THAT(data.presets()[0], ElementsAre(PresetIs("A.categ", "Desktop", "640 x 480"))); +} diff --git a/tests/auto/qml/qmldesigner/wizard/recentpresets-test.cpp b/tests/auto/qml/qmldesigner/wizard/recentpresets-test.cpp new file mode 100644 index 0000000000..b1bb0e0626 --- /dev/null +++ b/tests/auto/qml/qmldesigner/wizard/recentpresets-test.cpp @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "test-utilities.h" + +#include <QDir> +#include <QRandomGenerator> +#include <QTime> + +#include "recentpresets.h" +#include "utils/filepath.h" +#include "utils/temporarydirectory.h" + +using namespace StudioWelcome; + +constexpr char GROUP_NAME[] = "RecentPresets"; +constexpr char ITEMS[] = "Wizards"; + +class QdsRecentPresets : public ::testing::Test +{ +protected: + RecentPresetsStore aStoreWithRecents(const QStringList &items) + { + settings.beginGroup(GROUP_NAME); + settings.setValue(ITEMS, items); + settings.endGroup(); + + return RecentPresetsStore{&settings}; + } + + RecentPresetsStore aStoreWithOne(const QVariant &item) + { + settings.beginGroup(GROUP_NAME); + settings.setValue(ITEMS, item); + settings.endGroup(); + + return RecentPresetsStore{&settings}; + } + +protected: + Utils::TemporaryDirectory tempDir{"recentpresets-XXXXXX"}; + QSettings settings{tempDir.filePath("test").toString(), QSettings::IniFormat}; + +private: + QString settingsPath; +}; + +/******************* TESTS *******************/ + +TEST_F(QdsRecentPresets, readFromEmptyStore) +{ + RecentPresetsStore store{&settings}; + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, IsEmpty()); +} + +TEST_F(QdsRecentPresets, readEmptyRecentPresets) +{ + RecentPresetsStore store = aStoreWithOne(""); + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, IsEmpty()); +} + +TEST_F(QdsRecentPresets, readOneRecentPresetAsList) +{ + RecentPresetsStore store = aStoreWithRecents({"category/preset:640 x 480"}); + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, ElementsAre(RecentPreset("category", "preset", "640 x 480"))); +} + +TEST_F(QdsRecentPresets, readOneRecentPresetAsString) +{ + RecentPresetsStore store = aStoreWithOne("category/preset:200 x 300"); + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, ElementsAre(RecentPreset("category", "preset", "200 x 300"))); +} + +TEST_F(QdsRecentPresets, readBadRecentPresetAsString) +{ + RecentPresetsStore store = aStoreWithOne("no_category_only_preset"); + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, IsEmpty()); +} + +TEST_F(QdsRecentPresets, readBadRecentPresetAsInt) +{ + RecentPresetsStore store = aStoreWithOne(32); + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, IsEmpty()); +} + +TEST_F(QdsRecentPresets, readBadRecentPresetsInList) +{ + RecentPresetsStore store = aStoreWithRecents({"bad1", // no category, no size + "categ/name:800 x 600", // good + "categ/bad2", //no size + "categ/bad3:", //no size + "categ 1/bad4:200 x 300", // category has space + "categ/bad5: 400 x 300", // size starts with space + "categ/bad6:400"}); // bad size + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, ElementsAre(RecentPreset("categ", "name", "800 x 600"))); +} + +TEST_F(QdsRecentPresets, readTwoRecentPresets) +{ + RecentPresetsStore store = aStoreWithRecents( + {"category_1/preset 1:640 x 480", "category_2/preset 2:320 x 200"}); + + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, + ElementsAre(RecentPreset("category_1", "preset 1", "640 x 480"), + RecentPreset("category_2", "preset 2", "320 x 200"))); +} + +TEST_F(QdsRecentPresets, addFirstRecentPreset) +{ + RecentPresetsStore store{&settings}; + + store.add("A.Category", "Normal Application", "400 x 600"); + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, ElementsAre(RecentPreset("A.Category", "Normal Application", "400 x 600"))); +} + +TEST_F(QdsRecentPresets, addExistingFirstRecentPreset) +{ + RecentPresetsStore store = aStoreWithRecents({"category/preset"}); + + store.add("category", "preset", "200 x 300"); + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, ElementsAre(RecentPreset("category", "preset", "200 x 300"))); +} + +TEST_F(QdsRecentPresets, addSecondRecentPreset) +{ + RecentPresetsStore store = aStoreWithRecents({"A.Category/Preset 1:800 x 600"}); + + store.add("A.Category", "Preset 2", "640 x 480"); + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, + ElementsAre(RecentPreset("A.Category", "Preset 2", "640 x 480"), + RecentPreset("A.Category", "Preset 1", "800 x 600"))); +} + +TEST_F(QdsRecentPresets, addSecondRecentPresetSameKindButDifferentSize) +{ + RecentPresetsStore store = aStoreWithRecents({"A.Category/Preset:800 x 600"}); + + store.add("A.Category", "Preset", "640 x 480"); + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, + ElementsAre(RecentPreset("A.Category", "Preset", "640 x 480"), + RecentPreset("A.Category", "Preset", "800 x 600"))); +} + +TEST_F(QdsRecentPresets, fetchesRecentPresetsInTheReverseOrderTheyWereAdded) +{ + RecentPresetsStore store{&settings}; + + store.add("A.Category", "Preset 1", "640 x 480"); + store.add("A.Category", "Preset 2", "640 x 480"); + store.add("A.Category", "Preset 3", "800 x 600"); + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, + ElementsAre(RecentPreset("A.Category", "Preset 3", "800 x 600"), + RecentPreset("A.Category", "Preset 2", "640 x 480"), + RecentPreset("A.Category", "Preset 1", "640 x 480"))); +} + +TEST_F(QdsRecentPresets, addingAnExistingRecentPresetMakesItTheFirst) +{ + RecentPresetsStore store = aStoreWithRecents({"A.Category/Preset 1:200 x 300", + "A.Category/Preset 2:200 x 300", + "A.Category/Preset 3:640 x 480"}); + + store.add("A.Category", "Preset 3", "640 x 480"); + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, + ElementsAre(RecentPreset("A.Category", "Preset 3", "640 x 480"), + RecentPreset("A.Category", "Preset 1", "200 x 300"), + RecentPreset("A.Category", "Preset 2", "200 x 300"))); +} + +TEST_F(QdsRecentPresets, addingTooManyRecentPresetsRemovesTheOldestOne) +{ + RecentPresetsStore store = aStoreWithRecents( + {"A.Category/Preset 2:200 x 300", "A.Category/Preset 1:200 x 300"}); + store.setMaximum(2); + + store.add("A.Category", "Preset 3", "200 x 300"); + std::vector<RecentPreset> recents = store.fetchAll(); + + ASSERT_THAT(recents, + ElementsAre(RecentPreset("A.Category", "Preset 3", "200 x 300"), + RecentPreset("A.Category", "Preset 2", "200 x 300"))); +} diff --git a/tests/auto/qml/qmldesigner/wizard/test-main.cpp b/tests/auto/qml/qmldesigner/wizard/test-main.cpp new file mode 100644 index 0000000000..d419674ea1 --- /dev/null +++ b/tests/auto/qml/qmldesigner/wizard/test-main.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +* Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "test-utilities.h" + +#include <utils/temporarydirectory.h> + +class Environment : public testing::Environment +{ +public: + void SetUp() override + { + const QString temporayDirectoryPath = QDir::tempPath() + "/QtCreator-UnitTests-XXXXXX"; + Utils::TemporaryDirectory::setMasterTemporaryDirectory(temporayDirectoryPath); + qputenv("TMPDIR", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8()); + qputenv("TEMP", Utils::TemporaryDirectory::masterDirectoryPath().toUtf8()); + } + + void TearDown() override {} +}; + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + + auto environment = std::make_unique<Environment>(); + testing::AddGlobalTestEnvironment(environment.release()); + + return RUN_ALL_TESTS(); +} + diff --git a/tests/auto/qml/qmldesigner/wizard/test-utilities.h b/tests/auto/qml/qmldesigner/wizard/test-utilities.h index 3f708e121d..b368e532f4 100644 --- a/tests/auto/qml/qmldesigner/wizard/test-utilities.h +++ b/tests/auto/qml/qmldesigner/wizard/test-utilities.h @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include "gmock/gmock-matchers.h" #include <gmock/gmock.h> #include <gtest/gtest.h> @@ -38,8 +39,10 @@ using ::testing::Return; using ::testing::AtLeast; using ::testing::ElementsAreArray; +using ::testing::ElementsAre; using ::testing::IsEmpty; using ::testing::Not; +using ::testing::SizeIs; QT_BEGIN_NAMESPACE diff --git a/tests/auto/qml/qmldesigner/wizard/wizardfactories-test.cpp b/tests/auto/qml/qmldesigner/wizard/wizardfactories-test.cpp index 97ae04cccc..2e6a87617d 100644 --- a/tests/auto/qml/qmldesigner/wizard/wizardfactories-test.cpp +++ b/tests/auto/qml/qmldesigner/wizard/wizardfactories-test.cpp @@ -26,15 +26,17 @@ #include "test-utilities.h" #include <coreplugin/iwizardfactory.h> +#include <projectexplorer/jsonwizard/jsonwizardfactory.h> #include "wizardfactories.h" using namespace StudioWelcome; using Core::IWizardFactory; +using ProjectExplorer::JsonWizardFactory; namespace { -class MockWizardFactory : public IWizardFactory +class MockWizardFactory : public JsonWizardFactory { public: MOCK_METHOD(Utils::Wizard *, runWizardImpl, @@ -47,6 +49,8 @@ public: ), (override)); + MOCK_METHOD((std::pair<int, QStringList>), screenSizeInfoFromPage, (const QString &), (const)); + MOCK_METHOD(bool, isAvailable, (Utils::Id), (const, override)); }; @@ -78,12 +82,14 @@ protected: // a good wizard factory is a wizard factory that is not filtered out, and which is available on // platform `this->platform` - IWizardFactory *aGoodWizardFactory(const QString &name = "", const QString &id = "", const QString &categoryId = "") + IWizardFactory *aGoodWizardFactory(const QString &name = "", const QString &id = "", + const QString &categoryId = "", const std::pair<int, QStringList> &sizes = {}) { MockWizardFactory *factory = new MockWizardFactory; m_factories.push_back(std::unique_ptr<IWizardFactory>(factory)); - configureFactory(*factory, IWizardFactory::ProjectWizard, /*req QtStudio*/true, {platform, true}); + configureFactory(*factory, IWizardFactory::ProjectWizard, /*req QtStudio*/true, + {platform, true}, sizes); if (!name.isEmpty()) factory->setDisplayName(name); @@ -97,7 +103,8 @@ protected: void configureFactory(MockWizardFactory &factory, IWizardFactory::WizardKind kind, bool requiresQtStudio = true, - const QPair<QString, bool> &availableOnPlatform = {}) + const QPair<QString, bool> &availableOnPlatform = {}, + const QPair<int, QStringList> &sizes = {}) { if (kind == IWizardFactory::ProjectWizard) { QSet<Utils::Id> supported{Utils::Id{"QmlProjectManager.QmlProject"}}; @@ -127,6 +134,14 @@ protected: .Times(AtLeast(1)) .WillRepeatedly(Return(value)); } + + auto screenSizes = (sizes == std::pair<int, QStringList>{} + ? std::make_pair(0, QStringList({"640 x 480"})) + : sizes); + + EXPECT_CALL(factory, screenSizeInfoFromPage(QString("Fields"))) + .Times(AtLeast(0)) + .WillRepeatedly(Return(screenSizes)); } WizardFactories makeWizardFactoriesHandler(QList<IWizardFactory *> source, @@ -143,15 +158,21 @@ private: WizardFactories::GetIconUnicodeFunc oldIconUnicodeFunc; }; -inline QStringList projectNames(const ProjectCategory &cat) +QStringList presetNames(const WizardCategory &cat) +{ + QStringList result = Utils::transform<QStringList>(cat.items, &PresetItem::name); + return result; +} + +QStringList screenSizes(const WizardCategory &cat) { - QStringList result = Utils::transform<QStringList>(cat.items, &ProjectItem::name); + QStringList result = Utils::transform<QStringList>(cat.items, &PresetItem::screenSizeName); return result; } -inline QStringList categoryNames(const std::map<QString, ProjectCategory> &projects) +QStringList categoryNames(const std::map<QString, WizardCategory> &presets) { - QMap<QString, ProjectCategory> qmap{projects}; + const QMap<QString, WizardCategory> qmap{presets}; return qmap.keys(); } @@ -166,9 +187,9 @@ TEST_F(QdsWizardFactories, haveEmptyListOfWizardFactories) /*get wizards supporting platform*/ "platform" ); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(projects, IsEmpty()); + ASSERT_THAT(presets, IsEmpty()); } TEST_F(QdsWizardFactories, filtersOutNonProjectWizardFactories) @@ -178,9 +199,9 @@ TEST_F(QdsWizardFactories, filtersOutNonProjectWizardFactories) /*get wizards supporting platform*/ platform ); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(projects, IsEmpty()); + ASSERT_THAT(presets, IsEmpty()); } TEST_F(QdsWizardFactories, filtersOutWizardFactoriesUnavailableForPlatform) @@ -190,9 +211,9 @@ TEST_F(QdsWizardFactories, filtersOutWizardFactoriesUnavailableForPlatform) /*get wizards supporting platform*/ "Non-Desktop" ); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(projects, IsEmpty()); + ASSERT_THAT(presets, IsEmpty()); } TEST_F(QdsWizardFactories, filtersOutWizardFactoriesThatDontRequireQtStudio) @@ -203,18 +224,48 @@ TEST_F(QdsWizardFactories, filtersOutWizardFactoriesThatDontRequireQtStudio) }, /*get wizards supporting platform*/ platform); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(projects, IsEmpty()); + ASSERT_THAT(presets, IsEmpty()); } TEST_F(QdsWizardFactories, doesNotFilterOutAGoodWizardFactory) { WizardFactories wf = makeWizardFactoriesHandler({aGoodWizardFactory()}, platform); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); + + ASSERT_THAT(presets, Not(IsEmpty())); +} + +TEST_F(QdsWizardFactories, DISABLED_buildsPresetItemWithCorrectSizeName) +{ + WizardFactories wf = makeWizardFactoriesHandler( + { + aGoodWizardFactory("A", "A_id", "A.category", {1, {"size 0", "size 1"}}), + }, + platform); + + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(projects, Not(IsEmpty())); + ASSERT_THAT(categoryNames(presets), ElementsAreArray({"A.category"})); + ASSERT_THAT(presetNames(presets["A.category"]), ElementsAreArray({"A"})); + ASSERT_THAT(screenSizes(presets["A.category"]), ElementsAreArray({"size 1"})); +} + +TEST_F(QdsWizardFactories, whenSizeInfoIsBadBuildsPresetItemWithEmptySizeName) +{ + WizardFactories wf = makeWizardFactoriesHandler( + { + aGoodWizardFactory("A", "A_id", "A.category", {1, {/*empty*/}}), + }, + platform); + + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); + + ASSERT_THAT(categoryNames(presets), ElementsAreArray({"A.category"})); + ASSERT_THAT(presetNames(presets["A.category"]), ElementsAreArray({"A"})); + ASSERT_THAT(screenSizes(presets["A.category"]), ElementsAreArray({""})); } TEST_F(QdsWizardFactories, sortsWizardFactoriesByCategory) @@ -226,11 +277,11 @@ TEST_F(QdsWizardFactories, sortsWizardFactoriesByCategory) }, platform); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(categoryNames(projects), ElementsAreArray({"A.category", "Z.category"})); - ASSERT_THAT(projectNames(projects["A.category"]), ElementsAreArray({"X"})); - ASSERT_THAT(projectNames(projects["Z.category"]), ElementsAreArray({"B"})); + ASSERT_THAT(categoryNames(presets), ElementsAreArray({"A.category", "Z.category"})); + ASSERT_THAT(presetNames(presets["A.category"]), ElementsAreArray({"X"})); + ASSERT_THAT(presetNames(presets["Z.category"]), ElementsAreArray({"B"})); } TEST_F(QdsWizardFactories, sortsWizardFactoriesById) @@ -242,10 +293,10 @@ TEST_F(QdsWizardFactories, sortsWizardFactoriesById) }, platform); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(categoryNames(projects), ElementsAreArray({"category"})); - ASSERT_THAT(projectNames(projects["category"]), ElementsAreArray({"X", "B"})); + ASSERT_THAT(categoryNames(presets), ElementsAreArray({"category"})); + ASSERT_THAT(presetNames(presets["category"]), ElementsAreArray({"X", "B"})); } TEST_F(QdsWizardFactories, groupsWizardFactoriesByCategory) @@ -258,14 +309,14 @@ TEST_F(QdsWizardFactories, groupsWizardFactoriesByCategory) }, platform); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(categoryNames(projects), ElementsAreArray({"A.category", "Z.category"})); - ASSERT_THAT(projectNames(projects["A.category"]), ElementsAreArray({"A", "B"})); - ASSERT_THAT(projectNames(projects["Z.category"]), ElementsAreArray({"C"})); + ASSERT_THAT(categoryNames(presets), ElementsAreArray({"A.category", "Z.category"})); + ASSERT_THAT(presetNames(presets["A.category"]), ElementsAreArray({"A", "B"})); + ASSERT_THAT(presetNames(presets["Z.category"]), ElementsAreArray({"C"})); } -TEST_F(QdsWizardFactories, createsProjectItemAndCategoryCorrectlyFromWizardFactory) +TEST_F(QdsWizardFactories, createsPresetItemAndCategoryCorrectlyFromWizardFactory) { IWizardFactory *source = aGoodWizardFactory("myName", "myId", "myCategoryId"); @@ -280,23 +331,19 @@ TEST_F(QdsWizardFactories, createsProjectItemAndCategoryCorrectlyFromWizardFacto WizardFactories wf = makeWizardFactoriesHandler({source}, platform); - std::map<QString, ProjectCategory> projects = wf.projectsGroupedByCategory(); + std::map<QString, WizardCategory> presets = wf.presetsGroupedByCategory(); - ASSERT_THAT(categoryNames(projects), ElementsAreArray({"myCategoryId"})); - ASSERT_THAT(projectNames(projects["myCategoryId"]), ElementsAreArray({"myName"})); + ASSERT_THAT(categoryNames(presets), ElementsAreArray({"myCategoryId"})); + ASSERT_THAT(presetNames(presets["myCategoryId"]), ElementsAreArray({"myName"})); - auto category = projects["myCategoryId"]; + auto category = presets["myCategoryId"]; ASSERT_EQ("myCategoryId", category.id); ASSERT_EQ("myDisplayCategory", category.name); - auto projectItem = projects["myCategoryId"].items[0]; - ASSERT_EQ("myName", projectItem.name); - ASSERT_EQ("myDescription", projectItem.description); - ASSERT_EQ("qrc:/my/qml/path", projectItem.qmlPath.toString()); - ASSERT_EQ("\uABCD", projectItem.fontIconCode); + auto presetItem = presets["myCategoryId"].items[0]; + ASSERT_EQ("myName", presetItem.name); + ASSERT_EQ("myDescription", presetItem.description); + ASSERT_EQ("qrc:/my/qml/path", presetItem.qmlPath.toString()); + ASSERT_EQ("\uABCD", presetItem.fontIconCode); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} |