Waybar/test/hyprland/backend.cpp

56 lines
1.7 KiB
C++
Raw Normal View History

2024-05-29 02:52:54 +00:00
#include <cstdlib>
#if __has_include(<catch2/catch_test_macros.hpp>)
#include <catch2/catch_test_macros.hpp>
#else
#include <catch2/catch.hpp>
#endif
2024-06-09 15:18:42 +00:00
#include "fixtures/IPCTestFixture.hpp"
2024-05-29 02:52:54 +00:00
#include "modules/hyprland/backend.hpp"
namespace fs = std::filesystem;
namespace hyprland = waybar::modules::hyprland;
2024-06-09 15:18:42 +00:00
TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirExists", "[getSocketFolder]") {
// Test case: XDG_RUNTIME_DIR exists and contains "hypr" directory
// Arrange
tempDir = fs::temp_directory_path() / "hypr_test/run/user/1000";
fs::path expectedPath = tempDir / "hypr" / instanceSig;
fs::create_directories(tempDir / "hypr" / instanceSig);
setenv("XDG_RUNTIME_DIR", tempDir.c_str(), 1);
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
// Act
fs::path actualPath = getSocketFolder(instanceSig);
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
// Assert expected result
REQUIRE(actualPath == expectedPath);
}
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirDoesNotExist", "[getSocketFolder]") {
// Test case: XDG_RUNTIME_DIR does not exist
// Arrange
unsetenv("XDG_RUNTIME_DIR");
fs::path expectedPath = fs::path("/tmp") / "hypr" / instanceSig;
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
// Act
fs::path actualPath = getSocketFolder(instanceSig);
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
// Assert expected result
REQUIRE(actualPath == expectedPath);
}
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirExistsNoHyprDir", "[getSocketFolder]") {
// Test case: XDG_RUNTIME_DIR exists but does not contain "hypr" directory
// Arrange
fs::path tempDir = fs::temp_directory_path() / "hypr_test/run/user/1000";
fs::create_directories(tempDir);
setenv("XDG_RUNTIME_DIR", tempDir.c_str(), 1);
fs::path expectedPath = fs::path("/tmp") / "hypr" / instanceSig;
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
// Act
fs::path actualPath = getSocketFolder(instanceSig);
2024-05-29 02:52:54 +00:00
2024-06-09 15:18:42 +00:00
// Assert expected result
REQUIRE(actualPath == expectedPath);
2024-05-29 02:52:54 +00:00
}