Project

Profile

Help

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

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

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

    
12
// TODO: write test case for checking parameters which are null
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 << endl << "Test: TransformToString1:" << endl;
35
    XsltExecutable *executable1 = trans->compileFromFile("test.xsl");
36
    executable1->setInitialMatchSelectionAsFile("cat.xml");
37
    XsltExecutable *executable = trans->compileFromString("test.xsl");
38

    
39
    const char *output = executable->applyTemplatesReturningString();
40
    if (output == NULL) {
41
        printf("result is null ====== FAIL ====== \n");
42
        sresult->failure++;
43
        fflush(stdout);
44
        delete output;
45
        sresult->failureList.push_back("testApplyTemplatesString1-0");
46
        return;
47
    } else if (string(output).find(string("<out>text2</out>")) != std::string::npos) {
48
        //printf("%s", output);
49
        printf("result is OK \n");
50
        sresult->success++;
51
    } else {
52
        printf("result is null ====== FAIL ====== \n");
53
        sresult->failure++;
54
        sresult->failureList.push_back("testApplyTemplatesString1-1");
55
//        std::cout<<"output="<<output<<std::endl;
56
    }
57
    fflush(stdout);
58
    delete output;
59

    
60
}
61

    
62
/*
63
* Test transform to String. Source and stylesheet supplied as arguments
64
*/
65
void testTransformToStringExtensionFunc(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
66

    
67
    cout << endl << "Test: TransformToStringExtensionFunc:" << endl;
68
    bool nativeFound = processor->registerNativeMethods(SaxonProcessor::sxn_environ->env,
69
                                                        "com/saxonica/functions/extfn/cpp/NativeCall",
70
                                                        cppMethods, sizeof(cppMethods) / sizeof(cppMethods[0]));
71

    
72
    XsltExecutable * executable = trans->compileFromFile("testExtension.xsl");
73
    executable->setProperty("extc", "home/ond1/work/svn/latest9.9-saxonc/samples/cppTests/cppExtensionFunction");
74

    
75
    if (nativeFound) {
76
        const char *output = executable->transformFileToString("cat.xml");
77

    
78
        if (output == NULL) {
79
            SaxonProcessor::sxn_environ->env->ExceptionDescribe();
80
            printf("result is null ====== FAIL ======  \n");
81
            sresult->failureList.push_back("testTransformToStringExnteionFunc");
82
        } else {
83
            //printf("%s", output);
84
            printf("result is OK \n");
85
        }
86
        fflush(stdout);
87
        delete output;
88
    } else {
89
        printf("native Class not foun ====== FAIL ====== ");
90
        sresult->failureList.push_back("testTransformToStringExtensionFunc");
91
    }
92
}
93

    
94

    
95
/*
96
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
97
*/
98
void testApplyTemplatesString2(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
99

    
100
    cout << endl << "Test: TransformToString2:" << endl;
101
    trans->clearParameters(true);
102

    
103
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
104

    
105
    if (input == NULL) {
106
        cout << "Source document is null." << endl;
107

    
108
    }
109
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
110
    executable->setInitialMatchSelection((XdmValue *) input);
111
    const char *output = executable->applyTemplatesReturningString();
112
    if (output == NULL) {
113
        printf("result is null ====== FAIL ======  \n");
114
        sresult->failureList.push_back("testApplyTemplatesString2");
115
    } else {
116
        printf("%s", output);
117
        printf("result is OK \n");
118
    }
119
    fflush(stdout);
120
    delete output;
121
    delete executable;
122
}
123

    
124
/*
125
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
126
Should be error. Stylesheet file does not exist
127
*/
128
void testApplyTemplates2a(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
129

    
130
    cout << endl << "Test: TransformToString2a:" << endl;
131
    trans->clearParameters(true);
132
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
133

    
134
    if (input == NULL) {
135
        cout << "Source document is null. ====== FAIL ======" << endl;
136
        sresult->failure++;
137
        sresult->failureList.push_back("testApplyTemplates2a");
138
        return;
139
    }
140
    XsltExecutable * executable = trans->compileFromFile("test-error.xsl");
141
    executable->setInitialMatchSelection((XdmValue *) input);
142
    const char *output = executable->applyTemplatesReturningString();
143
    if (output == NULL) {
144
        printf("result is null \n");
145
        sresult->success++;
146
    } else {
147
        printf("%s", output);
148
        printf("result is OK - ======= FAIL ======= \n");
149
        sresult->failure++;
150
        sresult->failureList.push_back("testApplyTemplates2a");
151
    }
152
    fflush(stdout);
153
    delete output;
154

    
155

    
156
}
157

    
158
/*
159
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
160
Should be error. Source file does not exist
161
*/
162
void testTransformToString2b(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
163

    
164
    cout << endl << "Test: TransformToString2b:" << endl;
165
    trans->clearParameters(true);
166

    
167
    XdmNode *input = processor->parseXmlFromFile("cat-error.xml");
168

    
169
    if (input == NULL) {
170
        cout << "Source document is null. ====== FAIL ====== " << endl;
171
        sresult->failureList.push_back("testTransformToString2b");
172
        return;
173
    }
174
    XsltExecutable * executable = trans->compileFromString("test-error.xsl");
175
    executable->setInitialMatchSelection((XdmNode *) input);
176
    const char *output = executable->transformFileToString(NULL);
177
    if (output == NULL) {
178
        printf("result is null ====== FAIL ======  \nCheck For errors:");
179
        sresult->failureList.push_back("testTransformToString2b");
180
        if (executable->exceptionOccurred()) {
181
            cout << trans->getErrorMessage() << endl;
182
        }
183
    } else {
184
        printf("%s", output);
185
        printf("result is OK \n");
186
    }
187
    fflush(stdout);
188
    delete output;
189

    
190
    trans->exceptionClear();
191

    
192
}
193

    
194

    
195
/*
196
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
197
and integer parmater created and supplied
198
*/
199
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
200

    
201
    cout << endl << "Test: TransformToString3:" << endl;
202
    trans->clearParameters(true);
203

    
204
    XdmNode *inputi = processor->parseXmlFromString(
205
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
206

    
207
    XdmAtomicValue *value1 = processor->makeIntegerValue(10);
208

    
209
    trans->setParameter("numParam", (XdmValue *) value1);
210

    
211
    if (inputi == NULL) {
212
        cout << "Source document inputi is null. ====== FAIL ====== " << endl;
213
        sresult->failureList.push_back("testTransformToString3");
214
        return;
215
    }
216

    
217
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
218
    executable->setInitialMatchSelection((XdmNode *) inputi);
219
    const char *output = executable->applyTemplatesReturningString();
220
    if (output == NULL) {
221
        printf("result is null ====== FAIL ====== \n");
222
        sresult->failureList.push_back("testTransformToString3");
223
    } else {
224
        printf("%s", output);
225
        printf("result is OK \n");
226
    }
227
    fflush(stdout);
228
    delete output;
229

    
230
}
231

    
232
/*
233
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
234
and integer parmater created and supplied
235
*/
236
void testTransformToString4(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
237

    
238
    cout << endl << "Test: TransformToString4:" << endl;
239
    trans->clearParameters(true);
240

    
241
    XdmNode *input = processor->parseXmlFromString(
242
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
243

    
244
    XdmValue *values = new XdmValue(processor);
245
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(10));
246
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(5));
247
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(6));
248
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(7));
249

    
250
    trans->setParameter("values", (XdmValue *) values);
251

    
252
    if (input == NULL) {
253
        cout << "Source document is null. ====== FAIL ====== " << endl;
254
        sresult->failureList.push_back("testTransformToString4");
255
    }
256
    XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
257

    
258
    XsltExecutable *executable = trans->compileFromXdmNode(sheet);
259
    executable->setInitialMatchSelection((XdmNode *) input);
260
    const char *output = executable->applyTemplatesReturningString(/*"test2.xsl"*/);
261
    if (output == NULL) {
262
        printf("result is null \n");
263
        sresult->failureList.push_back("testTransformToString4");
264
    } else {
265
        printf("%s", output);
266
        printf("result is OK \n");
267
    }
268
    fflush(stdout);
269
    delete output;
270

    
271
}
272

    
273
void testTransformFromstring(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
274
    cout << endl << "Test: testTransfromFromstring:" << endl;
275
    trans->clearParameters(true);
276

    
277
    XdmNode *input = processor->parseXmlFromString(
278
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
279

    
280
    XsltExecutable * executable = trans->compileFromString(
281
            "<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>");
282

    
283
    const char *output = executable->transformToString((XdmNode *) input);
284
    if (output == NULL) {
285
        printf("result is null ====== FAIL ====== \n");
286
        sresult->failureList.push_back("testTransformFromString");
287
    } else {
288
        printf("%s", output);
289
        printf("result is OK \n");
290

    
291
    }
292
    fflush(stdout);
293
    delete output;
294

    
295

    
296
}
297

    
298
//Test case has error in the stylesheet
299
void testTransformFromstring2Err(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
300
    cout << endl << "Test: testTransfromFromstring2-Error:" << endl;
301
    trans->clearParameters(true);
302

    
303
    XdmNode *input = processor->parseXmlFromString(
304
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
305

    
306
    XsltExecutable * executable = trans->compileFromString(
307
            "<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>");
308
    executable->setInitialMatchSelection((XdmValue *) input);
309
    const char *output = executable->applyTemplatesReturningString();
310
    if (output == NULL) {
311
        printf("result is null ====== FAIL ======  \n\nCheck For errors:\n");
312
        sresult->failureList.push_back("testTransformFromstring2Err");
313
        if (executable->exceptionOccurred()) {
314
            cout << "Error message=" << executable->getErrorMessage() << endl;
315
        }
316
    } else {
317
        printf("%s", output);
318
        printf("result is OK \n");
319
    }
320
    fflush(stdout);
321
    delete output;
322

    
323
    trans->exceptionClear();
324

    
325

    
326
}
327

    
328
void testTrackingOfValueReference(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
329
    trans->clearParameters(true);
330

    
331
    cout << endl << "Test: TrackingOfValueReference:" << endl;
332
    ostringstream test;
333
    ostringstream valStr;
334
    ostringstream name;
335
    for (int i = 0; i < 10; i++) {
336
        test << "v" << i;
337
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
338
               << "</value></out>";
339
        name << "value" << i;
340

    
341
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
342
        //cout<<"Name:"<<name.str()<<", Value:"<<values->getHead()->getStringValue()<<endl;
343
        trans->setParameter(name.str().c_str(), values);
344
        test.str("");
345
        valStr.str("");
346
        name.str("");
347
    }
348

    
349
    std::map<std::string, XdmValue *> parMap = trans->getParameters();
350
    if (parMap.size() > 0) {
351
        //cout << "Parameter size: " << parMap.size() << endl;
352
        //cout << "Parameter size: " << parMap.size()<< endl;//", Value:"<<trans->getParameters()["value0"]->getHead()->getStringValue()<<endl;
353
        ostringstream name1;
354
        for (int i = 0; i < 10; i++) {
355
            name1 << "param:value" << i;
356
            cout << " i:" << i << " Map size:" << parMap.size() << ", ";
357
            XdmValue *valuei = parMap[name1.str()];
358
            if (valuei != NULL) {
359
                cout << name1.str();
360
                if (valuei->itemAt(0) != NULL)
361
                    cout << "= " << valuei->itemAt(0)->getStringValue();
362
                cout << endl;
363
            } else {
364
                sresult->failure++;
365
                std::cerr << "trackingValueReference ====== FAIL ======" << std::endl;
366
                sresult->failureList.push_back("testTrackingOfValueReference");
367
            }
368
            name1.str("");
369
        }
370
    }
371
    sresult->success++;
372
}
373

    
374
/*Test case should be error.*/
375
void testTrackingOfValueReferenceError(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
376
    trans->clearParameters(true);
377

    
378
    cout << endl << "Test: TrackingOfValueReference-Error:" << endl;
379
    cout << "Parameter Map size: " << (trans->getParameters().size()) << endl;
380
    ostringstream test;
381
    ostringstream valStr;
382
    ostringstream name;
383
    for (int i = 0; i < 10; i++) {
384
        test << "v" << i;
385
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
386
               << "<value></out>";
387
        name << "value" << i;
388

    
389
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
390
        trans->setParameter(name.str().c_str(), values);
391
        test.str("");
392
        valStr.str("");
393
        name.str("");
394
    }
395
    std::map<std::string, XdmValue *> parMap = trans->getParameters();
396
    cout << "Parameter Map size: " << parMap.size() << endl;
397

    
398
    ostringstream name1;
399
    bool errorFound = false;
400
    for (int i = 0; i < 10; i++) {
401
        name1 << "param:value" << i;
402
        cout << " i:" << i << " Map size:" << parMap.size() << ", ";
403
        try {
404
            XdmValue *valuei = parMap.at(name1.str());
405
            if (valuei != NULL) {
406
                cout << name1.str();
407
                if (valuei->itemAt(0) != NULL)
408
                    cout << "= " << valuei->itemAt(0)->getStringValue();
409
                cout << endl;
410
            }
411
        } catch (const std::out_of_range &oor) {
412
            cout << "Out of range exception occurred. Exception no. " << endl;
413
            if (!errorFound) {
414
                sresult->success++;
415
                errorFound = true;
416

    
417
                return;
418
            }
419
        }
420
        name1.str("");
421
    }
422
    sresult->failure++;
423
    sresult->failureList.push_back("testTrackingOfValueReferenceError");
424

    
425
}
426

    
427
void testValidation(Xslt30Processor *trans, sResultCount *sresult) {
428
    trans->clearParameters(true);
429

    
430

    
431

    
432
    XsltExecutable * executable = trans->compileFromString(
433
            "<?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>");
434

    
435
    const char *rootValue = executable->callTemplateReturningString("main");
436

    
437

    
438
    if (rootValue == NULL) {
439
        std::cout << "NULL found" << std::endl;
440
        sresult->failure++;
441
        sresult->failureList.push_back("testValidation");
442
        return;
443

    
444
    } else {
445
        std::cout << "Result=" << rootValue << endl;
446
        sresult->success++;
447
    }
448
}
449

    
450

    
451
void testXdmNodeOutput(Xslt30Processor *trans, sResultCount *sresult) {
452
    trans->clearParameters(true);
453

    
454

    
455
    std::cout << "testXdmNodeOutput" << std::endl;
456
    XsltExecutable * executable = trans->compileFromString(
457
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template name='go'><a/></xsl:template></xsl:stylesheet>");
458
    XdmValue *rootValue = executable->callTemplateReturningValue("go");
459
    if (rootValue == NULL) {
460
        cout << "Result is null ====== FAIL ====== " << endl;
461
        sresult->failure++;
462
        sresult->failureList.push_back("testXdmNodeOutput-0.0");
463
        return;
464
    }
465
    XdmItem *rootItem = rootValue->getHead();
466
    if (rootItem == NULL) {
467

    
468
        cout << "Result is null ====== FAIL ====== " << endl;
469
        sresult->failure++;
470
        sresult->failureList.push_back("testXdmNodeOutput-0");
471
        return;
472
    }
473
    XdmNode *root = (XdmNode *) rootItem;
474
    if (root->getNodeKind() == DOCUMENT) {
475
        cout << "Result is a Document" << endl;
476
    } else {
477
        cout << "Node is of kind:" << root->getNodeKind() << endl;
478
    }
479
    const char *result = executable->callTemplateReturningString("go");
480
    if (string(result).find(string("<a/>")) != std::string::npos) {
481
        sresult->success++;
482
    } else {
483
        //TODO - this test case prints the XML declaration. Check if this correct
484
        sresult->failure++;
485
        cout << "testXdmNodeOutputAndString ======= FAIL========" << endl;
486
        sresult->failureList.push_back(result);
487
    }
488

    
489

    
490
}
491

    
492
void exampleSimple1(Xslt30Processor *proc, sResultCount *sresult) {
493
    cout << "ExampleSimple1 taken from PHP:" << endl;
494

    
495
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
496
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
497
    const char *result = executable->applyTemplatesReturningString();
498
    if (result != NULL) {
499
        cout << result << endl;
500
        sresult->success++;
501
    } else {
502
        cout << "Result is null ====== FAIL ====== " << endl;
503
        sresult->failure++;
504
    }
505
    proc->clearParameters(true);
506

    
507
}
508

    
509
void exampleSimple1Err(Xslt30Processor *proc, sResultCount *sresult) {
510
    cout << "ExampleSimple1Err taken from PHP:" << endl;
511

    
512
    XsltExecutable * executable = proc->compileFromFile("err.xsl");
513
    if(proc->exceptionOccurred()) {
514
        cout << "Result expected as null " << endl;
515
        sresult->success++;
516
    } else {
517

    
518
        sresult->failure++;
519
        sresult->failureList.push_back("exampleSimple1Err");
520

    
521
    }
522
    proc->clearParameters(true);
523

    
524
}
525

    
526

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

    
531
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
532
    if(executable == NULL) {
533
        sresult->failure++;
534
        sresult->failureList.push_back("exampleSimple2");
535
        cerr << "exampleSimple2 NULL found" << endl;
536
        if (executable->exceptionOccurred()) {
537
            cerr <<"exampleSimple2 error: "<< proc->getErrorMessage() << endl;
538
        }
539
        return;
540
    }
541
    cout << "exampleSimple2 cp0" << endl;
542
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
543
    const char *filename = "output1.xml";
544
    executable->setOutputFile(filename);
545
    executable->applyTemplatesReturningFile("output1.xml");
546

    
547
    if (CppTestUtils::exists("output1.xml")) {
548
        cout << "The file $filename exists" << endl;
549
        remove("output1.xml");
550
        sresult->success++;
551
    } else {
552
        cout << "The file " << filename << " does not exist" << endl;
553
        if (executable->exceptionOccurred()) {
554
            cout << proc->getErrorMessage() << endl;
555
        }
556
        sresult->failure++;
557
        sresult->failureList.push_back("exampleSimple2");
558
    }
559
    proc->clearParameters(true);
560

    
561
}
562

    
563
void exampleSimple3(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
564
    cout << "<b>exampleSimple3:</b><br/>" << endl;
565
    proc->clearParameters(true);
566

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

    
569
    XdmNode *xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
570
    if (xdmNode == NULL) {
571
        cout << "Error: xdmNode is null'" << endl;
572
        sresult->failure++;
573
        sresult->failureList.push_back("exampleSimple3");
574
        return;
575
    }
576
    executable->setInitialMatchSelection((XdmNode *) xdmNode);
577
    cout << "end of exampleSimple3" << endl;
578
    executable->clearParameters(true);
579

    
580
    sresult->success++;
581
}
582

    
583
void exampleSimple3a(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
584
    cout << "<b>exampleSimple3:</b><br/>" << endl;
585
    proc->clearParameters(true);
586

    
587
    XsltExecutable * executable = proc->compileFromFile(nullptr);
588

    
589

    
590
    if (executable == nullptr) {
591

    
592

    
593
        cout << "end of exampleSimple3a" << endl;
594
        proc->clearParameters(true);
595

    
596
        sresult->success++;
597
        return;
598
    }
599

    
600
    cout << "Error: executable is not nullptr'" << endl;
601
    sresult->failure++;
602
    sresult->failureList.push_back("exampleSimple3a");
603
    return;
604

    
605

    
606
}
607

    
608
void exampleParam(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
609
    cout << "\nExampleParam:</b><br/>" << endl;
610

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

    
613
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
614

    
615
    XdmAtomicValue *xdmvalue = saxonProc->makeStringValue("Hello to you");
616
    if (xdmvalue != NULL) {
617

    
618
        executable->setParameter("a-param", (XdmValue *) xdmvalue);
619

    
620
    } else {
621
        cout << "Xdmvalue is null - ====== FAIL =====" << endl;
622
        sresult->failure++;
623
        sresult->failureList.push_back("exampleParam-1");
624
    }
625
    const char *result = executable->applyTemplatesReturningString();
626
    if (result != NULL) {
627
        cout << "Output:" << result << endl;
628
        sresult->success++;
629
    } else {
630
        cout << "Result is NULL<br/>  ======= fail =====" << endl;
631
        sresult->failure++;
632
        sresult->failureList.push_back("exampleParam-2");
633
    }
634

    
635
    //proc->clearParameters();
636
    //unset($result);
637
    //echo 'again with a no parameter value<br/>';
638

    
639
    executable->setProperty("!indent", "yes");
640
    const char *result2 = executable->applyTemplatesReturningString();
641

    
642

    
643
    if (result2 != NULL) {
644
        cout << result2 << endl;
645
        sresult->success++;
646
    }
647

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

    
653
    const char *result3 = executable->applyTemplatesReturningString();
654
    if (result3 != NULL) {
655
        cout << "Output =" << result3 << endl;
656
        sresult->success++;
657
    } else {
658
        cout << "Error in result ===== FAIL =======" << endl;
659
        sresult->failure++;
660
        sresult->failureList.push_back("exampleParam");
661
    }
662
    proc->clearParameters();
663

    
664

    
665
}
666

    
667
// test parameter and properties maps where we update key, value pair.
668
void exampleParam2(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
669
    cout << "\nExampleParam:</b><br/>" << endl;
670
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
671
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
672

    
673

    
674
    XdmAtomicValue *xdmvalue = saxonProc->makeStringValue("Hello to you");
675
    XdmAtomicValue *xdmvalue2i = saxonProc->makeStringValue("Hello from me");
676
    if (xdmvalue != NULL) {
677

    
678
        executable->setParameter("a-param", (XdmValue *) xdmvalue);
679
        executable->setParameter("a-param", (XdmValue *) xdmvalue2i);
680

    
681
    } else {
682
        cout << "Xdmvalue is null - ====== FAIL =====" << endl;
683
        sresult->failure++;
684
        sresult->failureList.push_back("exampleParam-1");
685
    }
686
    const char *result = executable->applyTemplatesReturningString();
687
    if (result != NULL) {
688
        string sresulti = string(result);
689
        if (sresulti.compare("Hello from me") == 0) {
690
            cout << "Output:" << result << endl;
691
            sresult->success++;
692
        } else {
693
            cout << "Result is " << result << " <br/> ======= fail ===== " << endl;
694
            sresult->failure++;
695
            sresult->failureList.push_back("exampleParam-2");
696
        }
697
    } else {
698
        cout<<"Result is NULL<br/>  ======= fail ====="<<endl;
699
        sresult->failure++;
700
        sresult->failureList.push_back("exampleParam-2");
701
    }
702

    
703
//proc->clearParameters();
704
//unset($result);
705
//echo 'again with a no parameter value<br/>';
706

    
707
    executable->setProperty("!indent", "no");
708
    executable->setProperty("!indent", "yes");
709
    const char *result2 = executable->applyTemplatesReturningString();
710

    
711
    executable->clearProperties();
712

    
713
    if(result2 != NULL) {
714
        cout<<result2<<endl;
715
        sresult->success++;
716

    
717
    }
718

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

    
724
    const char *result3 = executable->applyTemplatesReturningString();
725
    if(result3 != NULL) {
726
        cout<<"Output ="<<result3<<endl;
727

    
728
        sresult->success++;
729
    } else {
730
        cout<<"Error in result ===== FAIL ======="<<endl;
731
        sresult->failure++;
732
        sresult->failureList.push_back("exampleParam");
733
    }
734

    
735
}
736

    
737
/* XMarkbench mark test q12.xsl with just-in-time=true*/
738
void xmarkTest1(Xslt30Processor *proc, sResultCount *sresult) {
739
    cout << "XMarkbench mark test q12.xsl (JIT=true):" << endl;
740

    
741
    proc->setJustInTimeCompilation(true);
742

    
743
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
744
    if (result != NULL) {
745
        cout << "XdmNode returned" << endl;
746
        sresult->success++;
747
    } else {
748
        printf("result is null \nCheck For errors:");
749
        sresult->failure++;
750
        sresult->failureList.push_back("xmarkTest1");
751
        if (proc->exceptionOccurred() > 0) {
752
            cout << proc->getErrorMessage() << endl;
753
        }
754
    }
755
    proc->clearParameters(true);
756

    
757

    
758
}
759

    
760

    
761
/* XMarkbench mark test q12.xsl with just-in-time=true*/
762
void xmarkTest2(Xslt30Processor *proc, sResultCount *sresult) {
763
    cout << "XMarkbench mark test q12.xsl (JIT=true):" << endl;
764

    
765

    
766
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
767
    if (result != NULL) {
768
        cout << "XdmNode returned" << endl;
769
    } else {
770
        printf("result is null \nCheck For errors:");
771
        sresult->failure++;
772
        sresult->failureList.push_back("xmarkTest2");
773
        if (proc->exceptionOccurred() > 0) {
774
            cout << proc->getErrorMessage() << endl;
775
        }
776
    }
777
    proc->clearParameters(true);
778

    
779

    
780
}
781

    
782
/* XMarkbench mark test q12.xsl with just-in-time=true*/
783
void exampleSimple_xmark(Xslt30Processor *proc, sResultCount *sresult) {
784
    cout << "XMarkbench mark test q12.xsl:" << endl;
785

    
786
    proc->setJustInTimeCompilation(true);
787

    
788
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
789
    if (result != NULL) {
790
        cout << "XdmNode returned" << endl;
791
    } else {
792
        printf("result is null \nCheck For errors:");
793
        if (proc->exceptionOccurred() > 0) {
794
            cout << proc->getErrorMessage() << endl;
795
        }
796
    }
797
    proc->clearParameters(true);
798

    
799
}
800

    
801

    
802
/*
803
* Test saving nd loading a Xslt package
804
*/
805
void testPackage1(Xslt30Processor *trans, sResultCount *sresult) {
806

    
807
    cout << endl << "Test: Saving and loading Packages:" << endl;
808
    trans->clearParameters(true);
809

    
810

    
811
    trans->compileFromFileAndSave("test.xsl", "test1.sef");
812
    const char *output = trans->transformFileToString("cat.xml", "test1.sef");
813
    if (output == NULL) {
814
        printf("result is null \n");
815
        const char *message = trans->getErrorMessage();
816
        if (message != NULL) {
817
            cout << "Error message =" << message << endl;
818
        }
819
        sresult->failure++;
820
        sresult->failureList.push_back("testPackage1");
821

    
822
    } else {
823
        printf("%s", output);
824
        printf("result is OK \n");
825
        sresult->success++;
826
    }
827
    fflush(stdout);
828
    delete output;
829
}
830

    
831

    
832
/*
833
* Test saving and loading a Xslt package
834
*/
835
void testPackage2(Xslt30Processor *trans, sResultCount *sresult) {
836

    
837
    cout << endl << "Test: Saving and loading Packages2 - Error:" << endl;
838
    trans->clearParameters(true);
839

    
840

    
841
    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>";
842

    
843
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
844
    const char *output = trans->transformFileToString("cat.xml", "test2.sef");
845
    if (output == NULL) {
846
        printf("result is null as expected \n");
847
        const char *message = trans->getErrorMessage();
848
        if (message != NULL) {
849
            cout << "Error message =" << message << endl;
850
        }
851
        sresult->success++;
852
    } else {
853
        printf("%s", output);
854
        printf("result is OK \n");
855
        sresult->failure++;
856
        sresult->failureList.push_back("testPackage2");
857
    }
858
    fflush(stdout);
859
    delete output;
860
}
861

    
862
void testCallFunction(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
863

    
864
    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>";
865
    cout << endl << "Test: testCallFunction:" << endl;
866
    XsltExecutable * executable = trans->compileFromString(source);
867
    XdmValue **valueArray = new XdmValue *[2];
868

    
869
    valueArray[0] = (XdmValue *) (proc->makeIntegerValue(2));
870
    valueArray[1] = (XdmValue *) (proc->makeIntegerValue(3));
871
    XdmValue *v = executable->callFunctionReturningValue("{http://localhost/}add", valueArray, 2);
872

    
873
    if (v != NULL && (v->getHead())->isAtomic() && ((XdmAtomicValue *) (v->getHead()))->getLongValue() == 5) {
874
        sresult->success++;
875
    } else {
876
        if (v != NULL && !(v->getHead())->isAtomic()) {
877
            cout << "Value in callFunction is not atomic - but expected as atomic value" << endl;
878
        }
879
        cout << "testCallFunction ======= FAIL ======" << endl;
880
        const char *message = executable->getErrorMessage();
881
        if (message != NULL) {
882
            cout << "Error message =" << message << endl;
883
        }
884
        sresult->failure++;
885
        sresult->failureList.push_back("testCallFunction");
886
    }
887
    delete valueArray[0];
888
    delete valueArray[1];
889
    delete valueArray;
890
}
891

    
892
void testInitialTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
893

    
894

    
895
    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>";
896
    cout << endl << "Test:testInitialTemplate" << endl;
897
    XsltExecutable * executable = trans->compileFromString(source);
898
    XdmNode *node = proc->parseXmlFromString("<e/>");
899

    
900
    executable->setResultAsRawValue(false);
901
    std::map<std::string, XdmValue *> parameterValues;
902
    parameterValues["a"] = proc->makeIntegerValue(12);
903
    parameterValues["b"] = proc->makeIntegerValue(5);
904
    executable->setInitialTemplateParameters(parameterValues, false);
905
    executable->setInitialMatchSelection(node);
906
    XdmValue *result = executable->applyTemplatesReturningValue();
907
    if (result != NULL) {
908
        sresult->success++;
909
        cout << "Result=" << result->getHead()->getStringValue() << endl;
910
    } else {
911
        sresult->failure++;
912
    }
913

    
914
}
915

    
916
void testResolveUri(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
917
    cout << endl << "Test: testResolveUri:" << endl;
918

    
919
    XsltExecutable * executable = trans->compileFromString(
920
            "<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>");
921

    
922

    
923
    XdmValue *value = executable->callTemplateReturningValue("go");
924

    
925

    
926
    if (value == NULL) {
927

    
928
        sresult->failure++;
929
        sresult->failureList.push_back("testResolveUri");
930
    } else {
931

    
932
        const char *svalue = value->itemAt(0)->getStringValue();
933
        cout << "testResolveUri = " << svalue << endl;
934
        sresult->success++;
935
    }
936

    
937

    
938
}
939

    
940
void testContextNotRoot(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
941
    cout << endl << "Test: testContextNotRoot" << endl;
942

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

    
945
    XsltExecutable * executable = trans->compileFromString(
946
            "<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>");
947
    executable->setGlobalContextItem(node);
948
    if (node->getChildCount() > 0) {
949
        XdmNode *eNode = node->getChildren()[0]->getChildren()[0];
950
        cout << "Node content = " << eNode->toString() << endl;
951
        executable->setInitialMatchSelection(eNode);
952
        const char *result = executable->applyTemplatesReturningString();
953

    
954
        if (result == NULL) {
955

    
956
            cout << "testCallFunction ======= FAIL ======" << endl;
957
            const char *message = executable->getErrorMessage();
958
            if (message != NULL) {
959
                cout << "Error message =" << message << endl;
960
            }
961
            sresult->failure++;
962
            sresult->failureList.push_back("testContextNotRoot");
963
        } else {
964

    
965
            cout << "testContextNotRoot = " << result << endl;
966
            sresult->success++;
967
        }
968
    }
969
}
970

    
971

    
972
void testContextNotRootNamedTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
973
    cout << endl << "Test: testContextNotRootNamedTemplate" << endl;
974

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

    
977
    XsltExecutable * executable = trans->compileFromString(
978
            "<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>");
979
    executable->setGlobalContextItem(node);
980
    const char *result = executable->callTemplateReturningString("main");
981

    
982
    if (result == NULL) {
983

    
984
        cout << "testCallFunction ======= FAIL ======" << endl;
985
        const char *message = executable->getErrorMessage();
986
        if (message != NULL) {
987
            cout << "Error message =" << message << endl;
988
        }
989
        sresult->failure++;
990
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
991
    } else {
992

    
993
        cout << "testContextNotRoot = " << result << endl;
994
        sresult->success++;
995
    }
996

    
997
}
998

    
999

    
1000
void testContextNotRootNamedTemplateValue(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1001
    cout << endl << "Test: testContextNotRootNamedTemplateValue" << endl;
1002

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

    
1005
    XsltExecutable * executable = trans->compileFromString(
1006
            "<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>");
1007
    executable->setGlobalContextItem(node);
1008
    XdmValue *result = executable->callTemplateReturningValue("main");
1009

    
1010
    if (result == NULL) {
1011

    
1012
        cout << "testCallFunction ======= FAIL ======" << endl;
1013
        const char *message = executable->getErrorMessage();
1014
        if (message != NULL) {
1015
            cout << "Error message =" << message << endl;
1016
        }
1017
        sresult->failure++;
1018
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
1019
    } else {
1020

    
1021
        cout << "testContextNotRoot = " << result->getHead()->getStringValue() << endl;
1022
        sresult->success++;
1023
    }
1024

    
1025
}
1026

    
1027
void testCallSystemFunction(SaxonProcessor *proc, sResultCount *sresult) {
1028

    
1029
    XdmFunctionItem *fi = XdmFunctionItem::getSystemFunction(proc, "{http://www.w3.org/2005/xpath-functions}parse-json",
1030
                                                            1);
1031
    if (fi == NULL) {
1032
        sresult->failure++;
1033
        sresult->failureList.push_back("testCallSystemFunction");
1034
        return;
1035
    }
1036

    
1037
    XdmValue ** xdmValue = new XdmValue*[1];
1038
    xdmValue[0] = new XdmValue();
1039
    xdmValue[0]->addXdmItem(proc->makeStringValue("[1,2,3]"));
1040
    XdmValue *result = fi->call(xdmValue, 1);
1041

    
1042
    std::cerr << "Result = " << result->toString() << endl;
1043
    if(result->size() == 3) {
1044

    
1045
        cout << "testCallSystemFunction = " << result->getHead()->getStringValue() << endl;
1046
        sresult->success++;
1047

    
1048
    } else {
1049
        sresult->failure++;
1050
        sresult->failureList.push_back("testCallSystemFunction");
1051

    
1052
    }
1053

    
1054
}
1055

    
1056

    
1057
void testPipeline(SaxonProcessor *proc, sResultCount *sresult) {
1058
    cout << endl << "Test: testPipeline" << endl;
1059

    
1060
    Xslt30Processor * trans = proc->newXslt30Processor();
1061
    XsltExecutable * stage1 = trans->compileFromString(
1062
            "<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>");
1063
    XdmNode *inn = proc->parseXmlFromString("<z/>");
1064

    
1065
    XsltExecutable *stage2 = trans->compileFromString(
1066
            "<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>");
1067

    
1068
    XsltExecutable *stage3 = trans->compileFromString(
1069
            "<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>");
1070

    
1071
    XsltExecutable *stage4 = trans->compileFromString(
1072
            "<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>");
1073

    
1074
    XsltExecutable *stage5 = trans->compileFromString(
1075
            "<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>");
1076

    
1077
    if (stage2->exceptionOccurred()) {
1078
        const char *message = stage2->getErrorMessage();
1079
        cout << "exception-CP0=" << message << endl;
1080
        sresult->failure++;
1081
        sresult->failureList.push_back("testPipeline");
1082
        return;
1083
    }
1084

    
1085
    stage1->setProperty("!indent", "no");
1086
    stage1->setInitialMatchSelection(inn);
1087

    
1088
    XdmValue *d1 = stage1->applyTemplatesReturningValue();
1089
    if (stage1->exceptionOccurred()) {
1090
        cout << "Exception message=" << (stage1->getErrorMessage()) << endl;
1091
        return;
1092
    }
1093

    
1094
    if (d1 == nullptr) {
1095
        cout << "ERROR1" << endl;;
1096
        sresult->failure++;
1097
        sresult->failureList.push_back("testPipeline-0");
1098
        return;
1099
    }
1100
    XdmItem *d11 = d1->getHead();
1101
    if (d11 == NULL) {
1102

    
1103
        cout << "d11 is NULL\n" << endl;
1104
    }
1105
    const char *data = d1->getHead()->toString();
1106

    
1107
    if (data != NULL) {
1108
        cout << "d1 result=" << data << endl;
1109
    } else {
1110
        sresult->failure++;
1111
        sresult->failureList.push_back("testPipeline-1");
1112

    
1113
        return;
1114
    }
1115
    stage2->setProperty("!indent", "no");
1116
    stage2->setInitialMatchSelection(d1->getHead());
1117
    XdmValue *d2 = stage2->applyTemplatesReturningValue();
1118
    if (d2 == NULL) {
1119
        cout << "ERROR-11\n" << endl;
1120
        if (stage2->exceptionOccurred()) {
1121
            const char *message = stage2->getErrorMessage();
1122
            cout << "exception=" << message << endl;
1123
        }
1124
        sresult->failure++;
1125
        sresult->failureList.push_back("testPipeline-2");
1126
        return;
1127
    }
1128
    stage3->setProperty("!indent", "no");
1129
    stage3->setInitialMatchSelection(d2);
1130
    XdmValue * d3 = stage3->applyTemplatesReturningValue();
1131
    if(d3 == nullptr){
1132
        sresult->failure++;
1133
        sresult->failureList.push_back("testPipeline-3");
1134
      }
1135
    stage4->setProperty("!indent", "no");
1136
    stage4->setInitialMatchSelection(d3);
1137
    XdmValue * d4 = stage4->applyTemplatesReturningValue();
1138
    if(d3== nullptr){
1139
        sresult->failure++;
1140
        sresult->failureList.push_back("testPipeline-1");
1141
        return;
1142
      }
1143
    stage5->setProperty("!indent", "no");
1144
    stage5->setInitialMatchSelection(d4);
1145
    const char * sw = stage5->applyTemplatesReturningString();
1146
    if(sw==NULL){
1147
        sresult->failure++;
1148
        sresult->failureList.push_back("testPipeline-1");
1149
        return;
1150
      }
1151
    cout<<sw<<endl;
1152
    cout << "testPipeline = " << sw << endl;
1153
    sresult->success++;
1154

    
1155

    
1156
}
1157

    
1158

    
1159
void testCatalog(SaxonProcessor * proc, sResultCount *sresult) {
1160

    
1161
    Xslt30Processor * trans = proc->newXslt30Processor();
1162
    bool trace = false;
1163

    
1164
    proc->setCatalog("../php/catalog-test/catalog.xml", trace);
1165

    
1166

    
1167
    XsltExecutable  * executable = trans->compileFromFile("../php/catalog-test/test1.xsl");
1168
    //trans->setSourceFromFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/example.xml");
1169
    executable->setInitialMatchSelectionAsFile("../php/catalog-test/example.xml");
1170
//trans->compileFromFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/test1.xsl");
1171
    const char *result = executable->applyTemplatesReturningString();
1172

    
1173
    if(result != NULL) {
1174
        std::cerr << "testCatalog result= " << result << std::endl;
1175
    }
1176

    
1177
}
1178

    
1179

    
1180
/*
1181
 *
1182
 *void *RunThread(void *args) {
1183

1184
    struct arg_struct *argsi = (struct arg_struct *)args;
1185
    int threadid = argsi->id;
1186
    Xslt30Processor * trans = argsi->trans;
1187
    long tid;
1188
    tid = (long)threadid;
1189

1190
    trans->attachThread();
1191

1192
   trans->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
1193

1194
    const char *result = trans->applyTemplatesReturningString();
1195
    cout<<" Result from THREAD ID: "<< tid << ", " << result<<endl;
1196
    delete result;
1197
    //pthread_exit(NULL);
1198
    trans->detachThread();
1199
}
1200

1201
void testThreads (SaxonProcessor * processor) {
1202
    pthread_t threads[NUM_THREADS];
1203
    int rc;
1204
    int i;
1205

1206
    Xslt30Processor *  trans = processor->newXslt30Processor();
1207

1208
    trans->compileFromFile("../php/xsl/foo.xsl");
1209
    struct arg_struct args;
1210
    args.trans = trans;
1211

1212
    for( i = 0; i < NUM_THREADS; i++ ) {
1213
        cout << "main() : creating thread, " << i << endl;
1214
        args.id = i;
1215
        rc = pthread_create(&threads[i], NULL, RunThread, (void *)&args);
1216

1217
        if (rc) {
1218
            cout << "Error:unable to create thread," << rc << endl;
1219
            exit(-1);
1220
        }
1221
        (void) pthread_join(threads[i], NULL);
1222
    }
1223
  //  pthread_exit(NULL);
1224
}
1225

1226
 *
1227
 */
1228

    
1229

    
1230
int main() {
1231

    
1232
    SaxonProcessor *processor = new SaxonProcessor(true);
1233
    processor->setConfigurationProperty("http://saxon.sf.net/feature/licenseFileLocation", "/usr/local/lib/saxon-license.lic");
1234
    cout << "Test: Xslt30Processor with Saxon version=" << processor->version() << endl << endl;
1235
    char cwd[256];
1236
    char buff[FILENAME_MAX]; //create string buffer to hold path
1237
    GetCurrentDir( buff, FILENAME_MAX );
1238
    processor->setcwd("/Users/ond1/work/development/git/saxon-dev/saxondev/src/main/c/samples/cppTests"); //set to the current working directory
1239
    if (processor->isSchemaAwareProcessor()) {
1240

    
1241
        std::cerr << "Processor is Schema Aware" << std::endl;
1242
    } else {
1243
        std::cerr << "Processor is not Schema Aware" << std::endl;
1244
    }
1245

    
1246
    sResultCount *sresult = new sResultCount();
1247
    Xslt30Processor *trans = processor->newXslt30Processor();
1248
    //testValidation(trans,sresult);
1249
    std::cerr << "cp0" << std::endl;
1250
    testInitialTemplate(processor, trans, sresult);
1251
    std::cerr << "cp1" << std::endl;
1252
    exampleSimple1Err(trans, sresult);
1253
    std::cerr << "cp2" << std::endl;
1254
    exampleSimple1(trans, sresult);
1255
    std::cerr << "cp3" << std::endl;
1256

    
1257
    exampleSimple_xmark(trans, sresult);
1258
    std::cerr << "cp4" << std::endl;
1259
    exampleSimple2(trans, sresult);
1260
    std::cerr << "cp5" << std::endl;
1261
    exampleSimple3(processor, trans, sresult);
1262
    std::cerr << "cp6" << std::endl;
1263
    exampleSimple3a(processor, trans, sresult);
1264
    std::cerr << "cp7" << std::endl;
1265
    testApplyTemplatesString1(trans, sresult);
1266
    std::cerr << "cp8" << std::endl;
1267
    testApplyTemplatesString2(processor, trans, sresult);
1268

    
1269
    testApplyTemplates2a(processor, trans, sresult);
1270

    
1271
    testTransformToString4(processor, trans, sresult);
1272

    
1273
    testCatalog(processor,  sresult);
1274

    
1275
    /*testTransformToString2b(processor, trans, sresult);
1276

1277
    testTransformToString3(processor, trans, sresult);
1278
        
1279
    testTransformFromstring(processor, trans, sresult);
1280

1281
    testTransformFromstring2Err(processor, trans, sresult);      */
1282

    
1283
    testTrackingOfValueReference(processor, trans, sresult);
1284

    
1285
    testTrackingOfValueReferenceError(processor, trans, sresult);
1286

    
1287
    testPackage1(trans, sresult);
1288

    
1289
    testPackage2(trans, sresult);
1290

    
1291
    testXdmNodeOutput(trans, sresult);
1292

    
1293
    exampleParam(processor, trans, sresult);
1294

    
1295
    xmarkTest1(trans, sresult);
1296

    
1297
    xmarkTest2(trans, sresult);
1298
    testCallFunction(processor, trans, sresult);
1299
    testResolveUri(processor, trans, sresult);
1300
    testContextNotRoot(processor, trans, sresult);
1301
    testContextNotRootNamedTemplate(processor, trans, sresult);
1302
    testContextNotRootNamedTemplateValue(processor, trans, sresult);
1303
    testPipeline(processor, sresult);
1304

    
1305
    //Available in PE and EE
1306
    //testTransformToStringExtensionFunc(processor, trans);
1307

    
1308
    delete trans;
1309
    delete processor;
1310
    // processor->release();
1311

    
1312

    
1313
    SaxonProcessor *processor2 = new SaxonProcessor(true);
1314

    
1315
    Xslt30Processor *trans2 = processor2->newXslt30Processor();
1316
    testApplyTemplatesString1(trans2, sresult);
1317
    delete trans2;
1318
    processor2->release();
1319

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

    
1323
    std::list<std::string>::iterator it;
1324
    std::cout << "Failed tests:" << std::endl;
1325
// Make iterate point to begining and incerement it one by one till it reaches the end of list.
1326
    for (it = sresult->failureList.begin(); it != sresult->failureList.end(); it++) {
1327
        //Print the contents
1328
        std::cout << it->c_str() << std::endl;
1329

    
1330
    }
1331

    
1332

    
1333
    return 0;
1334
}
(27-27/28)