|
GnuCash 2.4.99
|
00001 /********************************************************************* 00002 * test-employee.c 00003 * Test the employee object (without Guile). 00004 * 00005 * Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU> 00006 * Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk> 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License as 00010 * published by the Free Software Foundation; either version 2 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, contact: 00020 * 00021 * Free Software Foundation Voice: +1-617-542-5942 00022 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00023 * Boston, MA 02110-1301, USA gnu@gnu.org 00024 * 00025 *********************************************************************/ 00026 00027 #include "config.h" 00028 #include <glib.h> 00029 #include "qof.h" 00030 #include "gncEmployeeP.h" 00031 #include "gncCustomerP.h" 00032 #include "gncJobP.h" 00033 #include "gncInvoiceP.h" 00034 #include "test-stuff.h" 00035 00036 static int count = 0; 00037 00038 static void 00039 test_string_fcn (QofBook *book, const char *message, 00040 void (*set) (GncEmployee *, const char *str), 00041 const char * (*get)(const GncEmployee *)); 00042 00043 static void 00044 test_numeric_fcn (QofBook *book, const char *message, 00045 void (*set) (GncEmployee *, gnc_numeric), 00046 gnc_numeric (*get)(const GncEmployee *)); 00047 00048 static void 00049 test_bool_fcn (QofBook *book, const char *message, 00050 void (*set) (GncEmployee *, gboolean), 00051 gboolean (*get) (const GncEmployee *)); 00052 00053 #if 0 00054 static void 00055 test_gint_fcn (QofBook *book, const char *message, 00056 void (*set) (GncEmployee *, gint), 00057 gint (*get) (GncEmployee *)); 00058 #endif 00059 00060 static void 00061 test_employee (void) 00062 { 00063 QofBook *book; 00064 GncEmployee *employee; 00065 00066 book = qof_book_new(); 00067 00068 /* Test creation/destruction */ 00069 { 00070 do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL"); 00071 employee = gncEmployeeCreate (book); 00072 do_test (employee != NULL, "employee create"); 00073 do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book, 00074 "getbook"); 00075 00076 gncEmployeeBeginEdit (employee); 00077 gncEmployeeDestroy (employee); 00078 success ("create/destroy"); 00079 } 00080 00081 /* Test setting/getting routines; does the active flag get set right? */ 00082 { 00083 GncGUID guid; 00084 00085 test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID); 00086 test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername); 00087 test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage); 00088 test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl); 00089 00090 test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday); 00091 test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate); 00092 00093 test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive); 00094 00095 do_test (gncEmployeeGetAddr (employee) != NULL, "Addr"); 00096 00097 guid_new (&guid); 00098 employee = gncEmployeeCreate (book); 00099 count++; 00100 gncEmployeeSetGUID (employee, &guid); 00101 do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare"); 00102 } 00103 { 00104 GList *list; 00105 00106 list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE); 00107 do_test (list != NULL, "getList all"); 00108 do_test (g_list_length (list) == count, "correct length: all"); 00109 g_list_free (list); 00110 00111 list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE); 00112 do_test (list != NULL, "getList active"); 00113 do_test (g_list_length (list) == 1, "correct length: active"); 00114 g_list_free (list); 00115 } 00116 { 00117 const char *str = get_random_string(); 00118 const char *res; 00119 GncAddress *addr; 00120 00121 addr = gncEmployeeGetAddr (employee); 00122 gncAddressSetName (addr, str); 00123 res = qof_object_printable (GNC_ID_EMPLOYEE, employee); 00124 do_test (res != NULL, "Printable NULL?"); 00125 do_test (safe_strcmp (str, res) == 0, "Printable equals"); 00126 } 00127 00128 qof_book_destroy (book); 00129 } 00130 00131 static void 00132 test_string_fcn (QofBook *book, const char *message, 00133 void (*set) (GncEmployee *, const char *str), 00134 const char * (*get)(const GncEmployee *)) 00135 { 00136 GncEmployee *employee = gncEmployeeCreate (book); 00137 char const *str = get_random_string (); 00138 00139 do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); 00140 gncEmployeeBeginEdit (employee); 00141 set (employee, str); 00142 /* Employee record should be dirty */ 00143 do_test (gncEmployeeIsDirty (employee), "test dirty later"); 00144 gncEmployeeCommitEdit (employee); 00145 /* Employee record should be not dirty */ 00146 /* Skip, because will always fail without a backend. 00147 * It's not possible to load a backend in the engine code 00148 * without having circular dependencies. 00149 */ 00150 // do_test (!gncEmployeeIsDirty (employee), "test dirty after commit"); 00151 do_test (safe_strcmp (get (employee), str) == 0, message); 00152 gncEmployeeSetActive (employee, FALSE); 00153 count++; 00154 } 00155 00156 static void 00157 test_numeric_fcn (QofBook *book, const char *message, 00158 void (*set) (GncEmployee *, gnc_numeric), 00159 gnc_numeric (*get)(const GncEmployee *)) 00160 { 00161 GncEmployee *employee = gncEmployeeCreate (book); 00162 gnc_numeric num = gnc_numeric_create (17, 1); 00163 00164 do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); 00165 gncEmployeeBeginEdit (employee); 00166 set (employee, num); 00167 /* Employee record should be dirty */ 00168 do_test (gncEmployeeIsDirty (employee), "test dirty later"); 00169 gncEmployeeCommitEdit (employee); 00170 /* Employee record should be not dirty */ 00171 /* Skip, because will always fail without a backend. 00172 * It's not possible to load a backend in the engine code 00173 * without having circular dependencies. 00174 */ 00175 // do_test (!gncEmployeeIsDirty (employee), "test dirty after commit"); 00176 do_test (gnc_numeric_equal (get (employee), num), message); 00177 gncEmployeeSetActive (employee, FALSE); 00178 count++; 00179 } 00180 00181 static void 00182 test_bool_fcn (QofBook *book, const char *message, 00183 void (*set) (GncEmployee *, gboolean), 00184 gboolean (*get) (const GncEmployee *)) 00185 { 00186 GncEmployee *employee = gncEmployeeCreate (book); 00187 gboolean num = get_random_boolean (); 00188 00189 do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); 00190 gncEmployeeBeginEdit (employee); 00191 set (employee, FALSE); 00192 set (employee, TRUE); 00193 set (employee, num); 00194 /* Employee record should be dirty */ 00195 do_test (gncEmployeeIsDirty (employee), "test dirty later"); 00196 gncEmployeeCommitEdit (employee); 00197 /* Employee record should be not dirty */ 00198 /* Skip, because will always fail without a backend. 00199 * It's not possible to load a backend in the engine code 00200 * without having circular dependencies. 00201 */ 00202 // do_test (!gncEmployeeIsDirty (employee), "test dirty after commit"); 00203 do_test (get (employee) == num, message); 00204 gncEmployeeSetActive (employee, FALSE); 00205 count++; 00206 } 00207 00208 #if 0 00209 static void 00210 test_gint_fcn (QofBook *book, const char *message, 00211 void (*set) (GncEmployee *, gint), 00212 gint (*get) (GncEmployee *)) 00213 { 00214 GncEmployee *employee = gncEmployeeCreate (book); 00215 gint num = 17; 00216 00217 do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); 00218 gncEmployeeBeginEdit (employee); 00219 set (employee, num); 00220 /* Employee record should be dirty */ 00221 do_test (gncEmployeeIsDirty (employee), "test dirty later"); 00222 gncEmployeeCommitEdit (employee); 00223 /* Employee record should be not dirty */ 00224 /* Skip, because will always fail without a backend. 00225 * It's not possible to load a backend in the engine code 00226 * without having circular dependencies. 00227 */ 00228 // do_test (!gncEmployeeIsDirty (employee), "test dirty after commit"); 00229 do_test (get (employee) == num, message); 00230 gncEmployeeSetActive (employee, FALSE); 00231 count++; 00232 } 00233 #endif 00234 00235 int 00236 main (int argc, char **argv) 00237 { 00238 qof_init(); 00239 do_test (gncInvoiceRegister(), "Cannot register GncInvoice"); 00240 do_test (gncJobRegister (), "Cannot register GncJob"); 00241 do_test (gncCustomerRegister(), "Cannot register GncCustomer"); 00242 do_test (gncEmployeeRegister(), "Cannot register GncEmployee"); 00243 test_employee(); 00244 print_test_results(); 00245 qof_close(); 00246 return get_rv(); 00247 }
1.7.4