Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1467: Mockable standard paths r=townsend2010 a=ricab Adds a mockable `StandardPaths` singleton, as a thin wrapper around `QStandardPaths`. Implements the corresponding mock with the same approach as `MockSettings`, that is, via: 1. a test environment, to run custom code during test setup and tear down 2. a test event listener, to verify and clear mock expectations on the singleton at the end of each test 3. default operations delegating on the parent To achieve that, this PR also extracts common stuff into a `MockSingletonHelper`. This approach enforces accounting of mock expectations in the respective test. It also avoids singleton state leaking from test to test and affecting the results based on execution order. Finally, it ensures that tests only deal with the mock. They use only parent operations that are deemed safe for testing, indirectly, via the mock itself. Co-authored-by: Ricardo Abreu <ricab@ricabhome.org>
- Loading branch information
Showing
19 changed files
with
457 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2020 Canonical, Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#ifndef MULTIPASS_STANDARD_PATHS_H | ||
#define MULTIPASS_STANDARD_PATHS_H | ||
|
||
#include "singleton.h" | ||
|
||
#include <QStandardPaths> | ||
|
||
namespace multipass | ||
{ | ||
class StandardPaths : public Singleton<StandardPaths> | ||
{ | ||
public: | ||
// TODO try to replace all the stuff below with `using enum` in C++20 (P1099R5) | ||
using LocateOption = QStandardPaths::LocateOption; | ||
static constexpr auto LocateFile = LocateOption::LocateFile; | ||
static constexpr auto LocateDirectory = LocateOption::LocateDirectory; | ||
using LocateOptions = QStandardPaths::LocateOptions; | ||
|
||
using StandardLocation = QStandardPaths::StandardLocation; | ||
static constexpr auto DesktopLocation = StandardLocation::DesktopLocation; | ||
static constexpr auto DocumentsLocation = StandardLocation::DocumentsLocation; | ||
static constexpr auto FontsLocation = StandardLocation::FontsLocation; | ||
static constexpr auto ApplicationsLocation = StandardLocation::ApplicationsLocation; | ||
static constexpr auto MusicLocation = StandardLocation::MusicLocation; | ||
static constexpr auto MoviesLocation = StandardLocation::MoviesLocation; | ||
static constexpr auto PicturesLocation = StandardLocation::PicturesLocation; | ||
static constexpr auto TempLocation = StandardLocation::TempLocation; | ||
static constexpr auto HomeLocation = StandardLocation::HomeLocation; | ||
static constexpr auto DataLocation = StandardLocation::DataLocation; | ||
static constexpr auto CacheLocation = StandardLocation::CacheLocation; | ||
static constexpr auto GenericCacheLocation = StandardLocation::GenericCacheLocation; | ||
static constexpr auto GenericDataLocation = StandardLocation::GenericDataLocation; | ||
static constexpr auto RuntimeLocation = StandardLocation::RuntimeLocation; | ||
static constexpr auto ConfigLocation = StandardLocation::ConfigLocation; | ||
static constexpr auto DownloadLocation = StandardLocation::DownloadLocation; | ||
static constexpr auto GenericConfigLocation = StandardLocation::GenericConfigLocation; | ||
static constexpr auto AppDataLocation = StandardLocation::AppDataLocation; | ||
static constexpr auto AppLocalDataLocation = StandardLocation::AppLocalDataLocation; | ||
static constexpr auto AppConfigLocation = StandardLocation::AppConfigLocation; | ||
|
||
StandardPaths(const Singleton<StandardPaths>::PrivatePass&); | ||
|
||
virtual QString locate(StandardLocation type, const QString& fileName, | ||
LocateOptions options = LocateOption::LocateFile) const; | ||
virtual QStringList standardLocations(StandardLocation type) const; | ||
virtual QString writableLocation(StandardLocation type) const; | ||
}; | ||
} // namespace multipass | ||
#endif // MULTIPASS_STANDARD_PATHS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2020 Canonical, Ltd. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <multipass/standard_paths.h> | ||
|
||
namespace mp = multipass; | ||
|
||
mp::StandardPaths::StandardPaths(const Singleton<StandardPaths>::PrivatePass& pass) | ||
: Singleton<StandardPaths>::Singleton{pass} | ||
{ | ||
} | ||
|
||
QString mp::StandardPaths::locate(StandardLocation type, const QString& fileName, LocateOptions options) const | ||
{ | ||
return QStandardPaths::locate(type, fileName, options); | ||
} | ||
|
||
QStringList mp::StandardPaths::standardLocations(StandardLocation type) const | ||
{ | ||
return QStandardPaths::standardLocations(type); | ||
} | ||
|
||
QString mp::StandardPaths::writableLocation(StandardLocation type) const | ||
{ | ||
return QStandardPaths::writableLocation(type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
8e085b5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macOS build available: multipass-1.2.0-dev.169+g7e3a083e.mac-Darwin.pkg