File: test-loadsave.c

package info (click to toggle)
gdome2 0.8.1%2Bdebian-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,492 kB
  • ctags: 1,947
  • sloc: ansic: 23,268; sh: 6,710; xml: 476; makefile: 474
file content (200 lines) | stat: -rw-r--r-- 7,418 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/* test-loadsave.c
 *
 * Copyright (C) 2001 Paolo Casarini <paolo@casarini.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <gdome.h>

char buffer1[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
                 "<!DOCTYPE TEST [\n"
                 "  <!ELEMENT TEST ANY>\n"
                 "  <!ELEMENT OTHER ANY>\n"
                 "  <!ELEMENT NODE ANY>\n"
                 "  <!ATTLIST NODE\n"
                 "    ITEM ID #REQUIRED\n"
                 "  >\n"
                 "]>\n"
                 "<TEST>\n"
                 "  <OTHER>\n"
                 "    <OTHER>\n"
                 "      <OTHER>\n"
                 "        <NODE ITEM=\"A\">zero</NODE>\n"
                 "        <NODE ITEM=\"B\">one</NODE>\n"
                 "      </OTHER>\n"
                 "      <NODE ITEM=\"C\">two</NODE>\n"
                 "    </OTHER>\n"
                 "  </OTHER>\n"
                 "  <NODE ITEM=\"D\">three\n"
                 "    <OTHER>\n"
                 "      <OTHER></OTHER>\n"
                 "    </OTHER>\n"
                 "    <NODE ITEM=\"E\">four</NODE>\n"
                 "    <NODE ITEM=\"F\">five</NODE>\n"
                 "  </NODE>\n"
                 "  <OTHER>\n"
                 "    <OTHER>\n"
                 "      <OTHER>\n"
                 "        <NODE ITEM=\"G\">six</NODE>\n"
                 "        <NODE ITEM=\"I\">seven</NODE>\n"
                 "      </OTHER>\n"
                 "      <NODE ITEM=\"L\">eight</NODE>\n"
                 "    </OTHER>\n"
                 "  </OTHER>\n"
                 "</TEST>\n";

char buffer2[] = "<?xml version=\"1.0\"?>\n"
                 "<!DOCTYPE TEST [\n"
                 "  <!ELEMENT TEST ANY>\n"
                 "  <!ENTITY foo \"bar\">\n"
                 "]>\n"
                 "<TEST>\n"
                 "  &Uogon;\n"
                 "  &foo;\n"
                 "  &UpArrowDownArrow;\n"
                 "</TEST>\n";

const GdomeEntitiesTableEntry entityTable[] = {
{ "UnderBar", "\xcc\xb2\x00", NULL, NULL },
{ "UnderBrace", "\xef\xb8\xb8\x00", NULL, NULL },
{ "UnderBracket", "\xe2\x8e\xb5\x00", NULL, NULL },
{ "UnderParenthesis", "\xef\xb8\xb6\x00", NULL, NULL },
{ "Union", "\xe2\x8b\x83\x00", NULL, NULL },
{ "UnionPlus", "\xe2\x8a\x8e\x00", NULL, NULL },
{ "uogon", "\xc5\xb3\x00", NULL, NULL },
{ "Uogon", "\xc5\xb2\x00", NULL, NULL },
{ "uopf", "\xf0\x9d\x95\xa6\x00", NULL, NULL },
{ "Uopf", "\xf0\x9d\x95\x8c\x00", NULL, NULL },
{ "uparrow", "\xe2\x86\x91\x00", NULL, NULL },
{ "Uparrow", "\xe2\x87\x91\x00", NULL, NULL },
{ "UpArrow", "\xe2\x86\x91\x00", NULL, NULL },
{ "UpArrowBar", "\xe2\xa4\x92\x00", NULL, NULL },
{ "UpArrowDownArrow", "\xe2\x87\x85\x00", NULL, NULL },
{ NULL, NULL, NULL, NULL}};

void
dot() {
	printf(".");
	fflush(stdout);
}

int
main (int argc, char **argv)
{
	GdomeDOMImplementation *domImpl = NULL;
	GdomeDocument *domdoc = NULL;
  GdomeException exc = 0;
  char *mem;

	domImpl = gdome_di_mkref();

  domdoc = gdome_di_createDocFromURI (domImpl, LOCALDIR"/test-document2.xml", GDOME_LOAD_PARSING, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromURI: parsing failed\n   test-document2.xml not found\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromURI (domImpl, LOCALDIR"/test-document2.xml", GDOME_LOAD_PARSING | GDOME_LOAD_SUBSTITUTE_ENTITIES, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromURI: parsing with substitution failed\n   test-document2.xml not found\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromURI (domImpl, LOCALDIR"/test-loadsave1.xml", GDOME_LOAD_VALIDATING, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromURI: validating failed\n   test-loadsave1.xml not found\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromMemory (domImpl, buffer1, GDOME_LOAD_PARSING, &exc);
  if (domdoc == NULL) {
		fprintf (stderr, "DOMImplementation.createDocFromMemory: parsing failed\n");
		return -1;
  }
	if (!gdome_di_saveDocToMemory (domImpl, domdoc, &mem, 0, &exc)) {
		fprintf (stderr, "DOMImplementation.saveDocToMemory: failed\n");
		return -1;
	}
  free (mem);
	if (!gdome_di_saveDocToMemoryEnc (domImpl, domdoc, &mem, "ISO-8859-1", 0, &exc)) {
		fprintf (stderr, "DOMImplementation.saveDocToMemory: failed\n");
		return -1;
  }
  free (mem);
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromMemory (domImpl, buffer1, GDOME_LOAD_VALIDATING, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromMemory: validating failed\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromURIWithEntitiesTable (domImpl, LOCALDIR"/test-loadsave2.xml", entityTable, GDOME_LOAD_PARSING, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromURIWithEntityTable: parsing failed\n   test-loadsave2.xml not found\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromURIWithEntitiesTable (domImpl, LOCALDIR"/test-loadsave2.xml", entityTable, GDOME_LOAD_PARSING | GDOME_LOAD_SUBSTITUTE_ENTITIES, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromURIWithEntityTable: parsing with substitution failed\n   test-loadsave2.xml not found\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromURIWithEntitiesTable (domImpl, LOCALDIR"/test-loadsave1.xml", entityTable,  GDOME_LOAD_VALIDATING, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromURIWithEntityTable: validating failed\n   test-loadsave2.xml not found\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromMemoryWithEntitiesTable (domImpl, buffer2, entityTable,  GDOME_LOAD_PARSING, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromMemoryWithEntityTable: parsing failed\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  domdoc = gdome_di_createDocFromMemoryWithEntitiesTable (domImpl, buffer2, entityTable, GDOME_LOAD_VALIDATING, &exc);
  if (domdoc == NULL) {
      fprintf (stderr, "DOMImplementation.createDocFromMemoryWithEntityTable: validating failed\n");
      return -1;
  }
  gdome_doc_unref(domdoc, &exc);
  dot();

  printf("test_loadsave\n");

  return 0;
}