diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-29 04:41:38 +0000 |
commit | 7b6e527f440cd7e6f8be2b07cee320ee6ca18786 (patch) | |
tree | 4a2738d69fa2814659fdadddf5826282e73d81f4 /test cases/fortran/10 find library | |
parent | Initial commit. (diff) | |
download | meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.tar.xz meson-7b6e527f440cd7e6f8be2b07cee320ee6ca18786.zip |
Adding upstream version 1.0.1.upstream/1.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test cases/fortran/10 find library')
-rw-r--r-- | test cases/fortran/10 find library/gzip.f90 | 32 | ||||
-rw-r--r-- | test cases/fortran/10 find library/main.f90 | 38 | ||||
-rw-r--r-- | test cases/fortran/10 find library/meson.build | 13 |
3 files changed, 83 insertions, 0 deletions
diff --git a/test cases/fortran/10 find library/gzip.f90 b/test cases/fortran/10 find library/gzip.f90 new file mode 100644 index 0000000..32f21d7 --- /dev/null +++ b/test cases/fortran/10 find library/gzip.f90 @@ -0,0 +1,32 @@ +module gzip + +use iso_c_binding, only: c_char, c_ptr, c_int +implicit none + +interface +type(c_ptr) function gzopen(path, mode) bind(C) +import c_char, c_ptr + +character(kind=c_char), intent(in) :: path(*), mode(*) +end function gzopen +end interface + +interface +integer(c_int) function gzwrite(file, buf, len) bind(C) +import c_int, c_ptr, c_char + +type(c_ptr), value, intent(in) :: file +character(kind=c_char), intent(in) :: buf +integer(c_int), value, intent(in) :: len +end function gzwrite +end interface + +interface +integer(c_int) function gzclose(file) bind(C) +import c_int, c_ptr + +type(c_ptr), value, intent(in) :: file +end function gzclose +end interface + +end module gzip diff --git a/test cases/fortran/10 find library/main.f90 b/test cases/fortran/10 find library/main.f90 new file mode 100644 index 0000000..e885d30 --- /dev/null +++ b/test cases/fortran/10 find library/main.f90 @@ -0,0 +1,38 @@ +program main +use iso_fortran_env, only: stderr=>error_unit +use iso_c_binding, only: c_int, c_char, c_null_char, c_ptr +use gzip, only: gzopen, gzwrite, gzclose + +implicit none + +character(kind=c_char,len=*), parameter :: path = c_char_"test.gz"//c_null_char +character(kind=c_char,len=*), parameter :: mode = c_char_"wb9"//c_null_char +integer(c_int), parameter :: buffer_size = 512 + +type(c_ptr) :: file +character(kind=c_char, len=buffer_size) :: buffer +integer(c_int) :: ret +integer :: i + +! open file +file = gzopen(path, mode) + +! fill buffer with data +do i=1,buffer_size/4 + write(buffer(4*(i-1)+1:4*i), '(i3.3, a)') i, new_line('') +end do +ret = gzwrite(file, buffer, buffer_size) +if (ret /= buffer_size) then + write(stderr,'(a, i3, a, i3, a)') 'Error: ', ret, ' / ', buffer_size, & + ' bytes written.' + stop 1 +end if + +! close file +ret = gzclose(file) +if (ret /= 0) then + write(stderr,*) 'Error: failure to close file with error code ', ret + stop 1 +end if + +end program diff --git a/test cases/fortran/10 find library/meson.build b/test cases/fortran/10 find library/meson.build new file mode 100644 index 0000000..2a2ef31 --- /dev/null +++ b/test cases/fortran/10 find library/meson.build @@ -0,0 +1,13 @@ +project('find fortran library', 'fortran') + +fc = meson.get_compiler('fortran') + +sources = ['main.f90', 'gzip.f90'] +zlib = fc.find_library('z', required: false) + +if not zlib.found() + error('MESON_SKIP_TEST: Z library not available.') +endif + +exe = executable('zlibtest', sources, dependencies : zlib) +test('testzlib', exe) |