|
| 1 | +#include "language-support.F90" |
| 2 | + |
| 3 | +module prif_co_broadcast_test_m |
| 4 | + use prif, only : prif_co_broadcast, prif_num_images, prif_this_image_no_coarray |
| 5 | + use julienne_m, only : & |
| 6 | + test_description_t & |
| 7 | + ,test_diagnosis_t & |
| 8 | + ,test_result_t & |
| 9 | + ,test_t & |
| 10 | + ,operator(//) & |
| 11 | + ,operator(.expect.) & |
| 12 | + ,operator(.equalsExpected.) |
| 13 | +#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY |
| 14 | + use julienne_m, only : diagnosis_function_i |
| 15 | +#endif |
| 16 | + |
| 17 | + implicit none |
| 18 | + private |
| 19 | + public :: prif_co_broadcast_test_t |
| 20 | + |
| 21 | + type, extends(test_t) :: prif_co_broadcast_test_t |
| 22 | + contains |
| 23 | + procedure, nopass, non_overridable :: subject |
| 24 | + procedure, nopass, non_overridable :: results |
| 25 | + end type |
| 26 | + |
| 27 | + type object_t |
| 28 | + integer i |
| 29 | + logical fallacy |
| 30 | + character(len=len("fooey")) actor |
| 31 | + complex issues |
| 32 | + end type |
| 33 | + |
| 34 | + interface operator(==) |
| 35 | + module procedure equals |
| 36 | + end interface |
| 37 | + |
| 38 | +contains |
| 39 | + |
| 40 | + pure function subject() result(test_subject) |
| 41 | + character(len=:), allocatable :: test_subject |
| 42 | + test_subject = "The prif_co_broadcast subroutine" |
| 43 | + end function |
| 44 | + |
| 45 | +#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY |
| 46 | + |
| 47 | + function results() result(test_results) |
| 48 | + type(test_result_t), allocatable :: test_results(:) |
| 49 | + type(prif_co_broadcast_test_t) prif_co_broadcast_test |
| 50 | + |
| 51 | + test_results = prif_co_broadcast_test%run([ & |
| 52 | + test_description_t("broadcasting a default integer scalar with no optional arguments present", broadcast_default_integer_scalar) & |
| 53 | + ,test_description_t("broadcasting a derived type scalar with no allocatable components", broadcast_derived_type) & |
| 54 | + ]) |
| 55 | + end function |
| 56 | + |
| 57 | +#else |
| 58 | + |
| 59 | + function results() result(test_results) |
| 60 | + type(test_result_t), allocatable :: test_results(:) |
| 61 | + type(prif_co_broadcast_test_t) prif_co_broadcast_test |
| 62 | + procedure(diagnosis_function_i), pointer :: & |
| 63 | + broadcast_default_integer_scalar_ptr => broadcast_default_integer_scalar & |
| 64 | + ,broadcast_derived_type_ptr => broadcast_derived_type |
| 65 | + |
| 66 | + test_results = prif_co_broadcast_test%run([ & |
| 67 | + test_description_t("broadcasting a default integer scalar with no optional arguments present", broadcast_default_integer_scalar_ptr) & |
| 68 | + ,test_description_t("broadcasting a derived type scalar with no allocatable components", broadcast_derived_type_ptr) & |
| 69 | + ]) |
| 70 | + end function |
| 71 | + |
| 72 | +#endif |
| 73 | + |
| 74 | + logical pure function equals(lhs, rhs) |
| 75 | + type(object_t), intent(in) :: lhs, rhs |
| 76 | + equals = all([ & |
| 77 | + lhs%i == rhs%i & |
| 78 | + ,lhs%fallacy .eqv. rhs%fallacy & |
| 79 | + ,lhs%actor == rhs%actor & |
| 80 | + ,lhs%issues == rhs%issues & |
| 81 | + ]) |
| 82 | + end function |
| 83 | + |
| 84 | + function broadcast_default_integer_scalar() result(test_diagnosis) |
| 85 | + type(test_diagnosis_t) test_diagnosis |
| 86 | + integer iPhone, me |
| 87 | + integer, parameter :: source_value = 7779311, junk = -99 |
| 88 | + |
| 89 | + call prif_this_image_no_coarray(this_image=me) |
| 90 | + iPhone = merge(source_value, junk, me==1) |
| 91 | + call prif_co_broadcast(iPhone, source_image=1) |
| 92 | + test_diagnosis = iPhone .equalsExpected. source_value |
| 93 | + end function |
| 94 | + |
| 95 | + function broadcast_derived_type() result(test_diagnosis) |
| 96 | + type(test_diagnosis_t) test_diagnosis |
| 97 | + type(object_t) object |
| 98 | + integer me, ni |
| 99 | + |
| 100 | + call prif_this_image_no_coarray(this_image=me) |
| 101 | + call prif_num_images(num_images=ni) |
| 102 | + object = object_t(me, .false., "gooey", me*(1.,0.)) |
| 103 | + call prif_co_broadcast(object, source_image=ni) |
| 104 | + associate(expected_object => object_t(ni, .false., "gooey", ni*(1.,0.))) |
| 105 | + test_diagnosis = .expect. (object == expected_object) // "co_broadcast derived type" |
| 106 | + end associate |
| 107 | + end function |
| 108 | + |
| 109 | +end module prif_co_broadcast_test_m |
0 commit comments