Skip to content

Commit a0b2f93

Browse files
author
Damian Rouson
committed
test(object): add object-pattern parent unit test
and add user-defined derived type output deferred binding to object class.
1 parent 8793741 commit a0b2f93

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

tests/main.f90

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ subroutine run()
1010
collective_subroutines_co_sum => test_co_sum
1111
use data_partition_test, only: &
1212
data_partition_data_partition => test_data_partition
13+
use object_interface_test, only: &
14+
object_interface_object => test_object
1315
use single_image_intrinsics_test, only: &
1416
single_image_intrinsics_findloc => test_findloc
1517
use vegetables, only: test_item_t, test_that, run_tests
1618

1719
type(test_item_t) :: tests
18-
type(test_item_t) :: individual_tests(4)
20+
type(test_item_t) :: individual_tests(5)
1921

2022
individual_tests(1) = collective_subroutines_co_all()
2123
individual_tests(2) = collective_subroutines_co_sum()
2224
individual_tests(3) = data_partition_data_partition()
23-
individual_tests(4) = single_image_intrinsics_findloc()
25+
individual_tests(4) = object_interface_object()
26+
individual_tests(5) = single_image_intrinsics_findloc()
2427
tests = test_that(individual_tests)
2528

2629
call run_tests(tests)

tests/object_interface_test.f90

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module object_interface_test
2+
!! author: Damian Rouson
3+
!!
4+
!! summary: verify object pattern asbtract parent
5+
use vegetables, only: &
6+
result_t, input_t, integer_input_t, test_item_t, & ! types
7+
describe, it, assert_equals, assert_that, assert_not ! functions
8+
use object_interface, only : object
9+
implicit none
10+
11+
private
12+
public :: test_object
13+
14+
type, extends(object) :: subject
15+
contains
16+
procedure write_formatted
17+
end type
18+
19+
contains
20+
21+
function test_object() result(tests)
22+
type(test_item_t) tests
23+
24+
tests = describe( &
25+
"object class", &
26+
[it( &
27+
".not. user_defined() if only default-initialized", &
28+
check_default_initialization), &
29+
it( &
30+
"user_defined() after call mark_as_defined", &
31+
check_mark_as_defined)])
32+
end function
33+
34+
function check_default_initialization() result(result_)
35+
!! Verify that user_defined() is .false. for a default-initialied object
36+
class(object), allocatable :: object_
37+
type(result_t) result_
38+
39+
allocate(subject :: object_)
40+
41+
result_ = assert_not(object_%user_defined())
42+
end function
43+
44+
function check_mark_as_defined() result(result_)
45+
!! Verify that mark_as_defined results in user_defined() being .true.
46+
class(object), allocatable :: object_
47+
type(result_t) result_
48+
49+
allocate(subject :: object_)
50+
51+
call object_%mark_as_defined
52+
result_ = assert_that(object_%user_defined())
53+
end function
54+
55+
subroutine write_formatted(self, unit, iotype, v_list, iostat, iomsg)
56+
class(subject), intent(in) :: self
57+
integer, intent(in) :: unit
58+
character(*), intent(in) :: iotype
59+
integer, intent(in) :: v_list(:)
60+
integer, intent(out) :: iostat
61+
character(*), intent(inout) :: iomsg
62+
63+
select case(iotype)
64+
case('LISTDIRECTED')
65+
write(unit,*) self%user_defined()
66+
iostat = 0
67+
iomsg = ""
68+
case default
69+
iostat = -1
70+
iomsg = "object_interface_test: subject%write_formatted iotype received unsupported iotype " // iotype
71+
end select
72+
73+
associate( unused => v_list)
74+
end associate
75+
end subroutine
76+
77+
end module object_interface_test

0 commit comments

Comments
 (0)