Project

Profile

Help

Download (71.8 KB) Statistics
| Branch: | Revision:

he / src / main / c / samples / cppTests / testXSLT30.cpp @ f299305b

1 55b80284 O'Neil Delpratt
2 72bf04c6 Norman Walsh
#include <sstream>
3
#include <stdio.h>
4 55b80284 O'Neil Delpratt
5 72bf04c6 Norman Walsh
#include "../../Saxon.C.API/SaxonProcessor.h"
6
#include "../../Saxon.C.API/XdmValue.h"
7
#include "../../Saxon.C.API/XdmItem.h"
8
#include "../../Saxon.C.API/XdmNode.h"
9 501beb26 O'Neil Delpratt
#include "../../Saxon.C.API/XdmFunctionItem.h"
10 55b80284 O'Neil Delpratt
#include "../../Saxon.C.API/XdmMap.h"
11
#include "../../Saxon.C.API/XdmArray.h"
12 e05bbe34 O'Neil Delpratt
#include "cppExtensionFunction.h"
13
#include "CppTestUtils.h"
14 72bf04c6 Norman Walsh
#include <string>
15 306962bc O'Neil Delpratt
#include <thread>
16 72bf04c6 Norman Walsh
17
18
19 55b80284 O'Neil Delpratt
20 72bf04c6 Norman Walsh
using namespace std;
21 55b80284 O'Neil Delpratt
22
23
#ifdef MEM_DEBUG
24
#define new new(__FILE__, __LINE__)
25
#endif
26
27
28
29
30
31 72bf04c6 Norman Walsh
char fname[] = "_nativeCall";
32
char funcParameters[] = "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;";
33
34
JNINativeMethod cppMethods[] =
35 501beb26 O'Neil Delpratt
        {
36
                {
37
                        fname,
38
                        funcParameters,
39 e05bbe34 O'Neil Delpratt
                        (void *) &cppExtensionFunction::cppNativeCall
40 501beb26 O'Neil Delpratt
                }
41
        };
42 72bf04c6 Norman Walsh
43
44
/*
45
* Test transform to String. Source and stylesheet supplied as arguments
46
*/
47 501beb26 O'Neil Delpratt
void testApplyTemplatesString1(Xslt30Processor *trans, sResultCount *sresult) {
48
49 4ee4355d O'Neil Delpratt
    cout << "Test: testApplyTemplatesString1:" << endl;
50 9458d238 O'Neil Delpratt
//    trans->setupXslMessage(false);
51
52 6b6a9706 O'Neil Delpratt
    XsltExecutable *executable = trans->compileFromFile("test.xsl");
53 9458d238 O'Neil Delpratt
54
    if(executable== nullptr) {
55
        sresult->failure++;
56
        sresult->failureList.push_back("testApplyTemplatesString1");
57
        cerr << "testApplyTemplatesString1 NULL found" << endl;
58
        if (trans->exceptionOccurred()) {
59
            cerr <<"testApplyTemplatesString1 error: "<< trans->getErrorMessage() << endl;
60
        }
61
        return;
62
    }
63 6b6a9706 O'Neil Delpratt
    executable->setInitialMatchSelectionAsFile("cat.xml");
64 501beb26 O'Neil Delpratt
65
    const char *output = executable->applyTemplatesReturningString();
66 9458d238 O'Neil Delpratt
    if (output == nullptr) {
67 501beb26 O'Neil Delpratt
        printf("result is null ====== FAIL ====== \n");
68
        sresult->failure++;
69
        fflush(stdout);
70
        sresult->failureList.push_back("testApplyTemplatesString1-0");
71
    } else if (string(output).find(string("<out>text2</out>")) != std::string::npos) {
72 9458d238 O'Neil Delpratt
        printf("%s", output);
73 501beb26 O'Neil Delpratt
        printf("result is OK \n");
74
        sresult->success++;
75 a69dd173 O'Neil Delpratt
        delete output;
76 72bf04c6 Norman Walsh
    } else {
77 501beb26 O'Neil Delpratt
        printf("result is null ====== FAIL ====== \n");
78
        sresult->failure++;
79
        sresult->failureList.push_back("testApplyTemplatesString1-1");
80 a69dd173 O'Neil Delpratt
            std::cout<<"output="<<output<<std::endl;
81
        delete output;
82 501beb26 O'Neil Delpratt
    }
83
    fflush(stdout);
84 9458d238 O'Neil Delpratt
    delete executable;
85 72bf04c6 Norman Walsh
86
}
87
88
/*
89
* Test transform to String. Source and stylesheet supplied as arguments
90
*/
91 501beb26 O'Neil Delpratt
void testTransformToStringExtensionFunc(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
92
93
    cout << endl << "Test: TransformToStringExtensionFunc:" << endl;
94
    bool nativeFound = processor->registerNativeMethods(SaxonProcessor::sxn_environ->env,
95
                                                        "com/saxonica/functions/extfn/cpp/NativeCall",
96
                                                        cppMethods, sizeof(cppMethods) / sizeof(cppMethods[0]));
97
98
    XsltExecutable * executable = trans->compileFromFile("testExtension.xsl");
99 9458d238 O'Neil Delpratt
100
    if(executable== nullptr) {
101
        sresult->failure++;
102
        sresult->failureList.push_back("TransformToStringExtensionFunc");
103
        cerr << "TransformToStringExtensionFunc NULL found" << endl;
104
        if (trans->exceptionOccurred()) {
105
            cerr <<"TransformToStringExtensionFunc error: "<< trans->getErrorMessage() << endl;
106
        }
107
        return;
108
    }
109
110 501beb26 O'Neil Delpratt
    executable->setProperty("extc", "home/ond1/work/svn/latest9.9-saxonc/samples/cppTests/cppExtensionFunction");
111
112
    if (nativeFound) {
113
        const char *output = executable->transformFileToString("cat.xml");
114
115 9458d238 O'Neil Delpratt
        if (output == nullptr) {
116 501beb26 O'Neil Delpratt
            SaxonProcessor::sxn_environ->env->ExceptionDescribe();
117
            printf("result is null ====== FAIL ======  \n");
118 4ee4355d O'Neil Delpratt
            sresult->failure++;
119 501beb26 O'Neil Delpratt
            sresult->failureList.push_back("testTransformToStringExnteionFunc");
120
        } else {
121 a69dd173 O'Neil Delpratt
            sresult->success++;
122 501beb26 O'Neil Delpratt
            printf("result is OK \n");
123
        }
124
        fflush(stdout);
125
        delete output;
126
    } else {
127
        printf("native Class not foun ====== FAIL ====== ");
128 4ee4355d O'Neil Delpratt
        sresult->failure++;
129 501beb26 O'Neil Delpratt
        sresult->failureList.push_back("testTransformToStringExtensionFunc");
130 72bf04c6 Norman Walsh
    }
131 9458d238 O'Neil Delpratt
    delete executable;
132 72bf04c6 Norman Walsh
}
133
134
135
/*
136
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
137
*/
138 501beb26 O'Neil Delpratt
void testApplyTemplatesString2(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
139 72bf04c6 Norman Walsh
140 4ee4355d O'Neil Delpratt
    cout << "Test: testApplyTemplatesString2:" << endl;
141
142 19d839c4 O'Neil Delpratt
143 501beb26 O'Neil Delpratt
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
144 72bf04c6 Norman Walsh
145 9458d238 O'Neil Delpratt
    if (input== nullptr) {
146 501beb26 O'Neil Delpratt
        cout << "Source document is null." << endl;
147 4ee4355d O'Neil Delpratt
        if(processor->exceptionOccurred()) {
148
            cerr<<processor->getErrorMessage()<<endl;
149
        }
150 a69dd173 O'Neil Delpratt
        sresult->failure++;
151
        sresult->failureList.push_back("testApplyTemplatesString2");
152
        return;
153 72bf04c6 Norman Walsh
154
    }
155 79d12c83 O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
156 a69dd173 O'Neil Delpratt
    if(executable == nullptr) {
157 9458d238 O'Neil Delpratt
        sresult->failure++;
158
        sresult->failureList.push_back("testApplyTemplatesString2");
159
        if (trans->exceptionOccurred()) {
160
            cerr <<"testApplyTemplatesString2 error: "<< trans->getErrorMessage() << endl;
161
        }
162 a69dd173 O'Neil Delpratt
        delete input;
163 9458d238 O'Neil Delpratt
        return;
164
    }
165 a69dd173 O'Neil Delpratt
166 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelection((XdmValue *) input);
167 4ee4355d O'Neil Delpratt
168 501beb26 O'Neil Delpratt
    const char *output = executable->applyTemplatesReturningString();
169 9458d238 O'Neil Delpratt
    if (output== nullptr) {
170 501beb26 O'Neil Delpratt
        printf("result is null ====== FAIL ======  \n");
171
        sresult->failureList.push_back("testApplyTemplatesString2");
172 4ee4355d O'Neil Delpratt
        sresult->failure++;
173 501beb26 O'Neil Delpratt
    } else {
174 a69dd173 O'Neil Delpratt
        sresult->success++;
175 501beb26 O'Neil Delpratt
        printf("%s", output);
176
        printf("result is OK \n");
177 a69dd173 O'Neil Delpratt
        delete output;
178 72bf04c6 Norman Walsh
    }
179 501beb26 O'Neil Delpratt
    fflush(stdout);
180 4ee4355d O'Neil Delpratt
    delete input;
181 501beb26 O'Neil Delpratt
    delete executable;
182 72bf04c6 Norman Walsh
}
183
184
/*
185
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
186
Should be error. Stylesheet file does not exist
187
*/
188 4ee4355d O'Neil Delpratt
void testApplyTemplates2a_Error(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
189
190
    cout << "Test: TransformToString2a_Error:" << endl;
191 72bf04c6 Norman Walsh
192 501beb26 O'Neil Delpratt
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
193
194 a69dd173 O'Neil Delpratt
    if (input == nullptr) {
195 501beb26 O'Neil Delpratt
        cout << "Source document is null. ====== FAIL ======" << endl;
196 4ee4355d O'Neil Delpratt
        if(processor->exceptionOccurred()) {
197
            cerr<<processor->getErrorMessage()<<endl;
198
        }
199 501beb26 O'Neil Delpratt
        sresult->failure++;
200 4ee4355d O'Neil Delpratt
        sresult->failureList.push_back("testApplyTemplates2a_Error");
201
        trans->exceptionClear();
202 501beb26 O'Neil Delpratt
        return;
203
    }
204
    XsltExecutable * executable = trans->compileFromFile("test-error.xsl");
205 9458d238 O'Neil Delpratt
206
    if(executable== nullptr) {
207 4ee4355d O'Neil Delpratt
        printf("Expected result is null \n");
208 a69dd173 O'Neil Delpratt
        sresult->success++;
209
210 9458d238 O'Neil Delpratt
        if (trans->exceptionOccurred()) {
211 4ee4355d O'Neil Delpratt
            cerr <<"testApplyTemplates2a_Error error: "<< trans->getErrorMessage() << endl;
212 9458d238 O'Neil Delpratt
        }
213 a69dd173 O'Neil Delpratt
        delete input;
214 4ee4355d O'Neil Delpratt
        trans->exceptionClear();
215 9458d238 O'Neil Delpratt
        return;
216
    }
217
218 a69dd173 O'Neil Delpratt
    sresult->failure++;
219 4ee4355d O'Neil Delpratt
    sresult->failureList.push_back("testApplyTemplates2a_Error");
220 501beb26 O'Neil Delpratt
    fflush(stdout);
221 4ee4355d O'Neil Delpratt
222 9458d238 O'Neil Delpratt
    delete executable;
223 501beb26 O'Neil Delpratt
224 72bf04c6 Norman Walsh
}
225
226
/*
227
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
228
Should be error. Source file does not exist
229
*/
230 501beb26 O'Neil Delpratt
void testTransformToString2b(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
231 72bf04c6 Norman Walsh
232 501beb26 O'Neil Delpratt
    cout << endl << "Test: TransformToString2b:" << endl;
233 72bf04c6 Norman Walsh
234 a69dd173 O'Neil Delpratt
    const char * result  = trans->transformFileToString("cat-error.xml", "test-error.xsl");
235 72bf04c6 Norman Walsh
236 a69dd173 O'Neil Delpratt
    if(result== nullptr) {
237 4ee4355d O'Neil Delpratt
        if(trans->exceptionOccurred()) {
238
            cerr<<"Expected failure = "<<trans->getErrorMessage()<<endl;
239
        }
240 a69dd173 O'Neil Delpratt
        sresult->success++;
241 4ee4355d O'Neil Delpratt
        trans->exceptionClear();
242 501beb26 O'Neil Delpratt
        return;
243 a69dd173 O'Neil Delpratt
    }else {
244
        delete result;
245 9458d238 O'Neil Delpratt
        sresult->failure++;
246
        sresult->failureList.push_back("testTransformToString2b");
247
        cerr << "testTransformToString2b NULL found" << endl;
248
        if (trans->exceptionOccurred()) {
249 4ee4355d O'Neil Delpratt
            cerr <<"Error: "<< trans->getErrorMessage() << endl;
250 9458d238 O'Neil Delpratt
        }
251 a69dd173 O'Neil Delpratt
        trans->exceptionClear();
252 9458d238 O'Neil Delpratt
        return;
253
    }
254
255 72bf04c6 Norman Walsh
256
}
257
258
259
/*
260
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
261
and integer parmater created and supplied
262
*/
263 501beb26 O'Neil Delpratt
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
264
265 55b80284 O'Neil Delpratt
    cout << endl << "Test: testTransformToString3" << endl;
266 72bf04c6 Norman Walsh
267 501beb26 O'Neil Delpratt
    XdmNode *inputi = processor->parseXmlFromString(
268
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
269 72bf04c6 Norman Walsh
270 9458d238 O'Neil Delpratt
    if (inputi== nullptr) {
271 4ee4355d O'Neil Delpratt
        cout << "Source document inputi is null." << endl;
272
        if (trans->exceptionOccurred()) {
273
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
274
        }
275
        sresult->failure++;
276 501beb26 O'Neil Delpratt
        sresult->failureList.push_back("testTransformToString3");
277 146cfacb O'Neil Delpratt
278 501beb26 O'Neil Delpratt
        return;
279 72bf04c6 Norman Walsh
    }
280
281 146cfacb O'Neil Delpratt
    XdmAtomicValue *value1 = processor->makeIntegerValue(10);
282
283 4ee4355d O'Neil Delpratt
    if (value1== nullptr) {
284
        cout << "value1 is null." << endl;
285
        if (trans->exceptionOccurred()) {
286
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
287
        }
288
        sresult->failure++;
289
        sresult->failureList.push_back("testTransformToString3");
290
        delete inputi;
291
        return;
292
    }
293 146cfacb O'Neil Delpratt
294 501beb26 O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
295 9458d238 O'Neil Delpratt
296
    if(executable== nullptr) {
297
        sresult->failure++;
298
        sresult->failureList.push_back("testTransformToString3");
299
        cerr << "testTransformToString3 NULL found" << endl;
300
        if (trans->exceptionOccurred()) {
301
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
302
        }
303 a69dd173 O'Neil Delpratt
        delete value1;
304 9458d238 O'Neil Delpratt
        return;
305
    }
306
307 146cfacb O'Neil Delpratt
308 4ee4355d O'Neil Delpratt
    executable->setParameter("numParam", (XdmValue *) value1);
309 146cfacb O'Neil Delpratt
310 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelection((XdmNode *) inputi);
311
    const char *output = executable->applyTemplatesReturningString();
312 a69dd173 O'Neil Delpratt
    if (output == nullptr) {
313 501beb26 O'Neil Delpratt
        printf("result is null ====== FAIL ====== \n");
314
        sresult->failureList.push_back("testTransformToString3");
315
    } else {
316
        printf("%s", output);
317
        printf("result is OK \n");
318 a69dd173 O'Neil Delpratt
        delete output;
319 72bf04c6 Norman Walsh
    }
320 501beb26 O'Neil Delpratt
    fflush(stdout);
321 a69dd173 O'Neil Delpratt
322 9458d238 O'Neil Delpratt
    delete value1;
323 4ee4355d O'Neil Delpratt
    delete inputi;
324 55b80284 O'Neil Delpratt
    inputi = nullptr;
325 9458d238 O'Neil Delpratt
    delete executable;
326 72bf04c6 Norman Walsh
327
}
328
329
/*
330
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
331
and integer parmater created and supplied
332
*/
333 501beb26 O'Neil Delpratt
void testTransformToString4(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
334
335 4ee4355d O'Neil Delpratt
    cout <<  "Test: testTransformToString4:" << endl;
336 501beb26 O'Neil Delpratt
337
    XdmNode *input = processor->parseXmlFromString(
338
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
339
340 a69dd173 O'Neil Delpratt
    if (input== nullptr) {
341
        cout << "Source document is null. ====== FAIL ====== " << endl;
342 4ee4355d O'Neil Delpratt
        sresult->failure++;
343 a69dd173 O'Neil Delpratt
        sresult->failureList.push_back("testTransformToString4");
344
    }
345
346
347 d791e94d O'Neil Delpratt
    XdmValue *values = new XdmValue();
348 4ee4355d O'Neil Delpratt
    XdmAtomicValue * a1 = processor->makeIntegerValue(10);
349
    XdmAtomicValue * a2 = processor->makeIntegerValue(5);
350
    XdmAtomicValue * a3 = processor->makeIntegerValue(6);
351
    XdmAtomicValue * a4 = processor->makeIntegerValue(7);
352
    values->addXdmItem(a1);
353
    values->addXdmItem(a2);
354
    values->addXdmItem(a3);
355
    values->addXdmItem(a4);
356 501beb26 O'Neil Delpratt
357 a69dd173 O'Neil Delpratt
358 4ee4355d O'Neil Delpratt
    XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
359 501beb26 O'Neil Delpratt
360
    XsltExecutable *executable = trans->compileFromXdmNode(sheet);
361 9458d238 O'Neil Delpratt
362
    if(executable== nullptr) {
363
        sresult->failure++;
364
        sresult->failureList.push_back("testTransformToString4");
365
        cerr << "testTransformToString4 NULL found" << endl;
366
        if (trans->exceptionOccurred()) {
367
            cerr <<"testTransformToString4 error: "<< trans->getErrorMessage() << endl;
368
        }
369 a69dd173 O'Neil Delpratt
        delete values;
370 9458d238 O'Neil Delpratt
        return;
371
    }
372
373
    executable->setParameter("values", (XdmValue *) values);
374 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelection((XdmNode *) input);
375 a69dd173 O'Neil Delpratt
    const char *output = executable->applyTemplatesReturningString();
376 9458d238 O'Neil Delpratt
    if (output== nullptr) {
377 501beb26 O'Neil Delpratt
        printf("result is null \n");
378 4ee4355d O'Neil Delpratt
        sresult->failure++;
379 501beb26 O'Neil Delpratt
        sresult->failureList.push_back("testTransformToString4");
380
    } else {
381
        printf("%s", output);
382
        printf("result is OK \n");
383 a69dd173 O'Neil Delpratt
        delete output;
384 72bf04c6 Norman Walsh
    }
385 501beb26 O'Neil Delpratt
    fflush(stdout);
386 a69dd173 O'Neil Delpratt
    delete sheet;
387 4ee4355d O'Neil Delpratt
    delete executable;
388 9458d238 O'Neil Delpratt
    delete input;
389
    delete values;
390 72bf04c6 Norman Walsh
391
}
392
393 501beb26 O'Neil Delpratt
void testTransformFromstring(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
394 4ee4355d O'Neil Delpratt
    cout << endl << "Test: testTransfromFromstring: "<< endl;
395
396 a69dd173 O'Neil Delpratt
    if(processor == nullptr) {
397
        cout<<" processor is null"<<endl;
398
        return;
399 72bf04c6 Norman Walsh
400 a69dd173 O'Neil Delpratt
    }
401 501beb26 O'Neil Delpratt
    XdmNode *input = processor->parseXmlFromString(
402
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
403 72bf04c6 Norman Walsh
404 146cfacb O'Neil Delpratt
    if(input == nullptr) {
405
        sresult->failure++;
406
        sresult->failureList.push_back("testTransformFromstring");
407
        cerr << "testTransformFromstring NULL found" << endl;
408
        if (trans->exceptionOccurred()) {
409
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
410
        }
411
        return;
412
    }
413
414 501beb26 O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromString(
415
            "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='2.0'>       <xsl:param name='values' select='(2,3,4)' /><xsl:output method='xml' indent='yes' /><xsl:template match='*'><output><xsl:for-each select='$values' ><out><xsl:value-of select='. * 3'/></out></xsl:for-each></output></xsl:template></xsl:stylesheet>");
416
417 146cfacb O'Neil Delpratt
    if(executable== nullptr) {
418 9458d238 O'Neil Delpratt
        sresult->failure++;
419
        sresult->failureList.push_back("testTransformFromstring");
420
        cerr << "testTransformFromstring NULL found" << endl;
421
        if (trans->exceptionOccurred()) {
422
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
423
        }
424 146cfacb O'Neil Delpratt
        delete input;
425 9458d238 O'Neil Delpratt
        return;
426
    }
427
428 501beb26 O'Neil Delpratt
    const char *output = executable->transformToString((XdmNode *) input);
429 9458d238 O'Neil Delpratt
    if (output== nullptr) {
430 501beb26 O'Neil Delpratt
        printf("result is null ====== FAIL ====== \n");
431 4ee4355d O'Neil Delpratt
        sresult->failure++;
432 501beb26 O'Neil Delpratt
        sresult->failureList.push_back("testTransformFromString");
433 a69dd173 O'Neil Delpratt
        if (trans->exceptionOccurred()) {
434
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
435
        }
436 501beb26 O'Neil Delpratt
    } else {
437
        printf("%s", output);
438
        printf("result is OK \n");
439 4ee4355d O'Neil Delpratt
        sresult->success++;
440 a69dd173 O'Neil Delpratt
        delete output;
441 72bf04c6 Norman Walsh
    }
442 501beb26 O'Neil Delpratt
    fflush(stdout);
443 9458d238 O'Neil Delpratt
    delete input;
444
    delete executable;
445 72bf04c6 Norman Walsh
446
447
}
448
449
//Test case has error in the stylesheet
450 501beb26 O'Neil Delpratt
void testTransformFromstring2Err(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
451
    cout << endl << "Test: testTransfromFromstring2-Error:" << endl;
452
453
    XsltExecutable * executable = trans->compileFromString(
454
            "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='2.0'>       <xsl:param name='values' select='(2,3,4)' /><xsl:output method='xml' indent='yes' /><xsl:template match='*'><output><xsl:for-each select='$values' ><out><xsl:value-of select='. * 3'/></out><xsl:for-each></output></xsl:template><xsl:stylesheet>");
455 9458d238 O'Neil Delpratt
456
    if(executable== nullptr) {
457 4ee4355d O'Neil Delpratt
        sresult->success++;
458
459 9458d238 O'Neil Delpratt
        if (trans->exceptionOccurred()) {
460 4ee4355d O'Neil Delpratt
            cerr <<"Error expected: "<< trans->getErrorMessage() << endl;
461 9458d238 O'Neil Delpratt
        }
462 306962bc O'Neil Delpratt
        trans->exceptionClear();
463 9458d238 O'Neil Delpratt
        return;
464
    }
465
466 72bf04c6 Norman Walsh
467 4ee4355d O'Neil Delpratt
    sresult->failure++;
468
    sresult->failureList.push_back("testTransfromFromstring2-Error");
469 9458d238 O'Neil Delpratt
    delete executable;
470 72bf04c6 Norman Walsh
471
}
472
473 501beb26 O'Neil Delpratt
void testTrackingOfValueReference(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
474
475
    cout << endl << "Test: TrackingOfValueReference:" << endl;
476
    ostringstream test;
477
    ostringstream valStr;
478
    ostringstream name;
479
    for (int i = 0; i < 10; i++) {
480
        test << "v" << i;
481
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
482
               << "</value></out>";
483
        name << "value" << i;
484
485
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
486
        //cout<<"Name:"<<name.str()<<", Value:"<<values->getHead()->getStringValue()<<endl;
487
        trans->setParameter(name.str().c_str(), values);
488
        test.str("");
489
        valStr.str("");
490
        name.str("");
491 4ee4355d O'Neil Delpratt
492
        if(values == nullptr) {
493
            cerr<<"TrackingOfValueReference failed to create XdmNode object" <<endl;
494
            sresult->failure++;
495
            sresult->failureList.push_back("TrackingOfValueReference");
496
497
        }
498 501beb26 O'Neil Delpratt
    }
499
500
    std::map<std::string, XdmValue *> parMap = trans->getParameters();
501
    if (parMap.size() > 0) {
502 fc47eaa6 O'Neil Delpratt
        //cout << "Parameter size: " << parMap.size() << endl;
503
        //cout << "Parameter size: " << parMap.size()<< endl;//", Value:"<<trans->getParameters()["value0"]->getHead()->getStringValue()<<endl;
504 501beb26 O'Neil Delpratt
        ostringstream name1;
505
        for (int i = 0; i < 10; i++) {
506 4ee4355d O'Neil Delpratt
            name1 << "sparam:value" << i;
507 501beb26 O'Neil Delpratt
            cout << " i:" << i << " Map size:" << parMap.size() << ", ";
508
            XdmValue *valuei = parMap[name1.str()];
509 4ee4355d O'Neil Delpratt
            if (valuei != nullptr) {
510 501beb26 O'Neil Delpratt
                cout << name1.str();
511 4ee4355d O'Neil Delpratt
                if (valuei->itemAt(0) != nullptr)
512 501beb26 O'Neil Delpratt
                    cout << "= " << valuei->itemAt(0)->getStringValue();
513
                cout << endl;
514 4ee4355d O'Neil Delpratt
515 501beb26 O'Neil Delpratt
            } else {
516
                sresult->failure++;
517
                std::cerr << "trackingValueReference ====== FAIL ======" << std::endl;
518
                sresult->failureList.push_back("testTrackingOfValueReference");
519 d0e6f8be O'Neil Delpratt
                return;
520 501beb26 O'Neil Delpratt
            }
521
            name1.str("");
522
        }
523
    }
524 4ee4355d O'Neil Delpratt
    if(parMap.size() > 0 ) {
525
        cerr<<"Deleting map"<<endl;
526
        trans->clearParameters(true);
527
    }
528 501beb26 O'Neil Delpratt
    sresult->success++;
529 72bf04c6 Norman Walsh
}
530
531
/*Test case should be error.*/
532 501beb26 O'Neil Delpratt
void testTrackingOfValueReferenceError(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
533 146cfacb O'Neil Delpratt
    trans->clearParameters();
534 501beb26 O'Neil Delpratt
535
    cout << endl << "Test: TrackingOfValueReference-Error:" << endl;
536
    cout << "Parameter Map size: " << (trans->getParameters().size()) << endl;
537
    ostringstream test;
538
    ostringstream valStr;
539
    ostringstream name;
540 4ee4355d O'Neil Delpratt
    for (int i = 0; i < 2; i++) {
541 501beb26 O'Neil Delpratt
        test << "v" << i;
542
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
543
               << "<value></out>";
544
        name << "value" << i;
545
546
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
547 4ee4355d O'Neil Delpratt
        if(values == nullptr) {
548
            cerr<<"values NULL ====== FAIL ======="<<endl;
549 306962bc O'Neil Delpratt
            processor->exceptionClear();
550 4ee4355d O'Neil Delpratt
        } else {
551
            trans->setParameter(name.str().c_str(), values);
552
        }
553 501beb26 O'Neil Delpratt
        test.str("");
554
        valStr.str("");
555
        name.str("");
556
    }
557
    std::map<std::string, XdmValue *> parMap = trans->getParameters();
558
    cout << "Parameter Map size: " << parMap.size() << endl;
559
560
    ostringstream name1;
561
    bool errorFound = false;
562 4ee4355d O'Neil Delpratt
    for (int i = 0; i < 2; i++) {
563
        name1 << "sparam:value" << i;
564 501beb26 O'Neil Delpratt
        cout << " i:" << i << " Map size:" << parMap.size() << ", ";
565
        try {
566 306962bc O'Neil Delpratt
567 501beb26 O'Neil Delpratt
            XdmValue *valuei = parMap.at(name1.str());
568
            if (valuei != NULL) {
569
                cout << name1.str();
570
                if (valuei->itemAt(0) != NULL)
571
                    cout << "= " << valuei->itemAt(0)->getStringValue();
572
                cout << endl;
573
            }
574
        } catch (const std::out_of_range &oor) {
575 306962bc O'Neil Delpratt
            cout << "Out of range exception occurred. Exception " << endl;
576 501beb26 O'Neil Delpratt
            if (!errorFound) {
577
                sresult->success++;
578
                errorFound = true;
579
580
                return;
581
            }
582
        }
583
        name1.str("");
584
    }
585
    sresult->failure++;
586
    sresult->failureList.push_back("testTrackingOfValueReferenceError");
587
588
}
589
590
void testValidation(Xslt30Processor *trans, sResultCount *sresult) {
591 146cfacb O'Neil Delpratt
    trans->clearParameters();
592 501beb26 O'Neil Delpratt
593
594
595
    XsltExecutable * executable = trans->compileFromString(
596
            "<?xml version='1.0'?><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'                 xmlns:xs='http://www.w3.org/2001/XMLSchema' version='3.0' exclude-result-prefixes='#all'>     <xsl:import-schema><xs:schema><xs:element name='x' type='xs:int'/></xs:schema></xsl:import-schema> <xsl:template name='main'>          <xsl:result-document validation='strict'> <x>3</x>   </xsl:result-document>    </xsl:template>    </xsl:stylesheet>");
597
598
    const char *rootValue = executable->callTemplateReturningString("main");
599
600
601 9458d238 O'Neil Delpratt
    if (rootValue== nullptr) {
602 501beb26 O'Neil Delpratt
        std::cout << "NULL found" << std::endl;
603
        sresult->failure++;
604
        sresult->failureList.push_back("testValidation");
605
        return;
606
607
    } else {
608
        std::cout << "Result=" << rootValue << endl;
609
        sresult->success++;
610
    }
611 9458d238 O'Neil Delpratt
    delete executable;
612 72bf04c6 Norman Walsh
}
613
614
615 501beb26 O'Neil Delpratt
void testXdmNodeOutput(Xslt30Processor *trans, sResultCount *sresult) {
616 72bf04c6 Norman Walsh
617 501beb26 O'Neil Delpratt
    std::cout << "testXdmNodeOutput" << std::endl;
618
    XsltExecutable * executable = trans->compileFromString(
619
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template name='go'><a/></xsl:template></xsl:stylesheet>");
620
    XdmValue *rootValue = executable->callTemplateReturningValue("go");
621 9458d238 O'Neil Delpratt
    if (rootValue== nullptr) {
622 501beb26 O'Neil Delpratt
        cout << "Result is null ====== FAIL ====== " << endl;
623
        sresult->failure++;
624
        sresult->failureList.push_back("testXdmNodeOutput-0.0");
625
        return;
626
    }
627
    XdmItem *rootItem = rootValue->getHead();
628 9458d238 O'Neil Delpratt
    if (rootItem== nullptr) {
629 72bf04c6 Norman Walsh
630 501beb26 O'Neil Delpratt
        cout << "Result is null ====== FAIL ====== " << endl;
631
        sresult->failure++;
632
        sresult->failureList.push_back("testXdmNodeOutput-0");
633 4ee4355d O'Neil Delpratt
        delete rootValue;
634
        delete executable;
635 501beb26 O'Neil Delpratt
        return;
636
    }
637
    XdmNode *root = (XdmNode *) rootItem;
638
    if (root->getNodeKind() == DOCUMENT) {
639
        cout << "Result is a Document" << endl;
640
    } else {
641
        cout << "Node is of kind:" << root->getNodeKind() << endl;
642
    }
643
    const char *result = executable->callTemplateReturningString("go");
644
    if (string(result).find(string("<a/>")) != std::string::npos) {
645
        sresult->success++;
646 4ee4355d O'Neil Delpratt
        delete result;
647 501beb26 O'Neil Delpratt
    } else {
648
        //TODO - this test case prints the XML declaration. Check if this correct
649
        sresult->failure++;
650
        cout << "testXdmNodeOutputAndString ======= FAIL========" << endl;
651 9458d238 O'Neil Delpratt
        sresult->failureList.push_back("testXdmNodeOutput");
652 501beb26 O'Neil Delpratt
    }
653 4ee4355d O'Neil Delpratt
    delete rootValue;
654 9458d238 O'Neil Delpratt
    delete executable;
655 72bf04c6 Norman Walsh
656
}
657
658 501beb26 O'Neil Delpratt
void exampleSimple1(Xslt30Processor *proc, sResultCount *sresult) {
659
    cout << "ExampleSimple1 taken from PHP:" << endl;
660
661
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
662 9458d238 O'Neil Delpratt
    if(executable== nullptr) {
663
        sresult->failure++;
664
        sresult->failureList.push_back("exampleSimple1");
665
        cerr << "exampleSimple1 NULL found" << endl;
666
        if (proc->exceptionOccurred()) {
667
            cerr <<"exampleSimple1 error: "<< proc->getErrorMessage() << endl;
668
        }
669
        return;
670
    }
671 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
672
    const char *result = executable->applyTemplatesReturningString();
673
    if (result != NULL) {
674
        cout << result << endl;
675
        sresult->success++;
676 a69dd173 O'Neil Delpratt
        delete result;
677 501beb26 O'Neil Delpratt
    } else {
678
        cout << "Result is null ====== FAIL ====== " << endl;
679
        sresult->failure++;
680
    }
681 146cfacb O'Neil Delpratt
    proc->clearParameters();
682 9458d238 O'Neil Delpratt
    delete executable;
683 72bf04c6 Norman Walsh
}
684
685 501beb26 O'Neil Delpratt
void exampleSimple1Err(Xslt30Processor *proc, sResultCount *sresult) {
686 e05bbe34 O'Neil Delpratt
    cout << "ExampleSimple1Err taken from PHP:" << endl;
687 72bf04c6 Norman Walsh
688 501beb26 O'Neil Delpratt
    XsltExecutable * executable = proc->compileFromFile("err.xsl");
689 a69dd173 O'Neil Delpratt
    if(executable == nullptr || proc->exceptionOccurred()) {
690
        if( proc->exceptionOccurred()) {
691
            cout << "Error Message= "<< proc->getErrorMessage() << endl;
692
        }
693 e05bbe34 O'Neil Delpratt
        cout << "Result expected as null " << endl;
694 4ee4355d O'Neil Delpratt
        proc->exceptionClear();
695 e05bbe34 O'Neil Delpratt
        sresult->success++;
696 a69dd173 O'Neil Delpratt
        return;
697 e05bbe34 O'Neil Delpratt
    } else {
698 501beb26 O'Neil Delpratt
        sresult->failure++;
699
        sresult->failureList.push_back("exampleSimple1Err");
700 e05bbe34 O'Neil Delpratt
701 a69dd173 O'Neil Delpratt
        delete executable;
702 501beb26 O'Neil Delpratt
    }
703 a69dd173 O'Neil Delpratt
704 501beb26 O'Neil Delpratt
}
705
706 72bf04c6 Norman Walsh
707 501beb26 O'Neil Delpratt
void exampleSimple2(Xslt30Processor *proc, sResultCount *sresult) {
708
    cout << "<b>exampleSimple2:</b><br/>" << endl;
709
710
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
711 9458d238 O'Neil Delpratt
    if(executable== nullptr) {
712 fc47eaa6 O'Neil Delpratt
        sresult->failure++;
713
        sresult->failureList.push_back("exampleSimple2");
714
        cerr << "exampleSimple2 NULL found" << endl;
715 9458d238 O'Neil Delpratt
        if (proc->exceptionOccurred()) {
716 fc47eaa6 O'Neil Delpratt
            cerr <<"exampleSimple2 error: "<< proc->getErrorMessage() << endl;
717
        }
718
        return;
719
    }
720 a69dd173 O'Neil Delpratt
721 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
722
    const char *filename = "output1.xml";
723
    executable->setOutputFile(filename);
724
    executable->applyTemplatesReturningFile("output1.xml");
725
726 e05bbe34 O'Neil Delpratt
    if (CppTestUtils::exists("output1.xml")) {
727 501beb26 O'Neil Delpratt
        cout << "The file $filename exists" << endl;
728
        remove("output1.xml");
729
        sresult->success++;
730
    } else {
731
        cout << "The file " << filename << " does not exist" << endl;
732
        if (executable->exceptionOccurred()) {
733
            cout << proc->getErrorMessage() << endl;
734
        }
735
        sresult->failure++;
736
        sresult->failureList.push_back("exampleSimple2");
737
    }
738 4ee4355d O'Neil Delpratt
739 9458d238 O'Neil Delpratt
    delete executable;
740 72bf04c6 Norman Walsh
741
}
742
743 501beb26 O'Neil Delpratt
void exampleSimple3(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
744
    cout << "<b>exampleSimple3:</b><br/>" << endl;
745 146cfacb O'Neil Delpratt
    proc->clearParameters();
746 501beb26 O'Neil Delpratt
747 4ee4355d O'Neil Delpratt
    XdmNode *xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
748
    if (xdmNode== nullptr) {
749
        cout << "Error: xdmNode is null'" << endl;
750
        if(saxonProc->exceptionOccurred()) {
751
            cout<<"Error message="<<saxonProc->getErrorMessage()<<endl;
752
        }
753
        sresult->failure++;
754
        sresult->failureList.push_back("exampleSimple3");
755
        return;
756
    }
757
758 501beb26 O'Neil Delpratt
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
759
760 146cfacb O'Neil Delpratt
   if(executable == nullptr) {
761 e9b06a56 O'Neil Delpratt
        cout << "executable is NULL" <<endl;
762
        if(proc->exceptionOccurred()) {
763
                cout << proc->getErrorMessage() <<endl;
764
                
765
        }
766 4ee4355d O'Neil Delpratt
        sresult->failure++;
767
        sresult->failureList.push_back("exampleSimple3");
768 e9b06a56 O'Neil Delpratt
        return;
769
   }
770
771 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelection((XdmNode *) xdmNode);
772
    sresult->success++;
773 4ee4355d O'Neil Delpratt
    delete xdmNode;
774 a69dd173 O'Neil Delpratt
    delete executable;
775 501beb26 O'Neil Delpratt
}
776
777 4ee4355d O'Neil Delpratt
void exampleSimple3aError(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
778
    cout << "<b>exampleSimple3aError:</b><br/>" << endl;
779 501beb26 O'Neil Delpratt
780
    XsltExecutable * executable = proc->compileFromFile(nullptr);
781
782
783
    if (executable == nullptr) {
784
785
786 4ee4355d O'Neil Delpratt
        cout << "Expected failure of test exampleSimple3aError:" << endl;
787
        if(proc->exceptionOccurred()) {
788
            cout<<proc->getErrorMessage()<<endl;
789
        }
790 501beb26 O'Neil Delpratt
791
        sresult->success++;
792 4ee4355d O'Neil Delpratt
        proc->exceptionClear();
793 501beb26 O'Neil Delpratt
        return;
794
    }
795
796
    cout << "Error: executable is not nullptr'" << endl;
797
    sresult->failure++;
798 4ee4355d O'Neil Delpratt
    sresult->failureList.push_back("exampleSimple3aError");
799 a69dd173 O'Neil Delpratt
    delete executable;
800 501beb26 O'Neil Delpratt
    return;
801
802
803
}
804
805
void exampleParam(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
806 4ee4355d O'Neil Delpratt
    cout << "Test: ExampleParam" << endl;
807 501beb26 O'Neil Delpratt
808
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
809
810 4ee4355d O'Neil Delpratt
811
    if(executable == nullptr) {
812
        cout << "executable is NULL" <<endl;
813
        if(proc->exceptionOccurred()) {
814
            cout << proc->getErrorMessage() <<endl;
815
816
        }
817
        sresult->failure++;
818
        sresult->failureList.push_back("exampleParam");
819
        return;
820
821
    }
822
823 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
824
825
    XdmAtomicValue *xdmvalue = saxonProc->makeStringValue("Hello to you");
826 4ee4355d O'Neil Delpratt
    if (xdmvalue != nullptr) {
827 501beb26 O'Neil Delpratt
828
        executable->setParameter("a-param", (XdmValue *) xdmvalue);
829
830
    } else {
831 4ee4355d O'Neil Delpratt
        cout << "Xdmvalue is NULL - ====== FAIL =====" << endl;
832 501beb26 O'Neil Delpratt
        sresult->failure++;
833 4ee4355d O'Neil Delpratt
        sresult->failureList.push_back("exampleParam");
834
        if(executable->exceptionOccurred()) {
835
            SaxonApiException * exception = executable->getException();
836
            cerr<<"Error: " << exception->getMessage() <<endl;
837
            delete exception;
838
        }
839
        delete executable;
840
        return;
841 501beb26 O'Neil Delpratt
    }
842
    const char *result = executable->applyTemplatesReturningString();
843 4ee4355d O'Neil Delpratt
    if (result != nullptr) {
844 501beb26 O'Neil Delpratt
        cout << "Output:" << result << endl;
845
        sresult->success++;
846 4ee4355d O'Neil Delpratt
        delete result;
847 501beb26 O'Neil Delpratt
    } else {
848
        cout << "Result is NULL<br/>  ======= fail =====" << endl;
849
        sresult->failure++;
850 4ee4355d O'Neil Delpratt
        sresult->failureList.push_back("exampleParam");
851
        if(executable->exceptionOccurred()) {
852
            SaxonApiException * exception = executable->getException();
853
            cerr<<"Error: " << exception->getMessage() <<endl;
854
            delete exception;
855
        }
856
        delete executable;
857
        return;
858 501beb26 O'Neil Delpratt
    }
859
860
    //proc->clearParameters();
861
    //unset($result);
862
    //echo 'again with a no parameter value<br/>';
863
864
    executable->setProperty("!indent", "yes");
865
    const char *result2 = executable->applyTemplatesReturningString();
866
867
868 4ee4355d O'Neil Delpratt
    if (result2 != nullptr) {
869
        cout << "Result2 output= " << result2 << endl;
870 501beb26 O'Neil Delpratt
        sresult->success++;
871 4ee4355d O'Neil Delpratt
        delete result2;
872
    } else {
873
        cout << "Result2 is NULL<br/>  ======= fail =====" << endl;
874
        sresult->failure++;
875
        sresult->failureList.push_back("exampleParam");
876
        if(executable->exceptionOccurred()) {
877
            SaxonApiException * exception = executable->getException();
878
            cerr<<"Error: " << exception->getMessage() <<endl;
879
            delete exception;
880
        }
881
        delete xdmvalue;
882
        delete executable;
883
        return;
884 501beb26 O'Neil Delpratt
    }
885
886
    //  unset($result);
887
    // echo 'again with no parameter and no properties value set. This should fail as no contextItem set<br/>';
888 4ee4355d O'Neil Delpratt
    //delete xdmvalue;
889
    //executable->clearParameters();
890
891 501beb26 O'Neil Delpratt
    XdmAtomicValue *xdmValue2 = saxonProc->makeStringValue("goodbye to you");
892 4ee4355d O'Neil Delpratt
893
    if (xdmValue2 == nullptr) {
894
        cout << "Xdmvalue is NULL - ====== FAIL =====" << endl;
895
        sresult->failure++;
896
        sresult->failureList.push_back("exampleParam");
897
        if(executable->exceptionOccurred()) {
898
            SaxonApiException * exception = executable->getException();
899
            cerr<<"Error: " << exception->getMessage() <<endl;
900
            delete exception;
901
        }
902
        delete executable;
903
        delete xdmvalue;
904
        return;
905
    }
906
907 501beb26 O'Neil Delpratt
    executable->setParameter("a-param", (XdmValue *) xdmValue2);
908 4ee4355d O'Neil Delpratt
    delete xdmvalue;
909
910 501beb26 O'Neil Delpratt
911
    const char *result3 = executable->applyTemplatesReturningString();
912 4ee4355d O'Neil Delpratt
    if (result3 != nullptr) {
913 501beb26 O'Neil Delpratt
        cout << "Output =" << result3 << endl;
914 4ee4355d O'Neil Delpratt
915 501beb26 O'Neil Delpratt
        sresult->success++;
916 4ee4355d O'Neil Delpratt
        delete result3;
917
918 501beb26 O'Neil Delpratt
    } else {
919
        cout << "Error in result ===== FAIL =======" << endl;
920
        sresult->failure++;
921
        sresult->failureList.push_back("exampleParam");
922 4ee4355d O'Neil Delpratt
        if(executable->exceptionOccurred()) {
923
            SaxonApiException * exception = executable->getException();
924
            cerr<<"Error: " << exception->getMessage() <<endl;
925
            delete exception;
926
        }
927
928 501beb26 O'Neil Delpratt
    }
929 4ee4355d O'Neil Delpratt
    delete xdmValue2;
930
    delete executable;
931
932 501beb26 O'Neil Delpratt
933
934 72bf04c6 Norman Walsh
}
935
936
// test parameter and properties maps where we update key, value pair.
937 501beb26 O'Neil Delpratt
void exampleParam2(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
938
    cout << "\nExampleParam:</b><br/>" << endl;
939
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
940
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
941
942
943
    XdmAtomicValue *xdmvalue = saxonProc->makeStringValue("Hello to you");
944
    XdmAtomicValue *xdmvalue2i = saxonProc->makeStringValue("Hello from me");
945
    if (xdmvalue != NULL) {
946
947
        executable->setParameter("a-param", (XdmValue *) xdmvalue);
948
        executable->setParameter("a-param", (XdmValue *) xdmvalue2i);
949
950
    } else {
951
        cout << "Xdmvalue is null - ====== FAIL =====" << endl;
952
        sresult->failure++;
953
        sresult->failureList.push_back("exampleParam-1");
954
    }
955
    const char *result = executable->applyTemplatesReturningString();
956
    if (result != NULL) {
957
        string sresulti = string(result);
958
        if (sresulti.compare("Hello from me") == 0) {
959
            cout << "Output:" << result << endl;
960
            sresult->success++;
961
        } else {
962
            cout << "Result is " << result << " <br/> ======= fail ===== " << endl;
963
            sresult->failure++;
964
            sresult->failureList.push_back("exampleParam-2");
965
        }
966
    } else {
967
        cout<<"Result is NULL<br/>  ======= fail ====="<<endl;
968
        sresult->failure++;
969
        sresult->failureList.push_back("exampleParam-2");
970
    }
971
972
//proc->clearParameters();
973
//unset($result);
974
//echo 'again with a no parameter value<br/>';
975
976
    executable->setProperty("!indent", "no");
977
    executable->setProperty("!indent", "yes");
978
    const char *result2 = executable->applyTemplatesReturningString();
979
980
    executable->clearProperties();
981
982
    if(result2 != NULL) {
983
        cout<<result2<<endl;
984
        sresult->success++;
985
986
    }
987
988
    //  unset($result);
989
    // echo 'again with no parameter and no properties value set. This should fail as no contextItem set<br/>';
990
    XdmAtomicValue *xdmValue2 = saxonProc->makeStringValue("goodbye to you");
991
    executable->setParameter("a-param", (XdmValue*)xdmValue2);
992
993
    const char *result3 = executable->applyTemplatesReturningString();
994
    if(result3 != NULL) {
995
        cout<<"Output ="<<result3<<endl;
996
997
        sresult->success++;
998
    } else {
999
        cout<<"Error in result ===== FAIL ======="<<endl;
1000
        sresult->failure++;
1001
        sresult->failureList.push_back("exampleParam");
1002
    }
1003
1004
}
1005
1006
/* XMarkbench mark test q12.xsl with just-in-time=true*/
1007
void xmarkTest1(Xslt30Processor *proc, sResultCount *sresult) {
1008 4ee4355d O'Neil Delpratt
    cout << "Test: xmarkTest1 - XMarkbench mark test q12.xsl (JIT=true):" << endl;
1009 501beb26 O'Neil Delpratt
1010
    proc->setJustInTimeCompilation(true);
1011
1012
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1013
    if (result != NULL) {
1014
        cout << "XdmNode returned" << endl;
1015
        sresult->success++;
1016 4ee4355d O'Neil Delpratt
        delete result;
1017 501beb26 O'Neil Delpratt
    } else {
1018
        printf("result is null \nCheck For errors:");
1019
        sresult->failure++;
1020
        sresult->failureList.push_back("xmarkTest1");
1021 306962bc O'Neil Delpratt
        cerr << "xmarkTest1 cp0" << endl;
1022 4ee4355d O'Neil Delpratt
        if (proc->exceptionOccurred()) {
1023 306962bc O'Neil Delpratt
            cerr << "xmarkTest1 cp1" << endl;
1024
            const char * message = proc->getErrorMessage();
1025
            cerr << "xmarkTest1 cp2" << endl;
1026
            if(message != nullptr) {
1027
                cerr << "xmarkTest1 cp2-1" << endl;
1028
                cerr << proc->getErrorMessage() << endl;
1029
            } else {
1030
                cerr << "Message is nullptr" << endl;
1031
                SaxonProcessor::sxn_environ->env->ExceptionDescribe();
1032
            }
1033 501beb26 O'Neil Delpratt
        }
1034 306962bc O'Neil Delpratt
        cerr << "xmarkTest1 cp3" << endl;
1035 501beb26 O'Neil Delpratt
    }
1036
1037 72bf04c6 Norman Walsh
1038
}
1039
1040 501beb26 O'Neil Delpratt
1041 72bf04c6 Norman Walsh
/* XMarkbench mark test q12.xsl with just-in-time=true*/
1042 501beb26 O'Neil Delpratt
void xmarkTest2(Xslt30Processor *proc, sResultCount *sresult) {
1043 4ee4355d O'Neil Delpratt
    cout << "Test: xmarkTest2 - XMarkbench mark test q12.xsl (JIT=true):" << endl;
1044 501beb26 O'Neil Delpratt
1045
1046
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1047
    if (result != NULL) {
1048
        cout << "XdmNode returned" << endl;
1049 4ee4355d O'Neil Delpratt
        sresult->success++;
1050
        delete result;
1051
1052 501beb26 O'Neil Delpratt
    } else {
1053
        printf("result is null \nCheck For errors:");
1054
        sresult->failure++;
1055
        sresult->failureList.push_back("xmarkTest2");
1056
        if (proc->exceptionOccurred() > 0) {
1057 306962bc O'Neil Delpratt
            SaxonApiException * exception = proc->getException();
1058
            if(exception != nullptr) {
1059
                const char *message = exception->getMessage();
1060
                if (message != nullptr) {
1061
                    cerr << "xmarkTest2 cp2-1" << endl;
1062
                    cerr << message << endl;
1063
                }
1064
                delete exception;
1065
            } else {
1066
                cerr << "Exception object is nullptr" << endl;
1067
                SaxonProcessor::sxn_environ->env->ExceptionDescribe();
1068
            }
1069 501beb26 O'Neil Delpratt
        }
1070
    }
1071
1072
1073
}
1074 72bf04c6 Norman Walsh
1075
/* XMarkbench mark test q12.xsl with just-in-time=true*/
1076 501beb26 O'Neil Delpratt
void exampleSimple_xmark(Xslt30Processor *proc, sResultCount *sresult) {
1077 4ee4355d O'Neil Delpratt
    cout << "exampleSimple_xmark test - test q12.xsl:" << endl;
1078 72bf04c6 Norman Walsh
1079 501beb26 O'Neil Delpratt
    proc->setJustInTimeCompilation(true);
1080 72bf04c6 Norman Walsh
1081 501beb26 O'Neil Delpratt
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1082
    if (result != NULL) {
1083
        cout << "XdmNode returned" << endl;
1084 4ee4355d O'Neil Delpratt
        sresult->success++;
1085 a69dd173 O'Neil Delpratt
        delete result;
1086 501beb26 O'Neil Delpratt
    } else {
1087 4ee4355d O'Neil Delpratt
        printf("Result is null \nCheck For errors:");
1088 501beb26 O'Neil Delpratt
        if (proc->exceptionOccurred() > 0) {
1089
            cout << proc->getErrorMessage() << endl;
1090
        }
1091 4ee4355d O'Neil Delpratt
        sresult->failure++;
1092
        sresult->failureList.push_back("exampleSimple_xmark");
1093
        proc->exceptionClear();
1094 501beb26 O'Neil Delpratt
    }
1095 146cfacb O'Neil Delpratt
    proc->clearParameters();
1096 72bf04c6 Norman Walsh
1097 501beb26 O'Neil Delpratt
}
1098 72bf04c6 Norman Walsh
1099
/*
1100
* Test saving nd loading a Xslt package
1101
*/
1102 501beb26 O'Neil Delpratt
void testPackage1(Xslt30Processor *trans, sResultCount *sresult) {
1103
1104 4ee4355d O'Neil Delpratt
    cout << endl << "Test: testPackage1 - Saving and loading Packages:" << endl;
1105 146cfacb O'Neil Delpratt
    trans->clearParameters();
1106 72bf04c6 Norman Walsh
1107
1108
    trans->compileFromFileAndSave("test.xsl", "test1.sef");
1109 501beb26 O'Neil Delpratt
    const char *output = trans->transformFileToString("cat.xml", "test1.sef");
1110 4ee4355d O'Neil Delpratt
1111 9458d238 O'Neil Delpratt
    if (output== nullptr) {
1112 501beb26 O'Neil Delpratt
        printf("result is null \n");
1113
        const char *message = trans->getErrorMessage();
1114
        if (message != NULL) {
1115
            cout << "Error message =" << message << endl;
1116
        }
1117
        sresult->failure++;
1118
        sresult->failureList.push_back("testPackage1");
1119
1120
    } else {
1121
        printf("%s", output);
1122
        printf("result is OK \n");
1123
        sresult->success++;
1124 72bf04c6 Norman Walsh
    }
1125 501beb26 O'Neil Delpratt
    fflush(stdout);
1126 72bf04c6 Norman Walsh
    delete output;
1127
}
1128
1129
1130
/*
1131
* Test saving and loading a Xslt package
1132
*/
1133 4ee4355d O'Neil Delpratt
void testPackage1a(Xslt30Processor *trans, sResultCount *sresult) {
1134 501beb26 O'Neil Delpratt
1135 4ee4355d O'Neil Delpratt
    cout << endl << "Test: testPackage1a" << endl;
1136 146cfacb O'Neil Delpratt
    trans->clearParameters();
1137 72bf04c6 Norman Walsh
1138 4ee4355d O'Neil Delpratt
    trans->compileFromFileAndSave("test.xsl", "test1a.sef");
1139 72bf04c6 Norman Walsh
1140 f299305b O'Neil Delpratt
    if(trans->exceptionOccurred()) {
1141
        const char *message = trans->getErrorMessage();
1142
        if (message != NULL) {
1143
            cout << "Error message =" << message << endl;
1144
        }
1145
        sresult->failure++;
1146
        sresult->failureList.push_back("testPackage1a");
1147
        trans->exceptionClear();
1148
        return;
1149
    }
1150
1151
1152
1153 4ee4355d O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromFile("test1.sef");
1154
    executable->setInitialMatchSelectionAsFile("cat.xml");
1155
    const char * output = executable->applyTemplatesReturningString();
1156 9458d238 O'Neil Delpratt
    if (output== nullptr) {
1157 4ee4355d O'Neil Delpratt
        printf("result is null \n");
1158 501beb26 O'Neil Delpratt
        const char *message = trans->getErrorMessage();
1159
        if (message != NULL) {
1160
            cout << "Error message =" << message << endl;
1161
        }
1162 4ee4355d O'Neil Delpratt
        sresult->failure++;
1163
        sresult->failureList.push_back("testPackage1a");
1164 55b80284 O'Neil Delpratt
        trans->exceptionClear();
1165 4ee4355d O'Neil Delpratt
1166 501beb26 O'Neil Delpratt
    } else {
1167
        printf("%s", output);
1168
        printf("result is OK \n");
1169 4ee4355d O'Neil Delpratt
        sresult->success++;
1170 55b80284 O'Neil Delpratt
        delete output;
1171 72bf04c6 Norman Walsh
    }
1172 501beb26 O'Neil Delpratt
    fflush(stdout);
1173 55b80284 O'Neil Delpratt
    delete executable;
1174 72bf04c6 Norman Walsh
}
1175
1176 4ee4355d O'Neil Delpratt
1177
/*
1178
* Test saving and loading a Xslt package
1179
*/
1180
void testPackage2_Error(Xslt30Processor *trans, sResultCount *sresult) {
1181
1182
    cout << endl << "Test: testPackage2_Error:" << endl;
1183
1184
    const char *stylesheet = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='2.0'>       <xsl:param name='values' select='(2,3,4)' /><xsl:output method='xml' indent='yes' /><xsl:template match='*'><output><xsl:for-each select='$values' ><out><xsl:value-of select='. * 3'/></out><xsl:for-each></output></xsl:template><xsl:stylesheet>";
1185
1186
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
1187
1188
    if(trans->exceptionOccurred()) {
1189
        const char *message = trans->getErrorMessage();
1190
        if (message != NULL) {
1191
            cout << "Error message =" << message << endl;
1192
        }
1193
        sresult->success++;
1194
        trans->exceptionClear();
1195
        return;
1196
1197
    }
1198
1199
    sresult->failure++;
1200
    sresult->failureList.push_back("testPackage2_Error");
1201
1202
}
1203
1204 501beb26 O'Neil Delpratt
void testCallFunction(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1205
1206
    const char *source = "<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:f='http://localhost/' version='3.0'> <xsl:function name='f:add' visibility='public'>    <xsl:param name='a'/><xsl:param name='b'/> <xsl:sequence select='$a + $b'/></xsl:function></xsl:stylesheet>";
1207
    cout << endl << "Test: testCallFunction:" << endl;
1208
    XsltExecutable * executable = trans->compileFromString(source);
1209 4ee4355d O'Neil Delpratt
1210
    if(executable == nullptr) {
1211
        if(trans->exceptionOccurred()) {
1212 306962bc O'Neil Delpratt
            SaxonApiException * exception = trans->getException();
1213
            if(exception != nullptr) {
1214
                cerr << "Error: " << exception->getMessage() << endl;
1215
                delete exception;
1216
            }
1217 4ee4355d O'Neil Delpratt
1218
        }
1219
        sresult->failure++;
1220
        sresult->failureList.push_back("testCallFunction");
1221 306962bc O'Neil Delpratt
        trans->exceptionClear();
1222 4ee4355d O'Neil Delpratt
        return;
1223
1224
1225
    }
1226
1227 501beb26 O'Neil Delpratt
    XdmValue **valueArray = new XdmValue *[2];
1228
1229
    valueArray[0] = (XdmValue *) (proc->makeIntegerValue(2));
1230
    valueArray[1] = (XdmValue *) (proc->makeIntegerValue(3));
1231
    XdmValue *v = executable->callFunctionReturningValue("{http://localhost/}add", valueArray, 2);
1232
1233
    if (v != NULL && (v->getHead())->isAtomic() && ((XdmAtomicValue *) (v->getHead()))->getLongValue() == 5) {
1234
        sresult->success++;
1235 55b80284 O'Neil Delpratt
        delete v;
1236 501beb26 O'Neil Delpratt
    } else {
1237
        if (v != NULL && !(v->getHead())->isAtomic()) {
1238
            cout << "Value in callFunction is not atomic - but expected as atomic value" << endl;
1239
        }
1240
        cout << "testCallFunction ======= FAIL ======" << endl;
1241 4ee4355d O'Neil Delpratt
        if(executable->exceptionOccurred()) {
1242
            SaxonApiException * exception = executable->getException();
1243 306962bc O'Neil Delpratt
            if(exception != nullptr) {
1244
                cerr << "Error: " << exception->getMessage() << endl;
1245
                delete exception;
1246
            }
1247 501beb26 O'Neil Delpratt
        }
1248
        sresult->failure++;
1249
        sresult->failureList.push_back("testCallFunction");
1250 55b80284 O'Neil Delpratt
        executable->exceptionClear();
1251
        delete v;
1252 501beb26 O'Neil Delpratt
    }
1253
    delete valueArray[0];
1254
    delete valueArray[1];
1255 901b6eca O'Neil Delpratt
    delete [] valueArray;
1256 55b80284 O'Neil Delpratt
    delete executable;
1257 501beb26 O'Neil Delpratt
}
1258
1259
void testInitialTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1260
1261
1262
    const char *source = "<?xml version='1.0'?>  <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'  xmlns:xs='http://www.w3.org/2001/XMLSchema'  version='3.0'>  <xsl:template match='*'>     <xsl:param name='a' as='xs:double'/>     <xsl:param name='b' as='xs:float'/>     <xsl:sequence select='., $a + $b'/>  </xsl:template>  </xsl:stylesheet>";
1263
    cout << endl << "Test:testInitialTemplate" << endl;
1264
    XsltExecutable * executable = trans->compileFromString(source);
1265 901b6eca O'Neil Delpratt
    if(executable == nullptr) {
1266
        if(trans->exceptionOccurred()) {
1267
            cout << "Error: "<< trans->getErrorMessage() << endl;
1268
        }
1269
        return;
1270
    }
1271 55b80284 O'Neil Delpratt
    XdmNode * node = proc->parseXmlFromString("<e/>");
1272 501beb26 O'Neil Delpratt
1273
    executable->setResultAsRawValue(false);
1274
    std::map<std::string, XdmValue *> parameterValues;
1275 4ee4355d O'Neil Delpratt
1276
    XdmAtomicValue * a1 = proc->makeIntegerValue(12);
1277
    XdmAtomicValue * a2 = proc->makeIntegerValue(5);;
1278
    parameterValues["a"] = a1;
1279
    parameterValues["b"] = a2;
1280 501beb26 O'Neil Delpratt
    executable->setInitialTemplateParameters(parameterValues, false);
1281
    executable->setInitialMatchSelection(node);
1282
    XdmValue *result = executable->applyTemplatesReturningValue();
1283
    if (result != NULL) {
1284
        sresult->success++;
1285
        cout << "Result=" << result->getHead()->getStringValue() << endl;
1286 4ee4355d O'Neil Delpratt
        delete result;
1287 501beb26 O'Neil Delpratt
    } else {
1288
        sresult->failure++;
1289 72bf04c6 Norman Walsh
    }
1290
1291 a69dd173 O'Neil Delpratt
    delete executable;
1292 4ee4355d O'Neil Delpratt
    delete a1;
1293
    delete a2;
1294 55b80284 O'Neil Delpratt
    delete node;
1295
    parameterValues.clear();
1296 72bf04c6 Norman Walsh
}
1297
1298 501beb26 O'Neil Delpratt
void testResolveUri(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1299
    cout << endl << "Test: testResolveUri:" << endl;
1300
1301
    XsltExecutable * executable = trans->compileFromString(
1302
            "<xsl:stylesheet version='3.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:err='http://www.w3.org/2005/xqt-errors'><xsl:template name='go'><xsl:try><xsl:variable name='uri' as='xs:anyURI' select=\"resolve-uri('notice trailing space /out.xml')\"/> <xsl:message select='$uri'/><xsl:result-document href='{$uri}'><out/></xsl:result-document><xsl:catch><xsl:sequence select=\"'$err:code: ' || $err:code  || ', $err:description: ' || $err:description\"/></xsl:catch></xsl:try></xsl:template></xsl:stylesheet>");
1303
1304 901b6eca O'Neil Delpratt
    if(executable == nullptr) {
1305
        sresult->failure++;
1306
        sresult->failureList.push_back("testResolveUri");
1307
        if(trans->exceptionOccurred()) {
1308 306962bc O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1309
            if(message != nullptr) {
1310
                cout << "Error: " << trans->getErrorMessage() << endl;
1311
            }
1312 901b6eca O'Neil Delpratt
        }
1313 306962bc O'Neil Delpratt
        trans->exceptionClear();
1314 901b6eca O'Neil Delpratt
        return;
1315
    }
1316 501beb26 O'Neil Delpratt
    XdmValue *value = executable->callTemplateReturningValue("go");
1317
1318
1319 9458d238 O'Neil Delpratt
    if (value== nullptr) {
1320 501beb26 O'Neil Delpratt
1321
        sresult->failure++;
1322
        sresult->failureList.push_back("testResolveUri");
1323
    } else {
1324
1325
        const char *svalue = value->itemAt(0)->getStringValue();
1326
        cout << "testResolveUri = " << svalue << endl;
1327
        sresult->success++;
1328 306962bc O'Neil Delpratt
        delete value;
1329 501beb26 O'Neil Delpratt
    }
1330
1331 55b80284 O'Neil Delpratt
    delete executable;
1332 72bf04c6 Norman Walsh
}
1333
1334 501beb26 O'Neil Delpratt
void testContextNotRoot(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1335
    cout << endl << "Test: testContextNotRoot" << endl;
1336 72bf04c6 Norman Walsh
1337 501beb26 O'Neil Delpratt
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1338 72bf04c6 Norman Walsh
1339 306962bc O'Neil Delpratt
    XsltExecutable *executable = trans->compileFromString(
1340 501beb26 O'Neil Delpratt
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:variable name='x' select='.'/><xsl:template match='/'>errorA</xsl:template><xsl:template match='e'>[<xsl:value-of select='name($x)'/>]</xsl:template></xsl:stylesheet>");
1341 901b6eca O'Neil Delpratt
1342 306962bc O'Neil Delpratt
    if (executable == nullptr) {
1343 901b6eca O'Neil Delpratt
        sresult->failure++;
1344
        sresult->failureList.push_back("testContextNotRoot");
1345 306962bc O'Neil Delpratt
        if (trans->exceptionOccurred()) {
1346
            cout << "Error: " << trans->getErrorMessage() << endl;
1347 901b6eca O'Neil Delpratt
        }
1348
        return;
1349
    }
1350
1351 501beb26 O'Neil Delpratt
    executable->setGlobalContextItem(node);
1352
    if (node->getChildCount() > 0) {
1353 306962bc O'Neil Delpratt
        XdmNode **eNodeL1 = node->getChildren();
1354
        if (eNodeL1 != nullptr) {
1355
            XdmNode ** eNodeChildren = eNodeL1[0]->getChildren();
1356
            if (eNodeChildren != nullptr) {
1357
                XdmNode *eNode = eNodeChildren[0];
1358
                cout << "Node content = " << eNode->toString() << endl;
1359
                executable->setInitialMatchSelection(eNode);
1360
                const char *result = executable->applyTemplatesReturningString();
1361 72bf04c6 Norman Walsh
1362 306962bc O'Neil Delpratt
                if (result == nullptr) {
1363 72bf04c6 Norman Walsh
1364 55b80284 O'Neil Delpratt
                    cout << "testContextNotRoot ======= FAIL ======" << endl;
1365 306962bc O'Neil Delpratt
                    if (executable->exceptionOccurred()) {
1366
                        SaxonApiException *exception = executable->getException();
1367
                        cerr << "Error: " << exception->getMessage() << endl;
1368
                        delete exception;
1369
                    }
1370
                    sresult->failure++;
1371
                    sresult->failureList.push_back("testContextNotRoot");
1372 72bf04c6 Norman Walsh
1373 306962bc O'Neil Delpratt
1374
                } else {
1375
1376
                    cout << "testContextNotRoot = " << result << endl;
1377
                    sresult->success++;
1378
                    delete result;
1379
1380
                }
1381
1382
            }
1383 501beb26 O'Neil Delpratt
        }
1384 306962bc O'Neil Delpratt
    } else {
1385
        sresult->failure++;
1386
        sresult->failureList.push_back("testContextNotRoot");
1387 501beb26 O'Neil Delpratt
    }
1388 306962bc O'Neil Delpratt
1389
    delete executable;
1390
    delete node;
1391 501beb26 O'Neil Delpratt
}
1392 72bf04c6 Norman Walsh
1393 501beb26 O'Neil Delpratt
1394
void testContextNotRootNamedTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1395
    cout << endl << "Test: testContextNotRootNamedTemplate" << endl;
1396
1397
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1398
1399 55b80284 O'Neil Delpratt
    if(node == nullptr) {
1400
        if(proc->exceptionOccurred()) {
1401
            const char * message = proc->getErrorMessage();
1402
            if(message != nullptr) {
1403
                cerr << "Error: " << message << endl;
1404
            }
1405
            proc->exceptionClear();
1406
        }
1407
        sresult->failure++;
1408
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1409
        return;
1410
    }
1411
1412 501beb26 O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromString(
1413
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:variable name='x' select='.'/><xsl:template match='/'>errorA</xsl:template><xsl:template name='main'>[<xsl:value-of select='name($x)'/>]</xsl:template></xsl:stylesheet>");
1414 901b6eca O'Neil Delpratt
1415
    if(executable == nullptr) {
1416
        sresult->failure++;
1417
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1418
        if(trans->exceptionOccurred()) {
1419
            cout << "Error: "<< trans->getErrorMessage() << endl;
1420
        }
1421 55b80284 O'Neil Delpratt
        delete node;
1422 901b6eca O'Neil Delpratt
        return;
1423
    }
1424
1425 501beb26 O'Neil Delpratt
    executable->setGlobalContextItem(node);
1426
    const char *result = executable->callTemplateReturningString("main");
1427
1428 9458d238 O'Neil Delpratt
    if (result== nullptr) {
1429 501beb26 O'Neil Delpratt
1430 55b80284 O'Neil Delpratt
        cout << "testContextNotRootNameTemplate ======= FAIL ======" << endl;
1431 4ee4355d O'Neil Delpratt
        if(executable->exceptionOccurred()) {
1432
            SaxonApiException * exception = executable->getException();
1433
            cerr<<"Error: " << exception->getMessage() <<endl;
1434
            delete exception;
1435 501beb26 O'Neil Delpratt
        }
1436
        sresult->failure++;
1437
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1438
    } else {
1439
1440
        cout << "testContextNotRoot = " << result << endl;
1441
        sresult->success++;
1442 55b80284 O'Neil Delpratt
        delete result;
1443 501beb26 O'Neil Delpratt
    }
1444 55b80284 O'Neil Delpratt
    delete node;
1445
    delete executable;
1446 72bf04c6 Norman Walsh
1447
}
1448
1449 501beb26 O'Neil Delpratt
1450
void testContextNotRootNamedTemplateValue(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1451
    cout << endl << "Test: testContextNotRootNamedTemplateValue" << endl;
1452
1453
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1454
1455 55b80284 O'Neil Delpratt
    if(node == nullptr) {
1456
        if(proc->exceptionOccurred()) {
1457
            const char * message = proc->getErrorMessage();
1458
            if(message != nullptr) {
1459
                cerr << "Error: " << message << endl;
1460
            }
1461
            proc->exceptionClear();
1462
        }
1463
        sresult->failure++;
1464
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
1465
        return;
1466
    }
1467
1468 501beb26 O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromString(
1469
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:variable name='x' select='.'/><xsl:template match='/'>errorA</xsl:template><xsl:template name='main'>[<xsl:value-of select='name($x)'/>]</xsl:template></xsl:stylesheet>");
1470 901b6eca O'Neil Delpratt
1471
    if(executable == nullptr) {
1472
        sresult->failure++;
1473
        sresult->failureList.push_back("testContentNotRootNamedTemplateValue");
1474
        if(trans->exceptionOccurred()) {
1475
            cout << "Error: "<< trans->getErrorMessage() << endl;
1476
        }
1477 55b80284 O'Neil Delpratt
        delete node;
1478 901b6eca O'Neil Delpratt
        return;
1479
    }
1480
1481 501beb26 O'Neil Delpratt
    executable->setGlobalContextItem(node);
1482
    XdmValue *result = executable->callTemplateReturningValue("main");
1483
1484 55b80284 O'Neil Delpratt
    if (result == nullptr) {
1485 501beb26 O'Neil Delpratt
1486
        cout << "testCallFunction ======= FAIL ======" << endl;
1487 4ee4355d O'Neil Delpratt
        if(executable->exceptionOccurred()) {
1488
            SaxonApiException * exception = executable->getException();
1489
            cerr<<"Error: " << exception->getMessage() <<endl;
1490
            delete exception;
1491 501beb26 O'Neil Delpratt
        }
1492
        sresult->failure++;
1493
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
1494
    } else {
1495
1496
        cout << "testContextNotRoot = " << result->getHead()->getStringValue() << endl;
1497
        sresult->success++;
1498 55b80284 O'Neil Delpratt
        delete result;
1499
        result = nullptr;
1500 72bf04c6 Norman Walsh
    }
1501
1502 55b80284 O'Neil Delpratt
    delete node;
1503
    delete executable;
1504
1505
1506 501beb26 O'Neil Delpratt
}
1507 72bf04c6 Norman Walsh
1508 501beb26 O'Neil Delpratt
void testCallSystemFunction(SaxonProcessor *proc, sResultCount *sresult) {
1509 72bf04c6 Norman Walsh
1510 501beb26 O'Neil Delpratt
    XdmFunctionItem *fi = XdmFunctionItem::getSystemFunction(proc, "{http://www.w3.org/2005/xpath-functions}parse-json",
1511
                                                            1);
1512 9458d238 O'Neil Delpratt
    if (fi== nullptr) {
1513 501beb26 O'Neil Delpratt
        sresult->failure++;
1514
        sresult->failureList.push_back("testCallSystemFunction");
1515
        return;
1516
    }
1517
1518
    XdmValue ** xdmValue = new XdmValue*[1];
1519
    xdmValue[0] = new XdmValue();
1520
    xdmValue[0]->addXdmItem(proc->makeStringValue("[1,2,3]"));
1521
    XdmValue *result = fi->call(xdmValue, 1);
1522
1523
    std::cerr << "Result = " << result->toString() << endl;
1524
    if(result->size() == 3) {
1525
1526
        cout << "testCallSystemFunction = " << result->getHead()->getStringValue() << endl;
1527
        sresult->success++;
1528
1529
    } else {
1530
        sresult->failure++;
1531
        sresult->failureList.push_back("testCallSystemFunction");
1532 72bf04c6 Norman Walsh
1533
    }
1534
1535 501beb26 O'Neil Delpratt
}
1536
1537
1538
void testPipeline(SaxonProcessor *proc, sResultCount *sresult) {
1539
    cout << endl << "Test: testPipeline" << endl;
1540 72bf04c6 Norman Walsh
1541 501beb26 O'Neil Delpratt
    Xslt30Processor * trans = proc->newXslt30Processor();
1542 55b80284 O'Neil Delpratt
    if(trans == nullptr) {
1543
        cout << "Error: Xslt30Processor is null - maybe unclean state of JNI" << endl;
1544
        sresult->failure++;
1545
        sresult->failureList.push_back("testPipeline");
1546
        return;
1547
    }
1548 501beb26 O'Neil Delpratt
    XsltExecutable * stage1 = trans->compileFromString(
1549
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1550 901b6eca O'Neil Delpratt
1551
    if(stage1 == nullptr) {
1552
        sresult->failure++;
1553
        sresult->failureList.push_back("testPipeline");
1554
        if(trans->exceptionOccurred()) {
1555 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1556
            cout << "stage 1 Error: " << message << endl;
1557
1558 901b6eca O'Neil Delpratt
        }
1559 55b80284 O'Neil Delpratt
        cout << "Stage 1 Error - exit method " << endl;
1560
        delete trans;
1561 901b6eca O'Neil Delpratt
        return;
1562
    }
1563
1564 501beb26 O'Neil Delpratt
    XdmNode *inn = proc->parseXmlFromString("<z/>");
1565 72bf04c6 Norman Walsh
1566 501beb26 O'Neil Delpratt
    XsltExecutable *stage2 = trans->compileFromString(
1567
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1568
1569 901b6eca O'Neil Delpratt
    if(stage2 == nullptr) {
1570
        sresult->failure++;
1571
        sresult->failureList.push_back("testPipeline");
1572
        if(trans->exceptionOccurred()) {
1573 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1574
            cout << "stage 2 Error: " << message << endl;
1575
1576 901b6eca O'Neil Delpratt
        }
1577 55b80284 O'Neil Delpratt
        cout << "Stage 2 Error - exit method " << endl;
1578
        delete stage1;
1579
        delete trans;
1580
        delete inn;
1581 901b6eca O'Neil Delpratt
        return;
1582
    }
1583 55b80284 O'Neil Delpratt
1584
1585 501beb26 O'Neil Delpratt
    XsltExecutable *stage3 = trans->compileFromString(
1586
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1587
1588 901b6eca O'Neil Delpratt
    if(stage3 == nullptr) {
1589
        sresult->failure++;
1590
        sresult->failureList.push_back("testPipeline");
1591
        if(trans->exceptionOccurred()) {
1592 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1593
            cout << "stage 3 Error: " << message << endl;
1594
1595
        } else {
1596
            cout << "Stage 3 Error: testPipeline failed with exception" << endl;
1597 901b6eca O'Neil Delpratt
        }
1598 55b80284 O'Neil Delpratt
        cout << "Stage 3 Error - exit method " << endl;
1599
        delete stage1;
1600
        delete stage2;
1601
        delete trans;
1602
        delete inn;
1603 901b6eca O'Neil Delpratt
        return;
1604
    }
1605 55b80284 O'Neil Delpratt
1606 501beb26 O'Neil Delpratt
    XsltExecutable *stage4 = trans->compileFromString(
1607
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1608
1609 55b80284 O'Neil Delpratt
    if(stage4 == nullptr) {
1610 901b6eca O'Neil Delpratt
        sresult->failure++;
1611
        sresult->failureList.push_back("testPipeline");
1612
        if(trans->exceptionOccurred()) {
1613 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1614
            cout << "stage 4 Error: " << message << endl;
1615
1616
        } else {
1617
            cout << "Stage 4 Error: testPipeline failed with exception" << endl;
1618
        }
1619
        cout << "Stage 4 Error - exit method " << endl;
1620
        delete stage1;
1621
        delete stage2;
1622
        delete stage3;
1623
        delete trans;
1624
        delete inn;
1625 901b6eca O'Neil Delpratt
        return;
1626
    }
1627
1628 501beb26 O'Neil Delpratt
    XsltExecutable *stage5 = trans->compileFromString(
1629
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1630
1631 901b6eca O'Neil Delpratt
    if(stage5 == nullptr) {
1632 501beb26 O'Neil Delpratt
        sresult->failure++;
1633
        sresult->failureList.push_back("testPipeline");
1634 901b6eca O'Neil Delpratt
        if(trans->exceptionOccurred()) {
1635 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1636
            cout << "stage 5 Error: " << message << endl;
1637
1638
        } else {
1639
            cout << "Stage 5 Error: testPipeline failed with exception" << endl;
1640
        }
1641
        cout << "Stage 5     Error - exit method " << endl;
1642
        delete stage1;
1643
        delete stage2;
1644
        delete stage3;
1645
        delete stage4;
1646
        delete trans;
1647
        delete inn;
1648 501beb26 O'Neil Delpratt
        return;
1649 72bf04c6 Norman Walsh
    }
1650
1651 501beb26 O'Neil Delpratt
    stage1->setProperty("!indent", "no");
1652
    stage1->setInitialMatchSelection(inn);
1653 72bf04c6 Norman Walsh
1654 501beb26 O'Neil Delpratt
    XdmValue *d1 = stage1->applyTemplatesReturningValue();
1655 55b80284 O'Neil Delpratt
    if(d1 == nullptr) {
1656
        if (stage1->exceptionOccurred()) {
1657
            sresult->failure++;
1658
            sresult->failureList.push_back("testPipeline");
1659
            if (stage1->exceptionOccurred()) {
1660
                SaxonApiException *exception = stage1->getException();
1661
                if (exception != nullptr) {
1662
                    cerr << "Error: " << exception->getMessage() << endl;
1663
                    delete exception;
1664
                    exception = nullptr;
1665
                }
1666
            }
1667
            cout << "Stage d1 Error - exit method " << endl;
1668
            delete stage1;
1669
            delete stage2;
1670
            delete stage3;
1671
            delete stage4;
1672
            delete stage5;
1673
            delete trans;
1674
            delete inn;
1675
            return;
1676 4ee4355d O'Neil Delpratt
        }
1677 501beb26 O'Neil Delpratt
    }
1678
1679
    XdmItem *d11 = d1->getHead();
1680 9458d238 O'Neil Delpratt
    if (d11== nullptr) {
1681 72bf04c6 Norman Walsh
1682 501beb26 O'Neil Delpratt
        cout << "d11 is NULL\n" << endl;
1683 55b80284 O'Neil Delpratt
        sresult->failure++;
1684
        sresult->failureList.push_back("testPipeline-1");
1685
        delete stage1;
1686
        delete stage2;
1687
        delete stage3;
1688
        delete stage4;
1689
        delete stage5;
1690
        delete d1;
1691
        delete inn;
1692
        delete trans;
1693
        return;
1694 501beb26 O'Neil Delpratt
    }
1695 55b80284 O'Neil Delpratt
    const char *data = d11->toString();
1696 501beb26 O'Neil Delpratt
1697
    if (data != NULL) {
1698
        cout << "d1 result=" << data << endl;
1699
    } else {
1700 72bf04c6 Norman Walsh
1701 55b80284 O'Neil Delpratt
        cout << "d1 result Error - toString is NULL" << endl;
1702
        delete stage1;
1703
        delete stage2;
1704
        delete stage3;
1705
        delete stage4;
1706
        delete stage5;
1707
        delete d1;
1708
        delete inn;
1709
        delete trans;
1710 501beb26 O'Neil Delpratt
        return;
1711
    }
1712
    stage2->setProperty("!indent", "no");
1713 55b80284 O'Neil Delpratt
    stage2->setInitialMatchSelection(d11);
1714 501beb26 O'Neil Delpratt
    XdmValue *d2 = stage2->applyTemplatesReturningValue();
1715 9458d238 O'Neil Delpratt
    if (d2== nullptr) {
1716 501beb26 O'Neil Delpratt
        cout << "ERROR-11\n" << endl;
1717
        sresult->failure++;
1718
        sresult->failureList.push_back("testPipeline-2");
1719 55b80284 O'Neil Delpratt
        if (stage2->exceptionOccurred()) {
1720
            SaxonApiException *exception = stage2->getException();
1721
            if (exception != nullptr) {
1722
                cerr << "Error: " << exception->getMessage() << endl;
1723
                delete exception;
1724
                exception = nullptr;
1725
            }
1726
        }
1727
        cout << "Stage d2 Error - exit method " << endl;
1728
        delete d1;
1729
        delete inn;
1730
        delete stage1;
1731
        delete stage2;
1732
        delete stage3;
1733
        delete stage4;
1734
        delete stage5;
1735
        delete trans;
1736 501beb26 O'Neil Delpratt
        return;
1737
    }
1738
    stage3->setProperty("!indent", "no");
1739
    stage3->setInitialMatchSelection(d2);
1740
    XdmValue * d3 = stage3->applyTemplatesReturningValue();
1741
    if(d3 == nullptr){
1742
        sresult->failure++;
1743
        sresult->failureList.push_back("testPipeline-3");
1744 55b80284 O'Neil Delpratt
        if (stage3->exceptionOccurred()) {
1745
            SaxonApiException *exception = stage3->getException();
1746
            if (exception != nullptr) {
1747
                cerr << "Error: " << exception->getMessage() << endl;
1748
                delete exception;
1749
                exception = nullptr;
1750
            }
1751 901b6eca O'Neil Delpratt
        }
1752 55b80284 O'Neil Delpratt
        cout << "Stage d3 Error - exit method " << endl;
1753
        delete d1;
1754
        delete d2;
1755
        delete inn;
1756
1757
        delete stage1;
1758
        delete stage2;
1759
        delete stage3;
1760
        delete stage4;
1761
        delete stage5;
1762
        delete trans;
1763
        return;
1764 501beb26 O'Neil Delpratt
      }
1765
    stage4->setProperty("!indent", "no");
1766
    stage4->setInitialMatchSelection(d3);
1767
    XdmValue * d4 = stage4->applyTemplatesReturningValue();
1768 55b80284 O'Neil Delpratt
    if(d4== nullptr){
1769 501beb26 O'Neil Delpratt
        sresult->failure++;
1770 55b80284 O'Neil Delpratt
        sresult->failureList.push_back("testPipeline-4");
1771
        if (stage4->exceptionOccurred()) {
1772
            SaxonApiException *exception = stage4->getException();
1773
            if (exception != nullptr) {
1774
                cerr << "Error: " << exception->getMessage() << endl;
1775
                delete exception;
1776
                exception = nullptr;
1777
            }
1778 901b6eca O'Neil Delpratt
        }
1779 55b80284 O'Neil Delpratt
        cout << "Stage d4 Error - exit method " << endl;
1780
        delete d3;
1781
        delete d2;
1782
        delete d1;
1783
        delete inn;
1784
        delete stage1;
1785
        delete stage2;
1786
        delete stage3;
1787
        delete stage4;
1788
        delete stage5;
1789
        delete trans;
1790 501beb26 O'Neil Delpratt
        return;
1791
      }
1792
    stage5->setProperty("!indent", "no");
1793
    stage5->setInitialMatchSelection(d4);
1794
    const char * sw = stage5->applyTemplatesReturningString();
1795 55b80284 O'Neil Delpratt
    if(sw == nullptr){
1796 501beb26 O'Neil Delpratt
        sresult->failure++;
1797 55b80284 O'Neil Delpratt
        sresult->failureList.push_back("testPipeline-5");
1798
        if (stage5->exceptionOccurred()) {
1799
            SaxonApiException *exception = stage5->getException();
1800
            if (exception != nullptr) {
1801
                cerr << "Error: " << exception->getMessage() << endl;
1802
                delete exception;
1803
            }
1804 901b6eca O'Neil Delpratt
        }
1805 55b80284 O'Neil Delpratt
        cout << "Stage sw Error - exit method " << endl;
1806
        delete stage1;
1807
        delete stage2;
1808
        delete stage3;
1809
        delete stage4;
1810
        delete stage5;
1811
        delete trans;
1812
        delete d4;
1813
        delete d3;
1814
        delete d2;
1815
        delete d1;
1816
        delete inn;
1817 501beb26 O'Neil Delpratt
        return;
1818
      }
1819
    cout<<sw<<endl;
1820
    cout << "testPipeline = " << sw << endl;
1821
    sresult->success++;
1822 55b80284 O'Neil Delpratt
    delete stage1;
1823
    stage1 = nullptr;
1824
1825
    delete stage2;
1826
    stage2 = nullptr;
1827
1828
1829
    delete stage3;
1830
    stage3 = nullptr;
1831
1832
    delete stage4;
1833
    stage4 = nullptr;
1834
1835
    delete stage5;
1836
    stage5 = nullptr;
1837
1838
    delete trans;
1839
    trans = nullptr;
1840
1841
    delete sw;
1842
    sw = nullptr;
1843 501beb26 O'Neil Delpratt
1844 55b80284 O'Neil Delpratt
    delete d4;
1845
    d4 = nullptr;
1846
1847
    delete d3;
1848
    d3 = nullptr;
1849
1850
    delete d2;
1851
    d2 = nullptr;
1852
1853
    delete d1;
1854
    d1 = nullptr;
1855
1856
    delete inn;
1857
    inn = nullptr;
1858 501beb26 O'Neil Delpratt
1859
}
1860
1861 72bf04c6 Norman Walsh
1862 9458d238 O'Neil Delpratt
void testCatalog(const char * cwd, SaxonProcessor * proc, sResultCount *sresult) {
1863 72bf04c6 Norman Walsh
1864 00082f6f O'Neil Delpratt
1865 d0e6f8be O'Neil Delpratt
    cout << endl << "Test: testCatalog" << endl;
1866 9458d238 O'Neil Delpratt
    bool trace = false;
1867
    proc->setcwd(cwd);
1868 501beb26 O'Neil Delpratt
    proc->setCatalog("../php/catalog-test/catalog.xml", trace);
1869
1870 9458d238 O'Neil Delpratt
    Xslt30Processor * trans = proc->newXslt30Processor();
1871
1872 501beb26 O'Neil Delpratt
    XsltExecutable  * executable = trans->compileFromFile("../php/catalog-test/test1.xsl");
1873 901b6eca O'Neil Delpratt
1874
    if(executable == nullptr) {
1875 00082f6f O'Neil Delpratt
1876 901b6eca O'Neil Delpratt
        if (trans->exceptionOccurred()) {
1877 00082f6f O'Neil Delpratt
1878
            if(trans->getErrorMessage() != nullptr) {
1879
                const char *message = trans->getErrorMessage();
1880 4ee4355d O'Neil Delpratt
                cerr << "exception=" << message << endl;
1881 00082f6f O'Neil Delpratt
            } else {
1882
                const char *message = proc->getErrorMessage();
1883
                if(message != nullptr) {
1884 4ee4355d O'Neil Delpratt
                    cerr << "exception-proc=" << message << endl;
1885 00082f6f O'Neil Delpratt
                }
1886
            }
1887 4ee4355d O'Neil Delpratt
        }
1888
        sresult->failure++;
1889
        sresult->failureList.push_back("testCatalog");
1890
        trans->exceptionClear();
1891 55b80284 O'Neil Delpratt
        delete trans;
1892
        trans= nullptr;
1893 d0e6f8be O'Neil Delpratt
        return;
1894 901b6eca O'Neil Delpratt
    }
1895 a69dd173 O'Neil Delpratt
1896 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelectionAsFile("../php/catalog-test/example.xml");
1897 4ee4355d O'Neil Delpratt
1898 501beb26 O'Neil Delpratt
    const char *result = executable->applyTemplatesReturningString();
1899
1900
    if(result != NULL) {
1901
        std::cerr << "testCatalog result= " << result << std::endl;
1902 55b80284 O'Neil Delpratt
        delete result;
1903
        sresult->success++; // TODO - check the results more carefully
1904
    } else {
1905
        sresult->failure++;
1906
        sresult->failureList.push_back("testCatalog");
1907 501beb26 O'Neil Delpratt
    }
1908 55b80284 O'Neil Delpratt
1909 4ee4355d O'Neil Delpratt
1910
    delete executable;
1911 55b80284 O'Neil Delpratt
    executable = nullptr;
1912
    delete trans;
1913
    trans = nullptr;
1914 501beb26 O'Neil Delpratt
1915
}
1916 72bf04c6 Norman Walsh
1917 306962bc O'Neil Delpratt
static int NUM_THREADS = 10;
1918 72bf04c6 Norman Walsh
1919 306962bc O'Neil Delpratt
void RunThread(XsltExecutable * executable, int tid, const std::string filename) {
1920 55b80284 O'Neil Delpratt
    JavaVMAttachArgs att_arg;
1921
    att_arg.version = JNI_VERSION_1_2;
1922
    att_arg.name = NULL;
1923
    att_arg.group = NULL;
1924
1925
   // SaxonProcessor::sxn_environ->jvm->AttachCurrentThread((void**)&SaxonProcessor::sxn_environ->env, &att_arg);
1926
    cerr<<endl<<"RunThread cp0,  THEAD ID="<<tid<<endl;
1927
    fflush(stderr);
1928
    fflush(stdout);
1929 72bf04c6 Norman Walsh
1930 55b80284 O'Neil Delpratt
    if(executable != nullptr) {
1931
       executable->setInitialMatchSelectionAsFile(filename.c_str());
1932 501beb26 O'Neil Delpratt
1933 55b80284 O'Neil Delpratt
        cerr << "RunThread cp1" << endl;
1934 306962bc O'Neil Delpratt
1935 55b80284 O'Neil Delpratt
       const char *result = nullptr;
1936
        result = executable->applyTemplatesReturningString();
1937
        if (result != nullptr) {
1938
            cout << " Result from THREAD ID: " << tid << ", " << result << endl;
1939
            delete result;
1940
        } else {
1941
            cerr << " ===== Failed in THREAD ID: " << tid << endl;
1942
           /* if(executable->exceptionOccurred()) {
1943
                SaxonApiException *exception = executable->getException();
1944

1945
                if (exception != nullptr) {
1946
                    const char *message = exception->getMessage();
1947
                    if (message != nullptr) {
1948
                        cerr << "Error = " << message << endl;
1949
                    }
1950
                    delete exception;
1951 306962bc O'Neil Delpratt
                }
1952 55b80284 O'Neil Delpratt
            } else {
1953
            cerr << "No exception found - result is nullptr" << endl;
1954
            }*/
1955 306962bc O'Neil Delpratt
1956 55b80284 O'Neil Delpratt
        }
1957
    delete executable;
1958
    } else {
1959
        cerr << "XsltExecutable is nullptr" << endl;
1960 306962bc O'Neil Delpratt
    }
1961 72bf04c6 Norman Walsh
1962 55b80284 O'Neil Delpratt
   // (   SaxonProcessor::sxn_environ->jvm)->DetachCurrentThread();
1963 72bf04c6 Norman Walsh
1964 306962bc O'Neil Delpratt
}
1965 72bf04c6 Norman Walsh
1966 306962bc O'Neil Delpratt
void testThreads (SaxonProcessor * processor, Xslt30Processor * trans, sResultCount *sresult) {
1967 501beb26 O'Neil Delpratt
1968 306962bc O'Neil Delpratt
    std::vector<std::string> s = {
1969
            "../data/xmark100k.xml",
1970
            "../data/xmark1.xml",
1971
            "../data/xmark4.xml",
1972
            "../data/xmark10.xml"
1973
    };
1974 501beb26 O'Neil Delpratt
1975 306962bc O'Neil Delpratt
    std::vector<std::thread> threads;
1976 501beb26 O'Neil Delpratt
1977 306962bc O'Neil Delpratt
    for (int i = 0; i < s.size(); i++) {
1978 55b80284 O'Neil Delpratt
1979 306962bc O'Neil Delpratt
        XsltExecutable * executable = trans->compileFromFile("q12.xsl");
1980
            threads.push_back(std::thread(RunThread, executable, i, s[i]));
1981 55b80284 O'Neil Delpratt
1982 501beb26 O'Neil Delpratt
    }
1983 306962bc O'Neil Delpratt
    cerr<<"testThreads cp0"<<endl;
1984
    for (auto &th : threads) {
1985
        th.join();
1986
        cerr<<"testThreads cp1 - loop"<<endl;
1987
    }
1988 501beb26 O'Neil Delpratt
}
1989
1990
1991
1992 e9b06a56 O'Neil Delpratt
int main(int argc, char* argv[]) {
1993
1994
1995
    const char * cwd = nullptr;
1996
    if(argc > 0) {
1997 4bed9808 O'Neil Delpratt
        cwd = argv[1];
1998 e9b06a56 O'Neil Delpratt
    }
1999 501beb26 O'Neil Delpratt
2000
    SaxonProcessor *processor = new SaxonProcessor(true);
2001 fc47eaa6 O'Neil Delpratt
    processor->setConfigurationProperty("http://saxon.sf.net/feature/licenseFileLocation", "/usr/local/lib/saxon-license.lic");
2002 501beb26 O'Neil Delpratt
    cout << "Test: Xslt30Processor with Saxon version=" << processor->version() << endl << endl;
2003 6b6a9706 O'Neil Delpratt
    
2004 e05bbe34 O'Neil Delpratt
    char buff[FILENAME_MAX]; //create string buffer to hold path
2005
    GetCurrentDir( buff, FILENAME_MAX );
2006 9458d238 O'Neil Delpratt
    cout<<"CWD = "<< buff<<endl;
2007 e9b06a56 O'Neil Delpratt
    if(cwd != nullptr) {
2008
            processor->setcwd(cwd);//"/Users/ond1/work/development/git/saxon-dev/saxondev/src/main/c/samples/cppTests"); //set to the current working directory
2009 306962bc O'Neil Delpratt
    } else {
2010
        processor->setcwd(buff);
2011 e9b06a56 O'Neil Delpratt
    }
2012 501beb26 O'Neil Delpratt
    if (processor->isSchemaAwareProcessor()) {
2013
2014
        std::cerr << "Processor is Schema Aware" << std::endl;
2015
    } else {
2016
        std::cerr << "Processor is not Schema Aware" << std::endl;
2017
    }
2018 e05bbe34 O'Neil Delpratt
2019 501beb26 O'Neil Delpratt
    sResultCount *sresult = new sResultCount();
2020
    Xslt30Processor *trans = processor->newXslt30Processor();
2021 8d5b64f3 O'Neil Delpratt
2022
    if( trans == nullptr) {
2023 dfaaba21 O'Neil Delpratt
        cout<< "Error creating Xslt30Processor"<<endl;
2024 8d5b64f3 O'Neil Delpratt
        if(processor->exceptionOccurred()) {
2025 dfaaba21 O'Neil Delpratt
            cout<< "Error message: " <<processor->getErrorMessage()<<endl;
2026 8d5b64f3 O'Neil Delpratt
2027
        }
2028 dfaaba21 O'Neil Delpratt
        return -1;
2029 8d5b64f3 O'Neil Delpratt
    }
2030 501beb26 O'Neil Delpratt
    //testValidation(trans,sresult);
2031 a69dd173 O'Neil Delpratt
2032 501beb26 O'Neil Delpratt
    testInitialTemplate(processor, trans, sresult);
2033 a69dd173 O'Neil Delpratt
2034 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2035 4ee4355d O'Neil Delpratt
2036 501beb26 O'Neil Delpratt
    exampleSimple1Err(trans, sresult);
2037 a69dd173 O'Neil Delpratt
2038 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2039
2040 72bf04c6 Norman Walsh
    exampleSimple1(trans, sresult);
2041 e05bbe34 O'Neil Delpratt
2042 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2043
2044 72bf04c6 Norman Walsh
    exampleSimple_xmark(trans, sresult);
2045 a69dd173 O'Neil Delpratt
2046 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2047
2048 72bf04c6 Norman Walsh
    exampleSimple2(trans, sresult);
2049 a69dd173 O'Neil Delpratt
2050 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2051
2052 72bf04c6 Norman Walsh
    exampleSimple3(processor, trans, sresult);
2053 a69dd173 O'Neil Delpratt
2054 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2055
2056 4ee4355d O'Neil Delpratt
    exampleSimple3aError(processor, trans, sresult);
2057 a69dd173 O'Neil Delpratt
2058 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2059
2060 72bf04c6 Norman Walsh
    testApplyTemplatesString1(trans, sresult);
2061 a69dd173 O'Neil Delpratt
2062 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2063
2064 72bf04c6 Norman Walsh
    testApplyTemplatesString2(processor, trans, sresult);
2065
2066 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2067
2068
2069 4ee4355d O'Neil Delpratt
    testApplyTemplates2a_Error(processor, trans, sresult);
2070 72bf04c6 Norman Walsh
2071 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2072
2073 72bf04c6 Norman Walsh
    testTransformToString4(processor, trans, sresult);
2074 00082f6f O'Neil Delpratt
2075 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2076
2077 9458d238 O'Neil Delpratt
    testCatalog(cwd, processor,  sresult);
2078 146cfacb O'Neil Delpratt
2079 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2080
2081 a69dd173 O'Neil Delpratt
    testTransformToString2b(processor, trans, sresult);
2082 72bf04c6 Norman Walsh
2083 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2084
2085 72bf04c6 Norman Walsh
    testTransformToString3(processor, trans, sresult);
2086 306962bc O'Neil Delpratt
2087
    cout<<endl<<"============================================================="<<endl<<endl;
2088 72bf04c6 Norman Walsh
        
2089
    testTransformFromstring(processor, trans, sresult);
2090
2091 55b80284 O'Neil Delpratt
2092 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2093
2094 a69dd173 O'Neil Delpratt
    testTransformFromstring2Err(processor, trans, sresult);
2095 72bf04c6 Norman Walsh
2096 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2097
2098 501beb26 O'Neil Delpratt
    testTrackingOfValueReference(processor, trans, sresult);
2099 72bf04c6 Norman Walsh
2100 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2101
2102
    testTrackingOfValueReferenceError(processor, trans, sresult);
2103
2104
    cout<<endl<<"============================================================="<<endl<<endl;
2105 72bf04c6 Norman Walsh
2106
    testPackage1(trans, sresult);
2107
2108 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2109
2110 4ee4355d O'Neil Delpratt
    testPackage1a(trans, sresult);
2111
2112 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2113
2114 4ee4355d O'Neil Delpratt
    testPackage2_Error(trans, sresult);
2115 72bf04c6 Norman Walsh
2116 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2117
2118 72bf04c6 Norman Walsh
    testXdmNodeOutput(trans, sresult);
2119
2120 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2121 72bf04c6 Norman Walsh
2122 306962bc O'Neil Delpratt
    exampleParam(processor, trans, sresult);
2123 4ee4355d O'Neil Delpratt
2124 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2125 4ee4355d O'Neil Delpratt
2126 72bf04c6 Norman Walsh
    xmarkTest1(trans, sresult);
2127
2128 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2129 4ee4355d O'Neil Delpratt
2130 306962bc O'Neil Delpratt
    xmarkTest2(trans, sresult);
2131 4ee4355d O'Neil Delpratt
2132 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2133 4ee4355d O'Neil Delpratt
2134 501beb26 O'Neil Delpratt
    testCallFunction(processor, trans, sresult);
2135 4ee4355d O'Neil Delpratt
2136 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2137 4ee4355d O'Neil Delpratt
2138 501beb26 O'Neil Delpratt
    testResolveUri(processor, trans, sresult);
2139 306962bc O'Neil Delpratt
2140
    cout<<endl<<"============================================================="<<endl<<endl;
2141
2142 72bf04c6 Norman Walsh
    testContextNotRoot(processor, trans, sresult);
2143 306962bc O'Neil Delpratt
2144
    cout<<endl<<"============================================================="<<endl<<endl;
2145
2146 501beb26 O'Neil Delpratt
    testContextNotRootNamedTemplate(processor, trans, sresult);
2147 306962bc O'Neil Delpratt
2148
    cout<<endl<<"============================================================="<<endl<<endl;
2149
2150 501beb26 O'Neil Delpratt
    testContextNotRootNamedTemplateValue(processor, trans, sresult);
2151 306962bc O'Neil Delpratt
2152
    cout<<endl<<"============================================================="<<endl<<endl;
2153
2154 55b80284 O'Neil Delpratt
   testPipeline(processor, sresult);
2155 72bf04c6 Norman Walsh
2156 306962bc O'Neil Delpratt
2157
    cout<<endl<<"============================================================="<<endl<<endl;
2158
2159 55b80284 O'Neil Delpratt
    fflush(stdout);
2160
2161 306962bc O'Neil Delpratt
2162 501beb26 O'Neil Delpratt
    //Available in PE and EE
2163
    //testTransformToStringExtensionFunc(processor, trans);
2164 72bf04c6 Norman Walsh
2165 55b80284 O'Neil Delpratt
2166
2167 a69dd173 O'Neil Delpratt
    //processor->release();
2168 55b80284 O'Neil Delpratt
    //return 0;
2169 72bf04c6 Norman Walsh
2170 55b80284 O'Neil Delpratt
    fflush(stdout);
2171 72bf04c6 Norman Walsh
2172
2173 55b80284 O'Neil Delpratt
    //set to the current working directory
2174 70e3c2b3 O'Neil Delpratt
    if(cwd != nullptr) {
2175 55b80284 O'Neil Delpratt
        processor->setcwd(cwd);
2176 70e3c2b3 O'Neil Delpratt
    } else {
2177
        processor->setcwd(buff);
2178
    }
2179 55b80284 O'Neil Delpratt
    Xslt30Processor *trans2 = processor->newXslt30Processor();
2180
    cerr<<" after trans2 cp0"<<endl;
2181 501beb26 O'Neil Delpratt
    testApplyTemplatesString1(trans2, sresult);
2182 306962bc O'Neil Delpratt
    cout<<endl<<"============================================================="<<endl<<endl;
2183
2184
2185
2186 55b80284 O'Neil Delpratt
    //testThreads (processor, trans2, sresult);
2187 306962bc O'Neil Delpratt
2188
2189 55b80284 O'Neil Delpratt
    delete trans;
2190 501beb26 O'Neil Delpratt
    delete trans2;
2191 55b80284 O'Neil Delpratt
    delete processor;
2192 01d6fdb6 O'Neil Delpratt
    processor->release();
2193 55b80284 O'Neil Delpratt
2194 72bf04c6 Norman Walsh
2195 306962bc O'Neil Delpratt
    cout<<endl<<"======================== Test Results ========================"<<endl<<endl;
2196
2197 501beb26 O'Neil Delpratt
    std::cout << "\nTest Results - Number of tests= " << (sresult->success + sresult->failure) << ", Successes = "
2198
              << sresult->success << ",  Failures= " << sresult->failure << std::endl;
2199 72bf04c6 Norman Walsh
2200 501beb26 O'Neil Delpratt
    std::list<std::string>::iterator it;
2201
    std::cout << "Failed tests:" << std::endl;
2202 306962bc O'Neil Delpratt
    // Make iterate point to beginning and increment it one by one until it reaches the end of list.
2203 501beb26 O'Neil Delpratt
    for (it = sresult->failureList.begin(); it != sresult->failureList.end(); it++) {
2204
        //Print the contents
2205
        std::cout << it->c_str() << std::endl;
2206 72bf04c6 Norman Walsh
2207 501beb26 O'Neil Delpratt
    }
2208 72bf04c6 Norman Walsh
2209 55b80284 O'Neil Delpratt
    delete sresult;
2210
2211
#ifdef MEM_DEBUG
2212
    SaxonProcessor::getInfo();
2213
#endif
2214 72bf04c6 Norman Walsh
2215
    return 0;
2216
}