IODA Bundle
general.f90
Go to the documentation of this file.
1 
3 
4  use odc
5  use odc_config
6  use, intrinsic :: iso_fortran_env
7  implicit none
8 
9 contains
10 
11  function test_odc_version() result(success)
12 
13  ! Test that we obtain the expected version number
14 
15  logical :: success
16  character(:), allocatable :: version_str
17 
18  success = .true.
19 
20  if (odc_version(version_str) /= odc_success) then
21  write(error_unit, *) 'getting version string failed'
22  success = .false.
23  end if
24 
25  if (version_str /= odc_version_str) then
26  write(error_unit, *) "Unexpected version: ", version_str
27  write(error_unit, *) "Expected: ", odc_version_str
28  success = .false.
29  endif
30 
31  end function
32 
33  function test_git_sha1() result(success)
34 
35  ! Test that we obtain the expected version number
36 
37  logical :: success
38  character(:), allocatable :: sha1
39 
40  success = .true.
41 
42  if (odc_vcs_version(sha1) /= odc_success) then
43  write(error_unit, *) 'getting git sha1 string failed'
44  success = .false.
45  end if
46 
47  if (sha1 /= odc_git_sha1_str .and. sha1 /= "not available") then
48  write(error_unit, *) "Unexpected git sha1: ", sha1
49  write(error_unit, *) "Expected: ", odc_git_sha1_str
50  success = .false.
51  endif
52 
53  end function
54 
55  function test_type_names() result(success)
56  logical :: success
57  integer :: test_types(6) = [odc_ignore, odc_integer, odc_real, odc_string, odc_bitfield, odc_double]
58  character(8) :: names(6) = [character(8) :: "ignore", "integer", "real", "string", "bitfield", "double"]
59  character(:), allocatable :: name
60  integer :: ntypes, n
61 
62  success = .true.
63 
64  if (odc_column_type_count(ntypes) /= odc_success) then
65  write(error_unit, *) 'Failed to get type count'
66  success = .false.
67  end if
68 
69  if (ntypes /= 6) then
70  write(error_unit, *) 'Unexpected number of types found'
71  success = .false.
72  endif
73 
74  do n = 1, ntypes
75  if (odc_column_type_name(test_types(n), name) /= odc_success) then
76  write(error_unit, *) 'Failed to get type name, type=', test_types(n)
77  success = .false.
78  end if
79 
80  if (name /= trim(names(n))) then
81  write(error_unit, *) 'Unexpected type name "', name, '" for type ', n
82  success = .false.
83  end if
84  end do
85 
86  end function
87 
88  function test_error_handling() result(success)
89  logical :: success
90  type(odc_reader) :: reader
91  integer :: j, err
92  success = .true.
93 
94  ! Check that an error is correctly reported
95 
96  do j = 1, 2
97 
98  err = reader%open_path("invalid-path")
99  if (err == odc_success) then
100  write(error_unit, *) 'open_path succeeded unexpectedly with "invalid-path"'
101  success = .false.
102  end if
103 
104  if (odc_error_string(err) /= "Cannot open invalid-path (No such file or directory)") then
105  write(error_unit, *) 'unexpected error message: ', odc_error_string(err)
106  success = .false.
107  endif
108  end do
109 
110  end function
111 
112 end module
113 
114 
116 
118  implicit none
119 
120  logical :: success
121  success = .true.
122 
123  if (odc_initialise_api() /= odc_success) then
124  write(error_unit, *) 'Failed to initialise ODC api'
125  success = .false.
126  end if
127 
128  success = success .and. test_odc_version()
129  success = success .and. test_git_sha1()
130  success = success .and. test_type_names()
131  success = success .and. test_error_handling()
132 
133  if (.not. success) stop -1
134 
135 end program
int odc_vcs_version(const char **sha1)
Definition: api/odc.cc:275
int odc_column_type_name(int type, const char **type_name)
Definition: api/odc.cc:169
int odc_initialise_api()
Definition: api/odc.cc:203
const char * odc_error_string(int err)
Definition: api/odc.cc:93
int odc_version(const char **version)
Definition: api/odc.cc:269
program fapi_general
Definition: encode.f90:421
logical function test_git_sha1()
Definition: general.f90:34
logical function test_error_handling()
Definition: general.f90:89
logical function test_type_names()
Definition: general.f90:56
logical function test_odc_version()
Definition: general.f90:12
Definition: ColumnInfo.h:23
integer(c_int), parameter, public odc_real
Definition: odc.f90:9
integer(c_int), parameter, public odc_string
Definition: odc.f90:10
integer(c_int), parameter, public odc_double
Definition: odc.f90:12
integer(c_int), parameter, public odc_bitfield
Definition: odc.f90:11
integer(c_int), parameter, public odc_ignore
Definition: odc.f90:7
integer(c_int), parameter, public odc_integer
Definition: odc.f90:8
integer, parameter, public odc_success
Definition: odc.f90:16