static gboolean employee_guid_handler (xmlNodePtr node, gpointer employee_pdata) { struct employee_pdata *pdata = employee_pdata; GncGUID *guid; GncEmployee *employee; guid = dom_tree_to_guid(node); g_return_val_if_fail(guid, FALSE); /* See if we've already created this one */ employee = gncEmployeeLookup (pdata->book, guid); if (employee) { gncEmployeeDestroy (pdata->employee); pdata->employee = employee; gncEmployeeBeginEdit (employee); } else { gncEmployeeSetGUID(pdata->employee, guid); } g_free(guid); return TRUE; }
void gncOwnerDestroy (GncOwner *owner) { if (!owner) return; switch (owner->type) { case GNC_OWNER_NONE : case GNC_OWNER_UNDEFINED : break; case GNC_OWNER_CUSTOMER : { gncCustomerDestroy(owner->owner.customer); break; } case GNC_OWNER_JOB : { gncJobDestroy(owner->owner.job); break; } case GNC_OWNER_VENDOR : { gncVendorDestroy(owner->owner.vendor); break; } case GNC_OWNER_EMPLOYEE : { gncEmployeeDestroy(owner->owner.employee); break; } } }
static void destroy_employee_on_book_close(QofInstance *ent, gpointer data) { GncEmployee* e = GNC_EMPLOYEE(ent); gncEmployeeBeginEdit(e); gncEmployeeDestroy(e); }
void gnc_employee_window_destroy_cb (GtkWidget *widget, gpointer data) { EmployeeWindow *ew = data; GncEmployee *employee = ew_get_employee (ew); gnc_suspend_gui_refresh (); if (ew->dialog_type == NEW_EMPLOYEE && employee != NULL) { gncEmployeeBeginEdit (employee); gncEmployeeDestroy (employee); ew->employee_guid = *guid_null (); } gnc_unregister_gui_component (ew->component_id); gnc_resume_gui_refresh (); g_free (ew); }
static GncEmployee* dom_tree_to_employee (xmlNodePtr node, QofBook *book) { struct employee_pdata employee_pdata; gboolean successful; employee_pdata.employee = gncEmployeeCreate(book); employee_pdata.book = book; gncEmployeeBeginEdit (employee_pdata.employee); successful = dom_tree_generic_parse (node, employee_handlers_v2, &employee_pdata); if (successful) gncEmployeeCommitEdit (employee_pdata.employee); else { PERR ("failed to parse employee tree"); gncEmployeeDestroy (employee_pdata.employee); employee_pdata.employee = NULL; } return employee_pdata.employee; }
static void test_employee (void) { QofBackend *be; QofBook *book; QofSession *session; GncEmployee *employee; session = qof_session_new(); qof_session_begin(session, QOF_STDOUT, FALSE, FALSE); book = qof_session_get_book(session); /* The book *must* have a backend to pass the test of the 'dirty' flag */ /* See the README file for details */ be = qof_book_get_backend (book); /* Test creation/destruction */ { do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL"); employee = gncEmployeeCreate (book); do_test (employee != NULL, "employee create"); do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book, "getbook"); gncEmployeeBeginEdit (employee); gncEmployeeDestroy (employee); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID); test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername); test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage); test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl); test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday); test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate); test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive); do_test (gncEmployeeGetAddr (employee) != NULL, "Addr"); guid_new (&guid); employee = gncEmployeeCreate (book); count++; gncEmployeeSetGUID (employee, &guid); do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare"); } #if 0 { GList *list; list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE); do_test (list != NULL, "getList all"); do_test (g_list_length (list) == count, "correct length: all"); g_list_free (list); list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE); do_test (list != NULL, "getList active"); do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } #endif { const char *str = get_random_string(); const char *res; GncAddress *addr; addr = gncEmployeeGetAddr (employee); gncAddressSetName (addr, str); res = qof_object_printable (GNC_ID_EMPLOYEE, employee); do_test (res != NULL, "Printable NULL?"); do_test (safe_strcmp (str, res) == 0, "Printable equals"); } }
static void test_employee (void) { QofBook *book; GncEmployee *employee; book = qof_book_new(); /* Test creation/destruction */ { do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL"); employee = gncEmployeeCreate (book); do_test (employee != NULL, "employee create"); do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book, "getbook"); gncEmployeeBeginEdit (employee); gncEmployeeDestroy (employee); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID); test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername); test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage); test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl); test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday); test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate); test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive); do_test (gncEmployeeGetAddr (employee) != NULL, "Addr"); guid_replace (&guid); employee = gncEmployeeCreate (book); count++; gncEmployeeSetGUID (employee, &guid); do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare"); } { GList *list; list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE); do_test (list != NULL, "getList all"); do_test (g_list_length (list) == count, "correct length: all"); g_list_free (list); list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE); do_test (list != NULL, "getList active"); do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } { const char *str = get_random_string(); const char *res; GncAddress *addr; addr = gncEmployeeGetAddr (employee); gncAddressSetName (addr, str); res = qof_object_printable (GNC_ID_EMPLOYEE, employee); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); } qof_book_destroy (book); }