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
28 /******************************************************************************
30 *****************************************************************************/
32 /* This test just verifies that purple_circular_buffer_new creates this
33 * properly according to the docs.
36 test_circular_buffer_new(void) {
37 PurpleCircularBuffer
*buffer
= purple_circular_buffer_new(0);
39 g_assert_true(PURPLE_IS_CIRCULAR_BUFFER(buffer
));
41 g_assert_cmpuint(256, ==, purple_circular_buffer_get_grow_size(buffer
));
42 g_assert_cmpuint(0, ==, purple_circular_buffer_get_used(buffer
));
43 g_assert_cmpuint(0, ==, purple_circular_buffer_get_max_read(buffer
));
45 g_object_unref(buffer
);
48 /* This test make sure that purple_circular_buffer_reset works as described in
52 test_circular_buffer_reset(void) {
53 PurpleCircularBuffer
*buffer
= purple_circular_buffer_new(0);
56 purple_circular_buffer_append(buffer
, "abc\0", 4);
57 g_assert_cmpuint(4, ==, purple_circular_buffer_get_used(buffer
));
58 g_assert_cmpuint(4, ==, purple_circular_buffer_get_max_read(buffer
));
60 purple_circular_buffer_get_output(buffer
);
61 data
= purple_circular_buffer_get_output(buffer
);
62 g_assert_cmpstr("abc", ==, data
);
64 purple_circular_buffer_reset(buffer
);
66 data
= purple_circular_buffer_get_output(buffer
);
67 g_assert_cmpstr("abc", ==, data
);
69 g_object_unref(buffer
);
72 /* This test verifies that purple_circular_buffer_mark_read works as described
73 * in the documentation.
76 test_circular_buffer_mark_read(void) {
77 PurpleCircularBuffer
*buffer
= purple_circular_buffer_new(0);
80 purple_circular_buffer_append(buffer
, "abc\0", 4);
81 g_assert_cmpuint(4, ==, purple_circular_buffer_get_used(buffer
));
82 g_assert_cmpuint(4, ==, purple_circular_buffer_get_max_read(buffer
));
84 /* force a read to move the output */
85 purple_circular_buffer_get_output(buffer
);
86 data
= purple_circular_buffer_get_output(buffer
);
87 g_assert_cmpstr("abc", ==, data
);
89 purple_circular_buffer_mark_read(buffer
, 4);
91 g_assert_cmpuint(0, ==, purple_circular_buffer_get_used(buffer
));
92 g_assert_cmpuint(0, ==, purple_circular_buffer_get_max_read(buffer
));
94 g_object_unref(buffer
);
97 /* this test verifies that the buffer will grow 1 grow size to fit the data. */
99 test_circular_buffer_single_default_grow(void) {
100 PurpleCircularBuffer
*buffer
= purple_circular_buffer_new(0);
103 purple_circular_buffer_append(buffer
, "abc\0", 4);
105 g_assert_cmpuint(4, ==, purple_circular_buffer_get_used(buffer
));
106 g_assert_cmpuint(4, ==, purple_circular_buffer_get_max_read(buffer
));
108 data
= purple_circular_buffer_get_output(buffer
);
110 g_assert_cmpstr("abc", ==, data
);
112 g_object_unref(buffer
);
115 /* this test create a circular buffer with a grow size of 1 to easily test
119 test_circular_buffer_multiple_grows(void) {
120 PurpleCircularBuffer
*buffer
= purple_circular_buffer_new(1);
122 purple_circular_buffer_append(buffer
, "abcdefghijklmnopqrstuvwxyz\0", 27);
124 g_assert_cmpuint(27, ==, purple_circular_buffer_get_used(buffer
));
125 g_assert_cmpuint(27, ==, purple_circular_buffer_get_max_read(buffer
));
127 g_assert_cmpstr("abcdefghijklmnopqrstuvwxyz", ==, purple_circular_buffer_get_output(buffer
));
129 g_object_unref(buffer
);
132 /******************************************************************************
134 *****************************************************************************/
136 main(gint argc
, gchar
**argv
) {
137 g_test_init(&argc
, &argv
, NULL
);
139 g_test_set_nonfatal_assertions();
141 g_test_add_func("/circular_buffer/new", test_circular_buffer_new
);
142 g_test_add_func("/circular_buffer/reset", test_circular_buffer_reset
);
143 g_test_add_func("/circular_buffer/mark_read", test_circular_buffer_mark_read
);
144 g_test_add_func("/circular_buffer/single_default_grow", test_circular_buffer_single_default_grow
);
145 g_test_add_func("/circular_buffer/multiple_grows", test_circular_buffer_multiple_grows
);