Run macOS applications on your Windows desktop, with a background runtime and integrated app windows.
C++
#include "wsm/runtime_storage.hpp"
#include <windows.h>
#include <filesystem>
#include <fstream>
#include <iostream>
int main() {
namespace fs = std::filesystem;
const auto parent = fs::current_path();
const auto base = parent / ("wsm-storage-test-" + std::to_string(GetCurrentProcessId()));
const auto root = base / "app", target = base / "data with spaces";
fs::create_directories(root);
std::string error;
if (!wsm::runtime::select_runtime_storage(root, target, error)) {
std::cerr << error << '\n'; return 1;
}
const auto vms = root / "runtime/reims-ctl/vms";
std::ofstream(vms / "disk-test.txt") << "preserve";
std::ofstream(root / "runtime/reims-ctl/installers/download-test.txt") << "download";
std::ofstream(root / "cache/tmp/temporary-test.txt") << "temporary";
if (!fs::exists(target / "vms/disk-test.txt") || !fs::exists(target / "installers/download-test.txt") ||
!fs::exists(target / "tmp/temporary-test.txt") || wsm::runtime::runtime_storage_path(root) != target) return 2;
if (wsm::runtime::select_runtime_storage(root, base / "other", error)) return 3;
if (!fs::exists(target / "vms/disk-test.txt")) return 4;
const auto other_root = base / "existing-app";
fs::create_directories(other_root / "runtime/reims-ctl/vms");
std::ofstream(other_root / "runtime/reims-ctl/vms/existing.qcow2") << "untouched";
if (wsm::runtime::select_runtime_storage(other_root, base / "refused", error)) return 5;
if (!fs::exists(other_root / "runtime/reims-ctl/vms/existing.qcow2")) return 6;
if (wsm::runtime::select_runtime_storage(base / "unsafe", base / "unsafe/cache/tmp/child", error)) return 7;
// Exercise a genuinely different volume, rather than only two folders on the same drive.
for (auto drive : {"D:\\", "E:\\"}) {
std::error_code ec;
if (!fs::exists(drive, ec) || fs::space(drive, ec).available < 59700000000ull || ec || fs::path(drive).root_name() == parent.root_name()) continue;
const auto external = fs::path(drive) / ("WSM-Storage-Test-" + std::to_string(GetCurrentProcessId()));
if (fs::exists(external)) return 10;
const auto cross_root = base / "cross-volume";
if (!wsm::runtime::select_runtime_storage(cross_root, external, error)) { std::cerr << error; return 11; }
std::ofstream(cross_root / "runtime/reims-ctl/vms/cross-volume.txt") << "cross-volume";
if (!fs::exists(external / "vms/cross-volume.txt")) return 12;
for (auto suffix : {"runtime/reims-ctl/vms", "runtime/reims-ctl/installers", "cache/tmp"})
if (!RemoveDirectoryW((cross_root / suffix).c_str())) return 13;
if (external.parent_path() != fs::path(drive) || external.filename().string().rfind("WSM-Storage-Test-", 0) != 0) return 14;
fs::remove_all(external);
break;
}
// Delete the test junctions themselves before recursively cleaning this verified unique test directory.
for (auto suffix : {"runtime/reims-ctl/vms", "runtime/reims-ctl/installers", "cache/tmp"})
if (!RemoveDirectoryW((root / suffix).c_str())) return 8;
if (base.parent_path() != parent || base.filename().string().rfind("wsm-storage-test-", 0) != 0) return 9;
fs::remove_all(base);
std::cout << "PASS: VM, installer and temporary files redirected; existing runtime and unsafe targets protected\n";
}