static void test_qof_object_book_end( Fixture *fixture, gconstpointer pData ) { QofBook *book = NULL, *book2 = NULL; gint32 list_length; g_test_message( "Test book with no objects" ); book = qof_book_new(); g_assert( book ); object_book_begin_struct.call_count = 0; g_assert_cmpint( 1, == , g_list_length( get_book_list() ) ); g_assert_cmpint( g_list_index( get_book_list(), (gconstpointer) book), != , -1 ); qof_book_destroy( book ); /* calls object_book_end */ g_assert_cmpint( object_book_begin_struct.call_count, == , 0 ); g_assert_cmpint( 0, == , g_list_length( get_book_list() ) ); list_length = generate_and_register_objects( 1, MOCK_OBJECT_BOOK_END ); g_test_message( "Test book end with random objects registered and book end set up" ); book2 = qof_book_new(); g_assert( book2 ); object_book_begin_struct.book = book2; g_assert_cmpint( 1, == , g_list_length( get_book_list() ) ); g_assert_cmpint( g_list_index( get_book_list(), (gconstpointer) book2 ), != , -1 ); qof_book_destroy( book2 ); /* calls object_book_end */ g_assert_cmpint( object_book_begin_struct.call_count, == , list_length ); g_assert_cmpint( 0, == , g_list_length( get_book_list() ) ); }
void SetUp() { QofBook *book = qof_book_new(); Account *root = gnc_account_create_root(book); t_asset_account1 = xaccMallocAccount(book); xaccAccountSetName(t_asset_account1, "Asset"); gnc_account_append_child(root, t_asset_account1); t_bank_account = xaccMallocAccount(book); xaccAccountSetName(t_bank_account, "Bank"); gnc_account_append_child(t_asset_account1, t_bank_account); t_asset_account2 = xaccMallocAccount(book); xaccAccountSetName(t_asset_account2, "Asset-Bank"); gnc_account_append_child(root, t_asset_account2); t_sav_account = xaccMallocAccount(book); xaccAccountSetName(t_sav_account, "Bank"); gnc_account_append_child(t_asset_account2, t_sav_account); t_expense_account = xaccMallocAccount(book); xaccAccountSetName(t_expense_account, "Expense"); gnc_account_append_child(root, t_expense_account); t_expense_account1 = xaccMallocAccount(book); xaccAccountSetName(t_expense_account1, "Food"); gnc_account_append_child(t_expense_account, t_expense_account1); t_expense_account2 = xaccMallocAccount(book); xaccAccountSetName(t_expense_account2, "Drink"); gnc_account_append_child(t_expense_account, t_expense_account2); }
static void test_object (void) { QofBook *book = qof_book_new(); do_test ((NULL != book), "book null"); /* Test the global registration and lookup functions */ { do_test (!qof_object_register (NULL), "register NULL"); do_test (qof_object_register (&bus_obj), "register test object"); do_test (!qof_object_register (&bus_obj), "register test object again"); do_test (qof_object_lookup (TEST_MODULE_NAME) == &bus_obj, "lookup our installed object"); do_test (qof_object_lookup ("snm98sn snml say dyikh9y9ha") == NULL, "lookup non-existant object object"); do_test (!g_strcmp0 (qof_object_get_type_label (TEST_MODULE_NAME), _(TEST_MODULE_DESC)), "test description return"); } test_foreach (book, TEST_MODULE_NAME); test_printable (TEST_MODULE_NAME, (gpointer)1); }
int main (int argc, char** argv) { qof_init (); cashobjects_register (); xaccLogDisable (); gnc_transaction_xml_v2_testing = TRUE; book = qof_book_new (); if (argc > 1) { test_files_in_dir (argc, argv, test_real_transaction, gnc_transaction_sixtp_parser_create (), "gnc:transaction", book); } else { test_transaction (); } print_test_results (); qof_close (); exit (get_rv ()); }
static void test_qof_object_foreach( Fixture *fixture, gconstpointer pData ) { gint user_data; QofBook *book = NULL; QofCollection *col = NULL; /* setup */ book = qof_book_new(); g_assert( book ); g_assert_cmpint( g_list_length( get_object_modules() ), == , 0 ); qof_object_register( fixture->qofobject ); g_assert_cmpint( g_list_length( get_object_modules() ), == , 1 ); col = qof_book_get_collection( book, fixture->qofobject->e_type ); /* make col already exist */ g_assert( col ); g_test_message( "Test foreach and data" ); foreach_cb_struct.user_data = ( gpointer ) &user_data; foreach_cb_struct.is_called = FALSE; foreach_cb_struct.col = col; foreach_cb_struct.cb = mock_instance_foreach_cb; fixture->qofobject->foreach = mock_foreach; qof_object_foreach( fixture->qofobject->e_type, book, mock_instance_foreach_cb, ( gpointer ) &user_data ); g_assert( foreach_cb_struct.is_called == TRUE ); qof_book_destroy( book ); }
static void test_qof_object_new_instance( Fixture *fixture, gconstpointer pData ) { QofBook *book = NULL; QofInstance *inst = NULL; book = qof_book_new(); g_assert( book ); g_test_message( "Test null check" ); g_assert( qof_object_new_instance( NULL, book ) == NULL ); g_test_message( "Test non existing object type" ); g_assert( qof_object_new_instance( "non existing type", book ) == NULL ); g_test_message( "Test with registered object type and create not set" ); g_assert( qof_object_register( fixture->qofobject ) ); g_assert( qof_object_new_instance( fixture->qofobject->e_type, book ) == NULL ); g_test_message( "Test with registered object type and create set" ); object_create_struct.is_called = FALSE; object_create_struct.book = book; object_create_struct.inst = NULL; fixture->qofobject->create = mock_object_create; inst = qof_object_new_instance( fixture->qofobject->e_type, book ); g_assert( inst ); g_assert( object_create_struct.is_called == TRUE ); g_assert( object_create_struct.inst == inst ); g_object_unref( inst ); qof_book_destroy( book ); }
static void test_address (void) { QofInstance *ent; GncAddress *address; QofBook *book = qof_book_new (); ent = g_object_new(QOF_TYPE_INSTANCE, "guid", guid_null(), NULL); ent->e_type = "asdf"; /* Test creation/destruction */ { do_test (gncAddressCreate (NULL, NULL) == NULL, "address create NULL"); address = gncAddressCreate (book, ent); do_test (address != NULL, "address create"); gncAddressBeginEdit (address); gncAddressDestroy (address); success ("create/destroy"); } /* Test setting routines */ { address = gncAddressCreate (book, ent); test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName); test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1); test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2); test_string_fcn (address, "Addr3", gncAddressSetAddr3, gncAddressGetAddr3); test_string_fcn (address, "Addr4", gncAddressSetAddr4, gncAddressGetAddr4); test_string_fcn (address, "Phone", gncAddressSetPhone, gncAddressGetPhone); test_string_fcn (address, "Fax", gncAddressSetFax, gncAddressGetFax); test_string_fcn (address, "Email", gncAddressSetEmail, gncAddressGetEmail); } }
static void test_qof_object_is_dirty( Fixture *fixture, gconstpointer pData ) { QofBook *book = NULL; gint32 list_length; g_test_message( "Test null check returns false" ); g_assert( qof_object_is_dirty( NULL ) == FALSE ); g_test_message( "Test with no objects" ); book = qof_book_new(); g_assert( book ); object_dirty_struct.call_count = 0; g_assert( qof_object_is_dirty( book ) == FALSE ); g_assert_cmpint( object_dirty_struct.call_count, == , 0 ); list_length = generate_and_register_objects( 1, MOCK_OBJECT_DIRTY ); g_test_message( "Test with registered objects and suppose all collections are clean" ); object_dirty_struct.objects = get_object_modules(); object_dirty_struct.result = FALSE; g_assert( qof_object_is_dirty( book ) == FALSE ); g_assert_cmpint( object_dirty_struct.call_count, == , list_length ); g_test_message( "Test with registered objects and suppose first collection is dirty" ); object_dirty_struct.objects = get_object_modules(); object_dirty_struct.result = TRUE; object_dirty_struct.call_count = 0; g_assert( qof_object_is_dirty( book ) == TRUE ); g_assert_cmpint( object_dirty_struct.call_count, == , 1 ); /* should break on first */ qof_book_destroy( book ); }
static void test_dom_tree_to_commodity_ref(void) { int i; for (i = 0; i < 20; i++) { gnc_commodity *test_com1; gchar *test_str1; gchar *test_str2; gnc_commodity *test_com2; xmlNodePtr test_node; QofBook *book; book = qof_book_new (); test_str1 = get_random_string(); test_str2 = get_random_string(); test_com1 = gnc_commodity_new(book, NULL, test_str1, test_str2, NULL, 0); test_node = commodity_ref_to_dom_tree("test-com", test_com1); test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, book); do_test(gnc_commodity_equiv(test_com1, test_com2), "dom_tree_to_commodity_ref_no_engine"); xmlFreeNode(test_node); gnc_commodity_destroy(test_com1); gnc_commodity_destroy(test_com2); g_free(test_str1); g_free(test_str2); qof_book_destroy (book); } }
static void setup( Fixture *fixture, gconstpointer pData ) { fixture->book = qof_book_new(); fixture->account = xaccMallocAccount(fixture->book); fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100); xaccAccountSetCommodity(fixture->account, fixture->commodity); }
static void test_qof_object_register( Fixture *fixture, gconstpointer pData ) { GList *books = NULL; gint32 list_length = g_test_rand_int_range( 0, 5 ); int i; QofObject *simple_object = NULL; for (i = 0; i < list_length; i++ ) { QofBook *book = qof_book_new(); g_assert( book ); books = g_list_prepend ( books, book ); g_assert_cmpint( g_list_length( books ), == , (i + 1) ); } g_assert_cmpint( list_length, == , g_list_length( books ) ); g_test_message( "Test null check" ); g_assert( qof_object_register( NULL ) == FALSE ); g_test_message( "Test new object register with book_begin specified" ); fixture->qofobject->book_begin = mock_book_begin; book_begin_struct.books = books; book_begin_struct.call_count = 0; g_assert( qof_object_register( fixture->qofobject ) == TRUE ); g_assert( qof_object_lookup( "my type object" ) == fixture->qofobject ); g_assert_cmpint( book_begin_struct.call_count, == , list_length ); g_test_message( "Test registering the same object one more time" ); book_begin_struct.call_count = 0; g_assert( qof_object_register( fixture->qofobject ) == FALSE ); g_assert( qof_object_lookup( "my type object" ) == fixture->qofobject ); g_assert_cmpint( book_begin_struct.call_count, == , 0 ); g_test_message( "Test new object register without book_begin specified" ); simple_object = new_object( "my type simple", "simple desc", EMPTY ); g_assert( qof_object_register( simple_object ) == TRUE ); g_assert( qof_object_lookup( "my type simple" ) == simple_object ); g_assert_cmpint( book_begin_struct.call_count, == , 0 ); g_test_message( "Test register simple object one more time" ); g_assert( qof_object_register( simple_object ) == FALSE ); g_assert( qof_object_lookup( "my type simple" ) == simple_object ); g_test_message( "Test book begin is called only one time when object is registered" ); simple_object->book_begin = mock_book_begin; book_begin_struct.books = books; book_begin_struct.call_count = 0; g_assert( qof_object_register( simple_object ) == FALSE ); g_assert_cmpint( book_begin_struct.call_count, == , 0 ); g_list_foreach( books, (GFunc) qof_book_destroy, NULL ); g_list_free( books ); g_free( simple_object ); }
static void setup( Fixture *fixture, gconstpointer pData ) { fixture->book = qof_book_new(); fixture->account = xaccMallocAccount(fixture->book); fixture->commodity = gnc_commodity_new(fixture->book, "foo", "bar", "xy", "xy", 100); xaccAccountSetCommodity(fixture->account, fixture->commodity); fixture->customer = gncCustomerCreate(fixture->book); gncOwnerInitCustomer(&fixture->owner, fixture->customer); }
static void qof_session_init (QofSession *session) { if (!session) return; session->entity.e_type = QOF_ID_SESSION; session->book = qof_book_new (); session->book_id = NULL; session->backend = NULL; session->lock = 1; qof_session_clear_error (session); }
static void test_main() { book = qof_book_new (); test_use(); test_some(); test_all(); qof_book_destroy (book); }
/* ================================================================= */ static void load_single_book (GncSqlBackend* sql_be, GncSqlRow& row) { QofBook* pBook; g_return_if_fail (sql_be != NULL); gnc_sql_load_guid (sql_be, row); pBook = sql_be->book(); if (pBook == NULL) { pBook = qof_book_new (); } qof_book_begin_edit (pBook); gnc_sql_load_object (sql_be, row, GNC_ID_BOOK, pBook, col_table); gnc_sql_slots_load (sql_be, QOF_INSTANCE (pBook)); qof_book_commit_edit (pBook); qof_instance_mark_clean (QOF_INSTANCE (pBook)); }
int main (int argc, char** argv) { g_setenv ("GNC_UNINSTALLED", "1", TRUE); gnc_engine_init (argc, argv); book = qof_book_new (); if (argc > 1) { test_files_in_dir (argc, argv, test_real_commodity, gnc_commodity_sixtp_parser_create (), "gnc:commodity", book); } else { test_generation (); } print_test_results (); exit (get_rv ()); }
static void test_qof_object_mark_clean( Fixture *fixture, gconstpointer pData ) { QofBook *book = NULL; gint32 list_length; g_test_message( "Test with no objects" ); book = qof_book_new(); g_assert( book ); object_mark_clean_struct.call_count = 0; g_assert_cmpint( g_list_length( get_object_modules() ), == , 0 ); qof_object_mark_clean( book ); g_assert_cmpint( object_mark_clean_struct.call_count, == , 0 ); list_length = generate_and_register_objects( 1, MOCK_OBJECT_MARK_CLEAN ); g_test_message( "Test with registered objects and mark clean set up" ); object_mark_clean_struct.objects = get_object_modules(); qof_object_mark_clean( book ); g_assert_cmpint( object_mark_clean_struct.call_count, == , list_length ); qof_book_destroy( book ); }
static void test_qof_object_foreach_sorted( Fixture *fixture, gconstpointer pData ) { int i; gint32 list_length = g_test_rand_int_range( 0, 5 ); gint user_data; QofBook *book = NULL; QofCollection *col = NULL; foreach_for_sorted_struct.instances = NULL; /* setup */ book = qof_book_new(); g_assert( book ); g_assert_cmpint( g_list_length( get_object_modules() ), == , 0 ); qof_object_register( fixture->qofobject ); g_assert_cmpint( g_list_length( get_object_modules() ), == , 1 ); fixture->qofobject->foreach = mock_foreach_for_sorted; /* init instances */ col = qof_book_get_collection( book, fixture->qofobject->e_type ); for (i = 0; i < list_length; i++ ) { QofInstance * inst = g_object_new( QOF_TYPE_INSTANCE, NULL ); g_assert( QOF_IS_INSTANCE( inst ) ); foreach_for_sorted_struct.instances = g_list_append( foreach_for_sorted_struct.instances, inst ); qof_collection_insert_entity( col, inst ); } g_assert_cmpint( list_length, == , g_list_length( foreach_for_sorted_struct.instances ) ); foreach_for_sorted_struct.call_count = 0; foreach_for_sorted_struct.user_data = &user_data; qof_object_foreach_sorted( fixture->qofobject->e_type, book, mock_instance_foreach_cb_for_sorted, ( gpointer ) &user_data ); g_assert_cmpint( list_length, == , foreach_for_sorted_struct.call_count ); qof_book_destroy( book ); g_list_free( foreach_for_sorted_struct.instances ); }
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); }
int main (int argc, char *argv[]) { int err, fake_argc = 1; char * fake_argv[] = {"hello", 0}; QofBook *book; Account *root; char *bufp; int rc, sz; /* intitialize the engine */ gnc_engine_init (fake_argc, fake_argv); /* contact the database, which is a flat file for this demo */ book = qof_book_new (); rc = gnc_book_begin (book, "file:/tmp/demo.gnucash", FALSE); if (!rc) goto bookerrexit; rc = gnc_book_load (book); if (!rc) goto bookerrexit; /* the root pointer points to our local cache of the data */ root = gnc_book_get_root_account (book); /* --------------------------------------------------- */ /* done with initialization, go into event loop */ while (FCGI_Accept() >= 0) { GList *split_list; Query *q = NULL; char *request_method; int read_len = 0; /* get the request method */ request_method = getenv ("REQUEST_METHOD"); /* Lets pretend that method=get means user has logged * in. Send the user the accounts and currencies, * but not the transactions/splits. */ if (!strcmp ("GET", request_method)) { gncxml_write_account_tree_to_buf(root, &bufp, &sz); /* print the HTTP header */ printf("Content-type: text/gnc-xml\r\n" "Content-Length: %d\r\n" "\r\n", sz); /* send the xml to the client */ printf ("%s", bufp); free (bufp); /* wait for the next request */ continue; } if (!strcmp ("POST", request_method)) { char * content_length = getenv("CONTENT_LENGTH"); read_len = atoi (content_length); /* read 'read_len' bytes from stdin ... */ bufp = (char *) malloc (read_len); fread (bufp, read_len, 1, stdin); /* conver the xml input into a gnucash query structure... */ q = gncxml_read_query (bufp, read_len); xaccQuerySetGroup (q, root); /* hack -- limit to 30 splits ... */ xaccQuerySetMaxSplits (q, 30); split_list = xaccQueryGetSplits (q); xaccFreeQuery (q); /* wait for the next request */ continue; } /* if we got to here, an error -- unknown method */ printf("Content-type: text/plain\r\n" "\r\n" "unknown request type \n"); } bookerrexit: err = gnc_book_get_error (book); /* 500 Server Error */ FCGI_SetExitStatus (500); printf("Content-type: text/plain\r\n\r\n" "error was %s\n", strerror (err)); FCGI_Finish(); /* close the book */ qof_book_destroy (book); /* shut down the engine */ gnc_engine_shutdown (); sleep (1); return 0; }
void qof_session_load (QofSession *session, QofPercentageFunc percentage_func) { QofBook *newbook, *oldbook; QofBackend *be; QofBackendError err; if (!session) return; if (!session->book_id) return; ENTER ("sess=%p book_id=%s", session, session->book_id ? session->book_id : "(null)"); /* At this point, we should are supposed to have a valid book * id and a lock on the file. */ oldbook = session->book; /* XXX why are we creating a book here? I think the books * need to be handled by the backend ... especially since * the backend may need to load multiple books ... XXX. FIXME. */ newbook = qof_book_new(); session->book = newbook; PINFO ("new book=%p", newbook); qof_session_clear_error (session); /* This code should be sufficient to initialize *any* backend, * whether http, postgres, or anything else that might come along. * Basically, the idea is that by now, a backend has already been * created & set up. At this point, we only need to get the * top-level account group out of the backend, and that is a * generic, backend-independent operation. */ be = session->backend; qof_book_set_backend(newbook, be); /* Starting the session should result in a bunch of accounts * and currencies being downloaded, but probably no transactions; * The GUI will need to do a query for that. */ if (be) { be->percentage = percentage_func; if (be->load) { be->load (be, newbook, LOAD_TYPE_INITIAL_LOAD); qof_session_push_error (session, qof_backend_get_error(be), NULL); } } /* XXX if the load fails, then we try to restore the old set of books; * however, we don't undo the session id (the URL). Thus if the * user attempts to save after a failed load, they weill be trying to * save to some bogus URL. This is wrong. XXX FIXME. */ err = qof_session_get_error(session); if ((err != ERR_BACKEND_NO_ERR) && (err != ERR_FILEIO_FILE_TOO_OLD) && (err != ERR_FILEIO_NO_ENCODING) && (err != ERR_FILEIO_FILE_UPGRADE) && (err != ERR_SQL_DB_TOO_OLD) && (err != ERR_SQL_DB_TOO_NEW)) { /* Something broke, put back the old stuff */ qof_book_set_backend (newbook, NULL); qof_book_destroy (newbook); session->book = oldbook; LEAVE("error from backend %d", qof_session_get_error(session)); return; } qof_book_set_backend (oldbook, NULL); qof_book_destroy (oldbook); LEAVE ("sess = %p, book_id=%s", session, session->book_id ? session->book_id : "(null)"); }
int main (int argc, char *argv[]) { int err, fake_argc = 1; char * fake_argv[] = {"hello", 0}; QofBook *book; Account *root; char *request_bufp, *reply_bufp; int rc, sz; /* intitialize the engine */ gnc_engine_init (fake_argc, fake_argv); /* contact the database, which is a flat file for this demo */ /* this should really be an SQL server */ book = qof_book_new (); rc = gnc_book_begin (book, "file:/tmp/demo.xac", FALSE); if (!rc) goto bookerrexit; rc = gnc_book_load (book); if (!rc) goto bookerrexit; /* the root pointer points to our local cache of the data */ root = gnc_book_get_root_account (book); /* --------------------------------------------------- */ /* done with initialization, go into event loop */ while (FCGI_Accept() >= 0) { GList *split_list; Query *q = NULL; const char *request_method; const char *user_agent; const char *auth_string; const char *content_length; int read_len = 0; int send_accts = 0; /* get the user agent; reject if wrong agent */ user_agent = getenv ("HTTP_USER_AGENT"); if (strncmp ("gnucash", user_agent, 7)) { reject_user_agent (user_agent); continue; } /* get the request method */ request_method = getenv ("REQUEST_METHOD"); if (strcmp ("POST", request_method)) { /* method=post is the only spported method*/ reject_method(request_method); continue; } /* ----------------------------------------------- */ /* look for an authentication cookie */ auth_string = find_cookie ("gnc-server"); /* found the cookie, lets make sure that it is valid */ if (auth_string) { gboolean valid_session; valid_session = have_session (auth_string); if (!valid_session) { /* XXX invalid sessions are a sign of hacking; * this event should be noted in a security log * and the server admin contacted. */ reject_session (auth_string); continue; } } /* go ahead and read the message body. * we'll need this soon enough */ content_length = getenv("CONTENT_LENGTH"); read_len = atoi (content_length); /* read 'read_len' bytes from stdin ... */ request_bufp = (char *) g_malloc (read_len); fread (request_bufp, read_len, 1, stdin); /* if no previously authenticated session, * authenticate now */ if (!auth_string) { char *name = NULL, *passwd = NULL; parse_for_login (request_bufp, &name, &passwd); auth_string = auth_user (name, passwd); if (!auth_string) { reject_auth(); g_free (request_bufp); continue; } send_accts = 1; } /* ----------------------------------------------- */ /* send only the accounts to the user */ if (send_accts) { /* print the HTTP header */ printf("Content-type: text/gnc-xml\r\n" "Set-Cookie: %s\r\n" "Content-Length: %d\r\n" "\r\n", auth_string, sz); /* since this is the first time the user is logging * in, send them the full set of accounts. * (Do not send them any transactions yet). */ gncxml_write_account_tree_to_buf(root, &reply_bufp, &sz); /* send the xml to the client */ printf ("%s", reply_bufp); g_free (request_bufp); /* wait for the next request */ continue; } /* ----------------------------------------------- */ /* If we got to here, then the ser should be sending * us a query xml. * we should somehow error check that what we got * is really a valid query */ /* conver the xml input into a gnucash query structure... */ q = gncxml_read_query (request_bufp, read_len); xaccQuerySetGroup (q, root); /* hack -- limit to 30 splits ... */ xaccQuerySetMaxSplits (q, 30); split_list = xaccQueryGetSplits (q); /* poke those splits into an ccount group structure */ /* XXX not implemented */ /* send the account group structure back to the user */ /* XXX not implemented */ xaccFreeQuery (q); g_free (request_bufp); } bookerrexit: err = gnc_book_get_error (book); /* 500 Server Error */ FCGI_SetExitStatus (500); printf("Content-type: text/plain\r\n\r\n" "error was %s\n", strerror (err)); FCGI_Finish(); /* close the book */ qof_book_destroy (book); /* shut down the engine */ gnc_engine_shutdown (); sleep (1); /* must return a non-zero error code, otherwise fastcgi * attempts to respawn this daemon. */ return 500; }
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); }
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); }