]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/gdome_xslt/C/test/test.c
Initial version.
[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 <libgdome/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 GdomeDocument* loadDocument(GdomeDOMImplementation *domimpl, char *uri)
31 {
32    GdomeDocument *doc;
33    GdomeException exc;
34
35    doc = gdome_di_createDocFromURI(domimpl, uri, GDOME_LOAD_PARSING, &exc);
36    if (doc == NULL) {
37       fprintf (stderr,
38                "DOMImplementation.createDocFromURI: failed\n\tException #%d\n",
39                exc);
40    }
41
42    return doc;
43 }
44
45 int saveDocument(GdomeDOMImplementation *domimpl, GdomeDocument* doc, char *uri)
46 {
47    GdomeException exc;
48
49    if (!gdome_di_saveDocToFile (domimpl, doc, uri, GDOME_SAVE_STANDARD, &exc)) {
50       fprintf (stderr,
51                "DOMImplementation.saveDocToFile: failed\n\tException #%d\n",
52                exc);
53       return 0;
54    }
55
56    return 1;
57 }
58
59
60 int main(void)
61 {
62    GdomeDOMImplementation *domimpl;
63    GdomeDocument *input;
64    GdomeDocument *style;
65    xsltStylesheetPtr style_libxslt;
66    GdomeDocument *output;
67    GdomeException exc;
68    const char* params[] = {"parameter1", "'value1'",
69                            "parameter2", "'value2'",
70                            "parameter3", "'value3'",
71                            NULL};
72
73    domimpl = gdome_di_mkref();
74
75    if (!(input = loadDocument(domimpl, "../../test_files/input.xml"))) return 1;
76    if (!(style = loadDocument(domimpl, "../../test_files/stylesheet.xsl"))) return 1;
77
78    style_libxslt = processStylesheet(style);
79
80    output = applyStylesheet(input, style_libxslt, params);
81
82    if (!(saveDocument(domimpl, output, "../../test_files/output.xml"))) return 1;
83
84    xsltFreeStylesheet(style_libxslt);
85    gdome_di_freeDoc (domimpl, input, &exc);
86    gdome_di_freeDoc (domimpl, style, &exc);
87    gdome_di_freeDoc (domimpl, output, &exc);
88    gdome_di_unref (domimpl, &exc);
89
90    printf("The test was successful iff ../../test_files/output.xml.correct is\n");
91    printf("equal to ../../test_files/output.xml\n");
92
93    return 0;
94 }