From 6965e39b90592e2fe44c960fbc8e1e460e70e36a Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 3 Apr 2024 19:08:50 +0200 Subject: [PATCH] Reformatting. --- README.md | 5 +++-- test/test_zstd.f90 | 44 ++++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d0f7ce5..1563d86 100644 --- a/README.md +++ b/README.md @@ -50,14 +50,15 @@ program main character(len=:), allocatable :: dst1, dst2, src integer(kind=c_size_t) :: dst_len, src_len, stat - src = repeat('Hello, there! ', 32) + src = repeat('Hello, there! ', 32) + src_len = len(src, kind=c_size_t) dst_len = zstd_compress_bound(src_len) allocate (character(len=dst_len) :: dst1) allocate (character(len=src_len) :: dst2) - stat = zstd_compress(dst1, dst_len, src, src_len, zstd_default_c_level()) + stat = zstd_compress(dst1, dst_len, src, src_len, zstd_default_c_level()) dst_len = stat if (zstd_is_error(stat)) then diff --git a/test/test_zstd.f90 b/test/test_zstd.f90 index 8cfc2f4..08ab07d 100644 --- a/test/test_zstd.f90 +++ b/test/test_zstd.f90 @@ -23,6 +23,27 @@ program main if (.not. tests(i)) error stop end do contains + integer(kind=c_size_t) function test_read(chunk, pos, to_read, src) result(nbytes) + !! Reads chunk from source `src` and returns chunk length. + character(len=*), intent(inout) :: chunk !! Output chunk. + integer(kind=c_size_t), intent(inout) :: pos !! Current cursor position. + integer(kind=c_size_t), intent(in) :: to_read !! Max. bytes to read. + character(len=*), intent(inout) :: src !! Source to read from. + + integer :: pos2 + + nbytes = 0 + if (to_read == 0) return + + pos = pos + 1 + if (pos > len(src)) return + + pos2 = min(pos + to_read, len(src, kind=c_size_t)) + chunk = src(pos:pos2) + nbytes = abs(pos2 - pos) + 1 + pos = pos2 + end function test_read + logical function test_simple() result(success) !! Simple API. character(len=:), allocatable :: dst1, dst2, src @@ -90,8 +111,8 @@ logical function test_simple_multi() result(success) allocate (character(len=dst_len) :: dst1) allocate (character(len=src_len) :: dst2) - level = zstd_default_c_level() c_ctx = zstd_create_c_ctx() + level = zstd_default_c_level() stat = zstd_compress_c_ctx(c_ctx, dst1, dst_len, src, src_len, level) stat2 = zstd_free_c_ctx(c_ctx) @@ -122,27 +143,6 @@ logical function test_simple_multi() result(success) success = .true. end function test_simple_multi - integer(kind=c_size_t) function test_read(chunk, pos, to_read, src) result(nbytes) - !! Reads chunks from source `src` and returns chunk length. - character(len=*), intent(inout) :: chunk !! Output chunk. - integer(kind=c_size_t), intent(inout) :: pos !! Current cursor position. - integer(kind=c_size_t), intent(in) :: to_read !! Max. bytes to read. - character(len=*), intent(inout) :: src !! Source to read from. - - integer :: pos2 - - nbytes = 0 - if (to_read == 0) return - - pos = pos + 1 - if (pos > len(src)) return - - pos2 = min(pos + to_read, len(src, kind=c_size_t)) - chunk = src(pos:pos2) - nbytes = abs(pos2 - pos) + 1 - pos = pos2 - end function test_read - logical function test_stream() result(success) !! Streaming API. character(len=:), allocatable :: dst, src1, src2