4 * Purple is the legal property of its developers, whose names are too
5 * numerous to list here. Please refer to the COPYRIGHT file distributed
6 * with this source distribution
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
29 // $ cat test-image.png | hexdump -v -e '1 1 "0x%02x," " "' | xargs -n 8 echo
30 static const gsize test_image_data_len
= 160;
31 static const guint8 test_image_data
[] = {
32 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
33 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
34 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02,
35 0x08, 0x02, 0x00, 0x00, 0x00, 0xfd, 0xd4, 0x9a,
36 0x73, 0x00, 0x00, 0x00, 0x09, 0x70, 0x48, 0x59,
37 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 0x0b,
38 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00,
39 0x00, 0x07, 0x74, 0x49, 0x4d, 0x45, 0x07, 0xe0,
40 0x0a, 0x02, 0x16, 0x30, 0x22, 0x28, 0xa4, 0xc9,
41 0xdd, 0x00, 0x00, 0x00, 0x1d, 0x69, 0x54, 0x58,
42 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x72, 0x65,
44 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74,
45 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x64, 0x2e,
46 0x65, 0x07, 0x00, 0x00, 0x00, 0x16, 0x49, 0x44,
47 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0xff, 0xff,
48 0x3f, 0x03, 0x03, 0x03, 0xe3, 0xb3, 0x4c, 0xb5,
49 0x9b, 0x4e, 0x0b, 0x00, 0x2f, 0xa9, 0x06, 0x2f,
50 0x8a, 0xd1, 0xc6, 0xb3, 0x00, 0x00, 0x00, 0x00,
51 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
54 /******************************************************************************
56 *****************************************************************************/
58 _test_image(PurpleImage
*image
,
63 const gchar
*mimetype
)
66 const guint8
*adata
= NULL
;
69 g_assert(PURPLE_IS_IMAGE(image
));
71 bytes
= purple_image_get_contents(image
);
72 adata
= g_bytes_get_data(bytes
, &alen
);
73 g_assert_cmpmem(adata
, alen
, edata
, elen
);
76 /* if the caller provided a path, check it, otherwise just make sure we
80 g_assert_cmpstr(purple_image_get_path(image
), ==, path
);
82 const gchar
*apath
= purple_image_get_path(image
);
85 g_assert_cmpstr(apath
, !=, "");
88 g_assert_cmpstr(purple_image_get_extension(image
), ==, ext
);
89 g_assert_cmpstr(purple_image_get_mimetype(image
), ==, mimetype
);
91 g_object_unref(G_OBJECT(image
));
94 /******************************************************************************
96 *****************************************************************************/
98 test_image_new_from_bytes(void) {
99 GBytes
*bytes
= g_bytes_new(test_image_data
, test_image_data_len
);
100 PurpleImage
*image
= purple_image_new_from_bytes(bytes
);
104 g_bytes_get_data(bytes
, NULL
),
105 g_bytes_get_size(bytes
),
111 g_bytes_unref(bytes
);
116 test_image_new_from_data(void) {
117 PurpleImage
*image
= purple_image_new_from_data(
133 test_image_new_from_file(void) {
134 PurpleImage
*image
= NULL
;
135 GError
*error
= NULL
;
140 path
= g_build_filename(TEST_DATA_DIR
, "test-image.png", NULL
);
141 image
= purple_image_new_from_file(path
, &error
);
142 g_assert_no_error(error
);
144 g_file_get_contents(path
, &edata
, &elen
, &error
);
145 g_assert_no_error(error
);
159 /******************************************************************************
161 *****************************************************************************/
163 main(gint argc
, gchar
**argv
) {
164 g_test_init(&argc
, &argv
, NULL
);
166 g_test_set_nonfatal_assertions();
168 g_test_add_func("/image/new-from-bytes", test_image_new_from_bytes
);
169 g_test_add_func("/image/new-from-data", test_image_new_from_data
);
170 g_test_add_func("/image/new-from-file", test_image_new_from_file
);