Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
#48 Add updater status to string converter
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDuquesnoy committed Jul 20, 2017
1 parent ec7140b commit d32eae4
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
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;
}
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;
};

}
2 changes: 1 addition & 1 deletion scripts/travis/commit-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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);
}
}
}
}

0 comments on commit d32eae4

Please sign in to comment.