Commit b1e0581f authored by gerd's avatar gerd

Added tests for marshalling and namespaces.


git-svn-id: https://godirepo.camlcity.org/svn/lib-pxp/trunk@345 dbe99aee-44db-0310-b2b3-d33182c8eb97
parent 9716e28c
......@@ -7,9 +7,17 @@
OCAMLPATH=../..
all: compile marshal marshal_namespace
compile: compile.ml
ocamlfind ocamlc -g -custom -o compile -package .,str -linkpkg compile.ml
marshal: marshal.ml
ocamlfind ocamlc -g -custom -o marshal -package .,str -linkpkg marshal.ml
marshal_namespace: marshal_namespace.ml
ocamlfind ocamlc -g -custom -o marshal_namespace -package .,str -linkpkg marshal_namespace.ml
#----------------------------------------------------------------------
.PHONY: all
all:
......@@ -17,6 +25,7 @@ all:
.PHONY: clean
clean:
rm -f *.cmi *.cmo *.cma *.cmx *.o *.a *.cmxa sample sample.ml out1 out2
rm -f *.d1 *.d2 *.d3 *.out
.PHONY: CLEAN
CLEAN: clean
......@@ -24,5 +33,5 @@ CLEAN: clean
.PHONY: distclean
distclean: clean
rm -f *~
rm -f compile
rm -f compile marshal marshal_namespace
(* $Id: marshal_namespace.ml,v 1.1 2001/06/07 20:14:47 gerd Exp $
* ----------------------------------------------------------------------
*
*)
(* This is not a good test whether marshalling works. It does:
* (a) serializes a document (sample002.d1), then unserializes it
* (b) serializes the output of (a) (sample002.d2), then unserializes it
* (c) serializes the output of (b) (sample002.d3)
* After that, it is checked whether the serialized document of (a) is
* equal to the output of (c).
* However, if information is lost during serialization/unserialization,
* this test cannot detect the loss. Because of this, a fourth file is
* written: sample002.xml.out (output of (a))
*)
open Pxp_yacc
open Pxp_document
open Pxp_types
let conf =
{ default_config with
enable_pinstr_nodes = true;
enable_super_root_node = true;
enable_comment_nodes = true;
enable_namespace_processing = Some (new namespace_manager);
encoding = `Enc_utf8;
};;
let spec = default_namespace_spec;;
let main() =
let doc = parse_document_entity
conf
(from_file "sample002.xml")
spec in
let out = open_out_bin "sample002.d1" in
Pxp_marshal.document_to_channel out doc;
close_out out;
let inc = open_in_bin "sample002.d1" in
let doc' = Pxp_marshal.document_from_channel inc conf spec in
close_in inc;
let xmlout = open_out "sample002.xml.out" in
doc' # write (Out_channel xmlout) `Enc_utf8;
close_out xmlout;
let out' = open_out_bin "sample002.d2" in
Pxp_marshal.document_to_channel out' doc';
close_out out';
let inc' = open_in_bin "sample002.d2" in
let doc'' = Pxp_marshal.document_from_channel inc' conf spec in
close_in inc';
let out'' = open_out_bin "sample002.d3" in
Pxp_marshal.document_to_channel out'' doc'';
close_out out'';
assert(Sys.command "cmp sample002.d1 sample002.d3" = 0);
()
;;
try
main()
with
ex ->
prerr_endline ("Error happened:\n" ^ string_of_exn ex);
exit 1
;;
(* ======================================================================
* History:
*
* $Log: marshal_namespace.ml,v $
* Revision 1.1 2001/06/07 20:14:47 gerd
* Added tests for marshalling and namespaces.
*
*
*)
(* $Id: marshal_simple.ml,v 1.1 2001/06/07 20:14:47 gerd Exp $
* ----------------------------------------------------------------------
*
*)
(* This is not a good test whether marshalling works. It does:
* (a) serializes a document (sample001.d1), then unserializes it
* (b) serializes the output of (a) (sample001.d2), then unserializes it
* (c) serializes the output of (b) (sample001.d3)
* After that, it is checked whether the serialized document of (a) is
* equal to the output of (c).
* However, if information is lost during serialization/unserialization,
* this test cannot detect the loss. Because of this, a fourth file is
* written: sample001.xml.out (output of (a))
*)
open Pxp_yacc
open Pxp_document
open Pxp_types
let conf =
{ default_config with
enable_pinstr_nodes = true;
enable_super_root_node = true;
enable_comment_nodes = true;
encoding = `Enc_utf8;
};;
let main() =
let doc = parse_document_entity
conf
(from_file "sample001.xml")
default_spec in
let out = open_out_bin "sample001.d1" in
Pxp_marshal.document_to_channel out doc;
close_out out;
let inc = open_in_bin "sample001.d1" in
let doc' = Pxp_marshal.document_from_channel inc conf default_spec in
close_in inc;
let xmlout = open_out "sample001.xml.out" in
doc' # write (Out_channel xmlout) `Enc_utf8;
close_out xmlout;
let out' = open_out_bin "sample001.d2" in
Pxp_marshal.document_to_channel out' doc';
close_out out';
let inc' = open_in_bin "sample001.d2" in
let doc'' = Pxp_marshal.document_from_channel inc' conf default_spec in
close_in inc';
let out'' = open_out_bin "sample001.d3" in
Pxp_marshal.document_to_channel out'' doc'';
close_out out'';
assert(Sys.command "cmp sample001.d1 sample001.d3" = 0);
()
;;
main();;
(* ======================================================================
* History:
*
* $Log: marshal_simple.ml,v $
* Revision 1.1 2001/06/07 20:14:47 gerd
* Added tests for marshalling and namespaces.
*
*
*)
<!DOCTYPE x:a [
<!ELEMENT x:a ANY>
<!ELEMENT x:b ANY>
<!ELEMENT y:a ANY>
<!ELEMENT y:b ANY>
<!ELEMENT z:a ANY>
<!ELEMENT z:b ANY>
<!ATTLIST x:a x:r CDATA #IMPLIED
y:r CDATA #IMPLIED
z:r CDATA #IMPLIED>
]>
<x:a xmlns:x="space-x" xmlns:y="space-y" xmlns:z="space-z">
<b xmlns="space-y" xmlns:z="space-x">
<z:a x:r="a" y:r="b"/> <!-- x:r would cause an error! -->
</b>
<b xmlns="space-z">
<z:a/>
</b>
</x:a>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment