| 1 |
program test_cache_root |
| 2 |
use fgof_cache, only : & |
| 3 |
FGOF_CACHE_ERR_INVALID_OPTIONS, & |
| 4 |
FGOF_CACHE_ERR_NOT_FOUND, & |
| 5 |
FGOF_CACHE_OK, & |
| 6 |
clear_cache_options, & |
| 7 |
ensure_cache_root |
| 8 |
use fgof_cache_types, only : cache_options, cache_root |
| 9 |
implicit none |
| 10 |
|
| 11 |
type(cache_options) :: options |
| 12 |
type(cache_root) :: root |
| 13 |
character(len=:), allocatable :: base_path |
| 14 |
logical :: exists |
| 15 |
|
| 16 |
base_path = unique_root("ready") |
| 17 |
options = clear_cache_options() |
| 18 |
options%root_dir = base_path |
| 19 |
options%namespace = "demo" |
| 20 |
root = ensure_cache_root(options) |
| 21 |
if (.not. root%ready) error stop "ensure_cache_root should create explicit namespaced roots" |
| 22 |
if (root%error_code /= FGOF_CACHE_OK) error stop "successful root creation should report ok" |
| 23 |
if (root%path /= base_path // "/demo") error stop "ensure_cache_root should append namespace to explicit roots" |
| 24 |
inquire(file=root%path, exist=exists) |
| 25 |
if (.not. exists) error stop "ensure_cache_root should create the cache directory on disk" |
| 26 |
|
| 27 |
options = clear_cache_options() |
| 28 |
options%create_root = .false. |
| 29 |
options%root_dir = unique_root("missing") |
| 30 |
root = ensure_cache_root(options) |
| 31 |
if (root%ready) error stop "ensure_cache_root should not report missing roots as ready" |
| 32 |
if (root%error_code /= FGOF_CACHE_ERR_NOT_FOUND) error stop "missing roots should report not-found" |
| 33 |
|
| 34 |
options = clear_cache_options() |
| 35 |
options%root_dir = unique_root("invalid") |
| 36 |
options%namespace = "bad/name" |
| 37 |
root = ensure_cache_root(options) |
| 38 |
if (root%ready) error stop "invalid namespace roots should not be ready" |
| 39 |
if (root%error_code /= FGOF_CACHE_ERR_INVALID_OPTIONS) error stop "invalid namespace should report invalid options" |
| 40 |
|
| 41 |
contains |
| 42 |
|
| 43 |
function unique_root(label) result(path) |
| 44 |
character(len=*), intent(in) :: label |
| 45 |
character(len=:), allocatable :: path |
| 46 |
character(len=32) :: count_text |
| 47 |
integer :: count_value |
| 48 |
|
| 49 |
call system_clock(count=count_value) |
| 50 |
write(count_text, "(i0)") count_value |
| 51 |
path = "build/fgof-cache-root-" // label // "-" // trim(count_text) |
| 52 |
end function unique_root |
| 53 |
|
| 54 |
end program test_cache_root |
| 55 |
|