| File: | _build/../tests/pixbuf-threads.c |
| Warning: | line 46, column 16 File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* -*- Mode: C; c-basic-offset: 2; -*- */ | |||
| 2 | /* CdkPixbuf library - test loaders | |||
| 3 | * | |||
| 4 | * Copyright (C) 2004 Matthias Clasen <mclasen@redhat.com> | |||
| 5 | * | |||
| 6 | * This program is free software; you can redistribute it and/or modify | |||
| 7 | * it under the terms of the GNU General Public License as published by | |||
| 8 | * the Free Software Foundation; either version 2 of the License, or | |||
| 9 | * (at your option) any later version. | |||
| 10 | * | |||
| 11 | * This program is distributed in the hope that it will be useful, | |||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| 14 | * GNU General Public License for more details. | |||
| 15 | * | |||
| 16 | * You should have received a copy of the GNU General Public License | |||
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |||
| 18 | */ | |||
| 19 | ||||
| 20 | #include "config.h" | |||
| 21 | #include <glib/gstdio.h> | |||
| 22 | #include "cdk-pixbuf/cdk-pixbuf.h" | |||
| 23 | #include "test-common.h" | |||
| 24 | ||||
| 25 | static void | |||
| 26 | load_image (gpointer data, | |||
| 27 | gpointer user_data) | |||
| 28 | { | |||
| 29 | gchar *filename = data; | |||
| 30 | const gchar *path; | |||
| 31 | FILE *file; | |||
| 32 | int nbytes; | |||
| 33 | guchar buffer[1024]; | |||
| 34 | CdkPixbufLoader *loader; | |||
| 35 | GError *error = NULL((void*)0); | |||
| 36 | ||||
| 37 | loader = cdk_pixbuf_loader_new (); | |||
| 38 | path = g_test_get_filename (G_TEST_DIST, "test-images/randomly-modified", filename, NULL((void*)0)); | |||
| 39 | ||||
| 40 | g_test_message ("reading %s", path); | |||
| 41 | file = g_fopenfopen (path, "rb"); | |||
| 42 | g_assert (file != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_11 = 0; if (file != ((void*)0)) _g_boolean_var_11 = 1; _g_boolean_var_11 ; }), 1)) ; else g_assertion_message_expr (((gchar*) 0), "../tests/pixbuf-threads.c" , 42, ((const char*) (__func__)), "file != NULL"); } while (0 ); | |||
| ||||
| 43 | ||||
| 44 | while (!feof (file)) | |||
| 45 | { | |||
| 46 | nbytes = fread (buffer, 1, sizeof (buffer), file); | |||
| ||||
| 47 | cdk_pixbuf_loader_write (loader, buffer, nbytes, &error); | |||
| 48 | g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "../tests/pixbuf-threads.c" , 48, ((const char*) (__func__)), "error", error, 0, 0); } while (0); | |||
| 49 | g_thread_yield (); | |||
| 50 | } | |||
| 51 | ||||
| 52 | fclose (file); | |||
| 53 | ||||
| 54 | cdk_pixbuf_loader_close (loader, &error); | |||
| 55 | ||||
| 56 | if (g_error_matches (error, CDK_PIXBUF_ERRORcdk_pixbuf_error_quark (), CDK_PIXBUF_ERROR_UNKNOWN_TYPE)) | |||
| 57 | { | |||
| 58 | g_test_message ("Unsupported format"); | |||
| 59 | g_clear_error (&error); | |||
| 60 | } | |||
| 61 | ||||
| 62 | g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "../tests/pixbuf-threads.c" , 62, ((const char*) (__func__)), "error", error, 0, 0); } while (0); | |||
| 63 | ||||
| 64 | g_object_unref (loader); | |||
| 65 | } | |||
| 66 | ||||
| 67 | static void | |||
| 68 | test_threads (void) | |||
| 69 | { | |||
| 70 | GThreadPool *pool; | |||
| 71 | gint iterations; | |||
| 72 | gint i; | |||
| 73 | ||||
| 74 | pool = g_thread_pool_new (load_image, NULL((void*)0), 20, FALSE(0), NULL((void*)0)); | |||
| 75 | ||||
| 76 | if (g_test_thorough ()(!g_test_config_vars->test_quick)) | |||
| 77 | iterations = 100; | |||
| 78 | else | |||
| 79 | iterations = 1; | |||
| 80 | ||||
| 81 | for (i = 0; i < iterations; i++) | |||
| 82 | { | |||
| 83 | if (format_supported ("jpeg")) | |||
| 84 | g_thread_pool_push (pool, "valid.1.jpeg", NULL((void*)0)); | |||
| 85 | if (format_supported ("png")) | |||
| 86 | g_thread_pool_push (pool, "valid.1.png", NULL((void*)0)); | |||
| 87 | if (format_supported ("gif")) | |||
| 88 | g_thread_pool_push (pool, "valid.1.gif", NULL((void*)0)); | |||
| 89 | if (format_supported ("bmp")) | |||
| 90 | g_thread_pool_push (pool, "valid.1.bmp", NULL((void*)0)); | |||
| 91 | if (format_supported ("jpeg")) | |||
| 92 | g_thread_pool_push (pool, "valid.2.jpeg", NULL((void*)0)); | |||
| 93 | if (format_supported ("xpm")) | |||
| 94 | g_thread_pool_push (pool, "valid.1.xpm", NULL((void*)0)); | |||
| 95 | if (format_supported ("tga")) | |||
| 96 | g_thread_pool_push (pool, "valid.1.tga", NULL((void*)0)); | |||
| 97 | if (format_supported ("tiff")) | |||
| 98 | g_thread_pool_push (pool, "valid.1.tiff", NULL((void*)0)); | |||
| 99 | } | |||
| 100 | ||||
| 101 | g_thread_pool_free (pool, FALSE(0), TRUE(!(0))); | |||
| 102 | } | |||
| 103 | ||||
| 104 | int | |||
| 105 | main (int argc, char **argv) | |||
| 106 | { | |||
| 107 | g_test_init (&argc, &argv, NULL((void*)0)); | |||
| 108 | ||||
| 109 | g_test_add_func ("/pixbuf/threads", test_threads); | |||
| 110 | ||||
| 111 | return g_test_run (); | |||
| 112 | } |