Project

Profile

Help

Revision 4ee4355d

Added by O'Neil Delpratt 5 months ago

Saxon/C bug fixes with exception handling and other

View differences:

src/main/c/samples/cppTests/testXSLT30.cpp
31 31
*/
32 32
void testApplyTemplatesString1(Xslt30Processor *trans, sResultCount *sresult) {
33 33

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

  
37 37
    XsltExecutable *executable = trans->compileFromFile("test.xsl");
......
100 100
        if (output == nullptr) {
101 101
            SaxonProcessor::sxn_environ->env->ExceptionDescribe();
102 102
            printf("result is null ====== FAIL ======  \n");
103
            sresult->failure++;
103 104
            sresult->failureList.push_back("testTransformToStringExnteionFunc");
104 105
        } else {
105 106
            sresult->success++;
......
109 110
        delete output;
110 111
    } else {
111 112
        printf("native Class not foun ====== FAIL ====== ");
113
        sresult->failure++;
112 114
        sresult->failureList.push_back("testTransformToStringExtensionFunc");
113 115
    }
114 116
    delete executable;
......
120 122
*/
121 123
void testApplyTemplatesString2(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
122 124

  
123
    cout << endl << "Test: testApplyTemplatesString2:" << endl;
124
    trans->clearParameters();
125
    cout << "Test: testApplyTemplatesString2:" << endl;
126

  
125 127

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

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

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

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

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

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

  
167
    cout << endl << "Test: TransformToString2a:" << endl;
168
    trans->clearParameters();
169 177
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
170 178

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

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

  
183 195
        if (trans->exceptionOccurred()) {
184
            cerr <<"testApplyTemplates2a error: "<< trans->getErrorMessage() << endl;
196
            cerr <<"testApplyTemplates2a_Error error: "<< trans->getErrorMessage() << endl;
185 197
        }
186 198
        delete input;
187
        cerr<< "testApplyTemplates2a - cp0"<<endl;
188
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
199
        trans->exceptionClear();
189 200
        return;
190 201
    }
191 202

  
192

  
193 203
    sresult->failure++;
194
    cout << endl << "cpp1" << endl;
195
    sresult->failureList.push_back("testApplyTemplates2a");
204
    sresult->failureList.push_back("testApplyTemplates2a_Error");
196 205
    fflush(stdout);
206

  
197 207
    delete executable;
198 208

  
199 209
}
......
205 215
void testTransformToString2b(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
206 216

  
207 217
    cout << endl << "Test: TransformToString2b:" << endl;
208
    trans->clearParameters();
209 218

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

  
212 221
    if(result== nullptr) {
222
        if(trans->exceptionOccurred()) {
223
            cerr<<"Expected failure = "<<trans->getErrorMessage()<<endl;
224
        }
213 225
        sresult->success++;
226
        trans->exceptionClear();
214 227
        return;
215 228
    }else {
216 229
        delete result;
......
218 231
        sresult->failureList.push_back("testTransformToString2b");
219 232
        cerr << "testTransformToString2b NULL found" << endl;
220 233
        if (trans->exceptionOccurred()) {
221
            cerr <<"testTransformToString2b error: "<< trans->getErrorMessage() << endl;
234
            cerr <<"Error: "<< trans->getErrorMessage() << endl;
222 235
        }
223 236
        trans->exceptionClear();
224 237
        return;
......
234 247
*/
235 248
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
236 249

  
237
    cout << endl << "Test: TransformToString3: param size=" << trans->getParameters().size() << endl;
238
    trans->clearParameters();
250
    cout << endl << "Test: TransformToString3" << endl;
239 251

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

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

  
247 263
        return;
......
249 265

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

  
252

  
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
    }
253 278

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

  
......
265 290
    }
266 291

  
267 292

  
268

  
269
    trans->setParameter("numParam", (XdmValue *) value1);
270

  
271
    cerr << "testTransformToString3  test test " << endl;
293
    executable->setParameter("numParam", (XdmValue *) value1);
272 294

  
273 295
    executable->setInitialMatchSelection((XdmNode *) inputi);
274 296
    const char *output = executable->applyTemplatesReturningString();
......
282 304
    }
283 305
    fflush(stdout);
284 306

  
285
    cout<<"value 1 object ref="<<(value1)<<endl;
286 307
    delete value1;
308
    delete inputi;
287 309
    delete executable;
288 310

  
289 311
}
......
294 316
*/
295 317
void testTransformToString4(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
296 318

  
297
    cout << endl << "Test: testTransformToString4:" << endl;
298
    cout << endl << "cpp0-1" << endl;
299
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
300

  
301
    trans->clearParameters();
302
    cout << endl << "cpp0-2" << endl;
303
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
319
    cout <<  "Test: testTransformToString4:" << endl;
304 320

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

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

  
314 330

  
315 331
    XdmValue *values = new XdmValue();
316
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(10));
317
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(5));
318
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(6));
319
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(7));
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);
320 340

  
321
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
322 341

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

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

  
......
340 359
    const char *output = executable->applyTemplatesReturningString();
341 360
    if (output== nullptr) {
342 361
        printf("result is null \n");
362
        sresult->failure++;
343 363
        sresult->failureList.push_back("testTransformToString4");
344 364
    } else {
345 365
        printf("%s", output);
......
348 368
    }
349 369
    fflush(stdout);
350 370
    delete sheet;
351
    delete executable;*/
371
    delete executable;
352 372
    delete input;
353 373
    delete values;
354 374

  
355 375
}
356 376

  
357 377
void testTransformFromstring(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
358
    cout << endl << "Test: testTransfromFromstring: param size="<< trans->getParameters().size() << endl;
359
    trans->clearParameters();
378
    cout << endl << "Test: testTransfromFromstring: "<< endl;
379

  
360 380
    if(processor == nullptr) {
361 381
        cout<<" processor is null"<<endl;
362 382
        return;
......
389 409
        return;
390 410
    }
391 411

  
392
    cout<<" checkpoint 00"<<endl;
393

  
394 412
    const char *output = executable->transformToString((XdmNode *) input);
395 413
    if (output== nullptr) {
396 414
        printf("result is null ====== FAIL ====== \n");
415
        sresult->failure++;
397 416
        sresult->failureList.push_back("testTransformFromString");
398 417
        if (trans->exceptionOccurred()) {
399 418
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
......
401 420
    } else {
402 421
        printf("%s", output);
403 422
        printf("result is OK \n");
423
        sresult->success++;
404 424
        delete output;
405 425
    }
406 426
    fflush(stdout);
407

  
408 427
    delete input;
409 428
    delete executable;
410 429

  
......
414 433
//Test case has error in the stylesheet
415 434
void testTransformFromstring2Err(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
416 435
    cout << endl << "Test: testTransfromFromstring2-Error:" << endl;
417
    trans->clearParameters();
418

  
419
    XdmNode *input = processor->parseXmlFromString(
420
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
421 436

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

  
425 440
    if(executable== nullptr) {
426
        sresult->failure++;
427
        sresult->failureList.push_back("testTransformFromstring2Err");
428
        cerr << "testTransformFromstring2Err NULL found" << endl;
441
        sresult->success++;
442

  
429 443
        if (trans->exceptionOccurred()) {
430
            cerr <<"testTransformFromstring2Err error: "<< trans->getErrorMessage() << endl;
444
            cerr <<"Error expected: "<< trans->getErrorMessage() << endl;
431 445
        }
432 446
        return;
433 447
    }
434 448

  
435
    executable->setInitialMatchSelection((XdmValue *) input);
436
    const char *output = executable->applyTemplatesReturningString();
437
    if (output== nullptr) {
438
        printf("result is null ====== FAIL ======  \n\nCheck For errors:\n");
439
        sresult->failureList.push_back("testTransformFromstring2Err");
440
        if (executable->exceptionOccurred()) {
441
            cout << "Error message=" << executable->getErrorMessage() << endl;
442
        }
443
    } else {
444
        printf("%s", output);
445
        printf("result is OK \n");
446
    }
447
    fflush(stdout);
448
    delete output;
449 449

  
450
    trans->exceptionClear();
451
    delete input;
450
    sresult->failure++;
451
    sresult->failureList.push_back("testTransfromFromstring2-Error");
452 452
    delete executable;
453 453

  
454 454
}
455 455

  
456 456
void testTrackingOfValueReference(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
457
    trans->clearParameters();
458 457

  
459 458
    cout << endl << "Test: TrackingOfValueReference:" << endl;
460 459
    ostringstream test;
......
472 471
        test.str("");
473 472
        valStr.str("");
474 473
        name.str("");
474

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

  
480
        }
475 481
    }
476 482

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

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

  
......
509 520
    ostringstream test;
510 521
    ostringstream valStr;
511 522
    ostringstream name;
512
    for (int i = 0; i < 10; i++) {
523
    for (int i = 0; i < 2; i++) {
513 524
        test << "v" << i;
514 525
        valStr << "<out><person>text1</person><person>text2</person><person>text3</person><value>" << test.str()
515 526
               << "<value></out>";
516 527
        name << "value" << i;
517 528

  
518 529
        XdmValue *values = (XdmValue *) processor->parseXmlFromString(valStr.str().c_str());
519
        trans->setParameter(name.str().c_str(), values);
530
        if(values == nullptr) {
531
            cerr<<"values NULL ====== FAIL ======="<<endl;
532
        } else {
533
            trans->setParameter(name.str().c_str(), values);
534
        }
520 535
        test.str("");
521 536
        valStr.str("");
522 537
        name.str("");
......
526 541

  
527 542
    ostringstream name1;
528 543
    bool errorFound = false;
529
    for (int i = 0; i < 10; i++) {
530
        name1 << "param:value" << i;
544
    for (int i = 0; i < 2; i++) {
545
        name1 << "sparam:value" << i;
531 546
        cout << " i:" << i << " Map size:" << parMap.size() << ", ";
532 547
        try {
533 548
            XdmValue *valuei = parMap.at(name1.str());
......
579 594

  
580 595

  
581 596
void testXdmNodeOutput(Xslt30Processor *trans, sResultCount *sresult) {
582
    trans->clearParameters();
583

  
584 597

  
585 598
    std::cout << "testXdmNodeOutput" << std::endl;
586 599
    XsltExecutable * executable = trans->compileFromString(
......
598 611
        cout << "Result is null ====== FAIL ====== " << endl;
599 612
        sresult->failure++;
600 613
        sresult->failureList.push_back("testXdmNodeOutput-0");
614
        delete rootValue;
615
        delete executable;
601 616
        return;
602 617
    }
603 618
    XdmNode *root = (XdmNode *) rootItem;
......
609 624
    const char *result = executable->callTemplateReturningString("go");
610 625
    if (string(result).find(string("<a/>")) != std::string::npos) {
611 626
        sresult->success++;
627
        delete result;
612 628
    } else {
613 629
        //TODO - this test case prints the XML declaration. Check if this correct
614 630
        sresult->failure++;
615 631
        cout << "testXdmNodeOutputAndString ======= FAIL========" << endl;
616 632
        sresult->failureList.push_back("testXdmNodeOutput");
617 633
    }
634
    delete rootValue;
618 635
    delete executable;
619
    delete result;
620 636

  
621 637
}
622 638

  
......
645 661
    }
646 662
    proc->clearParameters();
647 663
    delete executable;
648

  
649 664
}
650 665

  
651 666
void exampleSimple1Err(Xslt30Processor *proc, sResultCount *sresult) {
......
657 672
            cout << "Error Message= "<< proc->getErrorMessage() << endl;
658 673
        }
659 674
        cout << "Result expected as null " << endl;
675
        proc->exceptionClear();
660 676
        sresult->success++;
661 677
        return;
662 678
    } else {
......
665 681

  
666 682
        delete executable;
667 683
    }
668
    proc->clearParameters();
669 684

  
670 685
}
671 686

  
......
702 717
        sresult->failure++;
703 718
        sresult->failureList.push_back("exampleSimple2");
704 719
    }
705
    proc->clearParameters();
706
    executable->clearParameters();
720

  
707 721
    delete executable;
708 722

  
709 723
}
......
712 726
    cout << "<b>exampleSimple3:</b><br/>" << endl;
713 727
    proc->clearParameters();
714 728

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

  
715 740
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
716 741

  
717 742
   if(executable == nullptr) {
......
720 745
		cout << proc->getErrorMessage() <<endl;
721 746
		
722 747
	}
723

  
748
	sresult->failure++;
749
	sresult->failureList.push_back("exampleSimple3");
724 750
	return;
725

  
726 751
   }
727 752

  
728
    XdmNode *xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
729
    if (xdmNode== nullptr) {
730
        cout << "Error: xdmNode is null'" << endl;
731
        sresult->failure++;
732
        sresult->failureList.push_back("exampleSimple3");
733
        return;
734
    }
735 753
    executable->setInitialMatchSelection((XdmNode *) xdmNode);
736
    cout << "end of exampleSimple3" << endl;
737
    executable->clearParameters();
738

  
739 754
    sresult->success++;
755
    delete xdmNode;
740 756
    delete executable;
741

  
742
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
743

  
744 757
}
745 758

  
746
void exampleSimple3a(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
747
    cout << "<b>exampleSimple3a:</b><br/>" << endl;
748
    proc->clearParameters();
759
void exampleSimple3aError(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
760
    cout << "<b>exampleSimple3aError:</b><br/>" << endl;
749 761

  
750 762
    XsltExecutable * executable = proc->compileFromFile(nullptr);
751 763

  
......
753 765
    if (executable == nullptr) {
754 766

  
755 767

  
756
        cout << "end of exampleSimple3a" << endl;
757
        proc->clearParameters();
768
        cout << "Expected failure of test exampleSimple3aError:" << endl;
769
        if(proc->exceptionOccurred()) {
770
            cout<<proc->getErrorMessage()<<endl;
771
        }
758 772

  
759 773
        sresult->success++;
774
        proc->exceptionClear();
760 775
        return;
761 776
    }
762 777

  
763 778
    cout << "Error: executable is not nullptr'" << endl;
764 779
    sresult->failure++;
765
    sresult->failureList.push_back("exampleSimple3a");
780
    sresult->failureList.push_back("exampleSimple3aError");
766 781
    delete executable;
767 782
    return;
768 783

  
......
770 785
}
771 786

  
772 787
void exampleParam(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
773
    cout << "\nExampleParam:</b><br/>" << endl;
788
    cout << "Test: ExampleParam" << endl;
774 789

  
775 790
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
776 791

  
792

  
793
    if(executable == nullptr) {
794
        cout << "executable is NULL" <<endl;
795
        if(proc->exceptionOccurred()) {
796
            cout << proc->getErrorMessage() <<endl;
797

  
798
        }
799
        sresult->failure++;
800
        sresult->failureList.push_back("exampleParam");
801
        return;
802

  
803
    }
804

  
777 805
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
778 806

  
779 807
    XdmAtomicValue *xdmvalue = saxonProc->makeStringValue("Hello to you");
780
    if (xdmvalue != NULL) {
808
    if (xdmvalue != nullptr) {
781 809

  
782 810
        executable->setParameter("a-param", (XdmValue *) xdmvalue);
783 811

  
784 812
    } else {
785
        cout << "Xdmvalue is null - ====== FAIL =====" << endl;
813
        cout << "Xdmvalue is NULL - ====== FAIL =====" << endl;
786 814
        sresult->failure++;
787
        sresult->failureList.push_back("exampleParam-1");
815
        sresult->failureList.push_back("exampleParam");
816
        if(executable->exceptionOccurred()) {
817
            SaxonApiException * exception = executable->getException();
818
            cerr<<"Error: " << exception->getMessage() <<endl;
819
            delete exception;
820
        }
821
        delete executable;
822
        return;
788 823
    }
789 824
    const char *result = executable->applyTemplatesReturningString();
790
    if (result != NULL) {
825
    if (result != nullptr) {
791 826
        cout << "Output:" << result << endl;
792 827
        sresult->success++;
828
        delete result;
793 829
    } else {
794 830
        cout << "Result is NULL<br/>  ======= fail =====" << endl;
795 831
        sresult->failure++;
796
        sresult->failureList.push_back("exampleParam-2");
832
        sresult->failureList.push_back("exampleParam");
833
        if(executable->exceptionOccurred()) {
834
            SaxonApiException * exception = executable->getException();
835
            cerr<<"Error: " << exception->getMessage() <<endl;
836
            delete exception;
837
        }
838
        delete executable;
839
        return;
797 840
    }
798 841

  
799 842
    //proc->clearParameters();
......
804 847
    const char *result2 = executable->applyTemplatesReturningString();
805 848

  
806 849

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

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

  
814 873
    XdmAtomicValue *xdmValue2 = saxonProc->makeStringValue("goodbye to you");
874

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

  
815 889
    executable->setParameter("a-param", (XdmValue *) xdmValue2);
890
    delete xdmvalue;
891

  
816 892

  
817 893
    const char *result3 = executable->applyTemplatesReturningString();
818
    if (result3 != NULL) {
894
    if (result3 != nullptr) {
819 895
        cout << "Output =" << result3 << endl;
896

  
820 897
        sresult->success++;
898
        delete result3;
899

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

  
825 910
    }
826
    proc->clearParameters();
911
    delete xdmValue2;
912
    delete executable;
913

  
827 914

  
828 915

  
829 916
}
......
900 987

  
901 988
/* XMarkbench mark test q12.xsl with just-in-time=true*/
902 989
void xmarkTest1(Xslt30Processor *proc, sResultCount *sresult) {
903
    cout << "XMarkbench mark test q12.xsl (JIT=true):" << endl;
990
    cout << "Test: xmarkTest1 - XMarkbench mark test q12.xsl (JIT=true):" << endl;
904 991

  
905 992
    proc->setJustInTimeCompilation(true);
906 993

  
......
908 995
    if (result != NULL) {
909 996
        cout << "XdmNode returned" << endl;
910 997
        sresult->success++;
998
        delete result;
911 999
    } else {
912 1000
        printf("result is null \nCheck For errors:");
913 1001
        sresult->failure++;
914 1002
        sresult->failureList.push_back("xmarkTest1");
915
        if (proc->exceptionOccurred() > 0) {
916
            cout << proc->getErrorMessage() << endl;
1003
        if (proc->exceptionOccurred()) {
1004
            cerr << proc->getErrorMessage() << endl;
917 1005
        }
918 1006
    }
919
    proc->clearParameters();
920 1007

  
921 1008

  
922 1009
}
......
924 1011

  
925 1012
/* XMarkbench mark test q12.xsl with just-in-time=true*/
926 1013
void xmarkTest2(Xslt30Processor *proc, sResultCount *sresult) {
927
    cout << "XMarkbench mark test q12.xsl (JIT=true):" << endl;
1014
    cout << "Test: xmarkTest2 - XMarkbench mark test q12.xsl (JIT=true):" << endl;
928 1015

  
929 1016

  
930 1017
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
931 1018
    if (result != NULL) {
932 1019
        cout << "XdmNode returned" << endl;
1020
        sresult->success++;
1021
        delete result;
1022

  
933 1023
    } else {
934 1024
        printf("result is null \nCheck For errors:");
935 1025
        sresult->failure++;
......
938 1028
            cout << proc->getErrorMessage() << endl;
939 1029
        }
940 1030
    }
941
    proc->clearParameters();
942 1031

  
943 1032

  
944 1033
}
945 1034

  
946 1035
/* XMarkbench mark test q12.xsl with just-in-time=true*/
947 1036
void exampleSimple_xmark(Xslt30Processor *proc, sResultCount *sresult) {
948
    cout << "XMarkbench mark test q12.xsl:" << endl;
1037
    cout << "exampleSimple_xmark test - test q12.xsl:" << endl;
949 1038

  
950 1039
    proc->setJustInTimeCompilation(true);
951 1040

  
952 1041
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
953 1042
    if (result != NULL) {
954 1043
        cout << "XdmNode returned" << endl;
1044
        sresult->success++;
955 1045
        delete result;
956 1046
    } else {
957
        printf("result is null \nCheck For errors:");
1047
        printf("Result is null \nCheck For errors:");
958 1048
        if (proc->exceptionOccurred() > 0) {
959 1049
            cout << proc->getErrorMessage() << endl;
960 1050
        }
1051
        sresult->failure++;
1052
        sresult->failureList.push_back("exampleSimple_xmark");
1053
        proc->exceptionClear();
961 1054
    }
962 1055
    proc->clearParameters();
963 1056

  
964 1057
}
965 1058

  
966

  
967 1059
/*
968 1060
* Test saving nd loading a Xslt package
969 1061
*/
970 1062
void testPackage1(Xslt30Processor *trans, sResultCount *sresult) {
971 1063

  
972
    cout << endl << "Test: Saving and loading Packages:" << endl;
1064
    cout << endl << "Test: testPackage1 - Saving and loading Packages:" << endl;
973 1065
    trans->clearParameters();
974 1066

  
975 1067

  
976 1068
    trans->compileFromFileAndSave("test.xsl", "test1.sef");
977 1069
    const char *output = trans->transformFileToString("cat.xml", "test1.sef");
1070

  
978 1071
    if (output== nullptr) {
979 1072
        printf("result is null \n");
980 1073
        const char *message = trans->getErrorMessage();
......
997 1090
/*
998 1091
* Test saving and loading a Xslt package
999 1092
*/
1000
void testPackage2(Xslt30Processor *trans, sResultCount *sresult) {
1093
void testPackage1a(Xslt30Processor *trans, sResultCount *sresult) {
1001 1094

  
1002
    cout << endl << "Test: Saving and loading Packages2 - Error:" << endl;
1095
    cout << endl << "Test: testPackage1a" << endl;
1003 1096
    trans->clearParameters();
1004 1097

  
1098
    trans->compileFromFileAndSave("test.xsl", "test1a.sef");
1005 1099

  
1006
    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>";
1007

  
1008
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
1009
    const char *output = trans->transformFileToString("cat.xml", "test2.sef");
1100
    XsltExecutable * executable = trans->compileFromFile("test1.sef");
1101
    executable->setInitialMatchSelectionAsFile("cat.xml");
1102
    const char * output = executable->applyTemplatesReturningString();
1010 1103
    if (output== nullptr) {
1011
        printf("result is null as expected \n");
1104
        printf("result is null \n");
1012 1105
        const char *message = trans->getErrorMessage();
1013 1106
        if (message != NULL) {
1014 1107
            cout << "Error message =" << message << endl;
1015 1108
        }
1016
        sresult->success++;
1109
        sresult->failure++;
1110
        sresult->failureList.push_back("testPackage1a");
1111

  
1017 1112
    } else {
1018 1113
        printf("%s", output);
1019 1114
        printf("result is OK \n");
1020
        sresult->failure++;
1021
        sresult->failureList.push_back("testPackage2");
1115
        sresult->success++;
1022 1116
    }
1023 1117
    fflush(stdout);
1024 1118
    delete output;
1025 1119
}
1026 1120

  
1121

  
1122
/*
1123
* Test saving and loading a Xslt package
1124
*/
1125
void testPackage2_Error(Xslt30Processor *trans, sResultCount *sresult) {
1126

  
1127
    cout << endl << "Test: testPackage2_Error:" << endl;
1128

  
1129
    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>";
1130

  
1131
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
1132

  
1133
    if(trans->exceptionOccurred()) {
1134
        const char *message = trans->getErrorMessage();
1135
        if (message != NULL) {
1136
            cout << "Error message =" << message << endl;
1137
        }
1138
        sresult->success++;
1139
        trans->exceptionClear();
1140
        return;
1141

  
1142
    }
1143

  
1144
    sresult->failure++;
1145
    sresult->failureList.push_back("testPackage2_Error");
1146

  
1147
}
1148

  
1027 1149
void testCallFunction(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
1028 1150

  
1029 1151
    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>";
1030 1152
    cout << endl << "Test: testCallFunction:" << endl;
1031 1153
    XsltExecutable * executable = trans->compileFromString(source);
1154

  
1155
    if(executable == nullptr) {
1156
        if(trans->exceptionOccurred()) {
1157
            cerr<<"Error: "<<trans->getErrorMessage()<<endl;
1158

  
1159
        }
1160
        sresult->failure++;
1161
        sresult->failureList.push_back("testCallFunction");
1162
        return;
1163

  
1164

  
1165
    }
1166

  
1032 1167
    XdmValue **valueArray = new XdmValue *[2];
1033 1168

  
1034 1169
    valueArray[0] = (XdmValue *) (proc->makeIntegerValue(2));
......
1042 1177
            cout << "Value in callFunction is not atomic - but expected as atomic value" << endl;
1043 1178
        }
1044 1179
        cout << "testCallFunction ======= FAIL ======" << endl;
1045
        const char *message = executable->getErrorMessage();
1046
        if (message != NULL) {
1047
            cout << "Error message =" << message << endl;
1180
        if(executable->exceptionOccurred()) {
1181
            SaxonApiException * exception = executable->getException();
1182
            cerr<<"Error: " << exception->getMessage() <<endl;
1183
            delete exception;
1048 1184
        }
1049 1185
        sresult->failure++;
1050 1186
        sresult->failureList.push_back("testCallFunction");
......
1070 1206

  
1071 1207
    executable->setResultAsRawValue(false);
1072 1208
    std::map<std::string, XdmValue *> parameterValues;
1073
    parameterValues["a"] = proc->makeIntegerValue(12);
1074
    parameterValues["b"] = proc->makeIntegerValue(5);
1209

  
1210
    XdmAtomicValue * a1 = proc->makeIntegerValue(12);
1211
    XdmAtomicValue * a2 = proc->makeIntegerValue(5);;
1212
    parameterValues["a"] = a1;
1213
    parameterValues["b"] = a2;
1075 1214
    executable->setInitialTemplateParameters(parameterValues, false);
1076 1215
    executable->setInitialMatchSelection(node);
1077 1216
    XdmValue *result = executable->applyTemplatesReturningValue();
1078 1217
    if (result != NULL) {
1079 1218
        sresult->success++;
1080 1219
        cout << "Result=" << result->getHead()->getStringValue() << endl;
1220
        delete result;
1081 1221
    } else {
1082 1222
        sresult->failure++;
1083 1223
    }
1084 1224

  
1085
    executable->clearParameters();
1086
    delete result;
1087 1225
    delete executable;
1088

  
1226
    delete a1;
1227
    delete a2;
1089 1228
}
1090 1229

  
1091 1230
void testResolveUri(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
......
1146 1285
        if (result== nullptr) {
1147 1286

  
1148 1287
            cout << "testCallFunction ======= FAIL ======" << endl;
1149
            const char *message = executable->getErrorMessage();
1150
            if (message != NULL) {
1151
                cout << "Error message =" << message << endl;
1288
            if(executable->exceptionOccurred()) {
1289
                SaxonApiException * exception = executable->getException();
1290
                cerr<<"Error: " << exception->getMessage() <<endl;
1291
                delete exception;
1152 1292
            }
1153 1293
            sresult->failure++;
1154 1294
            sresult->failureList.push_back("testContextNotRoot");
......
1184 1324
    if (result== nullptr) {
1185 1325

  
1186 1326
        cout << "testCallFunction ======= FAIL ======" << endl;
1187
        const char *message = executable->getErrorMessage();
1188
        if (message != NULL) {
1189
            cout << "Error message =" << message << endl;
1327
        if(executable->exceptionOccurred()) {
1328
            SaxonApiException * exception = executable->getException();
1329
            cerr<<"Error: " << exception->getMessage() <<endl;
1330
            delete exception;
1190 1331
        }
1191 1332
        sresult->failure++;
1192 1333
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
......
1222 1363
    if (result== nullptr) {
1223 1364

  
1224 1365
        cout << "testCallFunction ======= FAIL ======" << endl;
1225
        const char *message = executable->getErrorMessage();
1226
        if (message != NULL) {
1227
            cout << "Error message =" << message << endl;
1366
        if(executable->exceptionOccurred()) {
1367
            SaxonApiException * exception = executable->getException();
1368
            cerr<<"Error: " << exception->getMessage() <<endl;
1369
            delete exception;
1228 1370
        }
1229 1371
        sresult->failure++;
1230 1372
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
......
1337 1479
    if (stage1->exceptionOccurred()) {
1338 1480
        sresult->failure++;
1339 1481
        sresult->failureList.push_back("testPipeline");
1340
        cout << "Exception message=" << (stage1->getErrorMessage()) << endl;
1482
        if(stage1->exceptionOccurred()) {
1483
            SaxonApiException * exception = stage1->getException();
1484
            cerr<<"Error: " << exception->getMessage() <<endl;
1485
            delete exception;
1486
        }
1341 1487
        return;
1342 1488
    }
1343 1489

  
1344 1490
    if (d1 == nullptr) {
1345
        cout << "ERROR1 :"<< stage1->getErrorMessage() << endl;;
1346 1491
        sresult->failure++;
1347 1492
        sresult->failureList.push_back("testPipeline-0");
1348 1493
        return;
......
1367 1512
    XdmValue *d2 = stage2->applyTemplatesReturningValue();
1368 1513
    if (d2== nullptr) {
1369 1514
        cout << "ERROR-11\n" << endl;
1370
        if (stage2->exceptionOccurred()) {
1371
            const char *message = stage2->getErrorMessage();
1372
            cout << "exception=" << message << endl;
1515
        if(stage2->exceptionOccurred()) {
1516
            SaxonApiException * exception = stage2->getException();
1517
            cerr<<"Error: " << exception->getMessage() <<endl;
1518
            delete exception;
1373 1519
        }
1374 1520
        sresult->failure++;
1375 1521
        sresult->failureList.push_back("testPipeline-2");
......
1381 1527
    if(d3 == nullptr){
1382 1528
        sresult->failure++;
1383 1529
        sresult->failureList.push_back("testPipeline-3");
1384
        if (stage3->exceptionOccurred()) {
1385
            const char *message = stage3->getErrorMessage();
1386
            cout << "exception=" << message << endl;
1530
        if(stage3->exceptionOccurred()) {
1531
            SaxonApiException * exception = stage3->getException();
1532
            cerr<<"Error: " << exception->getMessage() <<endl;
1533
            delete exception;
1387 1534
        }
1388 1535
      }
1389 1536
    stage4->setProperty("!indent", "no");
......
1392 1539
    if(d3== nullptr){
1393 1540
        sresult->failure++;
1394 1541
        sresult->failureList.push_back("testPipeline-1");
1395
        if (stage4->exceptionOccurred()) {
1396
            const char *message = stage4->getErrorMessage();
1397
            cout << "exception=" << message << endl;
1542
        if(stage4->exceptionOccurred()) {
1543
            SaxonApiException * exception = stage4->getException();
1544
            cerr<<"Error: " << exception->getMessage() <<endl;
1545
            delete exception;
1398 1546
        }
1399 1547
        return;
1400 1548
      }
......
1404 1552
    if(sw==NULL){
1405 1553
        sresult->failure++;
1406 1554
        sresult->failureList.push_back("testPipeline-1");
1407
        if (stage5->exceptionOccurred()) {
1408
            const char *message = stage5->getErrorMessage();
1409
            cout << "exception=" << message << endl;
1555
        if(stage5->exceptionOccurred()) {
1556
            SaxonApiException * exception = stage5->getException();
1557
            cerr<<"Error: " << exception->getMessage() <<endl;
1558
            delete exception;
1410 1559
        }
1411 1560
        return;
1412 1561
      }
......
1436 1585

  
1437 1586
            if(trans->getErrorMessage() != nullptr) {
1438 1587
                const char *message = trans->getErrorMessage();
1439
                cout << "exception=" << message << endl;
1588
                cerr << "exception=" << message << endl;
1440 1589
            } else {
1441 1590
                const char *message = proc->getErrorMessage();
1442 1591
                if(message != nullptr) {
1443
                    cout << "exception=" << message << endl;
1592
                    cerr << "exception-proc=" << message << endl;
1444 1593
                }
1445 1594
            }
1446
            }
1595
        }
1596
        sresult->failure++;
1597
        sresult->failureList.push_back("testCatalog");
1598
        trans->exceptionClear();
1447 1599
        return;
1448 1600
    }
1449 1601

  
1450 1602
    executable->setInitialMatchSelectionAsFile("../php/catalog-test/example.xml");
1451
//trans->compileFromFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/test1.xsl");
1603

  
1452 1604
    const char *result = executable->applyTemplatesReturningString();
1453 1605

  
1454 1606
    if(result != NULL) {
1455 1607
        std::cerr << "testCatalog result= " << result << std::endl;
1456 1608
    }
1609
    sresult->success++; // TODO - check the results more carefully
1610

  
1611
    delete executable;
1457 1612

  
1458 1613
}
1459 1614

  
......
1548 1703

  
1549 1704
    testInitialTemplate(processor, trans, sresult);
1550 1705

  
1706

  
1707

  
1551 1708
    exampleSimple1Err(trans, sresult);
1552 1709

  
1553 1710
    exampleSimple1(trans, sresult);
......
1558 1715

  
1559 1716
    exampleSimple3(processor, trans, sresult);
1560 1717

  
1561
    exampleSimple3a(processor, trans, sresult);
1718
    exampleSimple3aError(processor, trans, sresult);
1562 1719

  
1563 1720
    testApplyTemplatesString1(trans, sresult);
1564 1721

  
1565 1722
    testApplyTemplatesString2(processor, trans, sresult);
1566 1723

  
1567
    testApplyTemplates2a(processor, trans, sresult);
1724
    testApplyTemplates2a_Error(processor, trans, sresult);
1568 1725

  
1569 1726
    testTransformToString4(processor, trans, sresult);
1570 1727

  
1571

  
1572 1728
    testCatalog(cwd, processor,  sresult);
1573 1729

  
1574

  
1575 1730
    testTransformToString2b(processor, trans, sresult);
1576 1731

  
1577 1732
    testTransformToString3(processor, trans, sresult);
1578 1733
	
1579 1734
    testTransformFromstring(processor, trans, sresult);
1580 1735

  
1581
    //processor->release();
1582
    delete processor;
1583
    processor->release();
1584
    return 0;
1585

  
1586 1736
    testTransformFromstring2Err(processor, trans, sresult);
1587 1737

  
1588 1738
    testTrackingOfValueReference(processor, trans, sresult);
1589 1739

  
1590
    testTrackingOfValueReferenceError(processor, trans, sresult);
1740
    //testTrackingOfValueReferenceError(processor, trans, sresult);
1591 1741

  
1592 1742
    testPackage1(trans, sresult);
1593 1743

  
1594
    testPackage2(trans, sresult);
1744
    testPackage1a(trans, sresult);
1745

  
1746
    testPackage2_Error(trans, sresult);
1595 1747

  
1596 1748
    testXdmNodeOutput(trans, sresult);
1597 1749

  
1598 1750
    exampleParam(processor, trans, sresult);
1599 1751

  
1752
    //SaxonProcessor::sxn_environ->env->ExceptionDescribe();
1753

  
1754

  
1600 1755
    xmarkTest1(trans, sresult);
1601 1756

  
1602 1757
    xmarkTest2(trans, sresult);
1758

  
1759
    processor->release();
1760
    delete processor;
1761

  
1762
    return 0;
1763

  
1603 1764
    testCallFunction(processor, trans, sresult);
1765

  
1766

  
1767

  
1604 1768
    testResolveUri(processor, trans, sresult);
1605 1769
    testContextNotRoot(processor, trans, sresult);
1606 1770
    testContextNotRootNamedTemplate(processor, trans, sresult);

Also available in: Unified diff