This repository has been archived by the owner on May 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfabd2a
commit 6c166cf
Showing
5 changed files
with
309 additions
and
0 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,71 @@ | ||
@startuml | ||
|
||
package MellowPlayer::Application { | ||
interface IStreamingServiceLoader { | ||
+ load() | ||
} | ||
} | ||
|
||
package MellowPlayer::Infrastructure { | ||
class StreamingServiceLoader { | ||
+ load() | ||
- _filtersFactory: IPlatformFiltersFactory | ||
- _platform: IPlatform | ||
} | ||
|
||
IStreamingServiceLoader <|-- StreamingServiceLoader | ||
|
||
StreamingServiceLoader -left-> IPlatformFiltersFactory: _filtersFactory | ||
StreamingServiceLoader -right-> IPlatform: _platform | ||
|
||
interface IPlatform { | ||
+ name(): QString | ||
-- | ||
+ isLinux() : bool | ||
+ isAppImage() : bool | ||
+ isWindows() : bool | ||
+ isOsx() : bool | ||
-- | ||
+ match(QList<IPlatformFilter>): bool | ||
} | ||
|
||
class Platform | ||
IPlatform <|-- Platform | ||
|
||
Platform .left.> IPlatformFilter: <<match>> | ||
|
||
interface IPlatformFiltersFactory { | ||
+ create(QString) : QList<IPlatformFilter> | ||
} | ||
|
||
class PlatformFiltersFactory { | ||
+ create(QString) : QList<IPlatformFilter> | ||
} | ||
|
||
IPlatformFiltersFactory <|-- PlatformFiltersFactory | ||
|
||
interface IPlatformFilter { | ||
match(IPlatform): bool | ||
} | ||
IPlatform <.. IPlatformFilter: <<use>> | ||
|
||
class AllFilter | ||
IPlatformFilter <|-- AllFilter | ||
note left | ||
Always return true | ||
end note | ||
|
||
class LinuxFilter | ||
IPlatformFilter <|-- LinuxFilter | ||
|
||
class AppImageFilter | ||
IPlatformFilter <|-- AppImageFilter | ||
|
||
class OsxFilter | ||
IPlatformFilter <|-- OsxFilter | ||
|
||
class WindowsFilter | ||
IPlatformFilter <|-- WindowsFilter | ||
} | ||
|
||
@enduml |
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,59 @@ | ||
#include "Platform.hpp" | ||
|
||
using namespace MellowPlayer::Infrastructure; | ||
|
||
|
||
QString Platform::Unsupported = "Unsupported platform"; | ||
QString Platform::Linux = "GNU/Linux"; | ||
QString Platform::AppImage = "AppImage"; | ||
QString Platform::Windows = "Windows"; | ||
QString Platform::OSX = "Mac OSX"; | ||
|
||
QString Platform::name() const | ||
{ | ||
QString plaformName = Unsupported; | ||
|
||
#ifdef Q_OS_LINUX | ||
QString appImagePath = qgetenv("APPIMAGE"); | ||
if (appImagePath.isEmpty()) | ||
plaformName = Linux; | ||
else | ||
plaformName = AppImage; | ||
#endif | ||
|
||
#ifdef Q_OS_OSX | ||
plaformName = OSX; | ||
#endif | ||
|
||
#ifdef Q_OS_WIN | ||
plaformName = Windows; | ||
#endif | ||
|
||
return plaformName; | ||
} | ||
|
||
bool Platform::match(QList<IPlatformFilter>&) const | ||
{ | ||
return false; | ||
} | ||
|
||
bool Platform::isLinux() const | ||
{ | ||
return name() == Linux; | ||
} | ||
|
||
bool Platform::isAppImage() const | ||
{ | ||
return name() == AppImage; | ||
} | ||
|
||
bool Platform::isWindows() const | ||
{ | ||
return name() == Windows; | ||
} | ||
|
||
bool Platform::isOsx() const | ||
{ | ||
return name() == OSX; | ||
} | ||
|
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,46 @@ | ||
#pragma once | ||
|
||
#include <QList> | ||
|
||
namespace MellowPlayer::Infrastructure | ||
{ | ||
class IPlatformFilter; | ||
|
||
class IPlatform | ||
{ | ||
public: | ||
virtual ~IPlatform() = default; | ||
|
||
virtual QString name() const = 0; | ||
|
||
virtual bool isLinux() const = 0; | ||
virtual bool isAppImage() const = 0; | ||
virtual bool isWindows() const = 0; | ||
virtual bool isOsx() const = 0; | ||
|
||
virtual bool match(QList<IPlatformFilter>& filters) const = 0; | ||
}; | ||
|
||
class Platform: public IPlatform | ||
{ | ||
public: | ||
QString name() const override; | ||
|
||
bool isLinux() const override; | ||
|
||
bool isAppImage() const override; | ||
|
||
bool isWindows() const override; | ||
|
||
bool isOsx() const override; | ||
|
||
bool match(QList<IPlatformFilter>& filters) const override; | ||
|
||
private: | ||
static QString Unsupported; | ||
static QString Linux; | ||
static QString AppImage; | ||
static QString Windows; | ||
static QString OSX; | ||
}; | ||
} |
125 changes: 125 additions & 0 deletions
125
tests/UnitTests/Infrastructure/Platform/PlatformTests.cpp
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,125 @@ | ||
#include <catch.hpp> | ||
#include <MellowPlayer/Infrastructure/Platform/Platform.hpp> | ||
|
||
using namespace MellowPlayer::Infrastructure; | ||
|
||
SCENARIO("PlatformTests") | ||
{ | ||
GIVEN("A platform instance") | ||
{ | ||
Platform platform; | ||
|
||
WHEN("Call name()") | ||
{ | ||
auto name = platform.name(); | ||
|
||
THEN("name is not empty") | ||
{ | ||
REQUIRE(!name.isEmpty()); | ||
} | ||
} | ||
|
||
#ifdef Q_OS_LINUX | ||
WHEN("on GNU/Linux with no APPIMAGE environment variable defined") | ||
{ | ||
THEN("isLinux returns true") | ||
{ | ||
REQUIRE(platform.isLinux()); | ||
} | ||
|
||
THEN("isAppImage returns false") | ||
{ | ||
REQUIRE(!platform.isAppImage()); | ||
} | ||
|
||
THEN("isOsx returns false") | ||
{ | ||
REQUIRE(!platform.isOsx()); | ||
} | ||
|
||
THEN("isWindows returns false") | ||
{ | ||
REQUIRE(!platform.isWindows()); | ||
} | ||
} | ||
|
||
WHEN("on GNU/Linux with APPIMAGE environment variable defined") | ||
{ | ||
qputenv("APPIMAGE", "/path/to/appimage"); | ||
|
||
THEN("isAppImage returns true") | ||
{ | ||
REQUIRE(platform.isAppImage()); | ||
} | ||
|
||
THEN("isLinux returns false") | ||
{ | ||
REQUIRE(!platform.isLinux()); | ||
} | ||
|
||
THEN("isOsx returns false") | ||
{ | ||
REQUIRE(!platform.isOsx()); | ||
} | ||
|
||
THEN("isWindows returns false") | ||
{ | ||
REQUIRE(!platform.isWindows()); | ||
} | ||
|
||
qputenv("APPIMAGE", ""); | ||
} | ||
#endif | ||
|
||
#ifdef Q_OS_OSX | ||
WHEN("on Mac OSX") | ||
{ | ||
THEN("isOsx returns true") | ||
{ | ||
REQUIRE(platform.isOsx()); | ||
} | ||
|
||
THEN("isLinux returns false") | ||
{ | ||
REQUIRE(!platform.isLinux()); | ||
} | ||
|
||
THEN("isAppImage returns false") | ||
{ | ||
REQUIRE(!platform.isAppImage()); | ||
} | ||
|
||
THEN("isWindows returns false") | ||
{ | ||
REQUIRE(!platform.isWindows()); | ||
} | ||
} | ||
#endif | ||
|
||
#ifdef Q_OS_WIN | ||
WHEN("on Windows") | ||
{ | ||
THEN("isWindows returns true") | ||
{ | ||
REQUIRE(platform.isWindows()); | ||
} | ||
|
||
THEN("isOsx returns false") | ||
{ | ||
REQUIRE(!platform.isOsx()); | ||
} | ||
|
||
THEN("isLinux returns false") | ||
{ | ||
REQUIRE(!platform.isLinux()); | ||
} | ||
|
||
THEN("isAppImage returns false") | ||
{ | ||
REQUIRE(!platform.isAppImage()); | ||
} | ||
} | ||
#endif | ||
|
||
} | ||
} |