Test_GridManager.pf Source File


This file depends on

sourcefile~~test_gridmanager.pf~~EfferentGraph sourcefile~test_gridmanager.pf Test_GridManager.pf sourcefile~mapl_gridmanager.f90 MAPL_GridManager.F90 sourcefile~test_gridmanager.pf->sourcefile~mapl_gridmanager.f90 sourcefile~mockgridfactory.f90 MockGridFactory.F90 sourcefile~test_gridmanager.pf->sourcefile~mockgridfactory.f90 sourcefile~mapl_abstractgridfactory.f90 MAPL_AbstractGridFactory.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_errorhandling.f90 MAPL_ErrorHandling.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_errorhandling.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_keywordenforcer.f90 MAPL_KeywordEnforcer.F90 sourcefile~mapl_gridmanager.f90->sourcefile~mapl_keywordenforcer.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~pfio.f90 pFIO.F90 sourcefile~mapl_gridmanager.f90->sourcefile~pfio.f90 sourcefile~base_base.f90 Base_Base.F90 sourcefile~mockgridfactory.f90->sourcefile~base_base.f90 sourcefile~mockgridfactory.f90->sourcefile~mapl_abstractgridfactory.f90 sourcefile~mockgridfactory.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~mockgridfactory.f90->sourcefile~pfio.f90

Source Code

module Test_GridManager
   use MAPL_GridManager_private
   use MockGridFactoryMod
   use pFUnit
   use ESMF
   implicit none

   type (ESMF_Config) :: config

contains

   @before
   subroutine setup()
      integer :: unit, status
      
      open (newunit=unit, file = 'tmp.rc', access='sequential', form='formatted')
      write (unit,*) 'default.GRID_TYPE: grid_type_1'
      write (unit,*) 'other.GRID_TYPE: grid_type_2'
      close (unit)

      config = ESMF_ConfigCreate(rc=status)
      @assertEqual(0, status)
      call ESMF_ConfigLoadFile (config, 'tmp.rc', rc=status)
      @assertEqual(0, status)
 
   end subroutine setup

   @after
   subroutine teardown()
      integer :: unit,status
      call ESMF_ConfigDestroy(config, rc=status)
      @assertEqual(0, status)
      open (newunit=unit, file = 'tmp.rc')
      close(unit, status='delete')
     
   end subroutine teardown
   @test
   subroutine test_add_prototype()
      type (GridManager) :: grid_manager
      call grid_manager%add_prototype('mock', MockGridFactory('foo'))
   end subroutine test_add_prototype

   @test
   subroutine test_make_grid_no_prototype()
      type (GridManager) :: grid_manager
      type (ESMF_Grid) :: grid

      integer :: status

      grid = grid_manager%make_grid(config, rc=status)
      ! should have failed, but need to clean up otherwise
      if (status == 0) then
         call grid_manager%delete(grid)
      end if
      @assertExceptionRaised('label [GRID_TYPE:] not found')

      ! Check that it actually failed
      @assertFalse(0 == status, 'made a grid even though there is no prototype')
      
   end subroutine test_make_grid_no_prototype

   @test
   subroutine test_make_grid_prototype()
      type (GridManager) :: grid_manager
      type (ESMF_Grid) :: grid

      integer :: status

      call grid_manager%add_prototype('grid_type_1', MockGridFactory('foo'))
      grid = grid_manager%make_grid( config, prefix='default.', rc=status)
      @assertEqual(0, status)

      call grid_manager%delete(grid)

   end subroutine test_make_grid_prototype

   @test
   subroutine test_grid_type()
      type (GridManager) :: grid_manager
      type (ESMF_Grid) :: grid

      integer :: status
      character(len=40) :: grid_type

      call grid_manager%add_prototype('grid_type_1', MockGridFactory('foo'))
      grid = grid_manager%make_grid(config, prefix='default.', rc=status)
      @assertEqual(0, status)

      call ESMF_AttributeGet(grid, 'GridType', grid_type, rc=status)
      if (status /= 0) then
         call grid_manager%delete(grid)
         return
      end if
      @assertEqual(0, status)
      
      if ('mock' /= trim(grid_type)) then
         call grid_manager%delete(grid)
         return
      end if
      @assertEqual('grid_type_1', trim(grid_type))
      
      call grid_manager%delete(grid)

   end subroutine test_grid_type

   @test
   subroutine test_make_grid_multi()
      type (GridManager) :: grid_manager
      type (ESMF_Grid) :: grid

      integer :: status
      character(len=40) :: grid_name

      call grid_manager%add_prototype('grid_type_1', MockGridFactory('foo'))
      call grid_manager%add_prototype('grid_type_2', MockGridFactory('bar'))

      grid = grid_manager%make_grid(config, prefix='default.', rc=status)
      @assertEqual(0, status)

      call ESMF_AttributeGet(grid, 'GRID_NAME', grid_name, rc=status)
      if (status /= 0) then
         call grid_manager%delete(grid)
      end if
      @assertEqual(0, status)
      
      if ('mock' /= trim(grid_name)) then
         call grid_manager%delete(grid)
         return
      end if
      @assertEqual('foo', trim(grid_name))
      
      call grid_manager%delete(grid)


      grid = grid_manager%make_grid(config, prefix='other.', rc=status)

      call ESMF_AttributeGet(grid, 'GRID_NAME', grid_name, rc=status)
      if (status /= 0) then
         call grid_manager%delete(grid)
         return
      end if
      @assertEqual(0, status)
      
      if ('mock' /= trim(grid_name)) then
         call grid_manager%delete(grid)
      end if
      @assertEqual('bar', trim(grid_name))
      
      call grid_manager%delete(grid)

   end subroutine test_make_grid_multi

end module Test_GridManager