-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,13 @@ | ||
add_subdirectory(gestures) | ||
add_subdirectory(gestures) | ||
|
||
set(testCondition_SRCS | ||
test_condition.cpp | ||
mockwindowdataprovider.cpp | ||
) | ||
qt_add_executable(testCondition ${testCondition_SRCS}) | ||
add_test(NAME "condition" COMMAND testCondition) | ||
target_link_libraries(testCondition PRIVATE | ||
libgestures | ||
Qt::Core | ||
Qt::Test | ||
) |
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,13 @@ | ||
#include "mockwindowdataprovider.h" | ||
|
||
#include <utility> | ||
|
||
MockWindowDataProvider::MockWindowDataProvider(std::optional<const WindowData> data) | ||
: m_data(std::move(data)) | ||
{ | ||
} | ||
|
||
std::optional<const WindowData> MockWindowDataProvider::getDataForActiveWindow() const | ||
{ | ||
return m_data; | ||
} |
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,11 @@ | ||
#include "windowdataprovider.h" | ||
|
||
class MockWindowDataProvider : public WindowDataProvider | ||
{ | ||
public: | ||
MockWindowDataProvider(std::optional<const WindowData> data); | ||
|
||
std::optional<const WindowData> getDataForActiveWindow() const override; | ||
private: | ||
const std::optional<const WindowData> m_data; | ||
}; |
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,163 @@ | ||
#include "condition.h" | ||
#include "test_condition.h" | ||
|
||
TestCondition::TestCondition() | ||
: m_noActiveWindow(std::make_shared<MockWindowDataProvider>(std::nullopt)), | ||
m_normalWindow(std::make_shared<MockWindowDataProvider>(std::make_optional<WindowData>("Firefox", "firefox", "firefox", WindowState::Unimportant))), | ||
m_maximizedWindow(std::make_shared<MockWindowDataProvider>(std::make_optional<WindowData>("Firefox", "firefox", "firefox", WindowState::Maximized))), | ||
m_fullscreenWindow(std::make_shared<MockWindowDataProvider>(std::make_optional<WindowData>("Firefox", "firefox", "firefox", WindowState::Maximized))) | ||
{ | ||
} | ||
|
||
void TestCondition::isSatisfied_noActiveWindow_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_noActiveWindow, false, std::nullopt, std::nullopt); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndNoActiveWindow_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_noActiveWindow, true, std::nullopt, std::nullopt); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_noSubConditions_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, false, std::nullopt, std::nullopt); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndNoSubConditions_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, true, std::nullopt, std::nullopt); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowClassRegexMatchesResourceClass_returnsTrue() | ||
{ | ||
const auto window = std::make_shared<MockWindowDataProvider>(std::make_optional<WindowData>("Firefox", "firefox", "", WindowState::Unimportant)); | ||
const auto condition = std::make_shared<Condition>(window, false, QRegularExpression("firefox"), std::nullopt); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowClassRegexMatchesResourceName_returnsTrue() | ||
{ | ||
const auto window = std::make_shared<MockWindowDataProvider>(std::make_optional<WindowData>("Firefox", "", "firefox", WindowState::Unimportant)); | ||
const auto condition = std::make_shared<Condition>(window, false, QRegularExpression("firefox"), std::nullopt); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowClassRegexDoesntMatch_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, false, QRegularExpression("firefoxx"), std::nullopt); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowClassRegexMatches_returnsFalse() | ||
{ | ||
const auto window = std::make_shared<MockWindowDataProvider>(std::make_optional<WindowData>("Firefox", "firefox", "", WindowState::Unimportant)); | ||
const auto condition = std::make_shared<Condition>(window, true, QRegularExpression("firefox"), std::nullopt); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowClassRegexDoesntMatch_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, true, QRegularExpression("firefoxx"), std::nullopt); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowStateDoesntMatch_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, false, std::nullopt, WindowState::Maximized); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowStateMatches_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, false, std::nullopt, WindowState::Maximized); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowStateMatchesEither_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, false, std::nullopt, WindowState::Fullscreen | WindowState::Maximized); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowStateDoesntMatch_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, true, std::nullopt, WindowState::Maximized); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowStateMatches_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, true, std::nullopt, WindowState::Maximized); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowStateMatchesEither_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, true, std::nullopt, WindowState::Fullscreen | WindowState::Maximized); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowClassMatchesAndStateDoesnt_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, false, QRegularExpression("firefox"), WindowState::Maximized); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowClassDoesntMatchAndStateDoes_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, false, QRegularExpression("firefoxx"), WindowState::Maximized); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_windowClassMatchesAndStateMatches_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, false, QRegularExpression("firefox"), WindowState::Maximized); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowClassMatchesAndStateDoesnt_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_normalWindow, true, QRegularExpression("firefox"), WindowState::Maximized); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowClassDoesntMatchAndStateDoes_returnsTrue() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, true, QRegularExpression("firefoxx"), WindowState::Maximized); | ||
|
||
QVERIFY(condition->isSatisfied()); | ||
} | ||
|
||
void TestCondition::isSatisfied_negatedAndWindowClassMatchesAndStateMatches_returnsFalse() | ||
{ | ||
const auto condition = std::make_shared<Condition>(m_maximizedWindow, true, QRegularExpression("firefox"), WindowState::Maximized); | ||
|
||
QVERIFY(!condition->isSatisfied()); | ||
} | ||
|
||
QTEST_MAIN(TestCondition) | ||
#include "test_condition.moc" |
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,39 @@ | ||
#pragma once | ||
|
||
#include "mockwindowdataprovider.h" | ||
#include <QTest> | ||
|
||
class TestCondition : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
TestCondition(); | ||
private slots: | ||
void isSatisfied_noActiveWindow_returnsFalse(); | ||
void isSatisfied_negatedAndNoActiveWindow_returnsFalse(); | ||
void isSatisfied_noSubConditions_returnsTrue(); | ||
void isSatisfied_negatedAndNoSubConditions_returnsFalse(); | ||
void isSatisfied_windowClassRegexMatchesResourceClass_returnsTrue(); | ||
void isSatisfied_windowClassRegexMatchesResourceName_returnsTrue(); | ||
void isSatisfied_windowClassRegexDoesntMatch_returnsFalse(); | ||
void isSatisfied_negatedAndWindowClassRegexMatches_returnsFalse(); | ||
void isSatisfied_negatedAndWindowClassRegexDoesntMatch_returnsTrue(); | ||
void isSatisfied_windowStateDoesntMatch_returnsFalse(); | ||
void isSatisfied_windowStateMatches_returnsTrue(); | ||
void isSatisfied_windowStateMatchesEither_returnsTrue(); | ||
void isSatisfied_negatedAndWindowStateDoesntMatch_returnsTrue(); | ||
void isSatisfied_negatedAndWindowStateMatches_returnsFalse(); | ||
void isSatisfied_negatedAndWindowStateMatchesEither_returnsFalse(); | ||
void isSatisfied_windowClassMatchesAndStateDoesnt_returnsFalse(); | ||
void isSatisfied_windowClassDoesntMatchAndStateDoes_returnsFalse(); | ||
void isSatisfied_windowClassMatchesAndStateMatches_returnsTrue(); | ||
void isSatisfied_negatedAndWindowClassMatchesAndStateDoesnt_returnsTrue(); | ||
void isSatisfied_negatedAndWindowClassDoesntMatchAndStateDoes_returnsTrue(); | ||
void isSatisfied_negatedAndWindowClassMatchesAndStateMatches_returnsFalse(); | ||
private: | ||
const std::shared_ptr<MockWindowDataProvider> m_noActiveWindow; | ||
const std::shared_ptr<MockWindowDataProvider> m_normalWindow; | ||
const std::shared_ptr<MockWindowDataProvider> m_maximizedWindow; | ||
const std::shared_ptr<MockWindowDataProvider> m_fullscreenWindow; | ||
}; | ||
|