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, QofEntityForeachCB cb, gpointer u_d)
00039 {
00040     int *foo = u_d;
00041 
00042     do_test (col != NULL, "foreach: NULL collection");
00043     success ("called foreach callback");
00044 
00045     *foo = 1;
00046 }
00047 
00048 static const char *
00049 printable (gpointer obj)
00050 {
00051     do_test (obj != NULL, "printable: object is NULL");
00052     success ("called printable callback");
00053     return ((const char *) obj);
00054 }
00055 
00056 static QofObject bus_obj = {
00057   interface_version:QOF_OBJECT_VERSION,
00058   e_type:TEST_MODULE_NAME,
00059   type_label:TEST_MODULE_DESC,
00060   create:NULL,
00061   book_begin:NULL,
00062   book_end:NULL,
00063   is_dirty:NULL,
00064   mark_clean:NULL,
00065   foreach:obj_foreach,
00066   printable:printable,
00067   version_cmp:NULL,
00068 };
00069 
00070 static int
00071 test_sort (gpointer a, gpointer b)
00072 {
00073     return 0;
00074 }
00075 
00076 static int
00077 test_core_param (gpointer a)
00078 {
00079     return 0;
00080 }
00081 
00082 static void
00083 test_class (void)
00084 {
00085     static QofParam params[] = {
00086         {TEST_PARAM, TEST_CORE, (QofAccessFunc) test_core_param, NULL},
00087         {NULL},
00088     };
00089 
00090     fprintf (stderr, "\tTesting the qof_query_object interface. \n"
00091              "\tYou may see some \"** CRITICAL **\" messages, which you can safely ignore\n");
00092     do_test (qof_object_register (&bus_obj), "register test object");
00093 
00094     qof_class_register (TEST_MODULE_NAME, (QofSortFunc) test_sort, params);
00095 
00096     do_test (qof_class_get_parameter (TEST_MODULE_NAME, TEST_PARAM)
00097              == &params[0], "qof_class_get_parameter");
00098     do_test (qof_class_get_parameter (NULL, NULL) == NULL,
00099              "qof_class_get_parameter (NULL, NULL)");
00100     do_test (qof_class_get_parameter (TEST_MODULE_NAME, NULL) == NULL,
00101              "qof_class_get_parameter (TEST_MODULE_NAME, NULL)");
00102     do_test (qof_class_get_parameter (TEST_MODULE_NAME, BAD_PARAM) == NULL,
00103              "qof_class_get_parameter (TEST_MODULE_NAME, BAD_PARAM)");
00104     do_test (qof_class_get_parameter (NULL, TEST_PARAM) == NULL,
00105              "qof_class_get_parameter (NULL, TEST_PARAM)");
00106 
00107     do_test (qof_class_get_parameter_getter (TEST_MODULE_NAME, TEST_PARAM)
00108              == (QofAccessFunc) test_core_param,
00109              "qof_class_get_parameter_getter");
00110 
00111     do_test (safe_strcmp (qof_class_get_parameter_type (TEST_MODULE_NAME,
00112                                                         TEST_PARAM),
00113                           TEST_CORE) == 0, "qof_class_get_parameter_type");
00114 
00115     do_test (qof_class_get_default_sort (TEST_MODULE_NAME) ==
00116              (QofSortFunc) test_sort, "qof_class_get_default_sort");
00117     do_test (qof_class_get_default_sort (NULL) == NULL,
00118              "qof_class_get_default_sort (NULL)");
00119 }
00120 
00121 static void
00122 test_query_core (void)
00123 {
00124 
00125 }
00126 
00127 static void
00128 test_querynew (void)
00129 {
00130 }
00131 
00132 int
00133 main (int argc, char **argv)
00134 {
00135     qof_init ();
00136     test_query_core ();
00137     test_class ();
00138     test_querynew ();
00139     print_test_results ();
00140     qof_close ();
00141     return get_rv ();
00142 }

Generated on Mon May 21 17:42:22 2007 for QOF by  doxygen 1.5.1