MCPcopy Create free account
hub / github.com/MemNixFS/MemNixFS / main

Function main

tests/unit/app_paths_test.cpp:36–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36int main() {
37 // Linux, HOME only: data dir first, then the legacy cache dir.
38 {
39 auto env = make_env({{"HOME", "/home/u"}});
40 auto d = user_dirs_impl(/*windows=*/false, env, "yara");
41 CHECK(d.size() == 2, "linux/yara: two search dirs (data + cache)");
42 CHECK(!d.empty() && d[0] == fs::path("/home/u/.local/share/memnixfs/yara"),
43 "linux/yara: XDG data dir first");
44 CHECK(has(d, fs::path("/home/u/.cache/lmpfs/yara")),
45 "linux/yara: legacy ~/.cache/lmpfs/yara IS searched (issue #3 reporter's path)");
46 }
47 // Linux, XDG overrides win and suppress the ~/ fallbacks.
48 {
49 auto env = make_env({{"HOME", "/home/u"},
50 {"XDG_DATA_HOME", "/xdg/data"},
51 {"XDG_CACHE_HOME", "/xdg/cache"}});
52 auto d = user_dirs_impl(false, env, "symbols");
53 CHECK(has(d, fs::path("/xdg/data/memnixfs/symbols")), "linux/symbols: XDG_DATA_HOME honored");
54 CHECK(has(d, fs::path("/xdg/cache/lmpfs/symbols")), "linux/symbols: XDG_CACHE_HOME honored");
55 CHECK(!has(d, fs::path("/home/u/.local/share/memnixfs/symbols")),
56 "linux/symbols: XDG_DATA_HOME suppresses ~/.local/share fallback");
57 }
58 // Windows, LOCALAPPDATA.
59 {
60 auto env = make_env({{"LOCALAPPDATA", "C:\\Users\\u\\AppData\\Local"}});
61 auto d = user_dirs_impl(/*windows=*/true, env, "plugins");
62 CHECK(!d.empty() &&
63 d[0] == fs::path("C:\\Users\\u\\AppData\\Local") / "MemNixFS" / "plugins",
64 "windows/plugins: %LOCALAPPDATA%\\MemNixFS\\plugins");
65 }
66 // No home dir at all → empty, no crash.
67 {
68 auto env = make_env({});
69 CHECK(user_dirs_impl(false, env, "yara").empty(), "linux/no-HOME: empty search list");
70 CHECK(user_write_dir_impl(false, false, env, "yara").empty(), "linux/no-HOME: empty write dir");
71 }
72 // Write dirs: symbols → cache root; yara → data root.
73 {
74 auto env = make_env({{"HOME", "/home/u"}});
75 CHECK(user_write_dir_impl(false, /*cache=*/true, env, "symbols")
76 == fs::path("/home/u/.cache/lmpfs/symbols"),
77 "linux write: symbols (cache) -> ~/.cache/lmpfs/symbols");
78 CHECK(user_write_dir_impl(false, /*cache=*/false, env, "yara")
79 == fs::path("/home/u/.local/share/memnixfs/yara"),
80 "linux write: yara (data) -> ~/.local/share/memnixfs/yara");
81 }
82 {
83 auto env = make_env({{"LOCALAPPDATA", "C:\\LA"}});
84 CHECK(user_write_dir_impl(true, true, env, "symbols")
85 == fs::path("C:\\LA") / "MemNixFS" / "symbols",
86 "windows write: symbols -> %LOCALAPPDATA%\\MemNixFS\\symbols");
87 }
88 // Hints name the right convention per platform.
89 {
90 CHECK(user_dir_hint_impl(false, "yara").find(".cache/lmpfs/yara") != std::string::npos,
91 "linux hint mentions the cache dir");
92 CHECK(user_dir_hint_impl(true, "yara").find("LOCALAPPDATA") != std::string::npos,
93 "windows hint mentions LOCALAPPDATA");

Callers

nothing calls this directly

Calls 7

make_envFunction · 0.85
user_dirs_implFunction · 0.85
hasFunction · 0.85
user_write_dir_implFunction · 0.85
user_dir_hint_implFunction · 0.85
sizeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected