static void test_printable (const char *name, gpointer obj) { const char *res; do_test (qof_object_printable (NULL, NULL) == NULL, "object: Printable: NULL, NULL"); do_test (qof_object_printable (NULL, obj) == NULL, "object: Printable: NULL, object"); do_test (qof_object_printable (name, NULL) == NULL, "object: Printable: mod_name, NULL"); res = qof_object_printable (name, obj); do_test (res != NULL, "object: Printable: mod_name, object"); }
static void test_qof_object_printable( Fixture *fixture, gconstpointer pData ) { gint param; g_test_message( "Test null checks" ); g_assert( qof_object_printable( NULL, (gpointer)¶m ) == NULL ); g_assert( qof_object_printable( "test", NULL ) == NULL ); g_test_message( "Test with non registered object" ); g_assert( qof_object_printable( "test", (gpointer)¶m ) == NULL ); g_test_message( "Test with registered object and printable not set" ); g_assert( qof_object_register( fixture->qofobject ) == TRUE ); g_assert( qof_object_printable( "my type object", (gpointer)¶m ) == NULL ); g_test_message( "Test with registered object and printable set" ); fixture->qofobject->printable = mock_printable; printable_struct.param = (gpointer)¶m; g_assert_cmpstr( qof_object_printable( "my type object", (gpointer)¶m ), == , "printable was called" ); }
/* The "selection" contents have changed. Change the text. */ static void reset_selection_text (GNCGeneralSearch *gsl) { GNCGeneralSearchPrivate *priv; const char *text; priv = _PRIVATE(gsl); if (gsl->selected_item == NULL) text = ""; else text = qof_object_printable (priv->type, gsl->selected_item); gtk_entry_set_text(GTK_ENTRY(gsl->entry), text); }
static void create_children (GNCGeneralSearch *gsl, const char *label, gboolean text_editable, QofIdTypeConst type, QofBook *book) { GtkListStore * list_store; QofQuery * q; GtkTreeIter iter; GList * list, * it; GtkEntryCompletion *completion; /* Add a text entry box */ gsl->entry = gtk_entry_new (); if (!text_editable) gtk_editable_set_editable (GTK_EDITABLE (gsl->entry), FALSE); gtk_box_pack_start (GTK_BOX (gsl), gsl->entry, TRUE, TRUE, 0); /* Setup a GtkEntryCompletion auxiliary widget for our Entry box * This requires an internal table ("model") with the possible * auto-completion text entries */ /* Query for the requested object type */ q = qof_query_create_for (type); qof_query_add_boolean_match(q, g_slist_prepend (NULL, QOF_PARAM_ACTIVE), TRUE, QOF_QUERY_AND); qof_query_set_book (q, book); list = qof_query_run(q); /* Setup the internal model */ list_store = gtk_list_store_new (GSL_N_COLUMNS, G_TYPE_STRING, G_TYPE_OBJECT); for (it = list; it != NULL ; it = it->next) { char * name; name = g_strdup(qof_object_printable(type, it->data)); /* Add a new row to the model */ if (name) { gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, GSL_COLUMN_TEXT, name, GSL_COLUMN_QOFOBJECT, G_OBJECT(it->data), -1); g_free(name); } } qof_query_destroy(q); /* Add the GtkEntryCompletion widget */ completion = gtk_entry_completion_new(); gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(list_store)); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_set_completion(GTK_ENTRY(gsl->entry), completion); g_signal_connect (G_OBJECT (completion), "match_selected", G_CALLBACK (gnc_gsl_match_selected_cb), gsl); g_signal_connect (G_OBJECT (gsl->entry), "focus-out-event", G_CALLBACK (gnc_gsl_focus_out_cb), gsl); g_object_unref(completion); gtk_widget_show (gsl->entry); /* Add the search button */ gsl->button = gtk_button_new_with_label (label); gtk_box_pack_start (GTK_BOX (gsl), gsl->button, FALSE, FALSE, 0); g_signal_connect (G_OBJECT (gsl->button), "clicked", G_CALLBACK (search_cb), gsl); gtk_widget_show (gsl->button); }
/** The focus left the general search edit widget, so reset the widget to * its last known good value. If the widget value contained a valid * value then this is a noop. Otherwise the widget will be reset * to the last user selected value. This latter state will occur * if the user has typed characters directly into the widget but not * selected a completion. * * @param entry The entry widget in which the user is typing. * * @param event Unused. * * @param gsl A pointer to a general search widget. */ static gboolean gnc_gsl_focus_out_cb (GtkEntry *entry, GdkEventFocus *event, GNCGeneralSearch *gsl) { const gchar *text; GtkEntryCompletion *completion; GtkTreeModel *model; GtkTreeIter iter; gchar *lc_text, *tree_string, *lc_tree_string; gboolean match, valid_iter; QofObject *qofobject; gpointer selected_item = NULL; /* Attempt to match the current text to a qofobject. */ completion = gtk_entry_get_completion(entry); model = gtk_entry_completion_get_model(completion); /* Return if completion tree is empty */ valid_iter = gtk_tree_model_get_iter_first(model, &iter); if (!valid_iter) return FALSE; text = gtk_entry_get_text(entry); lc_text = g_utf8_strdown(text, -1); /* The last, valid selected entry can match the entered text * No need to search further in that case */ if (gsl->selected_item) { GNCGeneralSearchPrivate * priv; priv = _PRIVATE(gsl); tree_string = g_strdup(qof_object_printable(priv->type, gsl->selected_item)); lc_tree_string = g_utf8_strdown(tree_string, -1); match = g_utf8_collate(lc_text, lc_tree_string) == 0; g_free(tree_string); g_free(lc_tree_string); if (match) selected_item = gsl->selected_item; } /* Otherwise, find a match in the completion list */ while (valid_iter && !selected_item) { gtk_tree_model_get(model, &iter, GSL_COLUMN_TEXT, &tree_string, -1); lc_tree_string = g_utf8_strdown(tree_string, -1); match = g_utf8_collate(lc_text, lc_tree_string) == 0; g_free(tree_string); g_free(lc_tree_string); if (match) { gtk_tree_model_get(model, &iter, GSL_COLUMN_QOFOBJECT, &qofobject, -1); selected_item = qofobject; } else valid_iter = gtk_tree_model_iter_next(model, &iter); } g_free(lc_text); gnc_general_search_set_selected (gsl, selected_item); return FALSE; }
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); }
static void test_customer (void) { QofBook *book; GncCustomer *customer; book = qof_book_new (); /* Test creation/destruction */ { do_test (gncCustomerCreate (NULL) == NULL, "customer create NULL"); customer = gncCustomerCreate (book); do_test (customer != NULL, "customer create"); do_test (gncCustomerGetBook (customer) == book, "getbook"); gncCustomerBeginEdit (customer); gncCustomerDestroy (customer); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncCustomerSetID, gncCustomerGetID); test_string_fcn (book, "Name", gncCustomerSetName, gncCustomerGetName); test_string_fcn (book, "Notes", gncCustomerSetNotes, gncCustomerGetNotes); //test_string_fcn (book, "Terms", gncCustomerSetTerms, gncCustomerGetTerms); test_numeric_fcn (book, "Discount", gncCustomerSetDiscount, gncCustomerGetDiscount); test_numeric_fcn (book, "Credit", gncCustomerSetCredit, gncCustomerGetCredit); test_bool_fcn (book, "Active", gncCustomerSetActive, gncCustomerGetActive); do_test (gncCustomerGetAddr (customer) != NULL, "Addr"); do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr"); guid_replace (&guid); customer = gncCustomerCreate (book); count++; gncCustomerSetGUID (customer, &guid); do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare"); } { GList *list; list = gncBusinessGetList (book, GNC_ID_CUSTOMER, 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_ID_CUSTOMER, 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; res = NULL; gncCustomerBeginEdit(customer); gncCustomerSetName (customer, str); gncCustomerCommitEdit(customer); res = qof_object_printable (GNC_ID_CUSTOMER, customer); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); } do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty"); /* Test the Entity Table */ { const GncGUID *guid; guid = gncCustomerGetGUID (customer); do_test (gncCustomerLookup (book, guid) == customer, "Entity Table"); } /* Note: JobList is tested from the Job tests */ qof_book_destroy (book); }
static void test_vendor (void) { QofBook *book; GncVendor *vendor; book = qof_book_new(); /* Test creation/destruction */ { do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL"); vendor = gncVendorCreate (book); do_test (vendor != NULL, "vendor create"); do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book, "getbook"); gncVendorBeginEdit (vendor); gncVendorDestroy (vendor); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID); test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName); test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes); //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms); //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded); test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive); do_test (gncVendorGetAddr (vendor) != NULL, "Addr"); guid_new (&guid); vendor = gncVendorCreate (book); count++; gncVendorSetGUID (vendor, &guid); do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare"); } { GList *list; list = gncBusinessGetList (book, GNC_ID_VENDOR, 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_ID_VENDOR, 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; gncVendorSetName (vendor, str); res = qof_object_printable (GNC_ID_VENDOR, vendor); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); } qof_book_destroy (book); }