test/hyprland/backend: fix
This commit is contained in:
		
							parent
							
								
									959422f143
								
							
						
					
					
						commit
						b365831839
					
				| 
						 | 
					@ -4,107 +4,52 @@
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#include <catch2/catch.hpp>
 | 
					#include <catch2/catch.hpp>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
 | 
					 | 
				
			||||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "fixtures/IPCTestFixture.hpp"
 | 
				
			||||||
#include "modules/hyprland/backend.hpp"
 | 
					#include "modules/hyprland/backend.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace fs = std::filesystem;
 | 
					namespace fs = std::filesystem;
 | 
				
			||||||
namespace hyprland = waybar::modules::hyprland;
 | 
					namespace hyprland = waybar::modules::hyprland;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class testRunListener : public Catch::EventListenerBase {
 | 
					TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirExists", "[getSocketFolder]") {
 | 
				
			||||||
 public:
 | 
					  // Test case: XDG_RUNTIME_DIR exists and contains "hypr" directory
 | 
				
			||||||
  using Catch::EventListenerBase::EventListenerBase;
 | 
					  // 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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void testCaseStarting(Catch::TestCaseInfo const&) override {
 | 
					  // Act
 | 
				
			||||||
    // TODO: reset state of module here
 | 
					  fs::path actualPath = getSocketFolder(instanceSig);
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
CATCH_REGISTER_LISTENER(testRunListener)
 | 
					  // Assert expected result
 | 
				
			||||||
 | 
					  REQUIRE(actualPath == expectedPath);
 | 
				
			||||||
TEST_CASE("GetSocketFolderTest", "[getSocketFolder]") {
 | 
					}
 | 
				
			||||||
  SECTION("XDGRuntimeDirExists") {
 | 
					
 | 
				
			||||||
    // Test case: XDG_RUNTIME_DIR exists and contains "hypr" directory
 | 
					TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirDoesNotExist", "[getSocketFolder]") {
 | 
				
			||||||
    // Arrange
 | 
					  // Test case: XDG_RUNTIME_DIR does not exist
 | 
				
			||||||
    std::cout << "Starting XDGRuntimeDirExists " << '\n';
 | 
					  // Arrange
 | 
				
			||||||
    const char* instanceSig = "instance_sig";
 | 
					  unsetenv("XDG_RUNTIME_DIR");
 | 
				
			||||||
 | 
					  fs::path expectedPath = fs::path("/tmp") / "hypr" / instanceSig;
 | 
				
			||||||
    fs::path tempDir = fs::temp_directory_path() / "hypr_test/run/user/1000";
 | 
					
 | 
				
			||||||
    std::cout << "Temp dir: " << tempDir << '\n';
 | 
					  // Act
 | 
				
			||||||
 | 
					  fs::path actualPath = getSocketFolder(instanceSig);
 | 
				
			||||||
    fs::path expectedPath = tempDir / "hypr" / instanceSig;
 | 
					
 | 
				
			||||||
    std::cout << "Expected path: " << expectedPath << '\n';
 | 
					  // Assert expected result
 | 
				
			||||||
 | 
					  REQUIRE(actualPath == expectedPath);
 | 
				
			||||||
    fs::create_directories(tempDir / "hypr" / instanceSig);
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setenv("XDG_RUNTIME_DIR", tempDir.c_str(), 1);
 | 
					TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirExistsNoHyprDir", "[getSocketFolder]") {
 | 
				
			||||||
 | 
					  // Test case: XDG_RUNTIME_DIR exists but does not contain "hypr" directory
 | 
				
			||||||
    // Act/*
 | 
					  // Arrange
 | 
				
			||||||
    std::cout << "Getting socket folder" << '\n';
 | 
					  fs::path tempDir = fs::temp_directory_path() / "hypr_test/run/user/1000";
 | 
				
			||||||
    fs::path actualPath = hyprland::getSocketFolder(instanceSig);
 | 
					  fs::create_directories(tempDir);
 | 
				
			||||||
 | 
					  setenv("XDG_RUNTIME_DIR", tempDir.c_str(), 1);
 | 
				
			||||||
    // Assert expected result
 | 
					  fs::path expectedPath = fs::path("/tmp") / "hypr" / instanceSig;
 | 
				
			||||||
    REQUIRE(actualPath == expectedPath);
 | 
					
 | 
				
			||||||
 | 
					  // Act
 | 
				
			||||||
    // Cleanup
 | 
					  fs::path actualPath = getSocketFolder(instanceSig);
 | 
				
			||||||
    fs::remove_all(tempDir);
 | 
					
 | 
				
			||||||
 | 
					  // Assert expected result
 | 
				
			||||||
    std::cout << "Finishing XDGRuntimeDirExists " << '\n';
 | 
					  REQUIRE(actualPath == expectedPath);
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 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'; */
 | 
					 | 
				
			||||||
  /* } */
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					#include "modules/hyprland/backend.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace fs = std::filesystem;
 | 
				
			||||||
 | 
					namespace hyprland = waybar::modules::hyprland;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class IPCTestFixture : public hyprland::IPC {
 | 
				
			||||||
 | 
					 public:
 | 
				
			||||||
 | 
					  IPCTestFixture() : IPC() { IPC::socketFolder_ = ""; }
 | 
				
			||||||
 | 
					  ~IPCTestFixture() { fs::remove_all(tempDir); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 protected:
 | 
				
			||||||
 | 
					  const char* instanceSig = "instance_sig";
 | 
				
			||||||
 | 
					  fs::path tempDir = fs::temp_directory_path() / "hypr_test";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 private:
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
		Loading…
	
		Reference in New Issue