Project

Profile

Help

Revision 146cfacb

Added by O'Neil Delpratt 5 months ago

Saxon/C memory management patches

View differences:

src/main/c/samples/cppTests/testXSLT30.cpp
121 121
void testApplyTemplatesString2(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
122 122

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

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

  
......
165 165
void testApplyTemplates2a(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
166 166

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

  
171 171
    if (input == nullptr) {
......
184 184
            cerr <<"testApplyTemplates2a error: "<< trans->getErrorMessage() << endl;
185 185
        }
186 186
        delete input;
187
        cerr<< "testApplyTemplates2a - cp0"<<endl;
188
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
187 189
        return;
188 190
    }
189 191

  
......
203 205
void testTransformToString2b(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
204 206

  
205 207
    cout << endl << "Test: TransformToString2b:" << endl;
206
    trans->clearParameters(true);
208
    trans->clearParameters();
207 209

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

  
......
233 235
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
234 236

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

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

  
241
    XdmAtomicValue *value1 = processor->makeIntegerValue(10);
242

  
243
    trans->setParameter("numParam", (XdmValue *) value1);
244

  
245 243
    if (inputi== nullptr) {
246 244
        cout << "Source document inputi is null. ====== FAIL ====== " << endl;
247 245
        sresult->failureList.push_back("testTransformToString3");
246

  
248 247
        return;
249 248
    }
250 249

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

  
252

  
253

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

  
253 256
    if(executable== nullptr) {
......
261 264
        return;
262 265
    }
263 266

  
267

  
268

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

  
271
    cerr << "testTransformToString3  test test " << endl;
272

  
264 273
    executable->setInitialMatchSelection((XdmNode *) inputi);
265 274
    const char *output = executable->applyTemplatesReturningString();
266 275
    if (output == nullptr) {
......
273 282
    }
274 283
    fflush(stdout);
275 284

  
285
    cout<<"value 1 object ref="<<(value1)<<endl;
276 286
    delete value1;
277 287
    delete executable;
278 288

  
......
288 298
    cout << endl << "cpp0-1" << endl;
289 299
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
290 300

  
291
    trans->clearParameters(true);
301
    trans->clearParameters();
292 302
    cout << endl << "cpp0-2" << endl;
293 303
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
294 304

  
......
346 356

  
347 357
void testTransformFromstring(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
348 358
    cout << endl << "Test: testTransfromFromstring: param size="<< trans->getParameters().size() << endl;
349
    trans->clearParameters(true);
359
    trans->clearParameters();
350 360
    if(processor == nullptr) {
351 361
        cout<<" processor is null"<<endl;
352 362
        return;
......
355 365
    XdmNode *input = processor->parseXmlFromString(
356 366
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
357 367

  
368
    if(input == nullptr) {
369
        sresult->failure++;
370
        sresult->failureList.push_back("testTransformFromstring");
371
        cerr << "testTransformFromstring NULL found" << endl;
372
        if (trans->exceptionOccurred()) {
373
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
374
        }
375
        return;
376
    }
377

  
358 378
    XsltExecutable * executable = trans->compileFromString(
359 379
            "<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>");
360 380

  
361
    if(executable== nullptr || input == nullptr) {
381
    if(executable== nullptr) {
362 382
        sresult->failure++;
363 383
        sresult->failureList.push_back("testTransformFromstring");
364 384
        cerr << "testTransformFromstring NULL found" << endl;
365 385
        if (trans->exceptionOccurred()) {
366 386
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
367 387
        }
388
        delete input;
368 389
        return;
369 390
    }
370 391

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

  
398 419
    XdmNode *input = processor->parseXmlFromString(
399 420
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
......
433 454
}
434 455

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

  
438 459
    cout << endl << "Test: TrackingOfValueReference:" << endl;
439 460
    ostringstream test;
......
481 502

  
482 503
/*Test case should be error.*/
483 504
void testTrackingOfValueReferenceError(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
484
    trans->clearParameters(true);
505
    trans->clearParameters();
485 506

  
486 507
    cout << endl << "Test: TrackingOfValueReference-Error:" << endl;
487 508
    cout << "Parameter Map size: " << (trans->getParameters().size()) << endl;
......
533 554
}
534 555

  
535 556
void testValidation(Xslt30Processor *trans, sResultCount *sresult) {
536
    trans->clearParameters(true);
557
    trans->clearParameters();
537 558

  
538 559

  
539 560

  
......
558 579

  
559 580

  
560 581
void testXdmNodeOutput(Xslt30Processor *trans, sResultCount *sresult) {
561
    trans->clearParameters(true);
582
    trans->clearParameters();
562 583

  
563 584

  
564 585
    std::cout << "testXdmNodeOutput" << std::endl;
......
622 643
        cout << "Result is null ====== FAIL ====== " << endl;
623 644
        sresult->failure++;
624 645
    }
625
    proc->clearParameters(true);
646
    proc->clearParameters();
626 647
    delete executable;
627 648

  
628 649
}
......
644 665

  
645 666
        delete executable;
646 667
    }
647
    proc->clearParameters(true);
668
    proc->clearParameters();
648 669

  
649 670
}
650 671

  
......
681 702
        sresult->failure++;
682 703
        sresult->failureList.push_back("exampleSimple2");
683 704
    }
684
    proc->clearParameters(true);
685
    executable->clearParameters(true);
705
    proc->clearParameters();
706
    executable->clearParameters();
686 707
    delete executable;
687 708

  
688 709
}
689 710

  
690 711
void exampleSimple3(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
691 712
    cout << "<b>exampleSimple3:</b><br/>" << endl;
692
    proc->clearParameters(true);
713
    proc->clearParameters();
693 714

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

  
696
   if(executable== nullptr) {
717
   if(executable == nullptr) {
697 718
	cout << "executable is NULL" <<endl;
698 719
	if(proc->exceptionOccurred()) {
699 720
		cout << proc->getErrorMessage() <<endl;
700 721
		
701 722
	}
723

  
702 724
	return;
703 725

  
704 726
   }
......
712 734
    }
713 735
    executable->setInitialMatchSelection((XdmNode *) xdmNode);
714 736
    cout << "end of exampleSimple3" << endl;
715
    executable->clearParameters(true);
737
    executable->clearParameters();
716 738

  
717 739
    sresult->success++;
718 740
    delete executable;
719 741

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

  
720 744
}
721 745

  
722 746
void exampleSimple3a(SaxonProcessor *saxonProc, Xslt30Processor *proc, sResultCount *sresult) {
723
    cout << "<b>exampleSimple3:</b><br/>" << endl;
724
    proc->clearParameters(true);
747
    cout << "<b>exampleSimple3a:</b><br/>" << endl;
748
    proc->clearParameters();
725 749

  
726 750
    XsltExecutable * executable = proc->compileFromFile(nullptr);
727 751

  
......
730 754

  
731 755

  
732 756
        cout << "end of exampleSimple3a" << endl;
733
        proc->clearParameters(true);
757
        proc->clearParameters();
734 758

  
735 759
        sresult->success++;
736 760
        return;
......
892 916
            cout << proc->getErrorMessage() << endl;
893 917
        }
894 918
    }
895
    proc->clearParameters(true);
919
    proc->clearParameters();
896 920

  
897 921

  
898 922
}
......
914 938
            cout << proc->getErrorMessage() << endl;
915 939
        }
916 940
    }
917
    proc->clearParameters(true);
941
    proc->clearParameters();
918 942

  
919 943

  
920 944
}
......
935 959
            cout << proc->getErrorMessage() << endl;
936 960
        }
937 961
    }
938
    proc->clearParameters(true);
962
    proc->clearParameters();
939 963

  
940 964
}
941 965

  
......
946 970
void testPackage1(Xslt30Processor *trans, sResultCount *sresult) {
947 971

  
948 972
    cout << endl << "Test: Saving and loading Packages:" << endl;
949
    trans->clearParameters(true);
973
    trans->clearParameters();
950 974

  
951 975

  
952 976
    trans->compileFromFileAndSave("test.xsl", "test1.sef");
......
976 1000
void testPackage2(Xslt30Processor *trans, sResultCount *sresult) {
977 1001

  
978 1002
    cout << endl << "Test: Saving and loading Packages2 - Error:" << endl;
979
    trans->clearParameters(true);
1003
    trans->clearParameters();
980 1004

  
981 1005

  
982 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>";
......
1058 1082
        sresult->failure++;
1059 1083
    }
1060 1084

  
1061
    executable->clearParameters(true);
1085
    executable->clearParameters();
1062 1086
    delete result;
1063 1087
    delete executable;
1064 1088

  
......
1546 1570

  
1547 1571

  
1548 1572
    testCatalog(cwd, processor,  sresult);
1549
    processor->release();
1550
    return 0;
1573

  
1551 1574

  
1552 1575
    testTransformToString2b(processor, trans, sresult);
1553 1576

  
......
1555 1578
	
1556 1579
    testTransformFromstring(processor, trans, sresult);
1557 1580

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

  
1558 1585
    testTransformFromstring2Err(processor, trans, sresult);
1559 1586

  
1560 1587
    testTrackingOfValueReference(processor, trans, sresult);

Also available in: Unified diff