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

Commit

Permalink
#69 Add IUserScript and UserScriptBase
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDuquesnoy committed Sep 20, 2017
1 parent 3c11585 commit 27b87d1
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/MellowPlayer/Application/StreamingServices/IUserScript.hpp
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 lib/MellowPlayer/Application/StreamingServices/UserScriptBase.cpp
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 lib/MellowPlayer/Application/StreamingServices/UserScriptBase.hpp
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 tests/UnitTests/Application/StreamingServices/FakeUserScript.cpp
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 tests/UnitTests/Application/StreamingServices/FakeUserScript.hpp
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;
};
}
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);
}
}
}
}

0 comments on commit 27b87d1

Please sign in to comment.