MCPcopy Create free account
hub / github.com/crownengine/crown / test_file_monitor

Function test_file_monitor

src/core/unit_tests.cpp:1920–2145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1918}
1919
1920static void test_file_monitor()
1921{
1922#if !CROWN_PLATFORM_EMSCRIPTEN
1923 struct UserData
1924 {
1925 typedef void (*CheckFunction)(void *user_data, FileMonitorEvent::Enum fme, bool is_dir, const char *path, const char *path_modified);
1926
1927 bool done;
1928 Mutex m;
1929 ConditionVariable cv;
1930 CheckFunction check;
1931
1932 UserData()
1933 : done(false)
1934 {
1935 }
1936
1937 void wait(u32 ms)
1938 {
1939 WaitResult wr;
1940 wr.error = WaitResult::SUCCESS;
1941
1942 m.lock();
1943 while (!done && wr.error != WaitResult::TIMEOUT)
1944 wr = cv.wait(m, ms);
1945 m.unlock();
1946 ENSURE(done);
1947 }
1948
1949 static void callback(const char *begin, const char *end, void *user_data)
1950 {
1951 UserData *ud = (UserData *)user_data;
1952 ud->done = false;
1953
1954 for (const char *cur = begin; cur != end;) {
1955 const char *path = NULL;
1956 const char *path_modified = NULL;
1957
1958 u32 type = *(u32 *)cur;
1959 cur += 4;
1960 CE_UNUSED(*(u32 *)cur);
1961 cur += 4;
1962 bool is_dir = *(bool *)cur;
1963 cur += 1;
1964 path = (const char *)cur;
1965 cur += strlen32(path) + 1;
1966 if (type == FileMonitorEvent::RENAMED) {
1967 path_modified = (const char *)cur;
1968 cur += strlen32(path_modified) + 1;
1969 }
1970
1971 ud->check(user_data, (FileMonitorEvent::Enum)type, is_dir, path, path_modified);
1972 }
1973
1974 ud->done = true;
1975 ud->cv.signal();
1976 }
1977 };

Callers

nothing calls this directly

Calls 15

strcmpFunction · 0.85
renameFunction · 0.85
set_prefixMethod · 0.80
initFunction · 0.70
shutdownFunction · 0.70
joinFunction · 0.50
create_directoryMethod · 0.45
startMethod · 0.45
c_strMethod · 0.45
waitMethod · 0.45
stopMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected