X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fhbugs%2Ftest%2Ftest_serialization.ml;h=1afd74379b6cd566f10b530d9f422aab31511221;hb=3530223a9d7db5753c4f8ae897166e86db1bd2fa;hp=83fdef29d6caa7e1073a4e670e4343f51c9e7039;hpb=2153805fd8c6f53f2429a3c2c3fa53880de8a487;p=helm.git diff --git a/helm/hbugs/test/test_serialization.ml b/helm/hbugs/test/test_serialization.ml index 83fdef29d..1afd74379 100644 --- a/helm/hbugs/test/test_serialization.ml +++ b/helm/hbugs/test/test_serialization.ml @@ -26,25 +26,45 @@ * 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" +;; +