Skip to content

Commit

Permalink
[ftg] [tests] Tests for metainfo getters & setters
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Hovy committed Apr 4, 2018
1 parent e02ef6d commit 0184e51
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/serialbox-fortran/m_ser_ftg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ MODULE m_ser_ftg
PUBLIC :: ignore_bullshit, ignore_bullshit_max_dim_size, ignore_bullshit_allow_negative_indices, ignore_not_existing, &
ftg_set_serializer, ftg_get_serializer, ftg_destroy_serializer, ftg_print_serializer_debuginfo, &
ftg_set_savepoint, ftg_get_savepoint, ftg_destroy_savepoint, &
ftg_add_serializer_metainfo, ftg_add_savepoint_metainfo, &
ftg_add_serializer_metainfo, ftg_get_serializer_metainfo, ftg_add_field_metainfo, ftg_get_field_metainfo, &
ftg_add_savepoint_metainfo, ftg_get_savepoint_metainfo, &
ftg_field_exists, ftg_get_bounds, ftg_register_only, ftg_write, ftg_read, ftg_allocate, ftg_allocate_and_read

PRIVATE
Expand Down
118 changes: 118 additions & 0 deletions test/serialbox-fortran/ser_ftg_test.pf
Original file line number Diff line number Diff line change
Expand Up @@ -926,5 +926,123 @@ CONTAINS
@assertEqual(w_testfield_i4, ra_testfield_i4)

END SUBROUTINE testAllocateAndRead


@Test
SUBROUTINE testGlobalMetainfo()

CHARACTER(len=*), PARAMETER :: base_name = 'testGlobalMetainfo'

LOGICAL :: metalog
INTEGER(KIND=C_INT) :: metaint
INTEGER(KIND=C_LONG) :: metalong
REAL(KIND=C_FLOAT) :: metafloat
REAL(KIND=C_DOUBLE) :: metadouble

CALL ftg_set_serializer(dir, base_name, 'w')
CALL ftg_add_serializer_metainfo('ser-metalog-t', .TRUE.)
CALL ftg_add_serializer_metainfo('ser-metalog-f', .FALSE.)
CALL ftg_add_serializer_metainfo('ser-metaint', 42)
CALL ftg_add_serializer_metainfo('ser-metalong', -109470000042_8)
CALL ftg_add_serializer_metainfo('ser-metafloat', 23.0_4)
CALL ftg_add_serializer_metainfo('ser-metadouble', 109.47_8)
CALL ftg_destroy_serializer()

CALL ftg_set_serializer(dir, base_name, 'r')
CALL ftg_get_serializer_metainfo('ser-metalog-t', metalog)
@assertEqual(.TRUE., metalog)
CALL ftg_get_serializer_metainfo('ser-metalog-f', metalog)
@assertEqual(.FALSE., metalog)
CALL ftg_get_serializer_metainfo('ser-metaint', metaint)
@assertEqual(42, metaint)
CALL ftg_get_serializer_metainfo('ser-metalong', metalong)
@assertEqual(-109470000042_8, metalong)
CALL ftg_get_serializer_metainfo('ser-metafloat', metafloat)
@assertEqual(23.0_4, metafloat)
CALL ftg_get_serializer_metainfo('ser-metadouble', metadouble)
@assertEqual(109.47_8, metadouble)
CALL ftg_destroy_serializer()

END SUBROUTINE testGlobalMetainfo

@Test
SUBROUTINE testFieldMetainfo()

TYPE(t_serializer) :: serializer
CHARACTER(len=*), PARAMETER :: base_name = 'test_field_metainfo'
INTEGER :: field(2,1,4)
CHARACTER(len=*), PARAMETER :: field_name = 'field'

LOGICAL :: metalog
INTEGER(KIND=C_INT) :: metaint
INTEGER(KIND=C_LONG) :: metalong
REAL(KIND=C_FLOAT) :: metafloat
REAL(KIND=C_DOUBLE) :: metadouble

field = RESHAPE((/ 0, 1, 2, 3, 4, 5, 6, 7 /), SHAPE(field))

CALL ftg_set_serializer(dir, base_name, 'w')
CALL ftg_write(field_name, field, LBOUND(field), UBOUND(field))
CALL ftg_add_field_metainfo(field_name, 'field-metalog-t', .TRUE.)
CALL ftg_add_field_metainfo(field_name, 'field-metalog-f', .FALSE.)
CALL ftg_add_field_metainfo(field_name, 'field-metaint', 42)
CALL ftg_add_field_metainfo(field_name, 'field-metalong', -109470000042_8)
CALL ftg_add_field_metainfo(field_name, 'field-metafloat', 23.0_4)
CALL ftg_add_field_metainfo(field_name, 'field-metadouble', 109.47_8)
CALL ftg_destroy_serializer()

CALL ftg_set_serializer(dir, base_name, 'r')
CALL ftg_get_field_metainfo(field_name, 'field-metalog-t', metalog)
@assertEqual(.TRUE., metalog)
CALL ftg_get_field_metainfo(field_name, 'field-metalog-f', metalog)
@assertEqual(.FALSE., metalog)
CALL ftg_get_field_metainfo(field_name, 'field-metaint', metaint)
@assertEqual(42, metaint)
CALL ftg_get_field_metainfo(field_name, 'field-metalong', metalong)
@assertEqual(-109470000042_8, metalong)
CALL ftg_get_field_metainfo(field_name, 'field-metafloat', metafloat)
@assertEqual(23.0_4, metafloat)
CALL ftg_get_field_metainfo(field_name, 'field-metadouble', metadouble)
@assertEqual(109.47_8, metadouble)
CALL ftg_destroy_serializer()

END SUBROUTINE testFieldMetainfo

@Test
SUBROUTINE testSavepointMetainfo()

TYPE(t_savepoint) :: savepoint
CHARACTER(len=*), PARAMETER :: savepoint_name = 'test_savepoint_metainfo'

LOGICAL :: metalog
INTEGER(KIND=C_INT) :: metaint
INTEGER(KIND=C_LONG) :: metalong
REAL(KIND=C_FLOAT) :: metafloat
REAL(KIND=C_DOUBLE) :: metadouble

CALL ftg_set_savepoint(savepoint_name)

CALL ftg_add_savepoint_metainfo('metalog-t', .TRUE.)
CALL ftg_add_savepoint_metainfo('metalog-f', .FALSE.)
CALL ftg_add_savepoint_metainfo('metaint', 42)
CALL ftg_add_savepoint_metainfo('metalong', -109470000042_8)
CALL ftg_add_savepoint_metainfo('metafloat', 23.0_4)
CALL ftg_add_savepoint_metainfo('metadouble', 109.47_8)

CALL ftg_get_savepoint_metainfo('metalog-t', metalog)
@assertEqual(.TRUE., metalog)
CALL ftg_get_savepoint_metainfo('metalog-f', metalog)
@assertEqual(.FALSE., metalog)
CALL ftg_get_savepoint_metainfo('metaint', metaint)
@assertEqual(42, metaint)
CALL ftg_get_savepoint_metainfo('metalong', metalong)
@assertEqual(-109470000042_8, metalong)
CALL ftg_get_savepoint_metainfo('metafloat', metafloat)
@assertEqual(23.0_4, metafloat)
CALL ftg_get_savepoint_metainfo('metadouble', metadouble)
@assertEqual(109.47_8, metadouble)

CALL ftg_destroy_savepoint()

END SUBROUTINE testSavepointMetainfo
END MODULE ser_ftg_test

0 comments on commit 0184e51

Please sign in to comment.