| 1918 | } |
| 1919 | |
| 1920 | static 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 | }; |
nothing calls this directly
no test coverage detected