From 3530223a9d7db5753c4f8ae897166e86db1bd2fa Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Wed, 16 Apr 2003 12:49:35 +0000 Subject: [PATCH] updated serialization test --- helm/hbugs/test/HBUGS_MESSAGES.xml | 196 ++++++++++++++++---------- helm/hbugs/test/Makefile | 3 +- helm/hbugs/test/test_serialization.ml | 56 +++++--- 3 files changed, 159 insertions(+), 96 deletions(-) diff --git a/helm/hbugs/test/HBUGS_MESSAGES.xml b/helm/hbugs/test/HBUGS_MESSAGES.xml index f6ee8362b..cf15dde3d 100644 --- a/helm/hbugs/test/HBUGS_MESSAGES.xml +++ b/helm/hbugs/test/HBUGS_MESSAGES.xml @@ -1,102 +1,144 @@ + - + - + -usage string + usage string -corpo dell'exc + corpo dell'exc - + - + - + - + - - - - - - + + + + + + - - - + + + 0 + + + + + + - + + + - - - - - - descrizione del tutor - - + - + - + + + + + + descrizione del tutor + + - - - + - - extras - + - + - + + + - + + + + + - - description 1 - description 2 - - description N - + + + + + + + + - - description 1 - description 2 - - description N - + - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - + + description 1 + description 2 + + description N + + + description 1 + description 2 + + description N + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + diff --git a/helm/hbugs/test/Makefile b/helm/hbugs/test/Makefile index 9bd02bfa3..0b3debf74 100644 --- a/helm/hbugs/test/Makefile +++ b/helm/hbugs/test/Makefile @@ -1,4 +1,5 @@ -all: +all: test_serialization +test_serialization: test_serialization.ml OCAMLPATH="../meta" ocamlfind ocamlc -linkpkg -package hbugs-common -o test_serialization test_serialization.ml clean: rm -f *.cm[io] test_serialization 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" +;; + -- 2.39.2