QOF: test-querynew.c Source File

QOF 0.7.5

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

test-querynew.c
1 /***************************************************************************
2 * test-querynew.c
3 *
4 * Copyright 2004 Linas Vepstas <linas@linas.org>
5 ****************************************************************************/
6 /*
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
20 */
21
22 #include <glib.h>
23 #include <stdio.h>
24
25 #include "qof.h"
26 #include "qofclass-p.h"
27 #include "qofquerycore-p.h"
28
29 #include "test-stuff.h"
30
31 #define TEST_MODULE_NAME "TestModuleName"
32 #define TEST_MODULE_DESC "Test Object"
33 #define TEST_CORE "TestCoreType"
34 #define TEST_PARAM "test-param"
35 #define BAD_PARAM "bad-param"
36
37 static void
38 obj_foreach (QofCollection * col,
39 QofEntityForeachCB cb __attribute__ ((unused)), gpointer u_d)
40 {
41 int *foo = u_d;
42
43 do_test (col != NULL, "foreach: NULL collection");
44 success ("called foreach callback");
45
46 *foo = 1;
47 }
48
49 static const char *
50 printable (gpointer obj)
51 {
52 do_test (obj != NULL, "printable: object is NULL");
53 success ("called printable callback");
54 return ((const gchar *) obj);
55 }
56
57 static QofObject bus_obj = {
58 .interface_version = QOF_OBJECT_VERSION,
59 .e_type = TEST_MODULE_NAME,
60 .type_label = TEST_MODULE_DESC,
61 .create = NULL,
62 .book_begin = NULL,
63 .book_end = NULL,
64 .is_dirty = NULL,
65 .mark_clean = NULL,
66 .foreach = obj_foreach,
67 .printable = printable,
68 .version_cmp = NULL,
69 };
70
71 static int
72 test_sort (gpointer a __attribute__ ((unused)), gpointer b __attribute__ ((unused)))
73 {
74 return 0;
75 }
76
77 static int
78 test_core_param (gpointer a __attribute__ ((unused)))
79 {
80 return 0;
81 }
82
83 static void
84 test_class (void)
85 {
86 static QofParam params[] = {
87 {TEST_PARAM, TEST_CORE, (QofAccessFunc) test_core_param,
88 NULL, NULL},
89 {NULL, NULL, NULL, NULL, NULL},
90 };
91
92 fprintf (stderr, "\tTesting the qof_query_object interface. \n"
93 "\tYou may see some \"** CRITICAL **\" messages, which you can safely ignore\n");
94 do_test (qof_object_register (&bus_obj), "register test object");
95
96 qof_class_register (TEST_MODULE_NAME, (QofSortFunc) test_sort, params);
97
98 do_test (qof_class_get_parameter (TEST_MODULE_NAME, TEST_PARAM)
99 == &params[0], "qof_class_get_parameter");
100 do_test (qof_class_get_parameter (NULL, NULL) == NULL,
101 "qof_class_get_parameter (NULL, NULL)");
102 do_test (qof_class_get_parameter (TEST_MODULE_NAME, NULL) == NULL,
103 "qof_class_get_parameter (TEST_MODULE_NAME, NULL)");
104 do_test (qof_class_get_parameter (TEST_MODULE_NAME, BAD_PARAM) == NULL,
105 "qof_class_get_parameter (TEST_MODULE_NAME, BAD_PARAM)");
106 do_test (qof_class_get_parameter (NULL, TEST_PARAM) == NULL,
107 "qof_class_get_parameter (NULL, TEST_PARAM)");
108
109 do_test (qof_class_get_parameter_getter (TEST_MODULE_NAME, TEST_PARAM)
110 == (QofAccessFunc) test_core_param,
111 "qof_class_get_parameter_getter");
112
113 do_test (safe_strcmp (qof_class_get_parameter_type (TEST_MODULE_NAME,
114 TEST_PARAM),
115 TEST_CORE) == 0, "qof_class_get_parameter_type");
116
117 do_test (qof_class_get_default_sort (TEST_MODULE_NAME) ==
118 (QofSortFunc) test_sort, "qof_class_get_default_sort");
119 do_test (qof_class_get_default_sort (NULL) == NULL,
120 "qof_class_get_default_sort (NULL)");
121 }
122
123 static void
124 test_query_core (void)
125 {
126
127 }
128
129 static void
130 test_querynew (void)
131 {
132 }
133
134 int
135 main (void)
136 {
137 qof_init ();
138 test_query_core ();
139 test_class ();
140 test_querynew ();
141 print_test_results ();
142 qof_close ();
143 return get_rv ();
144 }
_QofParam
Definition: qofclass.h:195
QOF_OBJECT_VERSION
#define QOF_OBJECT_VERSION
Definition: qofobject.h:57
qof_class_register
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
registers a new object class with the Qof subsystem.
Definition: qofclass.c:93
QofEntityForeachCB
void(* QofEntityForeachCB)(QofEntity *, gpointer user_data)
Definition: qofid.h:187
QofSortFunc
gint(* QofSortFunc)(gconstpointer, gconstpointer)
Definition: qofclass.h:206
QofCollection
struct QofCollection_s QofCollection
Definition: qofid.h:138
qof_class_get_parameter
const QofParam * qof_class_get_parameter(QofIdTypeConst obj_name, const gchar *parameter)
Definition: qofclass.c:146
_QofObject
Definition: qofobject.h:70
QofAccessFunc
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
Definition: qofclass.h:169
qof_object_register
gboolean qof_object_register(const QofObject *object)
Definition: qofobject.c:278
qof_close
void qof_close(void)
Safely close down the Query Object Framework.
Definition: qofutil.c:844
qof_class_get_parameter_type
QofType qof_class_get_parameter_type(QofIdTypeConst obj_name, const gchar *param_name)
Definition: qofclass.c:198
safe_strcmp
gint safe_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:72
qof_class_get_parameter_getter
QofAccessFunc qof_class_get_parameter_getter(QofIdTypeConst obj_name, const gchar *parameter)
Definition: qofclass.c:166
qof_init
void qof_init(void)
Initialise the Query Object Framework.
Definition: qofutil.c:833