X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fhbugs%2Ftest%2Ftest_serialization.ml;h=1afd74379b6cd566f10b530d9f422aab31511221;hb=30cbad3167cf714a8edc2dbc05c1fe8908e2542b;hp=bc78e1cd03327cb51e4e78a65e1ab759a0cca3dc;hpb=4bf917b35e5ce1a71b5b8923800fb8eaba1b3943;p=helm.git diff --git a/helm/hbugs/test/test_serialization.ml b/helm/hbugs/test/test_serialization.ml index bc78e1cd0..1afd74379 100644 --- a/helm/hbugs/test/test_serialization.ml +++ b/helm/hbugs/test/test_serialization.ml @@ -1,5 +1,7 @@ (* - * Copyright (C) 2003, HELM Team. + * Copyright (C) 2003: + * Stefano Zacchiroli + * for the HELM Team http://helm.cs.unibo.it/ * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science @@ -21,28 +23,48 @@ * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, - * http://cs.unibo.it/helm/. + * http://helm.cs.unibo.it/ *) -(* test serialization/deserialization of Hbugs_messages module. File given as -cmd line argument is read line by line, each line is expected to contain a -Hbugs_types.message that is parsed, pretty printed and parsed again to check for -serialization consistency *) +open Pxp_document;; +open Pxp_dtd;; +open Pxp_types;; +open Pxp_yacc;; + open Printf;; -let fname = Sys.argv.(1) in -let ic = open_in fname in -let lineno = ref 1 in -try - while true do - let line = input_line ic in - let msg = Hbugs_messages.msg_of_string line in + +let test_data = "HBUGS_MESSAGES.xml" ;; + +let test_message (n:('a Pxp_document.extension as 'b) Pxp_document.node as 'a) = + try + let msg_string = + let buf = Buffer.create 1000 in + n#write (`Out_buffer buf) `Enc_utf8; + Buffer.contents buf + in + let msg = Hbugs_messages.msg_of_string msg_string in let pp = Hbugs_messages.string_of_msg msg in let msg' = Hbugs_messages.msg_of_string pp in - assert (msg = msg'); - incr lineno - done -with -| End_of_file -> prerr_endline "All done!" -| exc -> + if (msg <> msg') then + prerr_endline + (sprintf "Failure with msg %s" + (match n#node_type with T_element name -> name | _ -> assert false)) + with e -> prerr_endline - (sprintf "Failure at line %d: %s" !lineno (Printexc.to_string exc)) + (sprintf "Failure with msg %s: uncaught exception %s" + (match n#node_type with T_element name -> name | _ -> assert false) + (Printexc.to_string e)) +;; + +let is_xml_element n = + match n#node_type with T_element _ -> true | _ -> false +;; + +let root = + parse_wfcontent_entity default_config (from_file test_data) default_spec +in +printf "Testing all messages from %s ...\n" test_data; flush stdout; +List.iter test_message (List.filter is_xml_element root#sub_nodes); +printf "Done!\n" +;; +