|
| 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