|
| 1 | +!***************************************************************************************** |
| 2 | +!> author: Jacob Williams |
| 3 | +! date: 10/28/2015 |
| 4 | +! |
| 5 | +! Module for the 15th unit test. |
| 6 | +! This one is testing a lot of the error conditions. |
| 7 | + |
| 8 | +module jf_test_15_mod |
| 9 | + |
| 10 | + use json_module, CK => json_CK |
| 11 | + use, intrinsic :: iso_fortran_env , only: error_unit,output_unit,wp=>real64 |
| 12 | + |
| 13 | + implicit none |
| 14 | + |
| 15 | +contains |
| 16 | + |
| 17 | + subroutine test_15(error_cnt) |
| 18 | + |
| 19 | + !! Test some of the edge cases, and incorrect usages. |
| 20 | + |
| 21 | + implicit none |
| 22 | + |
| 23 | + integer,intent(out) :: error_cnt !! report number of errors to caller |
| 24 | + |
| 25 | + type(json_core) :: json |
| 26 | + type(json_value),pointer :: p,p2 |
| 27 | + type(json_file) :: file1, file2 |
| 28 | + logical :: found,status_ok |
| 29 | + integer :: var_type,i,n_children |
| 30 | + real(wp) :: d |
| 31 | + logical :: tf |
| 32 | + character(kind=CK,len=:),allocatable :: error_msg |
| 33 | + |
| 34 | + write(error_unit,'(A)') '' |
| 35 | + write(error_unit,'(A)') '=================================' |
| 36 | + write(error_unit,'(A)') ' TEST 15' |
| 37 | + write(error_unit,'(A)') '=================================' |
| 38 | + write(error_unit,'(A)') '' |
| 39 | + |
| 40 | + error_cnt = 0 |
| 41 | + |
| 42 | + nullify(p2) |
| 43 | + nullify(p) |
| 44 | + |
| 45 | + call json%parse(p2, '{"int": 1, "real": 2.0, "logical": true}') |
| 46 | + call json%get(p2,'real', i) |
| 47 | + call json%get(p2,'logical',i) |
| 48 | + call json%get(p2,'integer',d) |
| 49 | + call json%get(p2,'logical',d) |
| 50 | + call json%get(p2,'integer',tf) |
| 51 | + call json%get(p2,'real', tf) |
| 52 | + call json%check_for_errors(status_ok, error_msg) !error condition true |
| 53 | + call json%initialize(print_signs=.true.) !print signs flag |
| 54 | + |
| 55 | + call json%check_for_errors(status_ok, error_msg) !error condition false |
| 56 | + |
| 57 | + call file1%move(file2) !should throw an exception since points are not associated |
| 58 | + call file1%initialize() |
| 59 | + |
| 60 | + call file1%print_file(-1) !invalid input |
| 61 | + call file1%initialize() |
| 62 | + |
| 63 | + call file1%print_file(filename='') !invalid filename |
| 64 | + call file1%initialize() |
| 65 | + |
| 66 | + call file1%info('this path does not exist',found,var_type,n_children) |
| 67 | + call file1%initialize() |
| 68 | + |
| 69 | + call json%get_child(p2,-99,p) !invalid index |
| 70 | + call json%initialize() !clear exceptions |
| 71 | + |
| 72 | + call json%get_child(p2,'this child does not exist',p) !invalid index |
| 73 | + call json%initialize() !clear exceptions |
| 74 | + |
| 75 | + call json%print(p2,-1) !invalid input |
| 76 | + call json%initialize() !clear exceptions |
| 77 | + |
| 78 | + call json%print(p2,filename='') !invalid input |
| 79 | + call json%initialize() !clear exceptions |
| 80 | + |
| 81 | + end subroutine test_15 |
| 82 | + |
| 83 | +end module jf_test_15_mod |
| 84 | +!***************************************************************************************** |
| 85 | + |
| 86 | +!***************************************************************************************** |
| 87 | +program jf_test_15 |
| 88 | + |
| 89 | + !! 15th unit test. |
| 90 | + |
| 91 | + use jf_test_15_mod, only: test_15 |
| 92 | + implicit none |
| 93 | + integer :: n_errors |
| 94 | + call test_15(n_errors) |
| 95 | + if ( n_errors /= 0) stop 1 |
| 96 | + |
| 97 | +end program jf_test_15 |
| 98 | +!***************************************************************************************** |
0 commit comments