diff --git a/lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.cpp b/lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.cpp new file mode 100644 index 00000000..3201870c --- /dev/null +++ b/lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.cpp @@ -0,0 +1,34 @@ +#include +#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 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 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; +} diff --git a/lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.hpp b/lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.hpp new file mode 100644 index 00000000..5d18e8ea --- /dev/null +++ b/lib/MellowPlayer/Presentation/Converters/UpdaterStatusConverter.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +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; + }; + +} diff --git a/scripts/travis/commit-build.sh b/scripts/travis/commit-build.sh index 0aece36c..7c3029f6 100755 --- a/scripts/travis/commit-build.sh +++ b/scripts/travis/commit-build.sh @@ -10,7 +10,7 @@ pushd build; if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then # build - cmake -DCMAKE_BUILD_TYPE=Debug --DBUILD_TESTS=ON -DBUILD_INTEGRATION_TESTS=ON -DENABLE_COVERAGE=ON -DCMAKE_INSTALL_PREFIX=/usr ..; + cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DBUILD_INTEGRATION_TESTS=ON -DENABLE_COVERAGE=ON -DCMAKE_INSTALL_PREFIX=/usr ..; make; # run tests diff --git a/tests/UnitTests/Infrastructure/Utils/AlbumArt/LocalAlbumArtTests.cpp b/tests/UnitTests/Infrastructure/AlbumArt/LocalAlbumArtTests.cpp similarity index 100% rename from tests/UnitTests/Infrastructure/Utils/AlbumArt/LocalAlbumArtTests.cpp rename to tests/UnitTests/Infrastructure/AlbumArt/LocalAlbumArtTests.cpp diff --git a/tests/UnitTests/Presentation/Converters/UpdateStatusConverterTests.cpp b/tests/UnitTests/Presentation/Converters/UpdateStatusConverterTests.cpp new file mode 100644 index 00000000..b71e0630 --- /dev/null +++ b/tests/UnitTests/Presentation/Converters/UpdateStatusConverterTests.cpp @@ -0,0 +1,93 @@ +#include +#include + +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); + } + } + } +} \ No newline at end of file