Project

Profile

Help

How to connect?
Download (65.5 KB) Statistics
| Branch: | Revision:

he / src / main / c / samples / cppTests / testXSLT30.cpp @ 70e3c2b3

1
#include <sstream>
2
#include <stdio.h>
3
#include "../../Saxon.C.API/SaxonProcessor.h"
4
#include "../../Saxon.C.API/XdmValue.h"
5
#include "../../Saxon.C.API/XdmItem.h"
6
#include "../../Saxon.C.API/XdmNode.h"
7
#include "../../Saxon.C.API/XdmFunctionItem.h"
8
#include "cppExtensionFunction.h"
9
#include "CppTestUtils.h"
10
#include <string>
11
#include <thread>
12

    
13

    
14

    
15
using namespace std;
16
char fname[] = "_nativeCall";
17
char funcParameters[] = "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;";
18

    
19
JNINativeMethod cppMethods[] =
20
        {
21
                {
22
                        fname,
23
                        funcParameters,
24
                        (void *) &cppExtensionFunction::cppNativeCall
25
                }
26
        };
27

    
28

    
29
/*
30
* Test transform to String. Source and stylesheet supplied as arguments
31
*/
32
void testApplyTemplatesString1(Xslt30Processor *trans, sResultCount *sresult) {
33

    
34
    cout << "Test: testApplyTemplatesString1:" << endl;
35
//    trans->setupXslMessage(false);
36

    
37
    XsltExecutable *executable = trans->compileFromFile("test.xsl");
38

    
39
    if(executable== nullptr) {
40
        sresult->failure++;
41
        sresult->failureList.push_back("testApplyTemplatesString1");
42
        cerr << "testApplyTemplatesString1 NULL found" << endl;
43
        if (trans->exceptionOccurred()) {
44
            cerr <<"testApplyTemplatesString1 error: "<< trans->getErrorMessage() << endl;
45
        }
46
        return;
47
    }
48
    executable->setInitialMatchSelectionAsFile("cat.xml");
49

    
50
    const char *output = executable->applyTemplatesReturningString();
51
    if (output == nullptr) {
52
        printf("result is null ====== FAIL ====== \n");
53
        sresult->failure++;
54
        fflush(stdout);
55
        sresult->failureList.push_back("testApplyTemplatesString1-0");
56
    } else if (string(output).find(string("<out>text2</out>")) != std::string::npos) {
57
        printf("%s", output);
58
        printf("result is OK \n");
59
        sresult->success++;
60
        delete output;
61
    } else {
62
        printf("result is null ====== FAIL ====== \n");
63
        sresult->failure++;
64
        sresult->failureList.push_back("testApplyTemplatesString1-1");
65
            std::cout<<"output="<<output<<std::endl;
66
        delete output;
67
    }
68
    fflush(stdout);
69
    delete executable;
70

    
71
}
72

    
73
/*
74
* Test transform to String. Source and stylesheet supplied as arguments
75
*/
76
void testTransformToStringExtensionFunc(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
77

    
78
    cout << endl << "Test: TransformToStringExtensionFunc:" << endl;
79
    bool nativeFound = processor->registerNativeMethods(SaxonProcessor::sxn_environ->env,
80
                                                        "com/saxonica/functions/extfn/cpp/NativeCall",
81
                                                        cppMethods, sizeof(cppMethods) / sizeof(cppMethods[0]));
82

    
83
    XsltExecutable * executable = trans->compileFromFile("testExtension.xsl");
84

    
85
    if(executable== nullptr) {
86
        sresult->failure++;
87
        sresult->failureList.push_back("TransformToStringExtensionFunc");
88
        cerr << "TransformToStringExtensionFunc NULL found" << endl;
89
        if (trans->exceptionOccurred()) {
90
            cerr <<"TransformToStringExtensionFunc error: "<< trans->getErrorMessage() << endl;
91
        }
92
        return;
93
    }
94

    
95
    executable->setProperty("extc", "home/ond1/work/svn/latest9.9-saxonc/samples/cppTests/cppExtensionFunction");
96

    
97
    if (nativeFound) {
98
        const char *output = executable->transformFileToString("cat.xml");
99

    
100
        if (output == nullptr) {
101
            SaxonProcessor::sxn_environ->env->ExceptionDescribe();
102
            printf("result is null ====== FAIL ======  \n");
103
            sresult->failure++;
104
            sresult->failureList.push_back("testTransformToStringExnteionFunc");
105
        } else {
106
            sresult->success++;
107
            printf("result is OK \n");
108
        }
109
        fflush(stdout);
110
        delete output;
111
    } else {
112
        printf("native Class not foun ====== FAIL ====== ");
113
        sresult->failure++;
114
        sresult->failureList.push_back("testTransformToStringExtensionFunc");
115
    }
116
    delete executable;
117
}
118

    
119

    
120
/*
121
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
122
*/
123
void testApplyTemplatesString2(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
124

    
125
    cout << "Test: testApplyTemplatesString2:" << endl;
126

    
127

    
128
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
129

    
130
    if (input== nullptr) {
131
        cout << "Source document is null." << endl;
132
        if(processor->exceptionOccurred()) {
133
            cerr<<processor->getErrorMessage()<<endl;
134
        }
135
        sresult->failure++;
136
        sresult->failureList.push_back("testApplyTemplatesString2");
137
        return;
138

    
139
    }
140
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
141
    if(executable == nullptr) {
142
        sresult->failure++;
143
        sresult->failureList.push_back("testApplyTemplatesString2");
144
        if (trans->exceptionOccurred()) {
145
            cerr <<"testApplyTemplatesString2 error: "<< trans->getErrorMessage() << endl;
146
        }
147
        delete input;
148
        return;
149
    }
150

    
151
    executable->setInitialMatchSelection((XdmValue *) input);
152

    
153
    const char *output = executable->applyTemplatesReturningString();
154
    if (output== nullptr) {
155
        printf("result is null ====== FAIL ======  \n");
156
        sresult->failureList.push_back("testApplyTemplatesString2");
157
        sresult->failure++;
158
    } else {
159
        sresult->success++;
160
        printf("%s", output);
161
        printf("result is OK \n");
162
        delete output;
163
    }
164
    fflush(stdout);
165
    delete input;
166
    delete executable;
167
}
168

    
169
/*
170
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
171
Should be error. Stylesheet file does not exist
172
*/
173
void testApplyTemplates2a_Error(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
174

    
175
    cout << "Test: TransformToString2a_Error:" << endl;
176

    
177
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
178

    
179
    if (input == nullptr) {
180
        cout << "Source document is null. ====== FAIL ======" << endl;
181
        if(processor->exceptionOccurred()) {
182
            cerr<<processor->getErrorMessage()<<endl;
183
        }
184
        sresult->failure++;
185
        sresult->failureList.push_back("testApplyTemplates2a_Error");
186
        trans->exceptionClear();
187
        return;
188
    }
189
    XsltExecutable * executable = trans->compileFromFile("test-error.xsl");
190

    
191
    if(executable== nullptr) {
192
        printf("Expected result is null \n");
193
        sresult->success++;
194

    
195
        if (trans->exceptionOccurred()) {
196
            cerr <<"testApplyTemplates2a_Error error: "<< trans->getErrorMessage() << endl;
197
        }
198
        delete input;
199
        trans->exceptionClear();
200
        return;
201
    }
202

    
203
    sresult->failure++;
204
    sresult->failureList.push_back("testApplyTemplates2a_Error");
205
    fflush(stdout);
206

    
207
    delete executable;
208

    
209
}
210

    
211
/*
212
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
213
Should be error. Source file does not exist
214
*/
215
void testTransformToString2b(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
216

    
217
    cout << endl << "Test: TransformToString2b:" << endl;
218

    
219
    const char * result  = trans->transformFileToString("cat-error.xml", "test-error.xsl");
220

    
221
    if(result== nullptr) {
222
        if(trans->exceptionOccurred()) {
223
            cerr<<"Expected failure = "<<trans->getErrorMessage()<<endl;
224
        }
225
        sresult->success++;
226
        trans->exceptionClear();
227
        return;
228
    }else {
229
        delete result;
230
        sresult->failure++;
231
        sresult->failureList.push_back("testTransformToString2b");
232
        cerr << "testTransformToString2b NULL found" << endl;
233
        if (trans->exceptionOccurred()) {
234
            cerr <<"Error: "<< trans->getErrorMessage() << endl;
235
        }
236
        trans->exceptionClear();
237
        return;
238
    }
239

    
240

    
241
}
242

    
243

    
244
/*
245
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
246
and integer parmater created and supplied
247
*/
248
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
249

    
250
    cout << endl << "Test: TransformToString3" << endl;
251

    
252
    XdmNode *inputi = processor->parseXmlFromString(
253
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
254

    
255
    if (inputi== nullptr) {
256
        cout << "Source document inputi is null." << endl;
257
        if (trans->exceptionOccurred()) {
258
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
259
        }
260
        sresult->failure++;
261
        sresult->failureList.push_back("testTransformToString3");
262

    
263
        return;
264
    }
265

    
266
    XdmAtomicValue *value1 = processor->makeIntegerValue(10);
267

    
268
    if (value1== nullptr) {
269
        cout << "value1 is null." << endl;
270
        if (trans->exceptionOccurred()) {
271
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
272
        }
273
        sresult->failure++;
274
        sresult->failureList.push_back("testTransformToString3");
275
        delete inputi;
276
        return;
277
    }
278

    
279
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
280

    
281
    if(executable== nullptr) {
282
        sresult->failure++;
283
        sresult->failureList.push_back("testTransformToString3");
284
        cerr << "testTransformToString3 NULL found" << endl;
285
        if (trans->exceptionOccurred()) {
286
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
287
        }
288
        delete value1;
289
        return;
290
    }
291

    
292

    
293
    executable->setParameter("numParam", (XdmValue *) value1);
294

    
295
    executable->setInitialMatchSelection((XdmNode *) inputi);
296
    const char *output = executable->applyTemplatesReturningString();
297
    if (output == nullptr) {
298
        printf("result is null ====== FAIL ====== \n");
299
        sresult->failureList.push_back("testTransformToString3");
300
    } else {
301
        printf("%s", output);
302
        printf("result is OK \n");
303
        delete output;
304
    }
305
    fflush(stdout);
306

    
307
    delete value1;
308
    delete inputi;
309
    delete executable;
310

    
311
}
312

    
313
/*
314
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
315
and integer parmater created and supplied
316
*/
317
void testTransformToString4(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
318

    
319
    cout <<  "Test: testTransformToString4:" << endl;
320

    
321
    XdmNode *input = processor->parseXmlFromString(
322
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
323

    
324
    if (input== nullptr) {
325
        cout << "Source document is null. ====== FAIL ====== " << endl;
326
        sresult->failure++;
327
        sresult->failureList.push_back("testTransformToString4");
328
    }
329

    
330

    
331
    XdmValue *values = new XdmValue();
332
    XdmAtomicValue * a1 = processor->makeIntegerValue(10);
333
    XdmAtomicValue * a2 = processor->makeIntegerValue(5);
334
    XdmAtomicValue * a3 = processor->makeIntegerValue(6);
335
    XdmAtomicValue * a4 = processor->makeIntegerValue(7);
336
    values->addXdmItem(a1);
337
    values->addXdmItem(a2);
338
    values->addXdmItem(a3);
339
    values->addXdmItem(a4);
340

    
341

    
342
    XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
343

    
344
    XsltExecutable *executable = trans->compileFromXdmNode(sheet);
345

    
346
    if(executable== nullptr) {
347
        sresult->failure++;
348
        sresult->failureList.push_back("testTransformToString4");
349
        cerr << "testTransformToString4 NULL found" << endl;
350
        if (trans->exceptionOccurred()) {
351
            cerr <<"testTransformToString4 error: "<< trans->getErrorMessage() << endl;
352
        }
353
        delete values;
354
        return;
355
    }
356

    
357
    executable->setParameter("values", (XdmValue *) values);
358
    executable->setInitialMatchSelection((XdmNode *) input);
359
    const char *output = executable->applyTemplatesReturningString();
360
    if (output== nullptr) {
361
        printf("result is null \n");
362
        sresult->failure++;
363
        sresult->failureList.push_back("testTransformToString4");
364
    } else {
365
        printf("%s", output);
366
        printf("result is OK \n");
367
        delete output;
368
    }
369
    fflush(stdout);
370
    delete sheet;
371
    delete executable;
372
    delete input;
373
    delete values;
374

    
375
}
376

    
377
void testTransformFromstring(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
378
    cout << endl << "Test: testTransfromFromstring: "<< endl;
379

    
380
    if(processor == nullptr) {
381
        cout<<" processor is null"<<endl;
382
        return;
383

    
384
    }
385
    XdmNode *input = processor->parseXmlFromString(
386
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
387

    
388
    if(input == nullptr) {
389
        sresult->failure++;
390
        sresult->failureList.push_back("testTransformFromstring");
391
        cerr << "testTransformFromstring NULL found" << endl;
392
        if (trans->exceptionOccurred()) {
393
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
394
        }
395
        return;
396
    }
397

    
398
    XsltExecutable * executable = trans->compileFromString(
399
            "<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>");
400

    
401
    if(executable== nullptr) {
402
        sresult->failure++;
403
        sresult->failureList.push_back("testTransformFromstring");
404
        cerr << "testTransformFromstring NULL found" << endl;
405
        if (trans->exceptionOccurred()) {
406
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
407
        }
408
        delete input;
409
        return;
410
    }
411

    
412
    const char *output = executable->transformToString((XdmNode *) input);
413
    if (output== nullptr) {
414
        printf("result is null ====== FAIL ====== \n");
415
        sresult->failure++;
416
        sresult->failureList.push_back("testTransformFromString");
417
        if (trans->exceptionOccurred()) {
418
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
419
        }
420
    } else {
421
        printf("%s", output);
422
        printf("result is OK \n");
423
        sresult->success++;
424
        delete output;
425
    }
426
    fflush(stdout);
427
    delete input;
428
    delete executable;
429

    
430

    
431
}
432

    
433
//Test case has error in the stylesheet
434
void testTransformFromstring2Err(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
435
    cout << endl << "Test: testTransfromFromstring2-Error:" << endl;
436

    
437
    XsltExecutable * executable = trans->compileFromString(
438
            "<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>");
439

    
440
    if(executable== nullptr) {
441
        sresult->success++;
442

    
443
        if (trans->exceptionOccurred()) {
444
            cerr <<"Error expected: "<< trans->getErrorMessage() << endl;
445
        }
446
        trans->exceptionClear();
447
        return;
448
    }
449

    
450

    
451
    sresult->failure++;
452
    sresult->failureList.push_back("testTransfromFromstring2-Error");
453
    delete executable;
454

    
455
}
456

    
457
void testTrackingOfValueReference(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
458

    
459
    cout << endl << "Test: TrackingOfValueReference:" << endl;
460
    ostringstream test;
461
    ostringstream valStr;
462
    ostringstream name;
463
    for (int i = 0; i < 10; i++) {
464
        test << "v" << i;
465
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
466
               << "</value></out>";
467
        name << "value" << i;
468

    
469
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
470
        //cout<<"Name:"<<name.str()<<", Value:"<<values->getHead()->getStringValue()<<endl;
471
        trans->setParameter(name.str().c_str(), values);
472
        test.str("");
473
        valStr.str("");
474
        name.str("");
475

    
476
        if(values == nullptr) {
477
            cerr<<"TrackingOfValueReference failed to create XdmNode object" <<endl;
478
            sresult->failure++;
479
            sresult->failureList.push_back("TrackingOfValueReference");
480

    
481
        }
482
    }
483

    
484
    std::map<std::string, XdmValue *> parMap = trans->getParameters();
485
    if (parMap.size() > 0) {
486
        //cout << "Parameter size: " << parMap.size() << endl;
487
        //cout << "Parameter size: " << parMap.size()<< endl;//", Value:"<<trans->getParameters()["value0"]->getHead()->getStringValue()<<endl;
488
        ostringstream name1;
489
        for (int i = 0; i < 10; i++) {
490
            name1 << "sparam:value" << i;
491
            cout << " i:" << i << " Map size:" << parMap.size() << ", ";
492
            XdmValue *valuei = parMap[name1.str()];
493
            if (valuei != nullptr) {
494
                cout << name1.str();
495
                if (valuei->itemAt(0) != nullptr)
496
                    cout << "= " << valuei->itemAt(0)->getStringValue();
497
                cout << endl;
498

    
499
            } else {
500
                sresult->failure++;
501
                std::cerr << "trackingValueReference ====== FAIL ======" << std::endl;
502
                sresult->failureList.push_back("testTrackingOfValueReference");
503
                return;
504
            }
505
            name1.str("");
506
        }
507
    }
508
    if(parMap.size() > 0 ) {
509
        cerr<<"Deleting map"<<endl;
510
        trans->clearParameters(true);
511
    }
512
    sresult->success++;
513
}
514

    
515
/*Test case should be error.*/
516
void testTrackingOfValueReferenceError(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
517
    trans->clearParameters();
518

    
519
    cout << endl << "Test: TrackingOfValueReference-Error:" << endl;
520
    cout << "Parameter Map size: " << (trans->getParameters().size()) << endl;
521
    ostringstream test;
522
    ostringstream valStr;
523
    ostringstream name;
524
    for (int i = 0; i < 2; i++) {
525
        test << "v" << i;
526
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
527
               << "<value></out>";
528
        name << "value" << i;
529

    
530
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
531
        if(values == nullptr) {
532
            cerr<<"values NULL ====== FAIL ======="<<endl;
533
            processor->exceptionClear();
534
        } else {
535
            trans->setParameter(name.str().c_str(), values);
536
        }
537
        test.str("");
538
        valStr.str("");
539
        name.str("");
540
    }
541
    std::map<std::string, XdmValue *> parMap = trans->getParameters();
542
    cout << "Parameter Map size: " << parMap.size() << endl;
543

    
544
    ostringstream name1;
545
    bool errorFound = false;
546
    for (int i = 0; i < 2; i++) {
547
        name1 << "sparam:value" << i;
548
        cout << " i:" << i << " Map size:" << parMap.size() << ", ";
549
        try {
550

    
551
            XdmValue *valuei = parMap.at(name1.str());
552
            if (valuei != NULL) {
553
                cout << name1.str();
554
                if (valuei->itemAt(0) != NULL)
555
                    cout << "= " << valuei->itemAt(0)->getStringValue();
556
                cout << endl;
557
            }
558
        } catch (const std::out_of_range &oor) {
559
            cout << "Out of range exception occurred. Exception " << endl;
560
            if (!errorFound) {
561
                sresult->success++;
562
                errorFound = true;
563

    
564
                return;
565
            }
566
        }
567
        name1.str("");
568
    }
569
    sresult->failure++;
570
    sresult->failureList.push_back("testTrackingOfValueReferenceError");
571

    
572
}
573

    
574
void testValidation(Xslt30Processor *trans, sResultCount *sresult) {
575
    trans->clearParameters();
576

    
577

    
578

    
579
    XsltExecutable * executable = trans->compileFromString(
580
            "<?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>");
581

    
582
    const char *rootValue = executable->callTemplateReturningString("main");
583

    
584

    
585
    if (rootValue== nullptr) {
586
        std::cout << "NULL found" << std::endl;
587
        sresult->failure++;
588
        sresult->failureList.push_back("testValidation");
589
        return;
590

    
591
    } else {
592
        std::cout << "Result=" << rootValue << endl;
593
        sresult->success++;
594
    }
595
    delete executable;
596
}
597

    
598

    
599
void testXdmNodeOutput(Xslt30Processor *trans, sResultCount *sresult) {
600

    
601
    std::cout << "testXdmNodeOutput" << std::endl;
602
    XsltExecutable * executable = trans->compileFromString(
603
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template name='go'><a/></xsl:template></xsl:stylesheet>");
604
    XdmValue *rootValue = executable->callTemplateReturningValue("go");
605
    if (rootValue== nullptr) {
606
        cout << "Result is null ====== FAIL ====== " << endl;
607
        sresult->failure++;
608
        sresult->failureList.push_back("testXdmNodeOutput-0.0");
609
        return;
610
    }
611
    XdmItem *rootItem = rootValue->getHead();
612
    if (rootItem== nullptr) {
613

    
614
        cout << "Result is null ====== FAIL ====== " << endl;
615
        sresult->failure++;
616
        sresult->failureList.push_back("testXdmNodeOutput-0");
617
        delete rootValue;
618
        delete executable;
619
        return;
620
    }
621
    XdmNode *root = (XdmNode *) rootItem;
622
    if (root->getNodeKind() == DOCUMENT) {
623
        cout << "Result is a Document" << endl;
624
    } else {
625
        cout << "Node is of kind:" << root->getNodeKind() << endl;
626
    }
627
    const char *result = executable->callTemplateReturningString("go");
628
    if (string(result).find(string("<a/>")) != std::string::npos) {
629
        sresult->success++;
630
        delete result;
631
    } else {
632
        //TODO - this test case prints the XML declaration. Check if this correct
633
        sresult->failure++;
634
        cout << "testXdmNodeOutputAndString ======= FAIL========" << endl;
635
        sresult->failureList.push_back("testXdmNodeOutput");
636
    }
637
    delete rootValue;
638
    delete executable;
639

    
640
}
641

    
642
void exampleSimple1(Xslt30Processor *proc, sResultCount *sresult) {
643
    cout << "ExampleSimple1 taken from PHP:" << endl;
644

    
645
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
646
    if(executable== nullptr) {
647
        sresult->failure++;
648
        sresult->failureList.push_back("exampleSimple1");
649
        cerr << "exampleSimple1 NULL found" << endl;
650
        if (proc->exceptionOccurred()) {
651
            cerr <<"exampleSimple1 error: "<< proc->getErrorMessage() << endl;
652
        }
653
        return;
654
    }
655
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
656
    const char *result = executable->applyTemplatesReturningString();
657
    if (result != NULL) {
658
        cout << result << endl;
659
        sresult->success++;
660
        delete result;
661
    } else {
662
        cout << "Result is null ====== FAIL ====== " << endl;
663
        sresult->failure++;
664
    }
665
    proc->clearParameters();
666
    delete executable;
667
}
668

    
669
void exampleSimple1Err(Xslt30Processor *proc, sResultCount *sresult) {
670
    cout << "ExampleSimple1Err taken from PHP:" << endl;
671

    
672
    XsltExecutable * executable = proc->compileFromFile("err.xsl");
673
    if(executable == nullptr || proc->exceptionOccurred()) {
674
        if( proc->exceptionOccurred()) {
675
            cout << "Error Message= "<< proc->getErrorMessage() << endl;
676
        }
677
        cout << "Result expected as null " << endl;
678
        proc->exceptionClear();
679
        sresult->success++;
680
        return;
681
    } else {
682
        sresult->failure++;
683
        sresult->failureList.push_back("exampleSimple1Err");
684

    
685
        delete executable;
686
    }
687

    
688
}
689

    
690

    
691
void exampleSimple2(Xslt30Processor *proc, sResultCount *sresult) {
692
    cout << "<b>exampleSimple2:</b><br/>" << endl;
693
    proc->setcwd("/Users/ond1/work/development/git/saxon-dev/saxondev/src/main/c/samples/cppTests");
694

    
695
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
696
    if(executable== nullptr) {
697
        sresult->failure++;
698
        sresult->failureList.push_back("exampleSimple2");
699
        cerr << "exampleSimple2 NULL found" << endl;
700
        if (proc->exceptionOccurred()) {
701
            cerr <<"exampleSimple2 error: "<< proc->getErrorMessage() << endl;
702
        }
703
        return;
704
    }
705

    
706
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
707
    const char *filename = "output1.xml";
708
    executable->setOutputFile(filename);
709
    executable->applyTemplatesReturningFile("output1.xml");
710

    
711
    if (CppTestUtils::exists("output1.xml")) {
712
        cout << "The file $filename exists" << endl;
713
        remove("output1.xml");
714
        sresult->success++;
715
    } else {
716
        cout << "The file " << filename << " does not exist" << endl;
717
        if (executable->exceptionOccurred()) {
718
            cout << proc->getErrorMessage() << endl;
719
        }
720
        sresult->failure++;
721
        sresult->failureList.push_back("exampleSimple2");
722
    }
723

    
724
    delete executable;
725

    
726
}
727

    
728
void exampleSimple3(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
729
    cout << "<b>exampleSimple3:</b><br/>" << endl;
730
    proc->clearParameters();
731

    
732
    XdmNode *xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
733
    if (xdmNode== nullptr) {
734
        cout << "Error: xdmNode is null'" << endl;
735
        if(saxonProc->exceptionOccurred()) {
736
            cout<<"Error message="<<saxonProc->getErrorMessage()<<endl;
737
        }
738
        sresult->failure++;
739
        sresult->failureList.push_back("exampleSimple3");
740
        return;
741
    }
742

    
743
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
744

    
745
   if(executable == nullptr) {
746
        cout << "executable is NULL" <<endl;
747
        if(proc->exceptionOccurred()) {
748
                cout << proc->getErrorMessage() <<endl;
749
                
750
        }
751
        sresult->failure++;
752
        sresult->failureList.push_back("exampleSimple3");
753
        return;
754
   }
755

    
756
    executable->setInitialMatchSelection((XdmNode *) xdmNode);
757
    sresult->success++;
758
    delete xdmNode;
759
    delete executable;
760
}
761

    
762
void exampleSimple3aError(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
763
    cout << "<b>exampleSimple3aError:</b><br/>" << endl;
764

    
765
    XsltExecutable * executable = proc->compileFromFile(nullptr);
766

    
767

    
768
    if (executable == nullptr) {
769

    
770

    
771
        cout << "Expected failure of test exampleSimple3aError:" << endl;
772
        if(proc->exceptionOccurred()) {
773
            cout<<proc->getErrorMessage()<<endl;
774
        }
775

    
776
        sresult->success++;
777
        proc->exceptionClear();
778
        return;
779
    }
780

    
781
    cout << "Error: executable is not nullptr'" << endl;
782
    sresult->failure++;
783
    sresult->failureList.push_back("exampleSimple3aError");
784
    delete executable;
785
    return;
786

    
787

    
788
}
789

    
790
void exampleParam(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
791
    cout << "Test: ExampleParam" << endl;
792

    
793
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
794

    
795

    
796
    if(executable == nullptr) {
797
        cout << "executable is NULL" <<endl;
798
        if(proc->exceptionOccurred()) {
799
            cout << proc->getErrorMessage() <<endl;
800

    
801
        }
802
        sresult->failure++;
803
        sresult->failureList.push_back("exampleParam");
804
        return;
805

    
806
    }
807

    
808
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
809

    
810
    XdmAtomicValue *xdmvalue = saxonProc->makeStringValue("Hello to you");
811
    if (xdmvalue != nullptr) {
812

    
813
        executable->setParameter("a-param", (XdmValue *) xdmvalue);
814

    
815
    } else {
816
        cout << "Xdmvalue is NULL - ====== FAIL =====" << endl;
817
        sresult->failure++;
818
        sresult->failureList.push_back("exampleParam");
819
        if(executable->exceptionOccurred()) {
820
            SaxonApiException * exception = executable->getException();
821
            cerr<<"Error: " << exception->getMessage() <<endl;
822
            delete exception;
823
        }
824
        delete executable;
825
        return;
826
    }
827
    const char *result = executable->applyTemplatesReturningString();
828
    if (result != nullptr) {
829
        cout << "Output:" << result << endl;
830
        sresult->success++;
831
        delete result;
832
    } else {
833
        cout << "Result is NULL<br/>  ======= fail =====" << endl;
834
        sresult->failure++;
835
        sresult->failureList.push_back("exampleParam");
836
        if(executable->exceptionOccurred()) {
837
            SaxonApiException * exception = executable->getException();
838
            cerr<<"Error: " << exception->getMessage() <<endl;
839
            delete exception;
840
        }
841
        delete executable;
842
        return;
843
    }
844

    
845
    //proc->clearParameters();
846
    //unset($result);
847
    //echo 'again with a no parameter value<br/>';
848

    
849
    executable->setProperty("!indent", "yes");
850
    const char *result2 = executable->applyTemplatesReturningString();
851

    
852

    
853
    if (result2 != nullptr) {
854
        cout << "Result2 output= " << result2 << endl;
855
        sresult->success++;
856
        delete result2;
857
    } else {
858
        cout << "Result2 is NULL<br/>  ======= fail =====" << endl;
859
        sresult->failure++;
860
        sresult->failureList.push_back("exampleParam");
861
        if(executable->exceptionOccurred()) {
862
            SaxonApiException * exception = executable->getException();
863
            cerr<<"Error: " << exception->getMessage() <<endl;
864
            delete exception;
865
        }
866
        delete xdmvalue;
867
        delete executable;
868
        return;
869
    }
870

    
871
    //  unset($result);
872
    // echo 'again with no parameter and no properties value set. This should fail as no contextItem set<br/>';
873
    //delete xdmvalue;
874
    //executable->clearParameters();
875

    
876
    XdmAtomicValue *xdmValue2 = saxonProc->makeStringValue("goodbye to you");
877

    
878
    if (xdmValue2 == nullptr) {
879
        cout << "Xdmvalue is NULL - ====== FAIL =====" << endl;
880
        sresult->failure++;
881
        sresult->failureList.push_back("exampleParam");
882
        if(executable->exceptionOccurred()) {
883
            SaxonApiException * exception = executable->getException();
884
            cerr<<"Error: " << exception->getMessage() <<endl;
885
            delete exception;
886
        }
887
        delete executable;
888
        delete xdmvalue;
889
        return;
890
    }
891

    
892
    executable->setParameter("a-param", (XdmValue *) xdmValue2);
893
    delete xdmvalue;
894

    
895

    
896
    const char *result3 = executable->applyTemplatesReturningString();
897
    if (result3 != nullptr) {
898
        cout << "Output =" << result3 << endl;
899

    
900
        sresult->success++;
901
        delete result3;
902

    
903
    } else {
904
        cout << "Error in result ===== FAIL =======" << endl;
905
        sresult->failure++;
906
        sresult->failureList.push_back("exampleParam");
907
        if(executable->exceptionOccurred()) {
908
            SaxonApiException * exception = executable->getException();
909
            cerr<<"Error: " << exception->getMessage() <<endl;
910
            delete exception;
911
        }
912

    
913
    }
914
    delete xdmValue2;
915
    delete executable;
916

    
917

    
918

    
919
}
920

    
921
// test parameter and properties maps where we update key, value pair.
922
void exampleParam2(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
923
    cout << "\nExampleParam:</b><br/>" << endl;
924
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
925
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
926

    
927

    
928
    XdmAtomicValue *xdmvalue = saxonProc->makeStringValue("Hello to you");
929
    XdmAtomicValue *xdmvalue2i = saxonProc->makeStringValue("Hello from me");
930
    if (xdmvalue != NULL) {
931

    
932
        executable->setParameter("a-param", (XdmValue *) xdmvalue);
933
        executable->setParameter("a-param", (XdmValue *) xdmvalue2i);
934

    
935
    } else {
936
        cout << "Xdmvalue is null - ====== FAIL =====" << endl;
937
        sresult->failure++;
938
        sresult->failureList.push_back("exampleParam-1");
939
    }
940
    const char *result = executable->applyTemplatesReturningString();
941
    if (result != NULL) {
942
        string sresulti = string(result);
943
        if (sresulti.compare("Hello from me") == 0) {
944
            cout << "Output:" << result << endl;
945
            sresult->success++;
946
        } else {
947
            cout << "Result is " << result << " <br/> ======= fail ===== " << endl;
948
            sresult->failure++;
949
            sresult->failureList.push_back("exampleParam-2");
950
        }
951
    } else {
952
        cout<<"Result is NULL<br/>  ======= fail ====="<<endl;
953
        sresult->failure++;
954
        sresult->failureList.push_back("exampleParam-2");
955
    }
956

    
957
//proc->clearParameters();
958
//unset($result);
959
//echo 'again with a no parameter value<br/>';
960

    
961
    executable->setProperty("!indent", "no");
962
    executable->setProperty("!indent", "yes");
963
    const char *result2 = executable->applyTemplatesReturningString();
964

    
965
    executable->clearProperties();
966

    
967
    if(result2 != NULL) {
968
        cout<<result2<<endl;
969
        sresult->success++;
970

    
971
    }
972

    
973
    //  unset($result);
974
    // echo 'again with no parameter and no properties value set. This should fail as no contextItem set<br/>';
975
    XdmAtomicValue *xdmValue2 = saxonProc->makeStringValue("goodbye to you");
976
    executable->setParameter("a-param", (XdmValue*)xdmValue2);
977

    
978
    const char *result3 = executable->applyTemplatesReturningString();
979
    if(result3 != NULL) {
980
        cout<<"Output ="<<result3<<endl;
981

    
982
        sresult->success++;
983
    } else {
984
        cout<<"Error in result ===== FAIL ======="<<endl;
985
        sresult->failure++;
986
        sresult->failureList.push_back("exampleParam");
987
    }
988

    
989
}
990

    
991
/* XMarkbench mark test q12.xsl with just-in-time=true*/
992
void xmarkTest1(Xslt30Processor *proc, sResultCount *sresult) {
993
    cout << "Test: xmarkTest1 - XMarkbench mark test q12.xsl (JIT=true):" << endl;
994

    
995
    proc->setJustInTimeCompilation(true);
996

    
997
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
998
    if (result != NULL) {
999
        cout << "XdmNode returned" << endl;
1000
        sresult->success++;
1001
        delete result;
1002
    } else {
1003
        printf("result is null \nCheck For errors:");
1004
        sresult->failure++;
1005
        sresult->failureList.push_back("xmarkTest1");
1006
        cerr << "xmarkTest1 cp0" << endl;
1007
        if (proc->exceptionOccurred()) {
1008
            cerr << "xmarkTest1 cp1" << endl;
1009
            const char * message = proc->getErrorMessage();
1010
            cerr << "xmarkTest1 cp2" << endl;
1011
            if(message != nullptr) {
1012
                cerr << "xmarkTest1 cp2-1" << endl;
1013
                cerr << proc->getErrorMessage() << endl;
1014
            } else {
1015
                cerr << "Message is nullptr" << endl;
1016
                SaxonProcessor::sxn_environ->env->ExceptionDescribe();
1017
            }
1018
        }
1019
        cerr << "xmarkTest1 cp3" << endl;
1020
    }
1021

    
1022

    
1023
}
1024

    
1025

    
1026
/* XMarkbench mark test q12.xsl with just-in-time=true*/
1027
void xmarkTest2(Xslt30Processor *proc, sResultCount *sresult) {
1028
    cout << "Test: xmarkTest2 - XMarkbench mark test q12.xsl (JIT=true):" << endl;
1029

    
1030

    
1031
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1032
    if (result != NULL) {
1033
        cout << "XdmNode returned" << endl;
1034
        sresult->success++;
1035
        delete result;
1036

    
1037
    } else {
1038
        printf("result is null \nCheck For errors:");
1039
        sresult->failure++;
1040
        sresult->failureList.push_back("xmarkTest2");
1041
        if (proc->exceptionOccurred() > 0) {
1042
            SaxonApiException * exception = proc->getException();
1043
            if(exception != nullptr) {
1044
                const char *message = exception->getMessage();
1045
                if (message != nullptr) {
1046
                    cerr << "xmarkTest2 cp2-1" << endl;
1047
                    cerr << message << endl;
1048
                }
1049
                delete exception;
1050
            } else {
1051
                cerr << "Exception object is nullptr" << endl;
1052
                SaxonProcessor::sxn_environ->env->ExceptionDescribe();
1053
            }
1054
        }
1055
    }
1056

    
1057

    
1058
}
1059

    
1060
/* XMarkbench mark test q12.xsl with just-in-time=true*/
1061
void exampleSimple_xmark(Xslt30Processor *proc, sResultCount *sresult) {
1062
    cout << "exampleSimple_xmark test - test q12.xsl:" << endl;
1063

    
1064
    proc->setJustInTimeCompilation(true);
1065

    
1066
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1067
    if (result != NULL) {
1068
        cout << "XdmNode returned" << endl;
1069
        sresult->success++;
1070
        delete result;
1071
    } else {
1072
        printf("Result is null \nCheck For errors:");
1073
        if (proc->exceptionOccurred() > 0) {
1074
            cout << proc->getErrorMessage() << endl;
1075
        }
1076
        sresult->failure++;
1077
        sresult->failureList.push_back("exampleSimple_xmark");
1078
        proc->exceptionClear();
1079
    }
1080
    proc->clearParameters();
1081

    
1082
}
1083

    
1084
/*
1085
* Test saving nd loading a Xslt package
1086
*/
1087
void testPackage1(Xslt30Processor *trans, sResultCount *sresult) {
1088

    
1089
    cout << endl << "Test: testPackage1 - Saving and loading Packages:" << endl;
1090
    trans->clearParameters();
1091

    
1092

    
1093
    trans->compileFromFileAndSave("test.xsl", "test1.sef");
1094
    const char *output = trans->transformFileToString("cat.xml", "test1.sef");
1095

    
1096
    if (output== nullptr) {
1097
        printf("result is null \n");
1098
        const char *message = trans->getErrorMessage();
1099
        if (message != NULL) {
1100
            cout << "Error message =" << message << endl;
1101
        }
1102
        sresult->failure++;
1103
        sresult->failureList.push_back("testPackage1");
1104

    
1105
    } else {
1106
        printf("%s", output);
1107
        printf("result is OK \n");
1108
        sresult->success++;
1109
    }
1110
    fflush(stdout);
1111
    delete output;
1112
}
1113

    
1114

    
1115
/*
1116
* Test saving and loading a Xslt package
1117
*/
1118
void testPackage1a(Xslt30Processor *trans, sResultCount *sresult) {
1119

    
1120
    cout << endl << "Test: testPackage1a" << endl;
1121
    trans->clearParameters();
1122

    
1123
    trans->compileFromFileAndSave("test.xsl", "test1a.sef");
1124

    
1125
    XsltExecutable * executable = trans->compileFromFile("test1.sef");
1126
    executable->setInitialMatchSelectionAsFile("cat.xml");
1127
    const char * output = executable->applyTemplatesReturningString();
1128
    if (output== nullptr) {
1129
        printf("result is null \n");
1130
        const char *message = trans->getErrorMessage();
1131
        if (message != NULL) {
1132
            cout << "Error message =" << message << endl;
1133
        }
1134
        sresult->failure++;
1135
        sresult->failureList.push_back("testPackage1a");
1136

    
1137
    } else {
1138
        printf("%s", output);
1139
        printf("result is OK \n");
1140
        sresult->success++;
1141
    }
1142
    fflush(stdout);
1143
    delete output;
1144
}
1145

    
1146

    
1147
/*
1148
* Test saving and loading a Xslt package
1149
*/
1150
void testPackage2_Error(Xslt30Processor *trans, sResultCount *sresult) {
1151

    
1152
    cout << endl << "Test: testPackage2_Error:" << endl;
1153

    
1154
    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>";
1155

    
1156
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
1157

    
1158
    if(trans->exceptionOccurred()) {
1159
        const char *message = trans->getErrorMessage();
1160
        if (message != NULL) {
1161
            cout << "Error message =" << message << endl;
1162
        }
1163
        sresult->success++;
1164
        trans->exceptionClear();
1165
        return;
1166

    
1167
    }
1168

    
1169
    sresult->failure++;
1170
    sresult->failureList.push_back("testPackage2_Error");
1171

    
1172
}
1173

    
1174
void testCallFunction(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1175

    
1176
    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>";
1177
    cout << endl << "Test: testCallFunction:" << endl;
1178
    XsltExecutable * executable = trans->compileFromString(source);
1179

    
1180
    if(executable == nullptr) {
1181
        if(trans->exceptionOccurred()) {
1182
            SaxonApiException * exception = trans->getException();
1183
            if(exception != nullptr) {
1184
                cerr << "Error: " << exception->getMessage() << endl;
1185
                delete exception;
1186
            }
1187

    
1188
        }
1189
        sresult->failure++;
1190
        sresult->failureList.push_back("testCallFunction");
1191
        trans->exceptionClear();
1192
        return;
1193

    
1194

    
1195
    }
1196

    
1197
    XdmValue **valueArray = new XdmValue *[2];
1198

    
1199
    valueArray[0] = (XdmValue *) (proc->makeIntegerValue(2));
1200
    valueArray[1] = (XdmValue *) (proc->makeIntegerValue(3));
1201
    XdmValue *v = executable->callFunctionReturningValue("{http://localhost/}add", valueArray, 2);
1202

    
1203
    if (v != NULL && (v->getHead())->isAtomic() && ((XdmAtomicValue *) (v->getHead()))->getLongValue() == 5) {
1204
        sresult->success++;
1205
    } else {
1206
        if (v != NULL && !(v->getHead())->isAtomic()) {
1207
            cout << "Value in callFunction is not atomic - but expected as atomic value" << endl;
1208
        }
1209
        cout << "testCallFunction ======= FAIL ======" << endl;
1210
        if(executable->exceptionOccurred()) {
1211
            SaxonApiException * exception = executable->getException();
1212
            if(exception != nullptr) {
1213
                cerr << "Error: " << exception->getMessage() << endl;
1214
                delete exception;
1215
            }
1216
        }
1217
        sresult->failure++;
1218
        sresult->failureList.push_back("testCallFunction");
1219
    }
1220
    delete valueArray[0];
1221
    delete valueArray[1];
1222
    delete [] valueArray;
1223
}
1224

    
1225
void testInitialTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1226

    
1227

    
1228
    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>";
1229
    cout << endl << "Test:testInitialTemplate" << endl;
1230
    XsltExecutable * executable = trans->compileFromString(source);
1231
    if(executable == nullptr) {
1232
        if(trans->exceptionOccurred()) {
1233
            cout << "Error: "<< trans->getErrorMessage() << endl;
1234
        }
1235
        return;
1236
    }
1237
    XdmNode *node = proc->parseXmlFromString("<e/>");
1238

    
1239
    executable->setResultAsRawValue(false);
1240
    std::map<std::string, XdmValue *> parameterValues;
1241

    
1242
    XdmAtomicValue * a1 = proc->makeIntegerValue(12);
1243
    XdmAtomicValue * a2 = proc->makeIntegerValue(5);;
1244
    parameterValues["a"] = a1;
1245
    parameterValues["b"] = a2;
1246
    executable->setInitialTemplateParameters(parameterValues, false);
1247
    executable->setInitialMatchSelection(node);
1248
    XdmValue *result = executable->applyTemplatesReturningValue();
1249
    if (result != NULL) {
1250
        sresult->success++;
1251
        cout << "Result=" << result->getHead()->getStringValue() << endl;
1252
        delete result;
1253
    } else {
1254
        sresult->failure++;
1255
    }
1256

    
1257
    delete executable;
1258
    delete a1;
1259
    delete a2;
1260
}
1261

    
1262
void testResolveUri(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1263
    cout << endl << "Test: testResolveUri:" << endl;
1264

    
1265
    XsltExecutable * executable = trans->compileFromString(
1266
            "<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>");
1267

    
1268
    if(executable == nullptr) {
1269
        sresult->failure++;
1270
        sresult->failureList.push_back("testResolveUri");
1271
        if(trans->exceptionOccurred()) {
1272
            const char * message = trans->getErrorMessage();
1273
            if(message != nullptr) {
1274
                cout << "Error: " << trans->getErrorMessage() << endl;
1275
            }
1276
        }
1277
        trans->exceptionClear();
1278
        return;
1279
    }
1280
    XdmValue *value = executable->callTemplateReturningValue("go");
1281

    
1282

    
1283
    if (value== nullptr) {
1284

    
1285
        sresult->failure++;
1286
        sresult->failureList.push_back("testResolveUri");
1287
    } else {
1288

    
1289
        const char *svalue = value->itemAt(0)->getStringValue();
1290
        cout << "testResolveUri = " << svalue << endl;
1291
        sresult->success++;
1292
        delete value;
1293
    }
1294

    
1295

    
1296
}
1297

    
1298
void testContextNotRoot(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1299
    cout << endl << "Test: testContextNotRoot" << endl;
1300

    
1301
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1302

    
1303
    XsltExecutable *executable = trans->compileFromString(
1304
            "<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>");
1305

    
1306
    if (executable == nullptr) {
1307
        sresult->failure++;
1308
        sresult->failureList.push_back("testContextNotRoot");
1309
        if (trans->exceptionOccurred()) {
1310
            cout << "Error: " << trans->getErrorMessage() << endl;
1311
        }
1312
        return;
1313
    }
1314

    
1315
    executable->setGlobalContextItem(node);
1316
    if (node->getChildCount() > 0) {
1317
        XdmNode **eNodeL1 = node->getChildren();
1318
        if (eNodeL1 != nullptr) {
1319
            XdmNode ** eNodeChildren = eNodeL1[0]->getChildren();
1320
            if (eNodeChildren != nullptr) {
1321
                XdmNode *eNode = eNodeChildren[0];
1322
                cout << "Node content = " << eNode->toString() << endl;
1323
                executable->setInitialMatchSelection(eNode);
1324
                const char *result = executable->applyTemplatesReturningString();
1325

    
1326
                if (result == nullptr) {
1327

    
1328
                    cout << "testCallFunction ======= FAIL ======" << endl;
1329
                    if (executable->exceptionOccurred()) {
1330
                        SaxonApiException *exception = executable->getException();
1331
                        cerr << "Error: " << exception->getMessage() << endl;
1332
                        delete exception;
1333
                    }
1334
                    sresult->failure++;
1335
                    sresult->failureList.push_back("testContextNotRoot");
1336

    
1337

    
1338
                } else {
1339

    
1340
                    cout << "testContextNotRoot = " << result << endl;
1341
                    sresult->success++;
1342
                    delete result;
1343

    
1344
                }
1345

    
1346
            }
1347
        }
1348
    } else {
1349
        sresult->failure++;
1350
        sresult->failureList.push_back("testContextNotRoot");
1351
    }
1352

    
1353
    delete executable;
1354
    delete node;
1355
}
1356

    
1357

    
1358
void testContextNotRootNamedTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1359
    cout << endl << "Test: testContextNotRootNamedTemplate" << endl;
1360

    
1361
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1362

    
1363
    XsltExecutable * executable = trans->compileFromString(
1364
            "<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>");
1365

    
1366
    if(executable == nullptr) {
1367
        sresult->failure++;
1368
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1369
        if(trans->exceptionOccurred()) {
1370
            cout << "Error: "<< trans->getErrorMessage() << endl;
1371
        }
1372
        return;
1373
    }
1374

    
1375
    executable->setGlobalContextItem(node);
1376
    const char *result = executable->callTemplateReturningString("main");
1377

    
1378
    if (result== nullptr) {
1379

    
1380
        cout << "testCallFunction ======= FAIL ======" << endl;
1381
        if(executable->exceptionOccurred()) {
1382
            SaxonApiException * exception = executable->getException();
1383
            cerr<<"Error: " << exception->getMessage() <<endl;
1384
            delete exception;
1385
        }
1386
        sresult->failure++;
1387
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1388
    } else {
1389

    
1390
        cout << "testContextNotRoot = " << result << endl;
1391
        sresult->success++;
1392
    }
1393

    
1394
}
1395

    
1396

    
1397
void testContextNotRootNamedTemplateValue(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1398
    cout << endl << "Test: testContextNotRootNamedTemplateValue" << endl;
1399

    
1400
    XdmNode *node = proc->parseXmlFromString("<doc><e>text</e></doc>");
1401

    
1402
    XsltExecutable * executable = trans->compileFromString(
1403
            "<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>");
1404

    
1405
    if(executable == nullptr) {
1406
        sresult->failure++;
1407
        sresult->failureList.push_back("testContentNotRootNamedTemplateValue");
1408
        if(trans->exceptionOccurred()) {
1409
            cout << "Error: "<< trans->getErrorMessage() << endl;
1410
        }
1411
        return;
1412
    }
1413

    
1414
    executable->setGlobalContextItem(node);
1415
    XdmValue *result = executable->callTemplateReturningValue("main");
1416

    
1417
    if (result== nullptr) {
1418

    
1419
        cout << "testCallFunction ======= FAIL ======" << endl;
1420
        if(executable->exceptionOccurred()) {
1421
            SaxonApiException * exception = executable->getException();
1422
            cerr<<"Error: " << exception->getMessage() <<endl;
1423
            delete exception;
1424
        }
1425
        sresult->failure++;
1426
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
1427
    } else {
1428

    
1429
        cout << "testContextNotRoot = " << result->getHead()->getStringValue() << endl;
1430
        sresult->success++;
1431
    }
1432

    
1433
}
1434

    
1435
void testCallSystemFunction(SaxonProcessor *proc, sResultCount *sresult) {
1436

    
1437
    XdmFunctionItem *fi = XdmFunctionItem::getSystemFunction(proc, "{http://www.w3.org/2005/xpath-functions}parse-json",
1438
                                                            1);
1439
    if (fi== nullptr) {
1440
        sresult->failure++;
1441
        sresult->failureList.push_back("testCallSystemFunction");
1442
        return;
1443
    }
1444

    
1445
    XdmValue ** xdmValue = new XdmValue*[1];
1446
    xdmValue[0] = new XdmValue();
1447
    xdmValue[0]->addXdmItem(proc->makeStringValue("[1,2,3]"));
1448
    XdmValue *result = fi->call(xdmValue, 1);
1449

    
1450
    std::cerr << "Result = " << result->toString() << endl;
1451
    if(result->size() == 3) {
1452

    
1453
        cout << "testCallSystemFunction = " << result->getHead()->getStringValue() << endl;
1454
        sresult->success++;
1455

    
1456
    } else {
1457
        sresult->failure++;
1458
        sresult->failureList.push_back("testCallSystemFunction");
1459

    
1460
    }
1461

    
1462
}
1463

    
1464

    
1465
void testPipeline(SaxonProcessor *proc, sResultCount *sresult) {
1466
    cout << endl << "Test: testPipeline" << endl;
1467

    
1468
    Xslt30Processor * trans = proc->newXslt30Processor();
1469
    XsltExecutable * stage1 = trans->compileFromString(
1470
            "<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>");
1471

    
1472
    if(stage1 == nullptr) {
1473
        sresult->failure++;
1474
        sresult->failureList.push_back("testPipeline");
1475
        if(trans->exceptionOccurred()) {
1476
            cout << "stage 1 Error: "<< trans->getErrorMessage() << endl;
1477
        }
1478
        return;
1479
    }
1480

    
1481
    XdmNode *inn = proc->parseXmlFromString("<z/>");
1482

    
1483
    XsltExecutable *stage2 = trans->compileFromString(
1484
            "<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>");
1485

    
1486
    if(stage2 == nullptr) {
1487
        sresult->failure++;
1488
        sresult->failureList.push_back("testPipeline");
1489
        if(trans->exceptionOccurred()) {
1490
            cout << "stage 2 Error: "<< trans->getErrorMessage() << endl;
1491
        }
1492
        return;
1493
    }
1494
    XsltExecutable *stage3 = trans->compileFromString(
1495
            "<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>");
1496

    
1497
    if(stage3 == nullptr) {
1498
        sresult->failure++;
1499
        sresult->failureList.push_back("testPipeline");
1500
        if(trans->exceptionOccurred()) {
1501
            cout << "stage 3 Error: "<< trans->getErrorMessage() << endl;
1502
        }
1503
        return;
1504
    }
1505
    XsltExecutable *stage4 = trans->compileFromString(
1506
            "<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>");
1507

    
1508
    if(stage3 == nullptr) {
1509
        sresult->failure++;
1510
        sresult->failureList.push_back("testPipeline");
1511
        if(trans->exceptionOccurred()) {
1512
            cout << "stage 4 Error: "<< trans->getErrorMessage() << endl;
1513
        }
1514
        return;
1515
    }
1516

    
1517
    XsltExecutable *stage5 = trans->compileFromString(
1518
            "<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>");
1519

    
1520
    if(stage5 == nullptr) {
1521
        sresult->failure++;
1522
        sresult->failureList.push_back("testPipeline");
1523
        if(trans->exceptionOccurred()) {
1524
            cout << "stage 5 Error: "<< trans->getErrorMessage() << endl;
1525
        }
1526
        return;
1527
    }
1528

    
1529
    stage1->setProperty("!indent", "no");
1530
    stage1->setInitialMatchSelection(inn);
1531

    
1532
    XdmValue *d1 = stage1->applyTemplatesReturningValue();
1533
    if (stage1->exceptionOccurred()) {
1534
        sresult->failure++;
1535
        sresult->failureList.push_back("testPipeline");
1536
        if(stage1->exceptionOccurred()) {
1537
            SaxonApiException * exception = stage1->getException();
1538
            cerr<<"Error: " << exception->getMessage() <<endl;
1539
            delete exception;
1540
        }
1541
        return;
1542
    }
1543

    
1544
    if (d1 == nullptr) {
1545
        sresult->failure++;
1546
        sresult->failureList.push_back("testPipeline-0");
1547
        return;
1548
    }
1549
    XdmItem *d11 = d1->getHead();
1550
    if (d11== nullptr) {
1551

    
1552
        cout << "d11 is NULL\n" << endl;
1553
    }
1554
    const char *data = d1->getHead()->toString();
1555

    
1556
    if (data != NULL) {
1557
        cout << "d1 result=" << data << endl;
1558
    } else {
1559
        sresult->failure++;
1560
        sresult->failureList.push_back("testPipeline-1");
1561

    
1562
        return;
1563
    }
1564
    stage2->setProperty("!indent", "no");
1565
    stage2->setInitialMatchSelection(d1->getHead());
1566
    XdmValue *d2 = stage2->applyTemplatesReturningValue();
1567
    if (d2== nullptr) {
1568
        cout << "ERROR-11\n" << endl;
1569
        if(stage2->exceptionOccurred()) {
1570
            SaxonApiException * exception = stage2->getException();
1571
            cerr<<"Error: " << exception->getMessage() <<endl;
1572
            delete exception;
1573
        }
1574
        sresult->failure++;
1575
        sresult->failureList.push_back("testPipeline-2");
1576
        return;
1577
    }
1578
    stage3->setProperty("!indent", "no");
1579
    stage3->setInitialMatchSelection(d2);
1580
    XdmValue * d3 = stage3->applyTemplatesReturningValue();
1581
    if(d3 == nullptr){
1582
        sresult->failure++;
1583
        sresult->failureList.push_back("testPipeline-3");
1584
        if(stage3->exceptionOccurred()) {
1585
            SaxonApiException * exception = stage3->getException();
1586
            cerr<<"Error: " << exception->getMessage() <<endl;
1587
            delete exception;
1588
        }
1589
      }
1590
    stage4->setProperty("!indent", "no");
1591
    stage4->setInitialMatchSelection(d3);
1592
    XdmValue * d4 = stage4->applyTemplatesReturningValue();
1593
    if(d3== nullptr){
1594
        sresult->failure++;
1595
        sresult->failureList.push_back("testPipeline-1");
1596
        if(stage4->exceptionOccurred()) {
1597
            SaxonApiException * exception = stage4->getException();
1598
            cerr<<"Error: " << exception->getMessage() <<endl;
1599
            delete exception;
1600
        }
1601
        return;
1602
      }
1603
    stage5->setProperty("!indent", "no");
1604
    stage5->setInitialMatchSelection(d4);
1605
    const char * sw = stage5->applyTemplatesReturningString();
1606
    if(sw==NULL){
1607
        sresult->failure++;
1608
        sresult->failureList.push_back("testPipeline-1");
1609
        if(stage5->exceptionOccurred()) {
1610
            SaxonApiException * exception = stage5->getException();
1611
            cerr<<"Error: " << exception->getMessage() <<endl;
1612
            delete exception;
1613
        }
1614
        return;
1615
      }
1616
    cout<<sw<<endl;
1617
    cout << "testPipeline = " << sw << endl;
1618
    sresult->success++;
1619

    
1620

    
1621
}
1622

    
1623

    
1624
void testCatalog(const char * cwd, SaxonProcessor * proc, sResultCount *sresult) {
1625

    
1626

    
1627
    cout << endl << "Test: testCatalog" << endl;
1628
    bool trace = false;
1629
    proc->setcwd(cwd);
1630
    proc->setCatalog("../php/catalog-test/catalog.xml", trace);
1631

    
1632
    Xslt30Processor * trans = proc->newXslt30Processor();
1633

    
1634
    XsltExecutable  * executable = trans->compileFromFile("../php/catalog-test/test1.xsl");
1635

    
1636
    if(executable == nullptr) {
1637

    
1638
        if (trans->exceptionOccurred()) {
1639

    
1640
            if(trans->getErrorMessage() != nullptr) {
1641
                const char *message = trans->getErrorMessage();
1642
                cerr << "exception=" << message << endl;
1643
            } else {
1644
                const char *message = proc->getErrorMessage();
1645
                if(message != nullptr) {
1646
                    cerr << "exception-proc=" << message << endl;
1647
                }
1648
            }
1649
        }
1650
        sresult->failure++;
1651
        sresult->failureList.push_back("testCatalog");
1652
        trans->exceptionClear();
1653
        return;
1654
    }
1655

    
1656
    executable->setInitialMatchSelectionAsFile("../php/catalog-test/example.xml");
1657

    
1658
    const char *result = executable->applyTemplatesReturningString();
1659

    
1660
    if(result != NULL) {
1661
        std::cerr << "testCatalog result= " << result << std::endl;
1662
    }
1663
    sresult->success++; // TODO - check the results more carefully
1664

    
1665
    delete executable;
1666

    
1667
}
1668

    
1669
static int NUM_THREADS = 10;
1670

    
1671
void RunThread(XsltExecutable * executable, int tid, const std::string filename) {
1672

    
1673
    cerr<<"RunThread cp0,  THEAD ID="<<tid<<endl;
1674

    
1675
   executable->setInitialMatchSelectionAsFile(filename.c_str());
1676

    
1677
    cerr<<"RunThread cp1"<<endl;
1678

    
1679
    const char *result = nullptr; executable->applyTemplatesReturningString();
1680
    if(result != nullptr) {
1681
        cout << " Result from THREAD ID: " << tid << ", " << result << endl;
1682
        delete result;
1683
    } else {
1684
        cout << " ===== Failed in THREAD ID: "<< tid << endl;
1685
        /*if(executable->exceptionOccurred()) {
1686
            SaxonApiException *exception = executable->getException();
1687

1688
            if (exception != nullptr) {
1689
                const char *message = exception->getMessage();
1690
                if (message != nullptr) {
1691
                    cerr << "Error = " << message << endl;
1692
                }
1693
            }
1694
        } else {*/
1695
            cerr<<"No exception found - result is nullptr"<<endl;
1696
        //}
1697

    
1698
    }
1699

    
1700

    
1701
}
1702

    
1703
void testThreads (SaxonProcessor * processor, Xslt30Processor * trans, sResultCount *sresult) {
1704

    
1705
    std::vector<std::string> s = {
1706
            "../data/xmark100k.xml",
1707
            "../data/xmark1.xml",
1708
            "../data/xmark4.xml",
1709
            "../data/xmark10.xml"
1710
    };
1711

    
1712
    std::vector<std::thread> threads;
1713

    
1714
    for (int i = 0; i < s.size(); i++) {
1715
        XsltExecutable * executable = trans->compileFromFile("q12.xsl");
1716
        if(executable != nullptr) {
1717
            threads.push_back(std::thread(RunThread, executable, i, s[i]));
1718
        } else {
1719
            cerr<<"Error : Failed to create thread as executable is NULL"<<endl;
1720
        }
1721
    }
1722
    cerr<<"testThreads cp0"<<endl;
1723
    for (auto &th : threads) {
1724
        th.join();
1725
        cerr<<"testThreads cp1 - loop"<<endl;
1726
    }
1727
}
1728

    
1729

    
1730

    
1731
int main(int argc, char* argv[]) {
1732

    
1733

    
1734
    const char * cwd = nullptr;
1735
    if(argc > 0) {
1736
        cwd = argv[1];
1737
    }
1738

    
1739
    SaxonProcessor *processor = new SaxonProcessor(true);
1740
    processor->setConfigurationProperty("http://saxon.sf.net/feature/licenseFileLocation", "/usr/local/lib/saxon-license.lic");
1741
    cout << "Test: Xslt30Processor with Saxon version=" << processor->version() << endl << endl;
1742
    
1743
    char buff[FILENAME_MAX]; //create string buffer to hold path
1744
    GetCurrentDir( buff, FILENAME_MAX );
1745
    cout<<"CWD = "<< buff<<endl;
1746
    if(cwd != nullptr) {
1747
            processor->setcwd(cwd);//"/Users/ond1/work/development/git/saxon-dev/saxondev/src/main/c/samples/cppTests"); //set to the current working directory
1748
    } else {
1749
        processor->setcwd(buff);
1750
    }
1751
    if (processor->isSchemaAwareProcessor()) {
1752

    
1753
        std::cerr << "Processor is Schema Aware" << std::endl;
1754
    } else {
1755
        std::cerr << "Processor is not Schema Aware" << std::endl;
1756
    }
1757

    
1758
    sResultCount *sresult = new sResultCount();
1759
    Xslt30Processor *trans = processor->newXslt30Processor();
1760

    
1761
    if( trans == nullptr) {
1762
        cout<< "Error creating Xslt30Processor"<<endl;
1763
        if(processor->exceptionOccurred()) {
1764
            cout<< "Error message: " <<processor->getErrorMessage()<<endl;
1765

    
1766
        }
1767
        return -1;
1768
    }
1769
    //testValidation(trans,sresult);
1770

    
1771
    testInitialTemplate(processor, trans, sresult);
1772

    
1773
    cout<<endl<<"============================================================="<<endl<<endl;
1774

    
1775
    exampleSimple1Err(trans, sresult);
1776

    
1777
    cout<<endl<<"============================================================="<<endl<<endl;
1778

    
1779
    exampleSimple1(trans, sresult);
1780

    
1781
    cout<<endl<<"============================================================="<<endl<<endl;
1782

    
1783
    exampleSimple_xmark(trans, sresult);
1784

    
1785
    cout<<endl<<"============================================================="<<endl<<endl;
1786

    
1787
    exampleSimple2(trans, sresult);
1788

    
1789
    cout<<endl<<"============================================================="<<endl<<endl;
1790

    
1791
    exampleSimple3(processor, trans, sresult);
1792

    
1793
    cout<<endl<<"============================================================="<<endl<<endl;
1794

    
1795
    exampleSimple3aError(processor, trans, sresult);
1796

    
1797
    cout<<endl<<"============================================================="<<endl<<endl;
1798

    
1799
    testApplyTemplatesString1(trans, sresult);
1800

    
1801
    cout<<endl<<"============================================================="<<endl<<endl;
1802

    
1803
    testApplyTemplatesString2(processor, trans, sresult);
1804

    
1805
    cout<<endl<<"============================================================="<<endl<<endl;
1806

    
1807

    
1808
    testApplyTemplates2a_Error(processor, trans, sresult);
1809

    
1810
    cout<<endl<<"============================================================="<<endl<<endl;
1811

    
1812
    testTransformToString4(processor, trans, sresult);
1813

    
1814
    cout<<endl<<"============================================================="<<endl<<endl;
1815

    
1816
    testCatalog(cwd, processor,  sresult);
1817

    
1818
    cout<<endl<<"============================================================="<<endl<<endl;
1819

    
1820
    testTransformToString2b(processor, trans, sresult);
1821

    
1822
    cout<<endl<<"============================================================="<<endl<<endl;
1823

    
1824
    testTransformToString3(processor, trans, sresult);
1825

    
1826
    cout<<endl<<"============================================================="<<endl<<endl;
1827
        
1828
    testTransformFromstring(processor, trans, sresult);
1829

    
1830
    cout<<endl<<"============================================================="<<endl<<endl;
1831

    
1832
    testTransformFromstring2Err(processor, trans, sresult);
1833

    
1834
    cout<<endl<<"============================================================="<<endl<<endl;
1835

    
1836
    testTrackingOfValueReference(processor, trans, sresult);
1837

    
1838
    cout<<endl<<"============================================================="<<endl<<endl;
1839

    
1840
    testTrackingOfValueReferenceError(processor, trans, sresult);
1841

    
1842
    cout<<endl<<"============================================================="<<endl<<endl;
1843

    
1844
    testPackage1(trans, sresult);
1845

    
1846
    cout<<endl<<"============================================================="<<endl<<endl;
1847

    
1848
    testPackage1a(trans, sresult);
1849

    
1850
    cout<<endl<<"============================================================="<<endl<<endl;
1851

    
1852
    testPackage2_Error(trans, sresult);
1853

    
1854
    cout<<endl<<"============================================================="<<endl<<endl;
1855

    
1856
    testXdmNodeOutput(trans, sresult);
1857

    
1858
    cout<<endl<<"============================================================="<<endl<<endl;
1859

    
1860
    exampleParam(processor, trans, sresult);
1861

    
1862
    cout<<endl<<"============================================================="<<endl<<endl;
1863

    
1864
    xmarkTest1(trans, sresult);
1865

    
1866
    cout<<endl<<"============================================================="<<endl<<endl;
1867

    
1868
    xmarkTest2(trans, sresult);
1869

    
1870
    cout<<endl<<"============================================================="<<endl<<endl;
1871

    
1872
    testCallFunction(processor, trans, sresult);
1873

    
1874
    cout<<endl<<"============================================================="<<endl<<endl;
1875

    
1876
    testResolveUri(processor, trans, sresult);
1877

    
1878
    cout<<endl<<"============================================================="<<endl<<endl;
1879

    
1880
    testContextNotRoot(processor, trans, sresult);
1881

    
1882
    cout<<endl<<"============================================================="<<endl<<endl;
1883

    
1884
    testContextNotRootNamedTemplate(processor, trans, sresult);
1885

    
1886
    cout<<endl<<"============================================================="<<endl<<endl;
1887

    
1888
    testContextNotRootNamedTemplateValue(processor, trans, sresult);
1889

    
1890
    cout<<endl<<"============================================================="<<endl<<endl;
1891

    
1892
    testPipeline(processor, sresult);
1893

    
1894

    
1895
    cout<<endl<<"============================================================="<<endl<<endl;
1896

    
1897

    
1898
    //Available in PE and EE
1899
    //testTransformToStringExtensionFunc(processor, trans);
1900

    
1901
    delete trans;
1902
    delete processor;
1903
    //processor->release();
1904

    
1905

    
1906
    SaxonProcessor *processor2 = new SaxonProcessor(true);
1907

    
1908
    if(cwd != nullptr) {
1909
        processor->setcwd(cwd);//"/Users/ond1/work/development/git/saxon-dev/saxondev/src/main/c/samples/cppTests"); //set to the current working directory
1910
    } else {
1911
        processor->setcwd(buff);
1912
    }
1913
    Xslt30Processor *trans2 = processor2->newXslt30Processor();
1914
    testApplyTemplatesString1(trans2, sresult);
1915
    cout<<endl<<"============================================================="<<endl<<endl;
1916

    
1917

    
1918
    testThreads (processor2, trans2, sresult);
1919

    
1920

    
1921

    
1922
    delete trans2;
1923
    delete processor2;
1924
    processor2->release();
1925

    
1926
    cout<<endl<<"======================== Test Results ========================"<<endl<<endl;
1927

    
1928
    std::cout << "\nTest Results - Number of tests= " << (sresult->success + sresult->failure) << ", Successes = "
1929
              << sresult->success << ",  Failures= " << sresult->failure << std::endl;
1930

    
1931
    std::list<std::string>::iterator it;
1932
    std::cout << "Failed tests:" << std::endl;
1933
    // Make iterate point to beginning and increment it one by one until it reaches the end of list.
1934
    for (it = sresult->failureList.begin(); it != sresult->failureList.end(); it++) {
1935
        //Print the contents
1936
        std::cout << it->c_str() << std::endl;
1937

    
1938
    }
1939

    
1940

    
1941
    return 0;
1942
}
(27-27/28)