mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-16 06:36:32 -05:00
Add tests for process condition
Some checks are pending
debian-build / build (push) Waiting to run
Check locale / ubuntu64 (push) Waiting to run
Push to master / Check Formatting 🔍 (push) Waiting to run
Push to master / Build Project 🧱 (push) Waiting to run
Push to master / Create Release 🛫 (push) Blocked by required conditions
Some checks are pending
debian-build / build (push) Waiting to run
Check locale / ubuntu64 (push) Waiting to run
Push to master / Check Formatting 🔍 (push) Waiting to run
Push to master / Build Project 🧱 (push) Waiting to run
Push to master / Create Release 🛫 (push) Blocked by required conditions
This commit is contained in:
parent
1483f9d9dc
commit
94d49db196
|
|
@ -187,6 +187,13 @@ target_sources(
|
|||
${ADVSS_SOURCE_DIR}/lib/utils/file-selection.cpp
|
||||
${ADVSS_SOURCE_DIR}/lib/variables/variable-text-edit.cpp)
|
||||
|
||||
# --- macro-condition-process --- #
|
||||
|
||||
target_sources(
|
||||
${PROJECT_NAME}
|
||||
PRIVATE test-macro-condition-process.cpp stubs/platform-funcs.cpp
|
||||
${ADVSS_SOURCE_DIR}/plugins/base/macro-condition-process.cpp)
|
||||
|
||||
# --- Testing --- #
|
||||
|
||||
enable_testing()
|
||||
|
|
|
|||
101
tests/stubs/platform-funcs.cpp
Normal file
101
tests/stubs/platform-funcs.cpp
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
#include "platform-funcs.hpp"
|
||||
#include "selection-helpers.hpp"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace advss {
|
||||
|
||||
namespace {
|
||||
|
||||
std::string g_foregroundProcessName;
|
||||
std::string g_foregroundProcessPath;
|
||||
QStringList g_processList;
|
||||
QStringList g_processPathsFromName;
|
||||
|
||||
} // namespace
|
||||
|
||||
void SetStubForegroundProcessName(const std::string &name)
|
||||
{
|
||||
g_foregroundProcessName = name;
|
||||
}
|
||||
|
||||
void SetStubForegroundProcessPath(const std::string &path)
|
||||
{
|
||||
g_foregroundProcessPath = path;
|
||||
}
|
||||
|
||||
void SetStubProcessList(const QStringList &list)
|
||||
{
|
||||
g_processList = list;
|
||||
}
|
||||
|
||||
void SetStubProcessPaths(const QStringList &paths)
|
||||
{
|
||||
g_processPathsFromName = paths;
|
||||
}
|
||||
|
||||
// --- platform-funcs.hpp stubs ---
|
||||
|
||||
std::vector<std::string> GetWindowList()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string GetCurrentWindowTitle()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
bool IsFullscreen(const std::string &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsMaximized(const std::string &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<std::string> GetTextInWindow(const std::string &)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
int SecondsSinceLastInput()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QStringList GetProcessList()
|
||||
{
|
||||
return g_processList;
|
||||
}
|
||||
|
||||
std::string GetForegroundProcessName()
|
||||
{
|
||||
return g_foregroundProcessName;
|
||||
}
|
||||
|
||||
std::string GetForegroundProcessPath()
|
||||
{
|
||||
return g_foregroundProcessPath;
|
||||
}
|
||||
|
||||
QStringList GetProcessPathsFromName(const QString &)
|
||||
{
|
||||
return g_processPathsFromName;
|
||||
}
|
||||
|
||||
bool IsInFocus(const QString &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- selection-helpers.hpp stubs ---
|
||||
|
||||
void PopulateProcessSelection(QComboBox *, bool) {}
|
||||
|
||||
} // namespace advss
|
||||
170
tests/test-macro-condition-process.cpp
Normal file
170
tests/test-macro-condition-process.cpp
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
#include "catch.hpp"
|
||||
#include "macro-condition-process.hpp"
|
||||
|
||||
namespace advss {
|
||||
void SetStubForegroundProcessName(const std::string &);
|
||||
void SetStubForegroundProcessPath(const std::string &);
|
||||
void SetStubProcessList(const QStringList &);
|
||||
void SetStubProcessPaths(const QStringList &);
|
||||
} // namespace advss
|
||||
|
||||
using advss::MacroConditionProcess;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Name matching — no focus, no path
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("no focus: exact name match returns true",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubProcessList({"game.exe", "obs64.exe"});
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = false;
|
||||
|
||||
REQUIRE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
TEST_CASE("no focus: exact name mismatch returns false",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubProcessList({"obs64.exe"});
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = false;
|
||||
|
||||
REQUIRE_FALSE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
TEST_CASE("no focus: regex name match returns true",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubProcessList({"game.exe", "obs64.exe"});
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.*";
|
||||
cond._checkFocus = false;
|
||||
cond._regex.SetEnabled(true);
|
||||
|
||||
REQUIRE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
TEST_CASE("no focus: regex name mismatch returns false",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubProcessList({"obs64.exe"});
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.*";
|
||||
cond._checkFocus = false;
|
||||
cond._regex.SetEnabled(true);
|
||||
|
||||
REQUIRE_FALSE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Focus — name only
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("focus: foreground name matches returns true",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubForegroundProcessName("game.exe");
|
||||
advss::SetStubForegroundProcessPath("C:/Games/Game/game.exe");
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = true;
|
||||
|
||||
REQUIRE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
TEST_CASE("focus: foreground name does not match returns false",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubForegroundProcessName("obs64.exe");
|
||||
advss::SetStubForegroundProcessPath("C:/OBS/obs64.exe");
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = true;
|
||||
|
||||
REQUIRE_FALSE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Path matching — no focus
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("no focus with path: name and path both match returns true",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubProcessList({"game.exe"});
|
||||
advss::SetStubProcessPaths({"C:/Steam/steamapps/common/Game/game.exe"});
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = false;
|
||||
cond._checkPath = true;
|
||||
cond._processPath = "C:/Steam/steamapps/common/Game/game.exe";
|
||||
|
||||
REQUIRE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
TEST_CASE("no focus with path: name matches but path does not returns false",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubProcessList({"game.exe"});
|
||||
advss::SetStubProcessPaths({"C:/Epic/Games/Game/game.exe"});
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = false;
|
||||
cond._checkPath = true;
|
||||
cond._processPath = "Steam";
|
||||
|
||||
REQUIRE_FALSE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Focus + path
|
||||
//
|
||||
// When both focus and path are checked, both must be satisfied by the *same*
|
||||
// foreground process instance. A background process that matches the path
|
||||
// but is not in focus must not cause a false positive.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("focus with path: foreground matches both name and path returns true",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubForegroundProcessName("game.exe");
|
||||
advss::SetStubForegroundProcessPath(
|
||||
"C:/Steam/steamapps/common/Game/game.exe");
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = true;
|
||||
cond._checkPath = true;
|
||||
cond._processPath = "C:/Steam/steamapps/common/Game/game.exe";
|
||||
|
||||
REQUIRE(cond.CheckCondition());
|
||||
}
|
||||
|
||||
TEST_CASE(
|
||||
"focus with path: foreground name matches but path does not returns false",
|
||||
"[macro-condition-process]")
|
||||
{
|
||||
advss::SetStubForegroundProcessName("game.exe");
|
||||
advss::SetStubForegroundProcessPath("C:/Epic/Games/Game/game.exe");
|
||||
advss::SetStubProcessPaths({"C:/Steam/steamapps/common/Game/game.exe"});
|
||||
|
||||
MacroConditionProcess cond(nullptr);
|
||||
cond._process = "game.exe";
|
||||
cond._checkFocus = true;
|
||||
cond._checkPath = true;
|
||||
cond._processPath = "C:/Steam/steamapps/common/Game/game.exe";
|
||||
|
||||
REQUIRE_FALSE(cond.CheckCondition());
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user