Skip to content

Commit 8ff8876

Browse files
committed
add a separate unit test for clone
1 parent 590ec50 commit 8ff8876

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

src/tests/jf_test_48.F90

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
!*****************************************************************************************
2+
!>
3+
! Module for the 48th unit test.
4+
5+
module jf_test_48_mod
6+
7+
use json_module, wp => json_RK, IK => json_IK, LK => json_LK
8+
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
9+
10+
implicit none
11+
12+
private
13+
public :: test_48
14+
15+
character(len=*),parameter :: filename = '../files/inputs/big.json' !! large file to open
16+
17+
contains
18+
19+
subroutine test_48(error_cnt)
20+
21+
!! Clone test
22+
23+
implicit none
24+
25+
integer,intent(out) :: error_cnt
26+
27+
type(json_value),pointer :: p, p_clone
28+
type(json_core) :: json !! factory for manipulating `json_value` pointers
29+
30+
write(error_unit,'(A)') ''
31+
write(error_unit,'(A)') '================================='
32+
write(error_unit,'(A)') ' EXAMPLE 48'
33+
write(error_unit,'(A)') '================================='
34+
write(error_unit,'(A)') ''
35+
36+
error_cnt = 0
37+
call json%initialize()
38+
if (json%failed()) then
39+
call json%print_error_message(error_unit)
40+
error_cnt = error_cnt + 1
41+
end if
42+
43+
write(error_unit,'(A)') 'open file'
44+
call json%load(filename, p)
45+
if (json%failed()) then
46+
call json%print_error_message(error_unit)
47+
error_cnt = error_cnt + 1
48+
end if
49+
50+
!test the deep copy routine:
51+
write(error_unit,'(A)') 'json_clone test'
52+
call json%clone(p,p_clone)
53+
if (json%failed()) then
54+
call json%print_error_message(error_unit)
55+
error_cnt = error_cnt + 1
56+
end if
57+
58+
call json%destroy(p)
59+
if (json%failed()) then
60+
call json%print_error_message(error_unit)
61+
error_cnt = error_cnt + 1
62+
end if
63+
64+
call json%destroy(p_clone)
65+
if (json%failed()) then
66+
call json%print_error_message(error_unit)
67+
error_cnt = error_cnt + 1
68+
end if
69+
70+
if (error_cnt==0) then
71+
write(error_unit,'(A)') 'Success'
72+
else
73+
write(error_unit,'(A)') 'Failed'
74+
end if
75+
76+
write(error_unit,'(A)') ''
77+
78+
end subroutine test_48
79+
80+
end module jf_test_48_mod
81+
!*****************************************************************************************
82+
83+
!*****************************************************************************************
84+
#ifndef INTEGRATED_TESTS
85+
program jf_test_48
86+
87+
!! clone test
88+
89+
use jf_test_48_mod , only: test_48
90+
implicit none
91+
integer :: n_errors
92+
integer :: i !! counter
93+
94+
integer,parameter :: n_repeat = 1 !! number of times to repeat the test
95+
96+
do i = 1, n_repeat
97+
call test_48(n_errors)
98+
if (n_errors /= 0) stop 1
99+
end do
100+
101+
end program jf_test_48
102+
#endif
103+
!*****************************************************************************************

0 commit comments

Comments
 (0)