Project

Profile

Help

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

he / src / main / c / samples / cppTests / testXSLT30.cpp @ 55b80284

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 4ee4355d O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromFile("test1.sef");
1141
    executable->setInitialMatchSelectionAsFile("cat.xml");
1142
    const char * output = executable->applyTemplatesReturningString();
1143 9458d238 O'Neil Delpratt
    if (output== nullptr) {
1144 4ee4355d O'Neil Delpratt
        printf("result is null \n");
1145 501beb26 O'Neil Delpratt
        const char *message = trans->getErrorMessage();
1146
        if (message != NULL) {
1147
            cout << "Error message =" << message << endl;
1148
        }
1149 4ee4355d O'Neil Delpratt
        sresult->failure++;
1150
        sresult->failureList.push_back("testPackage1a");
1151 55b80284 O'Neil Delpratt
        trans->exceptionClear();
1152 4ee4355d O'Neil Delpratt
1153 501beb26 O'Neil Delpratt
    } else {
1154
        printf("%s", output);
1155
        printf("result is OK \n");
1156 4ee4355d O'Neil Delpratt
        sresult->success++;
1157 55b80284 O'Neil Delpratt
        delete output;
1158 72bf04c6 Norman Walsh
    }
1159 501beb26 O'Neil Delpratt
    fflush(stdout);
1160 55b80284 O'Neil Delpratt
    delete executable;
1161 72bf04c6 Norman Walsh
}
1162
1163 4ee4355d O'Neil Delpratt
1164
/*
1165
* Test saving and loading a Xslt package
1166
*/
1167
void testPackage2_Error(Xslt30Processor *trans, sResultCount *sresult) {
1168
1169
    cout << endl << "Test: testPackage2_Error:" << endl;
1170
1171
    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>";
1172
1173
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
1174
1175
    if(trans->exceptionOccurred()) {
1176
        const char *message = trans->getErrorMessage();
1177
        if (message != NULL) {
1178
            cout << "Error message =" << message << endl;
1179
        }
1180
        sresult->success++;
1181
        trans->exceptionClear();
1182
        return;
1183
1184
    }
1185
1186
    sresult->failure++;
1187
    sresult->failureList.push_back("testPackage2_Error");
1188
1189
}
1190
1191 501beb26 O'Neil Delpratt
void testCallFunction(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1192
1193
    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>";
1194
    cout << endl << "Test: testCallFunction:" << endl;
1195
    XsltExecutable * executable = trans->compileFromString(source);
1196 4ee4355d O'Neil Delpratt
1197
    if(executable == nullptr) {
1198
        if(trans->exceptionOccurred()) {
1199 306962bc O'Neil Delpratt
            SaxonApiException * exception = trans->getException();
1200
            if(exception != nullptr) {
1201
                cerr << "Error: " << exception->getMessage() << endl;
1202
                delete exception;
1203
            }
1204 4ee4355d O'Neil Delpratt
1205
        }
1206
        sresult->failure++;
1207
        sresult->failureList.push_back("testCallFunction");
1208 306962bc O'Neil Delpratt
        trans->exceptionClear();
1209 4ee4355d O'Neil Delpratt
        return;
1210
1211
1212
    }
1213
1214 501beb26 O'Neil Delpratt
    XdmValue **valueArray = new XdmValue *[2];
1215
1216
    valueArray[0] = (XdmValue *) (proc->makeIntegerValue(2));
1217
    valueArray[1] = (XdmValue *) (proc->makeIntegerValue(3));
1218
    XdmValue *v = executable->callFunctionReturningValue("{http://localhost/}add", valueArray, 2);
1219
1220
    if (v != NULL && (v->getHead())->isAtomic() && ((XdmAtomicValue *) (v->getHead()))->getLongValue() == 5) {
1221
        sresult->success++;
1222 55b80284 O'Neil Delpratt
        delete v;
1223 501beb26 O'Neil Delpratt
    } else {
1224
        if (v != NULL && !(v->getHead())->isAtomic()) {
1225
            cout << "Value in callFunction is not atomic - but expected as atomic value" << endl;
1226
        }
1227
        cout << "testCallFunction ======= FAIL ======" << endl;
1228 4ee4355d O'Neil Delpratt
        if(executable->exceptionOccurred()) {
1229
            SaxonApiException * exception = executable->getException();
1230 306962bc O'Neil Delpratt
            if(exception != nullptr) {
1231
                cerr << "Error: " << exception->getMessage() << endl;
1232
                delete exception;
1233
            }
1234 501beb26 O'Neil Delpratt
        }
1235
        sresult->failure++;
1236
        sresult->failureList.push_back("testCallFunction");
1237 55b80284 O'Neil Delpratt
        executable->exceptionClear();
1238
        delete v;
1239 501beb26 O'Neil Delpratt
    }
1240
    delete valueArray[0];
1241
    delete valueArray[1];
1242 901b6eca O'Neil Delpratt
    delete [] valueArray;
1243 55b80284 O'Neil Delpratt
    delete executable;
1244 501beb26 O'Neil Delpratt
}
1245
1246
void testInitialTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1247
1248
1249
    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>";
1250
    cout << endl << "Test:testInitialTemplate" << endl;
1251
    XsltExecutable * executable = trans->compileFromString(source);
1252 901b6eca O'Neil Delpratt
    if(executable == nullptr) {
1253
        if(trans->exceptionOccurred()) {
1254
            cout << "Error: "<< trans->getErrorMessage() << endl;
1255
        }
1256
        return;
1257
    }
1258 55b80284 O'Neil Delpratt
    XdmNode * node = proc->parseXmlFromString("<e/>");
1259 501beb26 O'Neil Delpratt
1260
    executable->setResultAsRawValue(false);
1261
    std::map<std::string, XdmValue *> parameterValues;
1262 4ee4355d O'Neil Delpratt
1263
    XdmAtomicValue * a1 = proc->makeIntegerValue(12);
1264
    XdmAtomicValue * a2 = proc->makeIntegerValue(5);;
1265
    parameterValues["a"] = a1;
1266
    parameterValues["b"] = a2;
1267 501beb26 O'Neil Delpratt
    executable->setInitialTemplateParameters(parameterValues, false);
1268
    executable->setInitialMatchSelection(node);
1269
    XdmValue *result = executable->applyTemplatesReturningValue();
1270
    if (result != NULL) {
1271
        sresult->success++;
1272
        cout << "Result=" << result->getHead()->getStringValue() << endl;
1273 4ee4355d O'Neil Delpratt
        delete result;
1274 501beb26 O'Neil Delpratt
    } else {
1275
        sresult->failure++;
1276 72bf04c6 Norman Walsh
    }
1277
1278 a69dd173 O'Neil Delpratt
    delete executable;
1279 4ee4355d O'Neil Delpratt
    delete a1;
1280
    delete a2;
1281 55b80284 O'Neil Delpratt
    delete node;
1282
    parameterValues.clear();
1283 72bf04c6 Norman Walsh
}
1284
1285 501beb26 O'Neil Delpratt
void testResolveUri(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1286
    cout << endl << "Test: testResolveUri:" << endl;
1287
1288
    XsltExecutable * executable = trans->compileFromString(
1289
            "<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>");
1290
1291 901b6eca O'Neil Delpratt
    if(executable == nullptr) {
1292
        sresult->failure++;
1293
        sresult->failureList.push_back("testResolveUri");
1294
        if(trans->exceptionOccurred()) {
1295 306962bc O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1296
            if(message != nullptr) {
1297
                cout << "Error: " << trans->getErrorMessage() << endl;
1298
            }
1299 901b6eca O'Neil Delpratt
        }
1300 306962bc O'Neil Delpratt
        trans->exceptionClear();
1301 901b6eca O'Neil Delpratt
        return;
1302
    }
1303 501beb26 O'Neil Delpratt
    XdmValue *value = executable->callTemplateReturningValue("go");
1304
1305
1306 9458d238 O'Neil Delpratt
    if (value== nullptr) {
1307 501beb26 O'Neil Delpratt
1308
        sresult->failure++;
1309
        sresult->failureList.push_back("testResolveUri");
1310
    } else {
1311
1312
        const char *svalue = value->itemAt(0)->getStringValue();
1313
        cout << "testResolveUri = " << svalue << endl;
1314
        sresult->success++;
1315 306962bc O'Neil Delpratt
        delete value;
1316 501beb26 O'Neil Delpratt
    }
1317
1318 55b80284 O'Neil Delpratt
    delete executable;
1319 72bf04c6 Norman Walsh
}
1320
1321 501beb26 O'Neil Delpratt
void testContextNotRoot(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1322
    cout << endl << "Test: testContextNotRoot" << endl;
1323 72bf04c6 Norman Walsh
1324 501beb26 O'Neil Delpratt
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1325 72bf04c6 Norman Walsh
1326 306962bc O'Neil Delpratt
    XsltExecutable *executable = trans->compileFromString(
1327 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>");
1328 901b6eca O'Neil Delpratt
1329 306962bc O'Neil Delpratt
    if (executable == nullptr) {
1330 901b6eca O'Neil Delpratt
        sresult->failure++;
1331
        sresult->failureList.push_back("testContextNotRoot");
1332 306962bc O'Neil Delpratt
        if (trans->exceptionOccurred()) {
1333
            cout << "Error: " << trans->getErrorMessage() << endl;
1334 901b6eca O'Neil Delpratt
        }
1335
        return;
1336
    }
1337
1338 501beb26 O'Neil Delpratt
    executable->setGlobalContextItem(node);
1339
    if (node->getChildCount() > 0) {
1340 306962bc O'Neil Delpratt
        XdmNode **eNodeL1 = node->getChildren();
1341
        if (eNodeL1 != nullptr) {
1342
            XdmNode ** eNodeChildren = eNodeL1[0]->getChildren();
1343
            if (eNodeChildren != nullptr) {
1344
                XdmNode *eNode = eNodeChildren[0];
1345
                cout << "Node content = " << eNode->toString() << endl;
1346
                executable->setInitialMatchSelection(eNode);
1347
                const char *result = executable->applyTemplatesReturningString();
1348 72bf04c6 Norman Walsh
1349 306962bc O'Neil Delpratt
                if (result == nullptr) {
1350 72bf04c6 Norman Walsh
1351 55b80284 O'Neil Delpratt
                    cout << "testContextNotRoot ======= FAIL ======" << endl;
1352 306962bc O'Neil Delpratt
                    if (executable->exceptionOccurred()) {
1353
                        SaxonApiException *exception = executable->getException();
1354
                        cerr << "Error: " << exception->getMessage() << endl;
1355
                        delete exception;
1356
                    }
1357
                    sresult->failure++;
1358
                    sresult->failureList.push_back("testContextNotRoot");
1359 72bf04c6 Norman Walsh
1360 306962bc O'Neil Delpratt
1361
                } else {
1362
1363
                    cout << "testContextNotRoot = " << result << endl;
1364
                    sresult->success++;
1365
                    delete result;
1366
1367
                }
1368
1369
            }
1370 501beb26 O'Neil Delpratt
        }
1371 306962bc O'Neil Delpratt
    } else {
1372
        sresult->failure++;
1373
        sresult->failureList.push_back("testContextNotRoot");
1374 501beb26 O'Neil Delpratt
    }
1375 306962bc O'Neil Delpratt
1376
    delete executable;
1377
    delete node;
1378 501beb26 O'Neil Delpratt
}
1379 72bf04c6 Norman Walsh
1380 501beb26 O'Neil Delpratt
1381
void testContextNotRootNamedTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1382
    cout << endl << "Test: testContextNotRootNamedTemplate" << endl;
1383
1384
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1385
1386 55b80284 O'Neil Delpratt
    if(node == nullptr) {
1387
        if(proc->exceptionOccurred()) {
1388
            const char * message = proc->getErrorMessage();
1389
            if(message != nullptr) {
1390
                cerr << "Error: " << message << endl;
1391
            }
1392
            proc->exceptionClear();
1393
        }
1394
        sresult->failure++;
1395
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1396
        return;
1397
    }
1398
1399 501beb26 O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromString(
1400
            "<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>");
1401 901b6eca O'Neil Delpratt
1402
    if(executable == nullptr) {
1403
        sresult->failure++;
1404
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1405
        if(trans->exceptionOccurred()) {
1406
            cout << "Error: "<< trans->getErrorMessage() << endl;
1407
        }
1408 55b80284 O'Neil Delpratt
        delete node;
1409 901b6eca O'Neil Delpratt
        return;
1410
    }
1411
1412 501beb26 O'Neil Delpratt
    executable->setGlobalContextItem(node);
1413
    const char *result = executable->callTemplateReturningString("main");
1414
1415 9458d238 O'Neil Delpratt
    if (result== nullptr) {
1416 501beb26 O'Neil Delpratt
1417 55b80284 O'Neil Delpratt
        cout << "testContextNotRootNameTemplate ======= FAIL ======" << endl;
1418 4ee4355d O'Neil Delpratt
        if(executable->exceptionOccurred()) {
1419
            SaxonApiException * exception = executable->getException();
1420
            cerr<<"Error: " << exception->getMessage() <<endl;
1421
            delete exception;
1422 501beb26 O'Neil Delpratt
        }
1423
        sresult->failure++;
1424
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1425
    } else {
1426
1427
        cout << "testContextNotRoot = " << result << endl;
1428
        sresult->success++;
1429 55b80284 O'Neil Delpratt
        delete result;
1430 501beb26 O'Neil Delpratt
    }
1431 55b80284 O'Neil Delpratt
    delete node;
1432
    delete executable;
1433 72bf04c6 Norman Walsh
1434
}
1435
1436 501beb26 O'Neil Delpratt
1437
void testContextNotRootNamedTemplateValue(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1438
    cout << endl << "Test: testContextNotRootNamedTemplateValue" << endl;
1439
1440
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1441
1442 55b80284 O'Neil Delpratt
    if(node == nullptr) {
1443
        if(proc->exceptionOccurred()) {
1444
            const char * message = proc->getErrorMessage();
1445
            if(message != nullptr) {
1446
                cerr << "Error: " << message << endl;
1447
            }
1448
            proc->exceptionClear();
1449
        }
1450
        sresult->failure++;
1451
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
1452
        return;
1453
    }
1454
1455 501beb26 O'Neil Delpratt
    XsltExecutable * executable = trans->compileFromString(
1456
            "<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>");
1457 901b6eca O'Neil Delpratt
1458
    if(executable == nullptr) {
1459
        sresult->failure++;
1460
        sresult->failureList.push_back("testContentNotRootNamedTemplateValue");
1461
        if(trans->exceptionOccurred()) {
1462
            cout << "Error: "<< trans->getErrorMessage() << endl;
1463
        }
1464 55b80284 O'Neil Delpratt
        delete node;
1465 901b6eca O'Neil Delpratt
        return;
1466
    }
1467
1468 501beb26 O'Neil Delpratt
    executable->setGlobalContextItem(node);
1469
    XdmValue *result = executable->callTemplateReturningValue("main");
1470
1471 55b80284 O'Neil Delpratt
    if (result == nullptr) {
1472 501beb26 O'Neil Delpratt
1473
        cout << "testCallFunction ======= FAIL ======" << endl;
1474 4ee4355d O'Neil Delpratt
        if(executable->exceptionOccurred()) {
1475
            SaxonApiException * exception = executable->getException();
1476
            cerr<<"Error: " << exception->getMessage() <<endl;
1477
            delete exception;
1478 501beb26 O'Neil Delpratt
        }
1479
        sresult->failure++;
1480
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
1481
    } else {
1482
1483
        cout << "testContextNotRoot = " << result->getHead()->getStringValue() << endl;
1484
        sresult->success++;
1485 55b80284 O'Neil Delpratt
        delete result;
1486
        result = nullptr;
1487 72bf04c6 Norman Walsh
    }
1488
1489 55b80284 O'Neil Delpratt
    delete node;
1490
    delete executable;
1491
1492
1493 501beb26 O'Neil Delpratt
}
1494 72bf04c6 Norman Walsh
1495 501beb26 O'Neil Delpratt
void testCallSystemFunction(SaxonProcessor *proc, sResultCount *sresult) {
1496 72bf04c6 Norman Walsh
1497 501beb26 O'Neil Delpratt
    XdmFunctionItem *fi = XdmFunctionItem::getSystemFunction(proc, "{http://www.w3.org/2005/xpath-functions}parse-json",
1498
                                                            1);
1499 9458d238 O'Neil Delpratt
    if (fi== nullptr) {
1500 501beb26 O'Neil Delpratt
        sresult->failure++;
1501
        sresult->failureList.push_back("testCallSystemFunction");
1502
        return;
1503
    }
1504
1505
    XdmValue ** xdmValue = new XdmValue*[1];
1506
    xdmValue[0] = new XdmValue();
1507
    xdmValue[0]->addXdmItem(proc->makeStringValue("[1,2,3]"));
1508
    XdmValue *result = fi->call(xdmValue, 1);
1509
1510
    std::cerr << "Result = " << result->toString() << endl;
1511
    if(result->size() == 3) {
1512
1513
        cout << "testCallSystemFunction = " << result->getHead()->getStringValue() << endl;
1514
        sresult->success++;
1515
1516
    } else {
1517
        sresult->failure++;
1518
        sresult->failureList.push_back("testCallSystemFunction");
1519 72bf04c6 Norman Walsh
1520
    }
1521
1522 501beb26 O'Neil Delpratt
}
1523
1524
1525
void testPipeline(SaxonProcessor *proc, sResultCount *sresult) {
1526
    cout << endl << "Test: testPipeline" << endl;
1527 72bf04c6 Norman Walsh
1528 501beb26 O'Neil Delpratt
    Xslt30Processor * trans = proc->newXslt30Processor();
1529 55b80284 O'Neil Delpratt
    if(trans == nullptr) {
1530
        cout << "Error: Xslt30Processor is null - maybe unclean state of JNI" << endl;
1531
        sresult->failure++;
1532
        sresult->failureList.push_back("testPipeline");
1533
        return;
1534
    }
1535 501beb26 O'Neil Delpratt
    XsltExecutable * stage1 = trans->compileFromString(
1536
            "<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>");
1537 901b6eca O'Neil Delpratt
1538
    if(stage1 == nullptr) {
1539
        sresult->failure++;
1540
        sresult->failureList.push_back("testPipeline");
1541
        if(trans->exceptionOccurred()) {
1542 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1543
            cout << "stage 1 Error: " << message << endl;
1544
1545 901b6eca O'Neil Delpratt
        }
1546 55b80284 O'Neil Delpratt
        cout << "Stage 1 Error - exit method " << endl;
1547
        delete trans;
1548 901b6eca O'Neil Delpratt
        return;
1549
    }
1550
1551 501beb26 O'Neil Delpratt
    XdmNode *inn = proc->parseXmlFromString("<z/>");
1552 72bf04c6 Norman Walsh
1553 501beb26 O'Neil Delpratt
    XsltExecutable *stage2 = trans->compileFromString(
1554
            "<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>");
1555
1556 901b6eca O'Neil Delpratt
    if(stage2 == nullptr) {
1557
        sresult->failure++;
1558
        sresult->failureList.push_back("testPipeline");
1559
        if(trans->exceptionOccurred()) {
1560 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1561
            cout << "stage 2 Error: " << message << endl;
1562
1563 901b6eca O'Neil Delpratt
        }
1564 55b80284 O'Neil Delpratt
        cout << "Stage 2 Error - exit method " << endl;
1565
        delete stage1;
1566
        delete trans;
1567
        delete inn;
1568 901b6eca O'Neil Delpratt
        return;
1569
    }
1570 55b80284 O'Neil Delpratt
1571
1572 501beb26 O'Neil Delpratt
    XsltExecutable *stage3 = trans->compileFromString(
1573
            "<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>");
1574
1575 901b6eca O'Neil Delpratt
    if(stage3 == nullptr) {
1576
        sresult->failure++;
1577
        sresult->failureList.push_back("testPipeline");
1578
        if(trans->exceptionOccurred()) {
1579 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1580
            cout << "stage 3 Error: " << message << endl;
1581
1582
        } else {
1583
            cout << "Stage 3 Error: testPipeline failed with exception" << endl;
1584 901b6eca O'Neil Delpratt
        }
1585 55b80284 O'Neil Delpratt
        cout << "Stage 3 Error - exit method " << endl;
1586
        delete stage1;
1587
        delete stage2;
1588
        delete trans;
1589
        delete inn;
1590 901b6eca O'Neil Delpratt
        return;
1591
    }
1592 55b80284 O'Neil Delpratt
1593 501beb26 O'Neil Delpratt
    XsltExecutable *stage4 = trans->compileFromString(
1594
            "<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>");
1595
1596 55b80284 O'Neil Delpratt
    if(stage4 == nullptr) {
1597 901b6eca O'Neil Delpratt
        sresult->failure++;
1598
        sresult->failureList.push_back("testPipeline");
1599
        if(trans->exceptionOccurred()) {
1600 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1601
            cout << "stage 4 Error: " << message << endl;
1602
1603
        } else {
1604
            cout << "Stage 4 Error: testPipeline failed with exception" << endl;
1605
        }
1606
        cout << "Stage 4 Error - exit method " << endl;
1607
        delete stage1;
1608
        delete stage2;
1609
        delete stage3;
1610
        delete trans;
1611
        delete inn;
1612 901b6eca O'Neil Delpratt
        return;
1613
    }
1614
1615 501beb26 O'Neil Delpratt
    XsltExecutable *stage5 = trans->compileFromString(
1616
            "<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>");
1617
1618 901b6eca O'Neil Delpratt
    if(stage5 == nullptr) {
1619 501beb26 O'Neil Delpratt
        sresult->failure++;
1620
        sresult->failureList.push_back("testPipeline");
1621 901b6eca O'Neil Delpratt
        if(trans->exceptionOccurred()) {
1622 55b80284 O'Neil Delpratt
            const char * message = trans->getErrorMessage();
1623
            cout << "stage 5 Error: " << message << endl;
1624
1625
        } else {
1626
            cout << "Stage 5 Error: testPipeline failed with exception" << endl;
1627
        }
1628
        cout << "Stage 5     Error - exit method " << endl;
1629
        delete stage1;
1630
        delete stage2;
1631
        delete stage3;
1632
        delete stage4;
1633
        delete trans;
1634
        delete inn;
1635 501beb26 O'Neil Delpratt
        return;
1636 72bf04c6 Norman Walsh
    }
1637
1638 501beb26 O'Neil Delpratt
    stage1->setProperty("!indent", "no");
1639
    stage1->setInitialMatchSelection(inn);
1640 72bf04c6 Norman Walsh
1641 501beb26 O'Neil Delpratt
    XdmValue *d1 = stage1->applyTemplatesReturningValue();
1642 55b80284 O'Neil Delpratt
    if(d1 == nullptr) {
1643
        if (stage1->exceptionOccurred()) {
1644
            sresult->failure++;
1645
            sresult->failureList.push_back("testPipeline");
1646
            if (stage1->exceptionOccurred()) {
1647
                SaxonApiException *exception = stage1->getException();
1648
                if (exception != nullptr) {
1649
                    cerr << "Error: " << exception->getMessage() << endl;
1650
                    delete exception;
1651
                    exception = nullptr;
1652
                }
1653
            }
1654
            cout << "Stage d1 Error - exit method " << endl;
1655
            delete stage1;
1656
            delete stage2;
1657
            delete stage3;
1658
            delete stage4;
1659
            delete stage5;
1660
            delete trans;
1661
            delete inn;
1662
            return;
1663 4ee4355d O'Neil Delpratt
        }
1664 501beb26 O'Neil Delpratt
    }
1665
1666
    XdmItem *d11 = d1->getHead();
1667 9458d238 O'Neil Delpratt
    if (d11== nullptr) {
1668 72bf04c6 Norman Walsh
1669 501beb26 O'Neil Delpratt
        cout << "d11 is NULL\n" << endl;
1670 55b80284 O'Neil Delpratt
        sresult->failure++;
1671
        sresult->failureList.push_back("testPipeline-1");
1672
        delete stage1;
1673
        delete stage2;
1674
        delete stage3;
1675
        delete stage4;
1676
        delete stage5;
1677
        delete d1;
1678
        delete inn;
1679
        delete trans;
1680
        return;
1681 501beb26 O'Neil Delpratt
    }
1682 55b80284 O'Neil Delpratt
    const char *data = d11->toString();
1683 501beb26 O'Neil Delpratt
1684
    if (data != NULL) {
1685
        cout << "d1 result=" << data << endl;
1686
    } else {
1687 72bf04c6 Norman Walsh
1688 55b80284 O'Neil Delpratt
        cout << "d1 result Error - toString is NULL" << endl;
1689
        delete stage1;
1690
        delete stage2;
1691
        delete stage3;
1692
        delete stage4;
1693
        delete stage5;
1694
        delete d1;
1695
        delete inn;
1696
        delete trans;
1697 501beb26 O'Neil Delpratt
        return;
1698
    }
1699
    stage2->setProperty("!indent", "no");
1700 55b80284 O'Neil Delpratt
    stage2->setInitialMatchSelection(d11);
1701 501beb26 O'Neil Delpratt
    XdmValue *d2 = stage2->applyTemplatesReturningValue();
1702 9458d238 O'Neil Delpratt
    if (d2== nullptr) {
1703 501beb26 O'Neil Delpratt
        cout << "ERROR-11\n" << endl;
1704
        sresult->failure++;
1705
        sresult->failureList.push_back("testPipeline-2");
1706 55b80284 O'Neil Delpratt
        if (stage2->exceptionOccurred()) {
1707
            SaxonApiException *exception = stage2->getException();
1708
            if (exception != nullptr) {
1709
                cerr << "Error: " << exception->getMessage() << endl;
1710
                delete exception;
1711
                exception = nullptr;
1712
            }
1713
        }
1714
        cout << "Stage d2 Error - exit method " << endl;
1715
        delete d1;
1716
        delete inn;
1717
        delete stage1;
1718
        delete stage2;
1719
        delete stage3;
1720
        delete stage4;
1721
        delete stage5;
1722
        delete trans;
1723 501beb26 O'Neil Delpratt
        return;
1724
    }
1725
    stage3->setProperty("!indent", "no");
1726
    stage3->setInitialMatchSelection(d2);
1727
    XdmValue * d3 = stage3->applyTemplatesReturningValue();
1728
    if(d3 == nullptr){
1729
        sresult->failure++;
1730
        sresult->failureList.push_back("testPipeline-3");
1731 55b80284 O'Neil Delpratt
        if (stage3->exceptionOccurred()) {
1732
            SaxonApiException *exception = stage3->getException();
1733
            if (exception != nullptr) {
1734
                cerr << "Error: " << exception->getMessage() << endl;
1735
                delete exception;
1736
                exception = nullptr;
1737
            }
1738 901b6eca O'Neil Delpratt
        }
1739 55b80284 O'Neil Delpratt
        cout << "Stage d3 Error - exit method " << endl;
1740
        delete d1;
1741
        delete d2;
1742
        delete inn;
1743
1744
        delete stage1;
1745
        delete stage2;
1746
        delete stage3;
1747
        delete stage4;
1748
        delete stage5;
1749
        delete trans;
1750
        return;
1751 501beb26 O'Neil Delpratt
      }
1752
    stage4->setProperty("!indent", "no");
1753
    stage4->setInitialMatchSelection(d3);
1754
    XdmValue * d4 = stage4->applyTemplatesReturningValue();
1755 55b80284 O'Neil Delpratt
    if(d4== nullptr){
1756 501beb26 O'Neil Delpratt
        sresult->failure++;
1757 55b80284 O'Neil Delpratt
        sresult->failureList.push_back("testPipeline-4");
1758
        if (stage4->exceptionOccurred()) {
1759
            SaxonApiException *exception = stage4->getException();
1760
            if (exception != nullptr) {
1761
                cerr << "Error: " << exception->getMessage() << endl;
1762
                delete exception;
1763
                exception = nullptr;
1764
            }
1765 901b6eca O'Neil Delpratt
        }
1766 55b80284 O'Neil Delpratt
        cout << "Stage d4 Error - exit method " << endl;
1767
        delete d3;
1768
        delete d2;
1769
        delete d1;
1770
        delete inn;
1771
        delete stage1;
1772
        delete stage2;
1773
        delete stage3;
1774
        delete stage4;
1775
        delete stage5;
1776
        delete trans;
1777 501beb26 O'Neil Delpratt
        return;
1778
      }
1779
    stage5->setProperty("!indent", "no");
1780
    stage5->setInitialMatchSelection(d4);
1781
    const char * sw = stage5->applyTemplatesReturningString();
1782 55b80284 O'Neil Delpratt
    if(sw == nullptr){
1783 501beb26 O'Neil Delpratt
        sresult->failure++;
1784 55b80284 O'Neil Delpratt
        sresult->failureList.push_back("testPipeline-5");
1785
        if (stage5->exceptionOccurred()) {
1786
            SaxonApiException *exception = stage5->getException();
1787
            if (exception != nullptr) {
1788
                cerr << "Error: " << exception->getMessage() << endl;
1789
                delete exception;
1790
            }
1791 901b6eca O'Neil Delpratt
        }
1792 55b80284 O'Neil Delpratt
        cout << "Stage sw Error - exit method " << endl;
1793
        delete stage1;
1794
        delete stage2;
1795
        delete stage3;
1796
        delete stage4;
1797
        delete stage5;
1798
        delete trans;
1799
        delete d4;
1800
        delete d3;
1801
        delete d2;
1802
        delete d1;
1803
        delete inn;
1804 501beb26 O'Neil Delpratt
        return;
1805
      }
1806
    cout<<sw<<endl;
1807
    cout << "testPipeline = " << sw << endl;
1808
    sresult->success++;
1809 55b80284 O'Neil Delpratt
    delete stage1;
1810
    stage1 = nullptr;
1811
1812
    delete stage2;
1813
    stage2 = nullptr;
1814
1815
1816
    delete stage3;
1817
    stage3 = nullptr;
1818
1819
    delete stage4;
1820
    stage4 = nullptr;
1821
1822
    delete stage5;
1823
    stage5 = nullptr;
1824
1825
    delete trans;
1826
    trans = nullptr;
1827
1828
    delete sw;
1829
    sw = nullptr;
1830 501beb26 O'Neil Delpratt
1831 55b80284 O'Neil Delpratt
    delete d4;
1832
    d4 = nullptr;
1833
1834
    delete d3;
1835
    d3 = nullptr;
1836
1837
    delete d2;
1838
    d2 = nullptr;
1839
1840
    delete d1;
1841
    d1 = nullptr;
1842
1843
    delete inn;
1844
    inn = nullptr;
1845 501beb26 O'Neil Delpratt
1846
}
1847
1848 72bf04c6 Norman Walsh
1849 9458d238 O'Neil Delpratt
void testCatalog(const char * cwd, SaxonProcessor * proc, sResultCount *sresult) {
1850 72bf04c6 Norman Walsh
1851 00082f6f O'Neil Delpratt
1852 d0e6f8be O'Neil Delpratt
    cout << endl << "Test: testCatalog" << endl;
1853 9458d238 O'Neil Delpratt
    bool trace = false;
1854
    proc->setcwd(cwd);
1855 501beb26 O'Neil Delpratt
    proc->setCatalog("../php/catalog-test/catalog.xml", trace);
1856
1857 9458d238 O'Neil Delpratt
    Xslt30Processor * trans = proc->newXslt30Processor();
1858
1859 501beb26 O'Neil Delpratt
    XsltExecutable  * executable = trans->compileFromFile("../php/catalog-test/test1.xsl");
1860 901b6eca O'Neil Delpratt
1861
    if(executable == nullptr) {
1862 00082f6f O'Neil Delpratt
1863 901b6eca O'Neil Delpratt
        if (trans->exceptionOccurred()) {
1864 00082f6f O'Neil Delpratt
1865
            if(trans->getErrorMessage() != nullptr) {
1866
                const char *message = trans->getErrorMessage();
1867 4ee4355d O'Neil Delpratt
                cerr << "exception=" << message << endl;
1868 00082f6f O'Neil Delpratt
            } else {
1869
                const char *message = proc->getErrorMessage();
1870
                if(message != nullptr) {
1871 4ee4355d O'Neil Delpratt
                    cerr << "exception-proc=" << message << endl;
1872 00082f6f O'Neil Delpratt
                }
1873
            }
1874 4ee4355d O'Neil Delpratt
        }
1875
        sresult->failure++;
1876
        sresult->failureList.push_back("testCatalog");
1877
        trans->exceptionClear();
1878 55b80284 O'Neil Delpratt
        delete trans;
1879
        trans= nullptr;
1880 d0e6f8be O'Neil Delpratt
        return;
1881 901b6eca O'Neil Delpratt
    }
1882 a69dd173 O'Neil Delpratt
1883 501beb26 O'Neil Delpratt
    executable->setInitialMatchSelectionAsFile("../php/catalog-test/example.xml");
1884 4ee4355d O'Neil Delpratt
1885 501beb26 O'Neil Delpratt
    const char *result = executable->applyTemplatesReturningString();
1886
1887
    if(result != NULL) {
1888
        std::cerr << "testCatalog result= " << result << std::endl;
1889 55b80284 O'Neil Delpratt
        delete result;
1890
        sresult->success++; // TODO - check the results more carefully
1891
    } else {
1892
        sresult->failure++;
1893
        sresult->failureList.push_back("testCatalog");
1894 501beb26 O'Neil Delpratt
    }
1895 55b80284 O'Neil Delpratt
1896 4ee4355d O'Neil Delpratt
1897
    delete executable;
1898 55b80284 O'Neil Delpratt
    executable = nullptr;
1899
    delete trans;
1900
    trans = nullptr;
1901 501beb26 O'Neil Delpratt
1902
}
1903 72bf04c6 Norman Walsh
1904 306962bc O'Neil Delpratt
static int NUM_THREADS = 10;
1905 72bf04c6 Norman Walsh
1906 306962bc O'Neil Delpratt
void RunThread(XsltExecutable * executable, int tid, const std::string filename) {
1907 55b80284 O'Neil Delpratt
    JavaVMAttachArgs att_arg;
1908
    att_arg.version = JNI_VERSION_1_2;
1909
    att_arg.name = NULL;
1910
    att_arg.group = NULL;
1911
1912
   // SaxonProcessor::sxn_environ->jvm->AttachCurrentThread((void**)&SaxonProcessor::sxn_environ->env, &att_arg);
1913
    cerr<<endl<<"RunThread cp0,  THEAD ID="<<tid<<endl;
1914
    fflush(stderr);
1915
    fflush(stdout);
1916 72bf04c6 Norman Walsh
1917 55b80284 O'Neil Delpratt
    if(executable != nullptr) {
1918
       executable->setInitialMatchSelectionAsFile(filename.c_str());
1919 501beb26 O'Neil Delpratt
1920 55b80284 O'Neil Delpratt
        cerr << "RunThread cp1" << endl;
1921 306962bc O'Neil Delpratt
1922 55b80284 O'Neil Delpratt
       const char *result = nullptr;
1923
        result = executable->applyTemplatesReturningString();
1924
        if (result != nullptr) {
1925
            cout << " Result from THREAD ID: " << tid << ", " << result << endl;
1926
            delete result;
1927
        } else {
1928
            cerr << " ===== Failed in THREAD ID: " << tid << endl;
1929
           /* if(executable->exceptionOccurred()) {
1930
                SaxonApiException *exception = executable->getException();
1931

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