|
| 1 | +!***************************************************************************************** |
| 2 | +!> |
| 3 | +! Module for the 34th unit test. |
| 4 | + |
| 5 | +module jf_test_34_mod |
| 6 | + |
| 7 | + use json_module, rk => json_rk, lk => json_lk, ik => json_ik, ck => json_ck, cdk => json_cdk |
| 8 | + use, intrinsic :: iso_fortran_env , only: error_unit, output_unit |
| 9 | + |
| 10 | + implicit none |
| 11 | + |
| 12 | + private |
| 13 | + public :: test_34 |
| 14 | + |
| 15 | +contains |
| 16 | + |
| 17 | + subroutine test_34(error_cnt) |
| 18 | + |
| 19 | + !! Test some of more obscure routines and exception cases. |
| 20 | + |
| 21 | + implicit none |
| 22 | + |
| 23 | + integer,intent(out) :: error_cnt |
| 24 | + |
| 25 | + type(json_core) :: json |
| 26 | + type(json_value),pointer :: p,e |
| 27 | + integer(IK) :: max_str_len |
| 28 | + logical(LK) :: found |
| 29 | + logical(LK) :: strict_type_checking |
| 30 | + integer :: i !! counter |
| 31 | + integer(IK),dimension(:),allocatable :: ilen |
| 32 | + character(kind=CK,len=:),allocatable :: str |
| 33 | + logical(LK) :: is_matrix |
| 34 | + integer(IK) :: var_type |
| 35 | + integer(IK) :: n_sets |
| 36 | + integer(IK) :: set_size |
| 37 | + character(kind=CK,len=:),allocatable :: name |
| 38 | + |
| 39 | + error_cnt = 0 |
| 40 | + |
| 41 | + write(error_unit,'(A)') '' |
| 42 | + write(error_unit,'(A)') '=================================' |
| 43 | + write(error_unit,'(A)') ' TEST 34' |
| 44 | + write(error_unit,'(A)') '=================================' |
| 45 | + write(error_unit,'(A)') '' |
| 46 | + |
| 47 | + ! test initialize_json_core: |
| 48 | + json = json_core( escape_solidus = .true.,& |
| 49 | + stop_on_error = .true.) |
| 50 | + call json%initialize(path_mode=1_IK) |
| 51 | + call json%initialize(stop_on_error = .false.) |
| 52 | + |
| 53 | + ! invalid path mode: |
| 54 | + call json%initialize(path_mode=-999_IK) |
| 55 | + call json%clear_exceptions() |
| 56 | + |
| 57 | + ! string_info: |
| 58 | + do i = 1, 2 |
| 59 | + |
| 60 | + strict_type_checking = i==1 |
| 61 | + |
| 62 | + call json%initialize(strict_type_checking=strict_type_checking) |
| 63 | + |
| 64 | + ! with found: |
| 65 | + call json%create_string(p,'string','abc') |
| 66 | + call json%string_info(p,max_str_len=max_str_len,ilen=ilen,found=found) |
| 67 | + call json%destroy(p) |
| 68 | + |
| 69 | + call json%create_array(p,'integer_array') |
| 70 | + call json%create_integer(e,1,CK_'') |
| 71 | + call json%add(p,e) |
| 72 | + call json%string_info(p,max_str_len=max_str_len,ilen=ilen,found=found) |
| 73 | + call json%destroy(p) |
| 74 | + |
| 75 | + ! without found: |
| 76 | + call json%create_string(p,'string','abc') |
| 77 | + call json%string_info(p,max_str_len=max_str_len,ilen=ilen) |
| 78 | + call json%clear_exceptions() |
| 79 | + call json%destroy(p) |
| 80 | + |
| 81 | + call json%create_array(p,'integer_array') |
| 82 | + call json%create_integer(e,1,CK_'') |
| 83 | + call json%add(p,e) |
| 84 | + call json%string_info(p,max_str_len=max_str_len,ilen=ilen) |
| 85 | + call json%clear_exceptions() |
| 86 | + call json%destroy(p) |
| 87 | + |
| 88 | + end do |
| 89 | + |
| 90 | + ! json_matrix_info: |
| 91 | + do i = 1, 3 |
| 92 | + |
| 93 | + select case (i) |
| 94 | + case(1) |
| 95 | + ! valid matrix: |
| 96 | + str = CK_'{"matrix":[[1,2,3,4],[5,6,7,8],[9,10,11,12]]}' |
| 97 | + case(2) |
| 98 | + ! not valid (wrong number of elements) |
| 99 | + str = CK_'{"matrix":[[1,2,3],[5,6,7,8],[9,10,11,12]]}' |
| 100 | + case(3) |
| 101 | + ! not valid (not same types) |
| 102 | + str = CK_'{"matrix":[["a",2,3,4],[5,6,7,8],[9,10,11,12]]}' |
| 103 | + end select |
| 104 | + |
| 105 | + call json%initialize() |
| 106 | + call json%parse(p,str) |
| 107 | + |
| 108 | + call json%matrix_info(p,is_matrix,var_type,& |
| 109 | + n_sets,set_size,name) |
| 110 | + call json%initialize() |
| 111 | + |
| 112 | + ! without found: |
| 113 | + call json%matrix_info(p,'path.not.there',is_matrix,& |
| 114 | + var_type=var_type,n_sets=n_sets,& |
| 115 | + set_size=set_size,name=name) |
| 116 | + call json%initialize() |
| 117 | + |
| 118 | + call json%matrix_info(p,'matrix',is_matrix,& |
| 119 | + var_type=var_type,n_sets=n_sets,& |
| 120 | + set_size=set_size,name=name) |
| 121 | + call json%initialize() |
| 122 | + |
| 123 | + ! with found: |
| 124 | + call json%matrix_info(p,'path.not.there',is_matrix,& |
| 125 | + var_type=var_type,n_sets=n_sets,& |
| 126 | + set_size=set_size,name=name,& |
| 127 | + found=found) |
| 128 | + call json%initialize() |
| 129 | + |
| 130 | + call json%matrix_info(p,'matrix',is_matrix,& |
| 131 | + var_type=var_type,n_sets=n_sets,& |
| 132 | + set_size=set_size,name=name,& |
| 133 | + found=found) |
| 134 | + call json%initialize() |
| 135 | + |
| 136 | + call json%destroy(p) |
| 137 | + |
| 138 | + end do |
| 139 | + |
| 140 | + ! rename: |
| 141 | + call json%initialize(trailing_spaces_significant=.true.) |
| 142 | + call json%create_integer(p,1,CK_'a') |
| 143 | + call json%rename(p,CK_'b ') |
| 144 | + |
| 145 | + end subroutine test_34 |
| 146 | + |
| 147 | +end module jf_test_34_mod |
| 148 | +!***************************************************************************************** |
| 149 | + |
| 150 | +#ifndef INTERGATED_TESTS |
| 151 | +!***************************************************************************************** |
| 152 | +program jf_test_34 |
| 153 | + |
| 154 | + !! 34th unit test. |
| 155 | + |
| 156 | + use jf_test_34_mod , only: test_34 |
| 157 | + implicit none |
| 158 | + integer :: n_errors |
| 159 | + n_errors = 0 |
| 160 | + call test_34(n_errors) |
| 161 | + if (n_errors /= 0) stop 1 |
| 162 | + |
| 163 | +end program jf_test_34 |
| 164 | +!***************************************************************************************** |
| 165 | +#endif |
0 commit comments