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.
#69 Add IUserScript and UserScriptBase
- Loading branch information
1 parent
3c11585
commit 27b87d1
Showing
6 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
lib/MellowPlayer/Application/StreamingServices/IUserScript.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,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; | ||
}; | ||
} |
23 changes: 23 additions & 0 deletions
23
lib/MellowPlayer/Application/StreamingServices/UserScriptBase.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,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; | ||
} |
23 changes: 23 additions & 0 deletions
23
lib/MellowPlayer/Application/StreamingServices/UserScriptBase.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,23 @@ | ||
#pragma once | ||
|
||
#include "IUserScript.hpp" | ||
#include <QObject> | ||
|
||
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_; | ||
}; | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/UnitTests/Application/StreamingServices/FakeUserScript.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,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; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/UnitTests/Application/StreamingServices/FakeUserScript.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,17 @@ | ||
#pragma once | ||
|
||
#include <MellowPlayer/Application/StreamingServices/UserScriptBase.hpp> | ||
#include <QtCore/QString> | ||
|
||
#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; | ||
}; | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/UnitTests/Application/StreamingServices/UserScriptBaseTests.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,56 @@ | ||
#include <catch.hpp> | ||
#include <MellowPlayer/Application/StreamingServices/UserScriptBase.hpp> | ||
#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); | ||
} | ||
} | ||
} | ||
} |