From 41c08b0ffb183ee7b031c34f5eebc6e2adb6d974 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 10 Nov 2019 12:30:21 +0100 Subject: [PATCH] Add svgload_stream to the descriptors test Seems to work! --- libvips/foreign/svgload.c | 3 +-- libvips/iofuncs/streami.c | 5 +---- libvips/iofuncs/streamiw.c | 33 ++++++++++++++++----------------- test/test-suite/test_stream.py | 8 ++++---- test/test_descriptors.c | 6 +++++- test/test_descriptors.sh | 12 ++++++++---- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/libvips/foreign/svgload.c b/libvips/foreign/svgload.c index ccd8039a..6becdaff 100644 --- a/libvips/foreign/svgload.c +++ b/libvips/foreign/svgload.c @@ -475,8 +475,7 @@ vips_foreign_load_svg_stream_is_a( VipsStreami *input ) { ssize_t n; - if( vips_streami_unminimise( input ) || - vips_streami_rewind( input ) ) + if( vips_streami_rewind( input ) ) return( FALSE ); g_byte_array_set_size( input->sniff, SVG_HEADER_SIZE ); diff --git a/libvips/iofuncs/streami.c b/libvips/iofuncs/streami.c index 5ec4a7e9..c1dd8b09 100644 --- a/libvips/iofuncs/streami.c +++ b/libvips/iofuncs/streami.c @@ -898,7 +898,6 @@ vips_streami_seek( VipsStreami *streami, gint64 offset, int whence ) vips_error( vips_stream_nick( VIPS_STREAM( streami ) ), "%s", _( "bad 'whence'" ) ); return( -1 ); - break; } } else if( streami->is_pipe ) { @@ -926,7 +925,6 @@ vips_streami_seek( VipsStreami *streami, gint64 offset, int whence ) vips_error( vips_stream_nick( VIPS_STREAM( streami ) ), "%s", _( "bad 'whence'" ) ); return( -1 ); - break; } } else { @@ -1029,8 +1027,7 @@ vips_streami_sniff( VipsStreami *streami, size_t length ) SANITY( streami ); - if( vips_streami_unminimise( streami ) || - vips_streami_rewind( streami ) ) + if( vips_streami_rewind( streami ) ) return( NULL ); g_byte_array_set_size( streami->sniff, length ); diff --git a/libvips/iofuncs/streamiw.c b/libvips/iofuncs/streamiw.c index c510dc82..13046236 100644 --- a/libvips/iofuncs/streamiw.c +++ b/libvips/iofuncs/streamiw.c @@ -78,7 +78,7 @@ vips_streamiw_get_property( GObject *object, guint prop_id, { VipsStreamiw *streamiw = VIPS_STREAMIW( object ); - switch (prop_id) { + switch( prop_id ) { case PROP_STREAM: g_value_set_object( value, streamiw->streami ); break; @@ -89,11 +89,11 @@ vips_streamiw_get_property( GObject *object, guint prop_id, static void vips_streamiw_set_property( GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) + const GValue *value, GParamSpec *pspec ) { VipsStreamiw *streamiw = VIPS_STREAMIW( object ); - switch (prop_id) { + switch( prop_id ) { case PROP_STREAM: streamiw->streami = g_value_dup_object( value ); break; @@ -125,9 +125,9 @@ vips_streamiw_tell( GSeekable *seekable ) pos = vips_streami_seek( streami, 0, SEEK_CUR ); if( pos == -1 ) - return 0; + return( 0 ); - return pos; + return( pos ); } static gboolean @@ -135,22 +135,22 @@ vips_streamiw_can_seek( GSeekable *seekable ) { VipsStreami *streami = VIPS_STREAMIW( seekable )->streami; - VIPS_DEBUG_MSG( "vips_streamiw_can_seek: %d\n", !streami->is_pipe); + VIPS_DEBUG_MSG( "vips_streamiw_can_seek: %d\n", !streami->is_pipe ); - return !streami->is_pipe; + return( !streami->is_pipe ); } static int seek_type_to_lseek( GSeekType type ) { - switch (type) { + switch( type ) { default: case G_SEEK_CUR: - return SEEK_CUR; + return( SEEK_CUR ); case G_SEEK_SET: - return SEEK_SET; + return( SEEK_SET ); case G_SEEK_END: - return SEEK_END; + return( SEEK_END ); } } @@ -206,7 +206,7 @@ vips_streamiw_read( GInputStream *stream, void *buffer, gsize count, VIPS_DEBUG_MSG( "vips_streamiw_read: count: %zd\n", count ); - if ( g_cancellable_set_error_if_cancelled( cancellable, error ) ) + if( g_cancellable_set_error_if_cancelled( cancellable, error ) ) return( -1 ); if( (res = vips_streami_read( streami, buffer, count )) == -1 ) @@ -234,14 +234,13 @@ vips_streamiw_skip( GInputStream *stream, gsize count, return( -1 ); start = vips_streami_seek( streami, 0, SEEK_CUR ); - if( start == -1 ) { g_set_error( error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Error while seeking: %s"), vips_error_buffer() ); - return -1; + return( -1 ); } end = vips_streami_seek( streami, 0, SEEK_END ); @@ -251,7 +250,7 @@ vips_streamiw_skip( GInputStream *stream, gsize count, G_IO_ERROR_FAILED, _("Error while seeking: %s"), vips_error_buffer() ); - return -1; + return( -1 ); } if( end - start > count ) @@ -264,7 +263,7 @@ vips_streamiw_skip( GInputStream *stream, gsize count, G_IO_ERROR_FAILED, _("Error while seeking: %s"), vips_error_buffer() ); - return -1; + return( -1 ); } } @@ -311,7 +310,7 @@ vips_streamiw_class_init( VipsStreamiwClass *class ) _("Input"), _("Stream to wrap"), VIPS_TYPE_STREAMI, G_PARAM_CONSTRUCT_ONLY | - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS) ); + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS ) ); } diff --git a/test/test-suite/test_stream.py b/test/test-suite/test_stream.py index 9c721ca2..03a6ecbd 100644 --- a/test/test-suite/test_stream.py +++ b/test/test-suite/test_stream.py @@ -44,7 +44,7 @@ class TestStream: assert x.filename() == JPEG_FILE - @skip_if_no("jpegload") + @skip_if_no("jpegload_stream") def test_image_new_from_stream_filename(self): x = pyvips.Streami.new_from_filename(JPEG_FILE) y = pyvips.Image.new_from_stream(x, "") @@ -58,7 +58,7 @@ class TestStream: assert x.filename() == filename - @skip_if_no("jpegload") + @skip_if_no("jpegload_stream") def test_image_write_to_stream_filename(self): filename = temp_filename(self.tempdir, ".jpg") x = pyvips.Streamo.new_to_filename(filename) @@ -75,7 +75,7 @@ class TestStream: assert x.filename() == None - @skip_if_no("jpegload") + @skip_if_no("jpegload_stream") def test_image_new_from_stream_memory(self): data = self.colour.write_to_buffer(".jpg") x = pyvips.Streami.new_from_memory(data) @@ -89,7 +89,7 @@ class TestStream: assert x.filename() == None - @skip_if_no("jpegload") + @skip_if_no("jpegload_stream") def test_image_write_to_stream_filename(self): x = pyvips.Streamo.new_to_memory() self.colour.write_to_stream(x, ".jpg") diff --git a/test/test_descriptors.c b/test/test_descriptors.c index c0b183e6..27950e6e 100644 --- a/test/test_descriptors.c +++ b/test/test_descriptors.c @@ -31,6 +31,7 @@ count_files( const char *dirname ) int main( int argc, char **argv ) { + VipsStreami *streami; VipsImage *image, *x; char fd_dir[256]; int n_files; @@ -56,7 +57,9 @@ main( int argc, char **argv ) /* Opening an image should read the header, then close the fd. */ printf( "** seq open ..\n" ); - if( !(image = vips_image_new_from_file( argv[1], + if( !(streami = vips_streami_new_from_filename( argv[1] )) ) + vips_error_exit( NULL ); + if( !(image = vips_image_new_from_stream( streami, "", "access", VIPS_ACCESS_SEQUENTIAL, NULL )) ) vips_error_exit( NULL ); @@ -92,6 +95,7 @@ main( int argc, char **argv ) */ printf( "** unref ..\n" ); g_object_unref( image ); + g_object_unref( streami ); printf( "** shutdown ..\n" ); vips_shutdown(); diff --git a/test/test_descriptors.sh b/test/test_descriptors.sh index a2fcd6ff..b708d6f5 100755 --- a/test/test_descriptors.sh +++ b/test/test_descriptors.sh @@ -10,18 +10,22 @@ set -e . ./variables.sh -if test_supported jpegload; then +if test_supported jpegload_stream; then ./test_descriptors $image fi -if test_supported pngload; then +if test_supported pngload_stream; then ./test_descriptors $test_images/sample.png fi -if test_supported tiffload; then +if test_supported tiffload_stream; then ./test_descriptors $test_images/sample.tif fi -if test_supported radload; then +if test_supported radload_stream; then ./test_descriptors $test_images/sample.hdr fi + +if test_supported svgload_stream; then + ./test_descriptors $test_images/logo.svg +fi