module test_Client use pfunit use pFIO_MockClientThreadMod use pFIO_AbstractSocketMod use pFIO_AbstractMessageMod use MockSocketMod use pFIO_ArrayReferenceMod use pFIO_TerminateMessageMod use pFIO_DoneMessageMod use pFIO_AddExtCollectionMessageMod use pFIO_IdMessageMod use pFIO_PrefetchDataMessageMod use, intrinsic :: iso_fortran_env, only: REAL32 implicit none contains @test subroutine test_addExtCollection_send_message() type (MockClientThread) :: c class (AbstractSocket), pointer :: connection integer :: handle_foo type (MockSocketLog), target :: log call c%set_connection(MockSocket(log)) connection => c%get_connection() handle_foo = c%add_ext_collection(template='foo') select type (connection) type is (MockSocket) @assertEqual("send<AddExtCollection('foo')>", log%log) end select end subroutine test_addExtCollection_send_message @test subroutine test_addExtCollection_unique_handle() type (MockClientThread) :: c class (AbstractSocket), pointer :: connection integer :: handle_foo integer :: handle_bar type (MockSocketLog), target :: log call c%set_connection(MockSocket(log)) connection => c%get_connection() select type (connection) type is (MockSocket) call connection%add_message(IdMessage(1)) call connection%add_message(IdMessage(2)) end select handle_foo = c%add_ext_collection(template='foo') handle_bar = c%add_ext_collection(template='bar') @assertFalse(handle_foo == handle_bar) end subroutine test_addExtCollection_unique_handle @test subroutine test_prefetch_data() type (MockClientThread) :: c class (AbstractSocket), pointer :: connection integer :: collection_id integer :: request_id real(kind=REAL32), target :: q character(len=:), allocatable :: expected_log type (MockSocketLog), target :: log call c%set_connection(MockSocket(log)) connection => c%get_connection() select type (connection) type is (MockSocket) call connection%add_message(IdMessage(1)) call connection%add_message(IdMessage(2)) connection%q1 = q end select collection_id = c%add_ext_collection(template='foo') request_id = c%prefetch_data(collection_id, 'foo', 'q', ArrayReference(q)) expected_log = "send<AddExtCollection('foo')>" expected_log = expected_log // " :: send<PrefetchData('q')> :: get()" select type (connection) type is (MockSocket) @assertEqual(expected_log, log%log) end select end subroutine test_prefetch_data @test subroutine test_wait() type (MockClientThread), target :: c class (AbstractSocket), pointer :: connection integer :: collection_id integer :: request_id1 integer :: request_id2 real(kind=REAL32), target :: q1 real(kind=REAL32), target :: q2(3) real(kind=REAL32) :: q1_expected = 3.14 real(kind=REAL32) :: q2_expected(3) = [1,2,3] character(len=:), allocatable :: expected_log type (MockSocketLog), target :: log type(MockSocket), target :: ms ms = MockSocket(log) call c%set_connection(ms) connection => c%get_connection() select type (connection) type is (MockSocket) call connection%add_message(IdMessage(1)) call connection%add_message(IdMessage(1)) ! note value not used call connection%add_message(IdMessage(2)) connection%q1 = q1_expected connection%q2 = q2_expected end select collection_id = c%add_ext_collection(template='foo') request_id1 = c%prefetch_data(collection_id, 'foo', 'q1', ArrayReference(q1)) request_id2 = c%prefetch_data(collection_id, 'foo', 'q2', ArrayReference(q2)) call c%wait(request_id1) call c%wait(request_id2) @assertTrue (request_id1 /= request_id2) expected_log = "send<AddExtCollection('foo')>" expected_log = expected_log // " :: send<PrefetchData('q1')>" expected_log = expected_log // " :: get()" expected_log = expected_log // " :: send<PrefetchData('q2')>" expected_log = expected_log // " :: get()" !write(str,'(i0)') request_id1 !expected_log = expected_log // " :: send<Wait("//trim(str)//")>" !write(str,'(i0)') request_id2 expected_log = expected_log // " :: wait()" !expected_log = expected_log // " :: send<Wait("//trim(str)//")>" expected_log = expected_log // " :: wait()" select type (connection) type is (MockSocket) @assertEqual(expected_log, log%log) end select @assertEqual(q1_expected, q1) @assertEqual(q2_expected, q2) end subroutine test_wait end module test_Client