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.
#48 Add updater status to string converter
- Loading branch information
1 parent
ec7140b
commit d32eae4
Showing
5 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.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,34 @@ | ||
#include <QtCore/QMap> | ||
#include "UpdaterStatusConverter.hpp" | ||
|
||
using namespace MellowPlayer::Application; | ||
using namespace MellowPlayer::Infrastructure; | ||
|
||
const QString UpdaterStatusConverter::NONE = ""; | ||
const QString UpdaterStatusConverter::CHECKING = QObject::tr("Checking for update"); | ||
const QString UpdaterStatusConverter::DOWNLOADING = QObject::tr("Downloading update"); | ||
const QString UpdaterStatusConverter::INSTALLING = QObject::tr("Installing update"); | ||
|
||
QString UpdaterStatusConverter::toString(Updater::Status status) { | ||
static QMap<Updater::Status, QString> map = { | ||
{ Updater::Status::None, NONE }, | ||
{ Updater::Status::Checking, CHECKING }, | ||
{ Updater::Status::Downloading, DOWNLOADING }, | ||
{ Updater::Status::Installing, INSTALLING } | ||
}; | ||
|
||
return map[status]; | ||
} | ||
|
||
Updater::Status UpdaterStatusConverter::fromString(const QString& string) { | ||
static QMap<QString, Updater::Status> map = { | ||
{ NONE, Updater::Status::None }, | ||
{ CHECKING, Updater::Status::Checking }, | ||
{ DOWNLOADING, Updater::Status::Downloading }, | ||
{ INSTALLING, Updater::Status::Installing } | ||
}; | ||
|
||
if (map.contains(string)) | ||
return map[string]; | ||
return Updater::Status::None; | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.hpp
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,18 @@ | ||
#pragma once | ||
|
||
#include <MellowPlayer/Application/Updater/Updater.hpp> | ||
|
||
namespace MellowPlayer::Infrastructure { | ||
|
||
class UpdaterStatusConverter { | ||
public: | ||
static QString toString(Application::Updater::Status status); | ||
static Application::Updater::Status fromString(const QString& string); | ||
|
||
static const QString NONE; | ||
static const QString CHECKING; | ||
static const QString DOWNLOADING; | ||
static const QString INSTALLING; | ||
}; | ||
|
||
} |
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
File renamed without changes.
93 changes: 93 additions & 0 deletions
93
tests/UnitTests/Presentation/Converters/UpdateStatusConverterTests.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,93 @@ | ||
#include <catch.hpp> | ||
#include <MellowPlayer/Presentation/Converters/UpdaterStatusConverter.hpp> | ||
|
||
using namespace MellowPlayer::Application; | ||
using namespace MellowPlayer::Infrastructure; | ||
|
||
SCENARIO("Updater status can be converted to a string") { | ||
GIVEN("UpdaterStatus::None") { | ||
Updater::Status status = Updater::Status::None; | ||
|
||
WHEN("converting to string") { | ||
QString statusString = UpdaterStatusConverter::toString(status); | ||
|
||
THEN("the string is empty") { | ||
REQUIRE(statusString.isEmpty()); | ||
} | ||
} | ||
} | ||
|
||
GIVEN("UpdaterStatus::Checking") { | ||
Updater::Status status = Updater::Status::Checking; | ||
|
||
WHEN("converting to string") { | ||
QString statusString = UpdaterStatusConverter::toString(status); | ||
|
||
THEN("the string is valid") { | ||
REQUIRE(statusString == UpdaterStatusConverter::CHECKING); | ||
} | ||
} | ||
} | ||
|
||
GIVEN("UpdaterStatus::Downloading") { | ||
Updater::Status status = Updater::Status::Downloading; | ||
|
||
WHEN("converting to string") { | ||
QString statusString = UpdaterStatusConverter::toString(status); | ||
|
||
THEN("the string is valid") { | ||
REQUIRE(statusString == UpdaterStatusConverter::DOWNLOADING); | ||
} | ||
} | ||
} | ||
|
||
GIVEN("UpdaterStatus::Installing") { | ||
Updater::Status status = Updater::Status::Installing; | ||
|
||
WHEN("converting to string") { | ||
QString statusString = UpdaterStatusConverter::toString(status); | ||
|
||
THEN("the string is valid") { | ||
REQUIRE(statusString == UpdaterStatusConverter::INSTALLING); | ||
} | ||
} | ||
} | ||
} | ||
|
||
SCENARIO("Updater status can be converted from a string") { | ||
GIVEN("an empty status string") { | ||
QString statusString = ""; | ||
|
||
WHEN("converting from string") { | ||
Updater::Status status = UpdaterStatusConverter::fromString(statusString); | ||
|
||
THEN("Status is None") { | ||
REQUIRE(status == Updater::Status::None); | ||
} | ||
} | ||
} | ||
|
||
GIVEN("a valid status string") { | ||
QString statusString = UpdaterStatusConverter::CHECKING; | ||
|
||
WHEN("converting from string") { | ||
Updater::Status status = UpdaterStatusConverter::fromString(statusString); | ||
|
||
THEN("Status is valid") { | ||
REQUIRE(status == Updater::Status::Checking); | ||
} | ||
} | ||
} | ||
|
||
GIVEN("an invalid status string") { | ||
QString statusString = "foo"; | ||
|
||
WHEN("converting from string") { | ||
Updater::Status status = UpdaterStatusConverter::fromString(statusString); | ||
|
||
THEN("Status is None") { | ||
REQUIRE(status == Updater::Status::None); | ||
} | ||
} | ||
} | ||
} |