sixtp * generic_timespec_parser_new(sixtp_end_handler end_handler) { sixtp *top_level = sixtp_set_any(sixtp_new(), FALSE, SIXTP_START_HANDLER_ID, generic_timespec_start_handler, SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace, SIXTP_END_HANDLER_ID, end_handler, SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data, SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children, SIXTP_RESULT_FAIL_ID, sixtp_child_free_data, SIXTP_NO_MORE_HANDLERS); g_return_val_if_fail(top_level, NULL); if (!sixtp_add_some_sub_parsers( top_level, TRUE, "s", timespec_sixtp_new(generic_timespec_secs_end_handler), "ns", timespec_sixtp_new(generic_timespec_nsecs_end_handler), 0)) { return NULL; } return(top_level); }
void test_files_in_dir(int argc, char **argv, gxpf_callback cb, sixtp *parser, const char *parser_tag, QofBook *book) { int count; sixtp *main_parser; sixtp *top_parser; top_parser = sixtp_new(); main_parser = sixtp_new(); if (!sixtp_add_some_sub_parsers(top_parser, TRUE, "gnc-v2", main_parser, NULL, NULL)) return; if (!sixtp_add_some_sub_parsers(main_parser, TRUE, parser_tag, parser, NULL, NULL)) return; for (count = 1; count < argc; count++) { struct stat file_info; const char *to_open = argv[count]; if (g_stat(to_open, &file_info) != 0) { printf("cannot stat %s.\n", to_open); failure("unable to stat file"); } else { if (!S_ISDIR(file_info.st_mode)) { #ifdef __DEBUG printf( "testing load of file \"%s\":\n", argv[count] ); #endif test_load_file(to_open, cb, top_parser, book); } } } sixtp_destroy(top_parser); }
static void test_db (GNCPriceDB* db) { xmlNodePtr test_node; gchar* filename1; int fd; QofBook* book = qof_instance_get_book (QOF_INSTANCE (db)); test_node = gnc_pricedb_dom_tree_create (db); if (!test_node && db) { failure_args ("pricedb_xml", __FILE__, __LINE__, "gnc_pricedb_dom_tree_create returned NULL"); return; } if (!db) return; filename1 = g_strdup_printf ("test_file_XXXXXX"); fd = g_mkstemp (filename1); write_dom_node_to_file (test_node, fd); close (fd); { sixtp *parser; load_counter lc = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; sixtp_gdv2 data = {book, lc, NULL, NULL, FALSE}; parser = sixtp_new (); if (!sixtp_add_some_sub_parsers (parser, TRUE, "gnc:pricedb", gnc_pricedb_sixtp_parser_create (), NULL, NULL)) { failure_args ("sixtp_add_some_sub_parsers failed", __FILE__, __LINE__, "%d", iter); } else if (!gnc_xml_parse_file (parser, filename1, test_add_pricedb, (gpointer)&data, qof_session_get_book (session))) { failure_args ("gnc_xml_parse_file returned FALSE", __FILE__, __LINE__, "%d", iter); } } g_unlink (filename1); g_free (filename1); xmlFreeNode (test_node); }