test-querynew.c

00001 /***************************************************************************
00002  *            test-querynew.c
00003  *
00004  *  Copyright  2004 Linas Vepstas <linas@linas.org>
00005  ****************************************************************************/
00006 /*
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA  02110-1301,  USA
00020  */
00021 
00022 #include <glib.h>
00023 #include <stdio.h>
00024 
00025 #include "qof.h"
00026 #include "qofclass-p.h"
00027 #include "qofquerycore-p.h"
00028 
00029 #include "test-stuff.h"
00030 
00031 #define TEST_MODULE_NAME    "TestModuleName"
00032 #define TEST_MODULE_DESC "Test Object"
00033 #define TEST_CORE       "TestCoreType"
00034 #define TEST_PARAM      "test-param"
00035 #define BAD_PARAM       "bad-param"
00036 
00037 static void
00038 obj_foreach (QofCollection * col, 
00039     QofEntityForeachCB cb __attribute__ ((unused)), gpointer u_d)
00040 {
00041     int *foo = u_d;
00042 
00043     do_test (col != NULL, "foreach: NULL collection");
00044     success ("called foreach callback");
00045 
00046     *foo = 1;
00047 }
00048 
00049 static const char *
00050 printable (gpointer obj)
00051 {
00052     do_test (obj != NULL, "printable: object is NULL");
00053     success ("called printable callback");
00054     return ((const gchar *) obj);
00055 }
00056 
00057 static QofObject bus_obj = {
00058   .interface_version = QOF_OBJECT_VERSION,
00059   .e_type = TEST_MODULE_NAME,
00060   .type_label = TEST_MODULE_DESC,
00061   .create = NULL,
00062   .book_begin = NULL,
00063   .book_end = NULL,
00064   .is_dirty = NULL,
00065   .mark_clean = NULL,
00066   .foreach = obj_foreach,
00067   .printable = printable,
00068   .version_cmp = NULL,
00069 };
00070 
00071 static int
00072 test_sort (gpointer a __attribute__ ((unused)), gpointer b __attribute__ ((unused)))
00073 {
00074     return 0;
00075 }
00076 
00077 static int
00078 test_core_param (gpointer a __attribute__ ((unused)))
00079 {
00080     return 0;
00081 }
00082 
00083 static void
00084 test_class (void)
00085 {
00086     static QofParam params[] = {
00087         {TEST_PARAM, TEST_CORE, (QofAccessFunc) test_core_param,
00088             NULL, NULL},
00089         {NULL, NULL, NULL, NULL, NULL},
00090     };
00091 
00092     fprintf (stderr, "\tTesting the qof_query_object interface. \n"
00093              "\tYou may see some \"** CRITICAL **\" messages, which you can safely ignore\n");
00094     do_test (qof_object_register (&bus_obj), "register test object");
00095 
00096     qof_class_register (TEST_MODULE_NAME, (QofSortFunc) test_sort, params);
00097 
00098     do_test (qof_class_get_parameter (TEST_MODULE_NAME, TEST_PARAM)
00099              == &params[0], "qof_class_get_parameter");
00100     do_test (qof_class_get_parameter (NULL, NULL) == NULL,
00101              "qof_class_get_parameter (NULL, NULL)");
00102     do_test (qof_class_get_parameter (TEST_MODULE_NAME, NULL) == NULL,
00103              "qof_class_get_parameter (TEST_MODULE_NAME, NULL)");
00104     do_test (qof_class_get_parameter (TEST_MODULE_NAME, BAD_PARAM) == NULL,
00105              "qof_class_get_parameter (TEST_MODULE_NAME, BAD_PARAM)");
00106     do_test (qof_class_get_parameter (NULL, TEST_PARAM) == NULL,
00107              "qof_class_get_parameter (NULL, TEST_PARAM)");
00108 
00109     do_test (qof_class_get_parameter_getter (TEST_MODULE_NAME, TEST_PARAM)
00110              == (QofAccessFunc) test_core_param,
00111              "qof_class_get_parameter_getter");
00112 
00113     do_test (safe_strcmp (qof_class_get_parameter_type (TEST_MODULE_NAME,
00114                                                         TEST_PARAM),
00115                           TEST_CORE) == 0, "qof_class_get_parameter_type");
00116 
00117     do_test (qof_class_get_default_sort (TEST_MODULE_NAME) ==
00118              (QofSortFunc) test_sort, "qof_class_get_default_sort");
00119     do_test (qof_class_get_default_sort (NULL) == NULL,
00120              "qof_class_get_default_sort (NULL)");
00121 }
00122 
00123 static void
00124 test_query_core (void)
00125 {
00126 
00127 }
00128 
00129 static void
00130 test_querynew (void)
00131 {
00132 }
00133 
00134 int
00135 main (void)
00136 {
00137     qof_init ();
00138     test_query_core ();
00139     test_class ();
00140     test_querynew ();
00141     print_test_results ();
00142     qof_close ();
00143     return get_rv ();
00144 }

Generated on Thu Jan 31 22:50:26 2008 for QOF by  doxygen 1.5.4