* 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"
+;;
+