GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test-qof-string-cache.c
1 
2 /********************************************************************
3  * test-qof-string-cache.c: GLib g_test test suite for string cache *
4  * functions *
5  * Copyright 2011 Christian Stimming *
6  * Copyright 2011 John Ralls <[email protected]> *
7  * Copyright 2012 Phil Longstaff <[email protected]> *
8  * *
9  * This program is free software; you can redistribute it and/or *
10  * modify it under the terms of the GNU General Public License as *
11  * published by the Free Software Foundation; either version 2 of *
12  * the License, or (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License*
20  * along with this program; if not, contact: *
21  * *
22  * Free Software Foundation Voice: +1-617-542-5942 *
23  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
24  * Boston, MA 02110-1301, USA [email protected] *
25 \********************************************************************/
26 
27 #include "config.h"
28 #include <string.h>
29 #include <glib.h>
30 #include <unittest-support.h>
31 #include "qof.h"
32 
33 static const gchar *suitename = "/qof/qof-string-cache";
34 void test_suite_qof_string_cache ( void );
35 
36 typedef struct
37 {
38 } Fixture;
39 
40 G_GNUC_UNUSED static void
41 setup( Fixture *fixture, gconstpointer pData )
42 {
44 }
45 
46 G_GNUC_UNUSED static void
47 teardown( Fixture *fixture, gconstpointer pData )
48 {
50 }
51 
52 static void
53 test_qof_string_cache( void )
54 {
55  /* Strings added to the cache should always return the same string address
56  * as long as the refcount > 0. */
57  gchar str[100];
58  gchar* str1_1;
59  gchar* str1_2;
60  gchar* str1_3;
61  gchar* str1_4;
62 
63  strncpy(str, "str1", sizeof(str));
64  str1_1 = qof_string_cache_insert(str); /* Refcount = 1 */
65  g_assert(str1_1 != str);
66  str1_2 = qof_string_cache_insert(str); /* Refcount = 2 */
67  g_assert(str1_1 == str1_2);
68  qof_string_cache_remove(str); /* Refcount = 1 */
69  str1_3 = qof_string_cache_insert(str); /* Refcount = 2 */
70  g_assert(str1_1 == str1_3);
71  qof_string_cache_remove(str); /* Refcount = 1 */
72  qof_string_cache_remove(str); /* Refcount = 0 */
73  strncpy(str, "str2", sizeof(str));
74  qof_string_cache_insert(str); /* Refcount = 1 */
75  strncpy(str, "str1", sizeof(str));
76  str1_4 = qof_string_cache_insert(str); /* Refcount = 1 */
77  g_assert(str1_1 != str1_4);
78 }
79 
80 void
81 test_suite_qof_string_cache ( void )
82 {
83  GNC_TEST_ADD_FUNC( suitename, "string-cache", test_qof_string_cache);
84 }
void qof_string_cache_destroy(void)
void qof_string_cache_remove(gconstpointer key)
gpointer qof_string_cache_insert(gconstpointer key)
void qof_string_cache_init(void)