test/hyprland/backend: init

This commit is contained in:
Austin Horstman 2024-05-28 21:52:54 -05:00
parent 749f46f86f
commit 87eaa75b8a
No known key found for this signature in database
3 changed files with 148 additions and 0 deletions

110
test/hyprland/backend.cpp Normal file
View File

@ -0,0 +1,110 @@
#include <cstdlib>
#if __has_include(<catch2/catch_test_macros.hpp>)
#include <catch2/catch_test_macros.hpp>
#else
#include <catch2/catch.hpp>
#endif
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_registrars.hpp>
#include "modules/hyprland/backend.hpp"
namespace fs = std::filesystem;
namespace hyprland = waybar::modules::hyprland;
class testRunListener : public Catch::EventListenerBase {
public:
using Catch::EventListenerBase::EventListenerBase;
void testCaseStarting(Catch::TestCaseInfo const&) override {
// TODO: reset state of module here
}
};
CATCH_REGISTER_LISTENER(testRunListener)
TEST_CASE("GetSocketFolderTest", "[getSocketFolder]") {
SECTION("XDGRuntimeDirExists") {
// Test case: XDG_RUNTIME_DIR exists and contains "hypr" directory
// Arrange
std::cout << "Starting XDGRuntimeDirExists " << '\n';
const char* instanceSig = "instance_sig";
fs::path tempDir = fs::temp_directory_path() / "hypr_test/run/user/1000";
std::cout << "Temp dir: " << tempDir << '\n';
fs::path expectedPath = tempDir / "hypr" / instanceSig;
std::cout << "Expected path: " << expectedPath << '\n';
fs::create_directories(tempDir / "hypr" / instanceSig);
setenv("XDG_RUNTIME_DIR", tempDir.c_str(), 1);
// Act/*
std::cout << "Getting socket folder" << '\n';
fs::path actualPath = hyprland::getSocketFolder(instanceSig);
// Assert expected result
REQUIRE(actualPath == expectedPath);
// Cleanup
fs::remove_all(tempDir);
std::cout << "Finishing XDGRuntimeDirExists " << '\n';
}
// TODO: properly clear state so we can actually test these....
/* SECTION("XDGRuntimeDirDoesNotExist") { */
/* // Test case: XDG_RUNTIME_DIR does not exist */
/* // Arrange */
/* std::cout << "Starting XDGRuntimeDirDoesNotExist " << '\n'; */
/* const char* instanceSig = "instance_sig"; */
/**/
/* std::cout << "Current XDG_RUNTIME_DIR: " << getenv("XDG_RUNTIME_DIR") << '\n'; */
/**/
/* unsetenv("XDG_RUNTIME_DIR"); */
/**/
/* std::cout << "New XDG_RUNTIME_DIR: " << getenv("XDG_RUNTIME_DIR") << '\n'; */
/**/
/* // Act */
/* fs::path actualPath = hyprland::getSocketFolder(instanceSig); */
/**/
/* // Assert expected result */
/* fs::path expectedPath = fs::path("/tmp") / "hypr" / instanceSig; */
/* REQUIRE(actualPath == expectedPath); */
/**/
/* // Cleanup */
/* std::cout << "Finishing XDGRuntimeDirDoesNotExist " << '\n'; */
/* } */
/**/
/* SECTION("XDGRuntimeDirExistsNoHyprDir") { */
/* // Test case: XDG_RUNTIME_DIR exists but does not contain "hypr" directory */
/* // Arrange */
/* std::cout << "Starting XDGRuntimeDirExistsNoHyprDir " << '\n'; */
/**/
/* const char* instanceSig = "instance_sig"; */
/**/
/* fs::path tempDir = fs::temp_directory_path() / "hypr_test/run/user/1000"; */
/* std::cout << "Temp dir: " << tempDir << '\n'; */
/**/
/* fs::create_directories(tempDir); */
/**/
/* setenv("XDG_RUNTIME_DIR", tempDir.c_str(), 1); */
/**/
/* std::cout << "Current XDG_RUNTIME_DIR: " << getenv("XDG_RUNTIME_DIR") << '\n'; */
/**/
/* // Act */
/* fs::path actualPath = hyprland::getSocketFolder(instanceSig); */
/**/
/* // Assert expected result */
/* fs::path expectedPath = fs::path("/tmp") / "hypr" / instanceSig; */
/* std::cout << "Expected path: " << expectedPath << '\n'; */
/**/
/* REQUIRE(actualPath == expectedPath); */
/**/
/* // Cleanup */
/* fs::remove_all(tempDir); */
/**/
/* std::cout << "Finishing XDGRuntimeDirExistsNoHyprDir " << '\n'; */
/* } */
}

34
test/hyprland/meson.build Normal file
View File

@ -0,0 +1,34 @@
test_inc = include_directories('../../include')
test_dep = [
catch2,
fmt,
gtkmm,
jsoncpp,
spdlog,
]
test_src = files(
'../main.cpp',
'../JsonParser.cpp',
'../SafeSignal.cpp',
'../config.cpp',
'../css_reload_helper.cpp',
'../../src/config.cpp',
'../../src/util/css_reload_helper.cpp',
'backend.cpp',
'../../src/modules/hyprland/backend.cpp'
)
hyprland_test = executable(
'hyprland_test',
test_src,
dependencies: test_dep,
include_directories: test_inc,
)
test(
'hyprland',
hyprland_test,
workdir: meson.project_source_root(),
)

View File

@ -1,4 +1,5 @@
test_inc = include_directories('../include')
test_dep = [
catch2,
fmt,
@ -6,6 +7,7 @@ test_dep = [
jsoncpp,
spdlog,
]
test_src = files(
'main.cpp',
'JsonParser.cpp',
@ -33,3 +35,5 @@ test(
waybar_test,
workdir: meson.project_source_root(),
)
subdir('hyprland')