]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/gdome_xslt/ocaml/test/test.ml
ocaml 3.09 transition
[helm.git] / helm / DEVEL / gdome_xslt / ocaml / test / test.ml
1 (* This file is part of an ocaml binding of an XSLT engine working on Gdome
2  * documents.
3  * 
4  * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT
5  * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT)
6  *
7  * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
8  * 
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  * 
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  *
23  * For more information, please send an email to <sacerdot@cs.unibo.it>
24  *)
25
26 let (output_file,
27      correct_output_file,
28      input_file,
29      stylesheet_file)  =
30   ("../../test_files/output.xml",
31    "../../test_files/output.xml.correct",
32    "../../test_files/input.xml",
33    "../../test_files/stylesheet.xsl")
34 in
35 let domImpl = Gdome.domImplementation () in
36  let input =
37   domImpl#createDocumentFromURI ~uri:input_file ()
38  and style =
39   domImpl#createDocumentFromURI ~uri:stylesheet_file ()
40  in
41   (* First of all, let's try the exception handling machinery *)
42   let _ =
43    try
44     ignore (Gdome_xslt.processStylesheet input);
45     assert false (* previous line should rise an exception *)
46    with
47     Gdome_xslt_init.ProcessStylesheetException -> ()
48   in
49   let pstyle = Gdome_xslt.processStylesheet style in
50    let output =
51     Gdome_xslt.applyStylesheet input pstyle
52      ["parameter1","'value1'" ;
53       "parameter2","'value2'" ;
54       "parameter3","'value3'"
55      ]
56    in
57 (*  (* old version: use gdome serialization functions *)
58     let res =
59      domImpl#saveDocumentToFile ~doc:output ~name:output_file ()
60     in
61      if not res then
62       prerr_endline ("Error saving to document " ^ output_file)
63      else
64       begin
65        Printf.printf
66         "The test was successful iff %s is equal to %s\n"
67         output_file
68         correct_output_file
69       end
70 *)
71   (* new version: use libxslt serialization functions *)
72   let outchan = open_out output_file in
73   Gdome_xslt.saveResultToChannel ~outchan ~result:output ~stylesheet:pstyle;
74   close_out outchan;
75   Printf.printf
76    "The test was successful iff %s is equal to %s\n"
77    output_file
78    correct_output_file
79 ;;