Skip to content

Commit 66a9a40

Browse files
committed
add some more units tests
1 parent 6b6e126 commit 66a9a40

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

src/tests/jf_test_15.f90

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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
11+
use, intrinsic :: iso_fortran_env , only: error_unit,output_unit
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_value),pointer :: json,p
26+
type(json_file) :: file1, file2
27+
logical :: found,status_ok
28+
integer :: var_type,i,n_children
29+
double precision :: d
30+
logical :: tf
31+
character(kind=CK,len=:),allocatable :: error_msg
32+
33+
write(error_unit,'(A)') ''
34+
write(error_unit,'(A)') '================================='
35+
write(error_unit,'(A)') ' TEST 15'
36+
write(error_unit,'(A)') '================================='
37+
write(error_unit,'(A)') ''
38+
39+
error_cnt = 0
40+
41+
call json_check_for_errors(status_ok, error_msg) !error condition true
42+
43+
call json_initialize(print_signs=.true.) !print signs flag
44+
45+
call json_check_for_errors(status_ok, error_msg) !error condition false
46+
47+
call file1%move(file2) !should throw an exception since points are not associated
48+
49+
call file1%print_file(-1) !invalid input
50+
51+
call file1%print_file(filename='') !invalid filename
52+
53+
call file1%info('this path does not exist',found,var_type,n_children)
54+
55+
call json_initialize()
56+
57+
call json_get_child(json,-99,p) !invalid index
58+
59+
call json_initialize() !clear exceptions
60+
61+
call json_get_child(json,'this child does not exist',p) !invalid index
62+
63+
call json_initialize() !clear exceptions
64+
65+
call json_print(json,-1) !invalid input
66+
call json_print(json,filename='') !invalid input
67+
68+
call json_initialize() !clear exceptions
69+
70+
call json_parse(json, '{"int": 1, "real": 2.0, "logical": true}')
71+
call json_get(json,'real', i)
72+
call json_get(json,'logical',i)
73+
call json_get(json,'integer',d)
74+
call json_get(json,'logical',d)
75+
call json_get(json,'integer',tf)
76+
call json_get(json,'real', tf)
77+
78+
end subroutine test_15
79+
80+
end module jf_test_15_mod
81+
!*****************************************************************************************
82+
83+
!*****************************************************************************************
84+
program jf_test_15
85+
86+
!! 15th unit test.
87+
88+
use jf_test_15_mod, only: test_15
89+
implicit none
90+
integer :: n_errors
91+
call test_15(n_errors)
92+
if ( n_errors /= 0) stop 1
93+
94+
end program jf_test_15
95+
!*****************************************************************************************

src/tests/jf_test_2.f90

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ subroutine test_2(error_cnt)
2525

2626
integer,intent(out) :: error_cnt
2727

28-
type(json_value),pointer :: p, inp, traj
28+
type(json_value),pointer :: p, inp, traj, tmp1, tmp2
2929

3030
integer :: iunit
3131

@@ -64,6 +64,10 @@ subroutine test_2(error_cnt)
6464
call json_print_error_message(error_unit)
6565
error_cnt = error_cnt + 1
6666
end if
67+
68+
!test get_parent:
69+
call json_get_parent(inp,tmp1) !will be root
70+
call json_get_parent(tmp1,tmp2) !has no parent -> null()
6771

6872
!trajectory structure:
6973
call json_create_array(traj,'trajectory') !an array

0 commit comments

Comments
 (0)