Skip to content

Commit 979e950

Browse files
committed
Merge pull request #159 from jacobwilliams/coverage
coverage increases
2 parents 46bf070 + 1016d2a commit 979e950

File tree

4 files changed

+117
-14
lines changed

4 files changed

+117
-14
lines changed

src/tests/jf_test_11.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module jf_test_11_mod
1212
implicit none
1313

1414
character(len=*),parameter :: dir = '../files/inputs/' !! working directory
15-
# ifdef USE_UCS4
15+
#ifdef USE_UCS4
1616
character(len=*),parameter :: unicode_file = 'hello-world-ucs4.json'
1717
#endif
1818
character(len=*),parameter :: ascii_equivalent = 'hello-world-ascii.json'

src/tests/jf_test_15.f90

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
!*****************************************************************************************

src/tests/jf_test_2.f90

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ subroutine test_2(error_cnt)
2525

2626
integer,intent(out) :: error_cnt
2727

28+
type(json_value),pointer :: p, inp, traj, tmp1, tmp2, p_tmp, p_integer_array, p_clone
2829
type(json_core) :: json !! factory for manipulating `json_value` pointers
29-
type(json_value),pointer :: p, inp, traj, p_tmp, p_integer_array, p_clone
3030

3131
integer :: iunit
3232
character(kind=json_CK,len=:),allocatable :: name
3333
integer :: ival,ival_clone
3434
logical :: found
3535

36+
write(error_unit,'(A)') ''
37+
write(error_unit,'(A)') '================================='
38+
write(error_unit,'(A)') ' EXAMPLE 2'
39+
write(error_unit,'(A)') '================================='
40+
write(error_unit,'(A)') ''
41+
3642
error_cnt = 0
3743
call json%initialize()
3844
if (json%failed()) then
3945
call json%print_error_message(error_unit)
4046
error_cnt = error_cnt + 1
4147
end if
4248

43-
write(error_unit,'(A)') ''
44-
write(error_unit,'(A)') '================================='
45-
write(error_unit,'(A)') ' EXAMPLE 2'
46-
write(error_unit,'(A)') '================================='
47-
write(error_unit,'(A)') ''
48-
4949
!root:
5050
call json%create_object(p,dir//filename2) ! create the value and associate the pointer
5151
! add the file name as the name of the overall structure
@@ -69,6 +69,10 @@ subroutine test_2(error_cnt)
6969
error_cnt = error_cnt + 1
7070
end if
7171

72+
!test get_parent:
73+
call json%get_parent(inp,tmp1) !will be root
74+
call json%get_parent(tmp1,tmp2) !has no parent -> null()
75+
7276
!trajectory structure:
7377
call json%create_array(traj,'trajectory') !an array
7478
if (json%failed()) then
@@ -348,5 +352,6 @@ program jf_test_2
348352
n_errors = 0
349353
call test_2(n_errors)
350354
if (n_errors /= 0) stop 1
355+
351356
end program jf_test_2
352357
!*****************************************************************************************

src/tests/jf_test_3.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ subroutine test_3(error_cnt)
3232
character(kind=json_CK,len=10) :: str
3333
real(wp),dimension(:),allocatable :: rvec
3434

35+
write(error_unit,'(A)') ''
36+
write(error_unit,'(A)') '================================='
37+
write(error_unit,'(A)') ' EXAMPLE 3'
38+
write(error_unit,'(A)') '================================='
39+
write(error_unit,'(A)') ''
40+
3541
error_cnt = 0
3642
call json%initialize()
3743
if (json%failed()) then
3844
call json%print_error_message(error_unit)
3945
error_cnt = error_cnt + 1
4046
end if
4147

42-
write(error_unit,'(A)') ''
43-
write(error_unit,'(A)') '================================='
44-
write(error_unit,'(A)') ' EXAMPLE 3'
45-
write(error_unit,'(A)') '================================='
46-
write(error_unit,'(A)') ''
47-
4848
! parse the json file:
4949
write(error_unit,'(A)') ''
5050
write(error_unit,'(A)') 'parsing file: '//dir//filename2

0 commit comments

Comments
 (0)