File: TestXalanTransformer.cpp

package info (click to toggle)
xalan 1.10-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 16,600 kB
  • ctags: 14,764
  • sloc: cpp: 152,342; xml: 6,835; sh: 3,267; makefile: 868; ansic: 370
file content (351 lines) | stat: -rw-r--r-- 7,060 bytes parent folder | download | duplicates (5)
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*
 * Copyright 1999-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <xalanc/Include/PlatformDefinitions.hpp>



#define TEST_XALAN_CPP


// This is here for memory leak testing.
#if defined(_DEBUG)
#include <crtdbg.h>
#endif



#include <xercesc/util/PlatformUtils.hpp>


#if defined(TEST_XALAN_CPP)

#include <xalanc/XalanTransformer/XalanTransformer.hpp>

#if defined(XALAN_CLASSIC_IOSTREAMS)
#include <iostream.h>
#include <strstream.h>
#else
#include <iostream>
#include <strstream>
#endif


XALAN_USING_STD(cerr)
XALAN_USING_STD(cout)
XALAN_USING_STD(endl)
XALAN_USING_STD(ostrstream)

#else

#include <xalanc/XalanTransformer/XalanCAPI.h>

#include <cstdio>

#endif


static CallbackSizeType xalan_output_handler(const char *data, CallbackSizeType length, void *handle)
{
	FILE *fp = (FILE*)handle;

	return fwrite( data, sizeof( char ), length, fp );
}



static void xalan_flush_handler(void *handle)
{
	FILE *fp = (FILE*)handle;

	fflush(fp);
}



int
runTests()
{
	const char* const		theXMLFileName = "d:\\xslt\\xsl-test\\perf\\basic\\basic-all_well.xml";
	const char* const 		theXSLFileName = "d:\\xslt\\xsl-test\\perf\\basic\\basic-all_well.xsl";
	const char* const		theOutFileName = "d:\\Transformer-Results\\basic-all_well.out";

	const char* const 		theXMLFileName2 = "d:\\xslt\\xsl-test\\perf\\basic\\miscfam.xml";
	const char* const		theXSLFileName2 = "d:\\xslt\\xsl-test\\perf\\basic\\miscfam.xsl";

	const char* const 		theXMLFileName3 = "d:\\xslt\\xsl-test\\conf\\embed\\embed01.xml";	
	const char* const		theOutFileName3 = "d:\\Transformer-Results\\embed01.out";

	const char* const 		theXMLFileName4 = "d:\\xml-xalan\\c\\samples\\UseStylesheetParam\\foo.xml";	
	const char* const 		theXSLFileName4 = "d:\\xml-xalan\\c\\samples\\UseStylesheetParam\\foo.xsl";	

#if defined(TEST_XALAN_CPP)

	XALAN_USING_XALAN(XalanTransformer)
	XALAN_USING_XALAN(XalanCompiledStylesheet)

	XalanTransformer	xalan;

	const XalanCompiledStylesheet*	css = 0;
	
	if (xalan.compileStylesheet(theXSLFileName, css) != 0)
	{
		cout << xalan.getLastError();

		return 0;	
	}

	for(int i=0; i<1; ++i)
	{

		if(xalan.transform(theXMLFileName, css, "d:\\transformer-results\\css.out"))
		{
			cout << xalan.getLastError();

			return 0;	
		}
		
		if(xalan.transform(theXMLFileName3, theOutFileName3))
		{
			cout << xalan.getLastError();

			return 0;	
		}

		if(xalan.transform(theXMLFileName, theXSLFileName, theOutFileName))
		{
			cout << xalan.getLastError();

			return 0;	
		}

		ostrstream	theOutput;

		if(xalan.transform(theXMLFileName2, theXSLFileName2, &theOutput))
		{
			cout << xalan.getLastError();

			return 0;	
		}

		theOutput << '\0';

		cout << theOutput.str();

		theOutput.freeze(false);

		ostrstream	theOutput3;

		if(xalan.transform(theXMLFileName3, theOutput3))
		{
			cout << xalan.getLastError();

			return 0;	
		}
/*		
		if(xalan.transform(theXMLFileName, css, cout))
		{
			cout << xalan.getLastError();

			return 0;	
		}
*/		
		xalan.setStylesheetParam("param1",
								 "'What is Up'");

		if(xalan.transform(theXMLFileName4, theXSLFileName4, &cout))
		{
			cout << xalan.getLastError();

			return 0;	
		}

		if(xalan.transform(theXMLFileName4, theXSLFileName4, &cout))
		{
			cout << xalan.getLastError();

			return 0;	
		}
	}

#else
	// $$$ ToDo: This C code is broken, because it returns without
	// shutting things down!!!!
	XalanInitialize();

	XalanHandle xalan = CreateXalanTransformer();
	XalanCSSHandle theXalanCSS2;
	XalanCSSHandle theXalanCSS4;
	XalanPSHandle  theXalanPS2;

	if (XalanCompileStylesheet(theXSLFileName2, xalan, &theXalanCSS2) != 0)
	{
		puts("Error");
		puts(XalanGetLastError(xalan));

		return 0;	
	}

	if (XalanCompileStylesheet(theXSLFileName4, xalan, &theXalanCSS4) != 0)
	{
		puts("Error");
		puts(XalanGetLastError(xalan));

		return 0;	
	}

	if (XalanParseSource(theXMLFileName2, xalan, &theXalanPS2) != 0)
	{
		puts("Error");
		puts(XalanGetLastError(xalan));

		return 0;	
	}

	for(int i = 0; i < 2; ++i)
	{
		if(XalanTransformToFile(theXMLFileName, theXSLFileName, theOutFileName, xalan))
		{
			puts("Error");
			puts(XalanGetLastError(xalan));
			return 0;	
		}

		char* 	theOutput;

		if(XalanTransformToData(theXMLFileName2, theXSLFileName2, &theOutput, xalan))
		{
			puts("Error");
			puts(XalanGetLastError(xalan));
			return 0;	
		}

		puts(theOutput);

		XalanFreeData(theOutput);

		if(XalanTransformToFile(theXMLFileName3, NULL, theOutFileName3, xalan))
		{
			puts("Error");
			puts(XalanGetLastError(xalan));
			return 0;	
		}
		
		if(XalanTransformToData(theXMLFileName3, NULL, &theOutput, xalan))
		{
			puts("Error");
			puts(XalanGetLastError(xalan));
			return 0;	
		}

		puts(theOutput);

		XalanFreeData(theOutput);

		if(XalanTransformToDataPrebuilt(theXalanPS2, theXalanCSS2, &theOutput, xalan))
		{
			puts("Error");
			puts(XalanGetLastError(xalan));
			return 0;	
		}

		puts(theOutput);

		XalanFreeData(theOutput);

		FILE* fp =0;
		fp = fopen("c:\\temp\\test.out", "w");

		if(XalanTransformToHandler(theXMLFileName2, theXSLFileName2, xalan, fp, xalan_output_handler, xalan_flush_handler))
		{
			puts("Error");
			puts(XalanGetLastError(xalan));
			return 0;	
		}

		fclose(fp);

		XalanSetStylesheetParam("param1", "'hi'", xalan);

		//if(xalan.transform(theXMLFileName4, theXSLFileName4, &cout))
		if(XalanTransformToDataPrebuilt(theXMLFileName4, theXalanCSS4, &theOutput, xalan))
		{
			puts("Error");
			puts(XalanGetLastError(xalan));
			return 0;
		}

		puts(theOutput);

		XalanFreeData(theOutput);
	}

	DeleteXalanTransformer(xalan);

	// Terminate Xerces and Xalan, and clean up the ICU...
	XalanTerminate(1);
#endif

	return 0;
}



int
main(
			int		/* argc */,
			char*	/* argv */ [])
{
#if !defined(NDEBUG) && defined(_MSC_VER)
	_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
	_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
	_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif

	int	theResult = 0;

#if defined(TEST_XALAN_CPP)
	try
	{
		XALAN_USING_XERCES(XMLPlatformUtils)

		XALAN_USING_XALAN(XalanTransformer)

		// Call the static initializers for xerces and xalan, and create a transformer
		//
		XMLPlatformUtils::Initialize();

		XalanTransformer::initialize();

		theResult = runTests();

		// Terminate everything...
		XalanTransformer::terminate();

		XMLPlatformUtils::Terminate();

		XalanTransformer::ICUCleanUp();
	}
	catch(...)
	{
		cerr << "Initialization failed!" << endl << endl;

		theResult = -1;
	}
#endif

	return theResult;
}