]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/gdome_xslt/C/test/test.c
ocaml 3.09 transition
[helm.git] / helm / DEVEL / gdome_xslt / C / test / test.c
1 /* This file is a test for the XSLT engine working on Gdome documents.
2  *
3  * Copyright (C) 2002 Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
4  * 
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * 
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * For more information, please send an email to <sacerdot@cs.unibo.it>
20  */
21
22 #include <stdio.h>
23 #include <gdome.h>
24 #include <libxslt/xsltconfig.h>
25 #include <libxslt/xslt.h>
26 #include <libxslt/imports.h>
27
28 #include "gdome_xslt.h"
29
30 #define OUTPUT_FILE             "../../test_files/output.xml"
31 #define CORRECT_OUTPUT_FILE     "../../test_files/output.xml.correct"
32
33 GdomeDocument* loadDocument(GdomeDOMImplementation *domimpl, char *uri)
34 {
35    GdomeDocument *doc;
36    GdomeException exc;
37
38    doc = gdome_di_createDocFromURI(domimpl, uri, GDOME_LOAD_PARSING, &exc);
39    if (doc == NULL) {
40       fprintf (stderr,
41                "DOMImplementation.createDocFromURI: failed\n\tException #%d\n",
42                exc);
43    }
44
45    return doc;
46 }
47
48 /*      // old version: use gdome serialization
49 int saveDocument(GdomeDOMImplementation *domimpl, GdomeDocument* doc, char *uri)
50 {
51    GdomeException exc;
52
53    if (!gdome_di_saveDocToFile (domimpl, doc, uri, GDOME_SAVE_STANDARD, &exc)) {
54       fprintf (stderr,
55                "DOMImplementation.saveDocToFile: failed\n\tException #%d\n",
56                exc);
57       return 0;
58    }
59
60    return 1;
61 }
62 */
63
64         /* new version, use libxslt serialization */
65 int saveDocument(char* fname, GdomeDocument* result, xsltStylesheetPtr style) {
66         return saveResultToFilename(fname, result, style, 0);
67 }
68
69 int main(void)
70 {
71    int bytes;
72    GdomeDOMImplementation *domimpl;
73    GdomeDocument *input;
74    GdomeDocument *style;
75    xsltStylesheetPtr style_libxslt;
76    GdomeDocument *output;
77    GdomeException exc;
78    const char* params[] = {"parameter1", "'value1'",
79                            "parameter2", "'value2'",
80                            "parameter3", "'value3'",
81                            NULL};
82
83    domimpl = gdome_di_mkref();
84
85    if (!(input = loadDocument(domimpl, "../../test_files/input.xml"))) return 1;
86    if (!(style = loadDocument(domimpl, "../../test_files/stylesheet.xsl"))) return 1;
87
88    style_libxslt = processStylesheet(style);
89
90    output = applyStylesheet(input, style_libxslt, params);
91
92 /*    if (!(saveDocument(domimpl, output, "../../test_files/output.xml"))) return 1; */
93    bytes = saveDocument("../../test_files/output.xml", output, style_libxslt);
94
95    xsltFreeStylesheet(style_libxslt);
96    gdome_di_freeDoc (domimpl, input, &exc);
97    gdome_di_freeDoc (domimpl, style, &exc);
98    gdome_di_freeDoc (domimpl, output, &exc);
99    gdome_di_unref (domimpl, &exc);
100
101    printf("The test was successful iff %s is equal to %s\n",
102           OUTPUT_FILE,
103           CORRECT_OUTPUT_FILE);
104
105    return 0;
106 }