Test_MAPL_Resource.pf Source File


This file depends on

sourcefile~~test_mapl_resource.pf~~EfferentGraph sourcefile~test_mapl_resource.pf Test_MAPL_Resource.pf sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~test_mapl_resource.pf->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_resource.f90 MAPL_Resource.F90 sourcefile~test_mapl_resource.pf->sourcefile~mapl_resource.f90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_throw.f90 sourcefile~mapl_resource.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~constants.f90 Constants.F90 sourcefile~mapl_resource.f90->sourcefile~constants.f90 sourcefile~esmfl_mod.f90 ESMFL_Mod.F90 sourcefile~mapl_resource.f90->sourcefile~esmfl_mod.f90 sourcefile~keywordenforcer.f90 KeywordEnforcer.F90 sourcefile~mapl_resource.f90->sourcefile~keywordenforcer.f90 sourcefile~mapl_comms.f90 MAPL_Comms.F90 sourcefile~mapl_resource.f90->sourcefile~mapl_comms.f90 sourcefile~internalconstants.f90 InternalConstants.F90 sourcefile~constants.f90->sourcefile~internalconstants.f90 sourcefile~mathconstants.f90 MathConstants.F90 sourcefile~constants.f90->sourcefile~mathconstants.f90 sourcefile~physicalconstants.f90 PhysicalConstants.F90 sourcefile~constants.f90->sourcefile~physicalconstants.f90 sourcefile~errorhandling.f90->sourcefile~mapl_throw.f90 sourcefile~esmfl_mod.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~esmfl_mod.f90->sourcefile~constants.f90 sourcefile~esmfl_mod.f90->sourcefile~mapl_comms.f90 sourcefile~base_base.f90 Base_Base.F90 sourcefile~esmfl_mod.f90->sourcefile~base_base.f90 sourcefile~mapl_abstractgridfactory.f90 MAPL_AbstractGridFactory.F90 sourcefile~esmfl_mod.f90->sourcefile~mapl_abstractgridfactory.f90 sourcefile~mapl_gridmanager.f90 MAPL_GridManager.F90 sourcefile~esmfl_mod.f90->sourcefile~mapl_gridmanager.f90 sourcefile~mapl_comms.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_comms.f90->sourcefile~constants.f90 sourcefile~mapl_comms.f90->sourcefile~base_base.f90 sourcefile~shmem.f90 Shmem.F90 sourcefile~mapl_comms.f90->sourcefile~shmem.f90 sourcefile~base_base.f90->sourcefile~constants.f90 sourcefile~base_base.f90->sourcefile~keywordenforcer.f90 sourcefile~mapl_range.f90 MAPL_Range.F90 sourcefile~base_base.f90->sourcefile~mapl_range.f90 sourcefile~maplgrid.f90 MaplGrid.F90 sourcefile~base_base.f90->sourcefile~maplgrid.f90 sourcefile~mapl_abstractgridfactory.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_abstractgridfactory.f90->sourcefile~constants.f90 sourcefile~mapl_abstractgridfactory.f90->sourcefile~keywordenforcer.f90 sourcefile~mapl_abstractgridfactory.f90->sourcefile~base_base.f90 sourcefile~pfio.f90 pFIO.F90 sourcefile~mapl_abstractgridfactory.f90->sourcefile~pfio.f90 sourcefile~mapl_gridmanager.f90->sourcefile~errorhandling.f90 sourcefile~mapl_gridmanager.f90->sourcefile~keywordenforcer.f90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_abstractgridfactory.f90 sourcefile~mapl_cubedspheregridfactory.f90 MAPL_CubedSphereGridFactory.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_cubedspheregridfactory.f90 sourcefile~mapl_externalgridfactory.f90 MAPL_ExternalGridFactory.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_externalgridfactory.f90 sourcefile~mapl_integer64gridfactorymap.f90 MAPL_Integer64GridFactoryMap.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_integer64gridfactorymap.f90 sourcefile~mapl_latlongridfactory.f90 MAPL_LatLonGridFactory.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_latlongridfactory.f90 sourcefile~mapl_stringgridfactorymap.f90 MAPL_StringGridFactoryMap.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_stringgridfactorymap.f90 sourcefile~mapl_swathgridfactory.f90 MAPL_SwathGridFactory.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_swathgridfactory.f90 sourcefile~mapl_tripolargridfactory.f90 MAPL_TripolarGridFactory.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_tripolargridfactory.f90 sourcefile~mapl_xygridfactory.f90 MAPL_XYGridFactory.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_xygridfactory.f90 sourcefile~mapl_gridmanager.f90->sourcefile~pfio.f90 sourcefile~physicalconstants.f90->sourcefile~mathconstants.f90 sourcefile~shmem.f90->sourcefile~constants.f90

Source Code

#include "MAPL_Exceptions.h"
#include "MAPL_ErrLog.h"

module Test_MAPL_Resource
   use MAPL_ResourceMod
   use ESMF
   use pfunit
   use MAPL_ExceptionHandling
   use, intrinsic :: iso_fortran_env, only: REAL32, REAL64, int32, int64

   implicit none

   integer, parameter :: PRINT_ALL = 1
   integer, parameter :: PRINT_DIFFERENT = 0
   integer, parameter :: PRINT_NOTHING = -1
   character(len=*), parameter :: EMPTY_STRING = ''
   character(len=*), parameter :: OUTPUT_BASE  = ' Resource Parameter: '
   character(len=*), parameter :: CHAR__PREFIX = 'Character'
   character(len=*), parameter :: INT4__PREFIX = 'Integer*4'
   character(len=*), parameter :: INT8__PREFIX = 'Integer*8'
   character(len=*), parameter :: REAL4_PREFIX = 'Real*4'
   character(len=*), parameter :: REAL8_PREFIX = 'Real*8'
   character(len=*), parameter :: LOGIC_PREFIX = 'Logical'
   character(len=*), parameter :: DEFAU_SUFFIX = ', (default value)'

contains

   @Test
   subroutine Test_MAPL_GetResource_scalar_int4()
      type(ESMF_Config) :: config
      integer :: status
      integer(kind=int32) :: expected, actual
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1'
      logical :: value_is_set
      character(len=MAX_LINE_LENGTH) :: output_string

      expected = 1
      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      call MAPL_GetResource_config_scalar(config, actual, label = LABEL, value_is_set = value_is_set, iunit=output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')
   end subroutine Test_MAPL_GetResource_scalar_int4

   @Test
   subroutine Test_MAPL_GetResource_scalar_int8()
      type(ESMF_Config) :: config
      integer :: status
      integer(kind=int64) :: expected, actual
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1'
      logical :: value_is_set

      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      expected = 1
      call MAPL_GetResource_config_scalar(config, actual, label = LABEL, value_is_set = value_is_set, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')
      
   end subroutine Test_MAPL_GetResource_scalar_int8

   @Test
   subroutine Test_MAPL_GetResource_scalar_real4()
      type(ESMF_Config) :: config
      integer :: status
      real(kind=real32) :: expected, actual
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1.0'
      logical :: value_is_set

      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      expected = 1.0
      call MAPL_GetResource_config_scalar(config, actual, label = LABEL, value_is_set = value_is_set, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')
      
   end subroutine Test_MAPL_GetResource_scalar_real4

   @Test
   subroutine Test_MAPL_GetResource_scalar_real8()
      type(ESMF_Config) :: config
      integer :: status
      real(kind=real64) :: expected, actual
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1.0'
      logical :: value_is_set

      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      expected = 1.0
      call MAPL_GetResource_config_scalar(config, actual, label = LABEL, value_is_set = value_is_set, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')
      
   end subroutine Test_MAPL_GetResource_scalar_real8

   @Test
   subroutine Test_MAPL_GetResource_scalar_character()
      type(ESMF_Config) :: config
      integer :: status
      character(ESMF_MAXSTR) :: expected, actual
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = 'value'
      character(len=MAX_LINE_LENGTH) :: output_string
      logical :: value_is_set

      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      expected = VAL
      call MAPL_GetResource_config_scalar(config, actual, label = LABEL, value_is_set = value_is_set, iunit = output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')
      @assertTrue(len_trim(output_string) > len(VAL), 'output_string should be longer than VAL')
      @assertTrue(len_trim(output_string) <= MAX_LINE_LENGTH, 'output_string is too long.')

   end subroutine Test_MAPL_GetResource_scalar_character

   @Test
   subroutine Test_MAPL_GetResource_scalar_logical()
      type(ESMF_Config) :: config
      integer :: status
      logical :: expected, actual, match
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '.T.'
      logical :: value_is_set

      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      expected = .TRUE.
      call MAPL_GetResource_config_scalar(config, actual, label = LABEL, value_is_set = value_is_set, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      match = expected .eqv. actual 
      @assertTrue(match, 'actual does not match expected.')

   end subroutine Test_MAPL_GetResource_scalar_logical

   @Test
   subroutine Test_MAPL_GetResource_array_int4()
      type(ESMF_Config) :: config
      integer :: status
      integer(kind=int32) :: expected(4), actual(4)
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1 2 3 4'
      logical :: value_is_set
      character(len=MAX_LINE_LENGTH) :: output_string

      expected = [1, 2, 3, 4]
      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      call MAPL_GetResource_config_array(config, actual, label = LABEL, value_is_set = value_is_set, iunit=output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')

   end subroutine Test_MAPL_GetResource_array_int4

   @Test
   subroutine Test_MAPL_GetResource_array_int8()
      type(ESMF_Config) :: config
      integer :: status
      integer(kind=int64) :: expected(4), actual(4)
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1 2 3 4'
      logical :: value_is_set
      character(len=MAX_LINE_LENGTH) :: output_string

      expected = [1, 2, 3, 4]
      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      call MAPL_GetResource_config_array(config, actual, label = LABEL, value_is_set = value_is_set, iunit=output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')

   end subroutine Test_MAPL_GetResource_array_int8

   @Test
   subroutine Test_MAPL_GetResource_array_real4()
      type(ESMF_Config) :: config
      integer :: status
      real(kind=real32) :: expected(4), actual(4)
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1.0 2.0 3.0 4.0'
      logical :: value_is_set
      character(len=MAX_LINE_LENGTH) :: output_string

      expected = [1.0, 2.0, 3.0, 4.0]
      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      call MAPL_GetResource_config_array(config, actual, label = LABEL, value_is_set = value_is_set, iunit=output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')

   end subroutine Test_MAPL_GetResource_array_real4

   @Test
   subroutine Test_MAPL_GetResource_array_real8()
      type(ESMF_Config) :: config
      integer :: status
      real(kind=real64) :: expected(4), actual(4)
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '1.0 2.0 3.0 4.0'
      logical :: value_is_set
      character(len=MAX_LINE_LENGTH) :: output_string

      expected = [1.0, 2.0, 3.0, 4.0]
      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      call MAPL_GetResource_config_array(config, actual, label = LABEL, value_is_set = value_is_set, iunit=output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')

   end subroutine Test_MAPL_GetResource_array_real8

   @Test
   subroutine Test_MAPL_GetResource_array_character()
      type(ESMF_Config) :: config
      integer :: status
      character(len=ESMF_MAXSTR) :: expected(4), actual(4)
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = 'bop fop hop mop' 
      logical :: value_is_set
      character(len=MAX_LINE_LENGTH) :: output_string

      expected = ['bop', 'fop', 'hop', 'mop']
      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      call MAPL_GetResource_config_array(config, actual, label = LABEL, value_is_set = value_is_set, iunit=output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      @assertEqual(expected, actual, 'actual does not match expected.')

   end subroutine Test_MAPL_GetResource_array_character

   @Test
   subroutine Test_MAPL_GetResource_array_logical()
      type(ESMF_Config) :: config
      integer :: status
      logical :: expected(4), actual(4), match
      character(len=*), parameter :: LABEL = 'label'
      character(len=*), parameter :: VAL = '.T. .F. .F. .T.'
      logical :: value_is_set
      character(len=MAX_LINE_LENGTH) :: output_string

      expected = [.TRUE., .FALSE., .FALSE., .TRUE.]
      config = ESMF_ConfigCreate(rc = status)
      @assertEqual(0, status, 'Failed to create ESMF_Config')
      call ESMF_ConfigSetAttribute(config, PRINT_ALL, label = 'PRINTRC:', rc = status)
      @assertEqual(0, status, 'Failed to set PRINTRC')
      call ESMF_ConfigSetAttribute(config, VAL, label = LABEL, rc = status)
      @assertEqual(0, status, 'Failed to set attribute')
      call MAPL_GetResource_config_array(config, actual, label = LABEL, value_is_set = value_is_set, iunit=output_string, rc = status)
      @assertEqual(0, status, 'Failed to get resource')
      match = all(expected .eqv. actual)
      @assertTrue(match, 'actual does not match expected.')

   end subroutine Test_MAPL_GetResource_array_logical

   @After
   subroutine tear_down()

   end subroutine tear_down

   @Before
   subroutine set_up()

   end subroutine set_up

end module Test_MAPL_Resource