From 27b87d133737a51a9fa73e88b7cc1fb13d08f557 Mon Sep 17 00:00:00 2001 From: ColinDuquesnoy Date: Wed, 20 Sep 2017 20:10:06 +0200 Subject: [PATCH] #69 Add IUserScript and UserScriptBase --- .../StreamingServices/IUserScript.hpp | 20 +++++++ .../StreamingServices/UserScriptBase.cpp | 23 ++++++++ .../StreamingServices/UserScriptBase.hpp | 23 ++++++++ .../StreamingServices/FakeUserScript.cpp | 16 ++++++ .../StreamingServices/FakeUserScript.hpp | 17 ++++++ .../StreamingServices/UserScriptBaseTests.cpp | 56 +++++++++++++++++++ 6 files changed, 155 insertions(+) create mode 100644 lib/MellowPlayer/Application/StreamingServices/IUserScript.hpp create mode 100644 lib/MellowPlayer/Application/StreamingServices/UserScriptBase.cpp create mode 100644 lib/MellowPlayer/Application/StreamingServices/UserScriptBase.hpp create mode 100644 tests/UnitTests/Application/StreamingServices/FakeUserScript.cpp create mode 100644 tests/UnitTests/Application/StreamingServices/FakeUserScript.hpp create mode 100644 tests/UnitTests/Application/StreamingServices/UserScriptBaseTests.cpp diff --git a/lib/MellowPlayer/Application/StreamingServices/IUserScript.hpp b/lib/MellowPlayer/Application/StreamingServices/IUserScript.hpp new file mode 100644 index 00000000..b1d49494 --- /dev/null +++ b/lib/MellowPlayer/Application/StreamingServices/IUserScript.hpp @@ -0,0 +1,20 @@ +#pragma once + +class QString; + +namespace MellowPlayer::Application +{ + class IUserScript + { + public: + virtual ~IUserScript() = default; + virtual QString path() const = 0; + virtual QString code() const = 0; + virtual QString name() const = 0; + + virtual void setName(const QString& name) = 0; + + virtual void import(const QString& path) = 0; + virtual void load(const QString& path) = 0; + }; +} diff --git a/lib/MellowPlayer/Application/StreamingServices/UserScriptBase.cpp b/lib/MellowPlayer/Application/StreamingServices/UserScriptBase.cpp new file mode 100644 index 00000000..c228964d --- /dev/null +++ b/lib/MellowPlayer/Application/StreamingServices/UserScriptBase.cpp @@ -0,0 +1,23 @@ +#include "UserScriptBase.hpp" + +using namespace MellowPlayer::Application; + +QString UserScriptBase::path() const +{ + return path_; +} + +QString UserScriptBase::code() const +{ + return code_; +} + +QString UserScriptBase::name() const +{ + return name_; +} + +void UserScriptBase::setName(const QString& name) +{ + name_ = name; +} diff --git a/lib/MellowPlayer/Application/StreamingServices/UserScriptBase.hpp b/lib/MellowPlayer/Application/StreamingServices/UserScriptBase.hpp new file mode 100644 index 00000000..b9b53dd9 --- /dev/null +++ b/lib/MellowPlayer/Application/StreamingServices/UserScriptBase.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "IUserScript.hpp" +#include + +namespace MellowPlayer::Application +{ + class UserScriptBase: public QObject, public IUserScript + { + public: + QString path() const override; + QString code() const override; + QString name() const override; + void setName(const QString& name) override; + + protected: + QString code_; + QString path_; + + private: + QString name_; + }; +} diff --git a/tests/UnitTests/Application/StreamingServices/FakeUserScript.cpp b/tests/UnitTests/Application/StreamingServices/FakeUserScript.cpp new file mode 100644 index 00000000..ec1f2e3d --- /dev/null +++ b/tests/UnitTests/Application/StreamingServices/FakeUserScript.cpp @@ -0,0 +1,16 @@ +#include "FakeUserScript.hpp" + +using namespace MellowPlayer::Application; +using namespace MellowPlayer::Application::Tests; + + +void FakeUserScript::import(const QString& path) +{ + load(path); +} + +void FakeUserScript::load(const QString& path) +{ + UserScriptBase::path_ = path; + Application::UserScriptBase::code_ = FAKE_USER_SCRIPT_CODE; +} diff --git a/tests/UnitTests/Application/StreamingServices/FakeUserScript.hpp b/tests/UnitTests/Application/StreamingServices/FakeUserScript.hpp new file mode 100644 index 00000000..93db69c8 --- /dev/null +++ b/tests/UnitTests/Application/StreamingServices/FakeUserScript.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +#define FAKE_USER_SCRIPT_CODE "foo" + +namespace MellowPlayer::Application::Tests +{ + class FakeUserScript: public UserScriptBase + { + public: + void import(const QString& path) override; + + void load(const QString& path) override; + }; +} \ No newline at end of file diff --git a/tests/UnitTests/Application/StreamingServices/UserScriptBaseTests.cpp b/tests/UnitTests/Application/StreamingServices/UserScriptBaseTests.cpp new file mode 100644 index 00000000..6e01b6c8 --- /dev/null +++ b/tests/UnitTests/Application/StreamingServices/UserScriptBaseTests.cpp @@ -0,0 +1,56 @@ +#include +#include +#include "FakeUserScript.hpp" + +using namespace MellowPlayer::Application; +using namespace MellowPlayer::Application::Tests; + +SCENARIO("UserScriptBaseTests") +{ + GIVEN("A fake user script") + { + FakeUserScript userScript; + + WHEN("in initial state") + { + THEN("path is empty") + { + REQUIRE(userScript.path().isEmpty()); + } + + THEN("name is empty") + { + REQUIRE(userScript.name().isEmpty()); + } + + THEN("code is empty") + { + REQUIRE(userScript.code().isEmpty()); + } + } + + WHEN("setName") + { + userScript.setName("toto"); + THEN("name is set") + { + REQUIRE(userScript.name() == "toto"); + } + } + + WHEN("fake load is called") + { + userScript.load("/a/path"); + + THEN("path is set") + { + REQUIRE(userScript.path() == "/a/path"); + } + + THEN("code is set") + { + REQUIRE(userScript.code() == FAKE_USER_SCRIPT_CODE); + } + } + } +}