1 | /* -*- Mode: C; c-basic-offset: 2; -*- */ |
2 | /* GdkPixbuf 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 "gdk-pixbuf/gdk-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 | GdkPixbufLoader *loader; |
35 | GError *error = NULL; |
36 | |
37 | loader = gdk_pixbuf_loader_new (); |
38 | path = g_test_get_filename (file_type: G_TEST_DIST, first_path: "test-images/randomly-modified" , filename, NULL); |
39 | |
40 | g_test_message (format: "reading %s" , path); |
41 | file = g_fopen (filename: path, modes: "rb" ); |
42 | g_assert (file != NULL); |
43 | |
44 | while (!feof (stream: file)) |
45 | { |
46 | nbytes = fread (ptr: buffer, size: 1, n: sizeof (buffer), stream: file); |
47 | gdk_pixbuf_loader_write (loader, buf: buffer, count: nbytes, error: &error); |
48 | g_assert_no_error (error); |
49 | g_thread_yield (); |
50 | } |
51 | |
52 | fclose (stream: file); |
53 | |
54 | gdk_pixbuf_loader_close (loader, error: &error); |
55 | g_assert_no_error (error); |
56 | |
57 | g_object_unref (object: loader); |
58 | } |
59 | |
60 | static void |
61 | test_threads (void) |
62 | { |
63 | GThreadPool *pool; |
64 | gint iterations; |
65 | gint i; |
66 | |
67 | pool = g_thread_pool_new (func: load_image, NULL, max_threads: 20, FALSE, NULL); |
68 | |
69 | if (g_test_thorough ()) |
70 | iterations = 100; |
71 | else |
72 | iterations = 1; |
73 | |
74 | for (i = 0; i < iterations; i++) |
75 | { |
76 | if (format_supported (filename: "jpeg" )) |
77 | g_thread_pool_push (pool, data: "valid.1.jpeg" , NULL); |
78 | if (format_supported (filename: "png" )) |
79 | g_thread_pool_push (pool, data: "valid.1.png" , NULL); |
80 | if (format_supported (filename: "gif" )) |
81 | g_thread_pool_push (pool, data: "valid.1.gif" , NULL); |
82 | if (format_supported (filename: "bmp" )) |
83 | g_thread_pool_push (pool, data: "valid.1.bmp" , NULL); |
84 | if (format_supported (filename: "jpeg" )) |
85 | g_thread_pool_push (pool, data: "valid.2.jpeg" , NULL); |
86 | if (format_supported (filename: "xpm" )) |
87 | g_thread_pool_push (pool, data: "valid.1.xpm" , NULL); |
88 | if (format_supported (filename: "tga" )) |
89 | g_thread_pool_push (pool, data: "valid.1.tga" , NULL); |
90 | if (format_supported (filename: "tiff" )) |
91 | g_thread_pool_push (pool, data: "valid.1.tiff" , NULL); |
92 | } |
93 | |
94 | g_thread_pool_free (pool, FALSE, TRUE); |
95 | } |
96 | |
97 | int |
98 | main (int argc, char **argv) |
99 | { |
100 | g_test_init (argc: &argc, argv: &argv, NULL); |
101 | |
102 | g_test_add_func (testpath: "/pixbuf/threads" , test_func: test_threads); |
103 | |
104 | return g_test_run (); |
105 | } |
106 | |