#include "../lighthouse_driver_wrapper.h" #include "test_utils.h" #include #include #include using namespace SaunaTest; using namespace sauna; // Test fixture for LighthouseDriverWrapper tests class LighthouseDriverWrapperTest { private: std::unique_ptr wrapper; public: LighthouseDriverWrapperTest() { wrapper = std::make_unique(); } ~LighthouseDriverWrapperTest() { wrapper->Shutdown(); } TestResult testInitialize() { // This test attempts to initialize the lighthouse driver wrapper // Note: This test may fail if the lighthouse driver is not installed bool result = wrapper->Initialize(); // We don't assert the result because it depends on the environment // Instead, we log the result and return success if (result) { std::cout << "Lighthouse driver initialized successfully" << std::endl; } else { std::cout << "Lighthouse driver initialization failed - this may be expected if the driver is not installed" << std::endl; } return TestResult(true, "Initialization test completed"); } TestResult testGetDriverProvider() { // Initialize the wrapper bool initResult = wrapper->Initialize(); // Get the driver provider vr::IServerTrackedDeviceProvider* provider = wrapper->GetDriverProvider(); // If initialization succeeded, the provider should not be null if (initResult && !provider) { return TestResult(false, "Driver provider is null after successful initialization"); } // If initialization failed, the provider should be null if (!initResult && provider) { return TestResult(false, "Driver provider is not null after failed initialization"); } return TestResult(true, "GetDriverProvider test passed"); } TestResult testRunFrame() { // Initialize the wrapper bool initResult = wrapper->Initialize(); if (initResult) { // Run a frame try { wrapper->RunFrame(); return TestResult(true, "RunFrame executed without exceptions"); } catch (const std::exception& e) { return TestResult(false, std::string("RunFrame threw an exception: ") + e.what()); } catch (...) { return TestResult(false, "RunFrame threw an unknown exception"); } } else { // Skip the test if initialization failed std::cout << "Skipping RunFrame test because initialization failed" << std::endl; return TestResult(true, "RunFrame test skipped"); } } TestResult testStandbyModes() { // Initialize the wrapper bool initResult = wrapper->Initialize(); if (initResult) { // Test entering and leaving standby try { wrapper->EnterStandby(); wrapper->LeaveStandby(); return TestResult(true, "Standby modes executed without exceptions"); } catch (const std::exception& e) { return TestResult(false, std::string("Standby mode test threw an exception: ") + e.what()); } catch (...) { return TestResult(false, "Standby mode test threw an unknown exception"); } } else { // Skip the test if initialization failed std::cout << "Skipping standby mode test because initialization failed" << std::endl; return TestResult(true, "Standby mode test skipped"); } } TestResult testShutdown() { // Initialize the wrapper bool initResult = wrapper->Initialize(); if (initResult) { // Shutdown the wrapper try { wrapper->Shutdown(); // After shutdown, the driver provider should be null vr::IServerTrackedDeviceProvider* provider = wrapper->GetDriverProvider(); if (provider) { return TestResult(false, "Driver provider is not null after shutdown"); } return TestResult(true, "Shutdown executed without exceptions"); } catch (const std::exception& e) { return TestResult(false, std::string("Shutdown threw an exception: ") + e.what()); } catch (...) { return TestResult(false, "Shutdown threw an unknown exception"); } } else { // Skip the test if initialization failed std::cout << "Skipping shutdown test because initialization failed" << std::endl; return TestResult(true, "Shutdown test skipped"); } } TestResult testReinitializeAfterShutdown() { // Initialize the wrapper bool initResult = wrapper->Initialize(); if (initResult) { // Shutdown the wrapper wrapper->Shutdown(); // Try to initialize again bool reinitResult = wrapper->Initialize(); if (!reinitResult) { return TestResult(false, "Failed to reinitialize after shutdown"); } return TestResult(true, "Reinitialization after shutdown succeeded"); } else { // Skip the test if initialization failed std::cout << "Skipping reinitialization test because initialization failed" << std::endl; return TestResult(true, "Reinitialization test skipped"); } } void runAllTests() { TestSuite suite("LighthouseDriverWrapper Tests"); suite.addTest("Initialize", [this]() { return testInitialize(); }); suite.addTest("GetDriverProvider", [this]() { return testGetDriverProvider(); }); suite.addTest("RunFrame", [this]() { return testRunFrame(); }); suite.addTest("StandbyModes", [this]() { return testStandbyModes(); }); suite.addTest("Shutdown", [this]() { return testShutdown(); }); suite.addTest("ReinitializeAfterShutdown", [this]() { return testReinitializeAfterShutdown(); }); suite.runAll(); } }; // Main function for this test file int lighthouse_driver_wrapper_test_main(int argc, char** argv) { std::cout << "Running LighthouseDriverWrapper tests..." << std::endl; LighthouseDriverWrapperTest test; test.runAllTests(); return 0; } // Entry point when running this test directly int main(int argc, char** argv) { return lighthouse_driver_wrapper_test_main(argc, argv); }