Standardize all protocol header guard macros.
[pidgin-git.git] / libpurple / tests / test_smiley.c
blob4664a2066e7cb921b0dc9ac16265951310c3dcaa
1 /*
2 * Purple
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
23 #include <glib.h>
24 #include <string.h>
26 #include <purple.h>
28 // generated via:
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 /******************************************************************************
55 * Helpers
56 *****************************************************************************/
57 static void
58 _test_smiley(PurpleSmiley *smiley,
59 const gchar *path,
60 const guint8 *edata,
61 gsize elen,
62 const gchar *ext,
63 const gchar *mimetype,
64 const gchar *shortcut)
66 GBytes *bytes = NULL;
67 const guint8 *adata = NULL;
68 gsize alen;
70 g_assert(PURPLE_IS_SMILEY(PURPLE_IMAGE(smiley)));
72 bytes = purple_image_get_contents(PURPLE_IMAGE(smiley));
73 adata = g_bytes_get_data(bytes, &alen);
74 g_assert_cmpmem(adata, alen, edata, elen);
75 g_bytes_unref(bytes);
77 g_assert_cmpstr(
78 purple_image_get_extension(PURPLE_IMAGE(smiley)),
79 ==,
80 ext
82 g_assert_cmpstr(
83 purple_image_get_mimetype(PURPLE_IMAGE(smiley)),
84 ==,
85 mimetype
87 g_assert_cmpstr(purple_smiley_get_shortcut(smiley), ==, shortcut);
89 if(path)
90 g_assert_cmpstr(purple_image_get_path(PURPLE_IMAGE(smiley)), ==, path);
92 g_object_unref(G_OBJECT(smiley));
95 /******************************************************************************
96 * Tests
97 *****************************************************************************/
98 static void
99 test_smiley_new_from_data(void) {
100 PurpleSmiley *smiley = purple_smiley_new_from_data(
101 ":-X",
102 test_image_data,
103 test_image_data_len
106 _test_smiley(
107 smiley,
108 NULL,
109 test_image_data,
110 test_image_data_len,
111 "png",
112 "image/png",
113 ":-X"
117 static void
118 test_smiley_new_from_file(void) {
119 PurpleSmiley *smiley = NULL;
120 GError *error = NULL;
121 gchar *path = NULL;
122 gchar *edata = NULL;
123 gsize elen;
125 path = g_build_filename(TEST_DATA_DIR, "test-image.png", NULL);
126 smiley = purple_smiley_new("^_^", path);
127 g_assert_no_error(error);
129 g_file_get_contents(path, &edata, &elen, &error);
130 g_assert_no_error(error);
132 _test_smiley(
133 smiley,
134 path,
135 (guint8 *)edata,
136 elen,
137 "png",
138 "image/png",
139 "^_^"
142 g_free(path);
145 /******************************************************************************
146 * Main
147 *****************************************************************************/
148 gint
149 main(gint argc, gchar **argv) {
150 g_test_init(&argc, &argv, NULL);
152 g_test_set_nonfatal_assertions();
154 g_test_add_func("/smiley/new-from-data", test_smiley_new_from_data);
155 g_test_add_func("/smiley/new-from-file", test_smiley_new_from_file);
157 return g_test_run();