Project

Profile

Help

Revision a69dd173

Added by O'Neil Delpratt 6 months ago

Saxon/C update

View differences:

src/main/c/samples/cppTests/testXSLT30.cpp
53 53
        sresult->failure++;
54 54
        fflush(stdout);
55 55
        sresult->failureList.push_back("testApplyTemplatesString1-0");
56
        return;
57 56
    } else if (string(output).find(string("<out>text2</out>")) != std::string::npos) {
58 57
        printf("%s", output);
59 58
        printf("result is OK \n");
60 59
        sresult->success++;
60
        delete output;
61 61
    } else {
62 62
        printf("result is null ====== FAIL ====== \n");
63 63
        sresult->failure++;
64 64
        sresult->failureList.push_back("testApplyTemplatesString1-1");
65
//	std::cout<<"output="<<output<<std::endl;
65
    	std::cout<<"output="<<output<<std::endl;
66
        delete output;
66 67
    }
67 68
    fflush(stdout);
68
    cout<<"checkout XXX0"<<endl;
69
    delete output;
70
    cout<<"checkout XXX1"<<endl;
71 69
    delete executable;
72 70

  
73 71
}
......
104 102
            printf("result is null ====== FAIL ======  \n");
105 103
            sresult->failureList.push_back("testTransformToStringExnteionFunc");
106 104
        } else {
107
            //printf("%s", output);
105
            sresult->success++;
108 106
            printf("result is OK \n");
109 107
        }
110 108
        fflush(stdout);
......
129 127

  
130 128
    if (input== nullptr) {
131 129
        cout << "Source document is null." << endl;
130
        sresult->failure++;
131
        sresult->failureList.push_back("testApplyTemplatesString2");
132
        return;
132 133

  
133 134
    }
134 135
    XsltExecutable * executable = trans->compileFromFile("test.xsl");
135
    if(executable== nullptr) {
136
    if(executable == nullptr) {
136 137
        sresult->failure++;
137 138
        sresult->failureList.push_back("testApplyTemplatesString2");
138
        cerr << "testApplyTemplatesString2 NULL found" << endl;
139 139
        if (trans->exceptionOccurred()) {
140 140
            cerr <<"testApplyTemplatesString2 error: "<< trans->getErrorMessage() << endl;
141 141
        }
142
        delete input;
142 143
        return;
143 144
    }
145

  
144 146
    executable->setInitialMatchSelection((XdmValue *) input);
145 147
    const char *output = executable->applyTemplatesReturningString();
146 148
    if (output== nullptr) {
147 149
        printf("result is null ====== FAIL ======  \n");
148 150
        sresult->failureList.push_back("testApplyTemplatesString2");
149 151
    } else {
152
        sresult->success++;
150 153
        printf("%s", output);
151 154
        printf("result is OK \n");
155
        delete output;
152 156
    }
153 157
    fflush(stdout);
154
    delete output;
155 158
    delete executable;
156 159
}
157 160

  
......
165 168
    trans->clearParameters(true);
166 169
    XdmNode *input = processor->parseXmlFromFile("cat.xml");
167 170

  
168
    if (input== nullptr) {
171
    if (input == nullptr) {
169 172
        cout << "Source document is null. ====== FAIL ======" << endl;
170 173
        sresult->failure++;
171 174
        sresult->failureList.push_back("testApplyTemplates2a");
......
174 177
    XsltExecutable * executable = trans->compileFromFile("test-error.xsl");
175 178

  
176 179
    if(executable== nullptr) {
177
        sresult->failure++;
178
        sresult->failureList.push_back("testApplyTemplates2a");
179
        cerr << "testApplyTemplates2a NULL found" << endl;
180
        printf("result is null \n");
181
        sresult->success++;
182

  
180 183
        if (trans->exceptionOccurred()) {
181 184
            cerr <<"testApplyTemplates2a error: "<< trans->getErrorMessage() << endl;
182 185
        }
186
        delete input;
183 187
        return;
184 188
    }
185 189

  
186
    executable->setInitialMatchSelection((XdmValue *) input);
187
    const char *output = executable->applyTemplatesReturningString();
188
    if (output== nullptr) {
189
        printf("result is null \n");
190
        sresult->success++;
191
    } else {
192
        printf("%s", output);
193
        printf("result is OK - ======= FAIL ======= \n");
194
        sresult->failure++;
195
        sresult->failureList.push_back("testApplyTemplates2a");
196
    }
190

  
191
    sresult->failure++;
192
    sresult->failureList.push_back("testApplyTemplates2a");
197 193
    fflush(stdout);
198
    delete output;
199 194
    delete executable;
200 195

  
201

  
202 196
}
203 197

  
204 198
/*
......
210 204
    cout << endl << "Test: TransformToString2b:" << endl;
211 205
    trans->clearParameters(true);
212 206

  
213
    XdmNode *input = processor->parseXmlFromFile("cat-error.xml");
207
    const char * result  = trans->transformFileToString("cat-error.xml", "test-error.xsl");
214 208

  
215
    if (input== nullptr) {
216
        cout << "Source document is null. ====== FAIL ====== " << endl;
217
        sresult->failureList.push_back("testTransformToString2b");
209
    if(result== nullptr) {
210
        sresult->success++;
218 211
        return;
219
    }
220
    XsltExecutable * executable = trans->compileFromString("test-error.xsl");
221

  
222
    if(executable== nullptr) {
212
    }else {
213
        delete result;
223 214
        sresult->failure++;
224 215
        sresult->failureList.push_back("testTransformToString2b");
225 216
        cerr << "testTransformToString2b NULL found" << endl;
226 217
        if (trans->exceptionOccurred()) {
227 218
            cerr <<"testTransformToString2b error: "<< trans->getErrorMessage() << endl;
228 219
        }
220
        trans->exceptionClear();
229 221
        return;
230 222
    }
231 223

  
232
    executable->setInitialMatchSelection((XdmNode *) input);
233
    const char *output = executable->transformFileToString(NULL);
234
    if (output== nullptr) {
235
        printf("result is null ====== FAIL ======  \nCheck For errors:");
236
        sresult->failureList.push_back("testTransformToString2b");
237
        if (executable->exceptionOccurred()) {
238
            cout << trans->getErrorMessage() << endl;
239
        }
240
    } else {
241
        printf("%s", output);
242
        printf("result is OK \n");
243
    }
244
    fflush(stdout);
245
    delete output;
246

  
247
    trans->exceptionClear();
248
    delete executable;
249 224

  
250 225
}
251 226

  
......
256 231
*/
257 232
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
258 233

  
259
    cout << endl << "Test: TransformToString3:" << endl;
234
    cout << endl << "Test: TransformToString3: param size=" << trans->getParameters().size() << endl;
260 235
    trans->clearParameters(true);
261 236

  
262 237
    XdmNode *inputi = processor->parseXmlFromString(
......
281 256
        if (trans->exceptionOccurred()) {
282 257
            cerr <<"testTransformToString3 error: "<< trans->getErrorMessage() << endl;
283 258
        }
259
        delete value1;
284 260
        return;
285 261
    }
286 262

  
287 263
    executable->setInitialMatchSelection((XdmNode *) inputi);
288 264
    const char *output = executable->applyTemplatesReturningString();
289
    if (output== nullptr) {
265
    if (output == nullptr) {
290 266
        printf("result is null ====== FAIL ====== \n");
291 267
        sresult->failureList.push_back("testTransformToString3");
292 268
    } else {
293 269
        printf("%s", output);
294 270
        printf("result is OK \n");
271
        delete output;
295 272
    }
296 273
    fflush(stdout);
297
    delete output;
274

  
298 275
    delete value1;
299 276
    delete executable;
300 277

  
......
306 283
*/
307 284
void testTransformToString4(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
308 285

  
309
    cout << endl << "Test: TransformToString4:" << endl;
286
    cout << endl << "Test: testTransformToString4:" << endl;
310 287
    trans->clearParameters(true);
311 288

  
312 289
    XdmNode *input = processor->parseXmlFromString(
313 290
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
314 291

  
292
    if (input== nullptr) {
293
        sresult->failure++;
294
        cout << "Source document is null. ====== FAIL ====== " << endl;
295
        sresult->failureList.push_back("testTransformToString4");
296
    }
297

  
298

  
315 299
    XdmValue *values = new XdmValue();
316 300
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(10));
317 301
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(5));
......
319 303
    values->addXdmItem((XdmItem *) processor->makeIntegerValue(7));
320 304

  
321 305

  
322
    if (input== nullptr) {
323
        cout << "Source document is null. ====== FAIL ====== " << endl;
324
        sresult->failureList.push_back("testTransformToString4");
325
    }
326
    XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
306

  
307
   /* XdmNode *sheet = processor->parseXmlFromFile("test2.xsl");
327 308

  
328 309
    XsltExecutable *executable = trans->compileFromXdmNode(sheet);
329 310

  
......
334 315
        if (trans->exceptionOccurred()) {
335 316
            cerr <<"testTransformToString4 error: "<< trans->getErrorMessage() << endl;
336 317
        }
318
        delete values;
337 319
        return;
338 320
    }
339 321

  
340 322
    executable->setParameter("values", (XdmValue *) values);
341 323
    executable->setInitialMatchSelection((XdmNode *) input);
342
    const char *output = executable->applyTemplatesReturningString(/*"test2.xsl"*/);
324
    const char *output = executable->applyTemplatesReturningString();
343 325
    if (output== nullptr) {
344 326
        printf("result is null \n");
345 327
        sresult->failureList.push_back("testTransformToString4");
346 328
    } else {
347 329
        printf("%s", output);
348 330
        printf("result is OK \n");
331
        delete output;
349 332
    }
350 333
    fflush(stdout);
351
    delete output;
352
    delete executable;
334
    delete sheet;
335
    delete executable;*/
353 336
    delete input;
354 337
    delete values;
355 338

  
356 339
}
357 340

  
358 341
void testTransformFromstring(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
359
    cout << endl << "Test: testTransfromFromstring:" << endl;
342
    cout << endl << "Test: testTransfromFromstring: param size="<< trans->getParameters().size() << endl;
360 343
    trans->clearParameters(true);
344
    if(processor == nullptr) {
345
        cout<<" processor is null"<<endl;
346
        return;
361 347

  
348
    }
362 349
    XdmNode *input = processor->parseXmlFromString(
363 350
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
364 351

  
365 352
    XsltExecutable * executable = trans->compileFromString(
366 353
            "<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>");
367 354

  
368
    if(executable== nullptr) {
355
    if(executable== nullptr || input == nullptr) {
369 356
        sresult->failure++;
370 357
        sresult->failureList.push_back("testTransformFromstring");
371 358
        cerr << "testTransformFromstring NULL found" << endl;
......
375 362
        return;
376 363
    }
377 364

  
365
    cout<<" checkpoint 00"<<endl;
366

  
378 367
    const char *output = executable->transformToString((XdmNode *) input);
379 368
    if (output== nullptr) {
380 369
        printf("result is null ====== FAIL ====== \n");
381 370
        sresult->failureList.push_back("testTransformFromString");
371
        if (trans->exceptionOccurred()) {
372
            cerr <<"testTransformFromstring error: "<< trans->getErrorMessage() << endl;
373
        }
382 374
    } else {
383 375
        printf("%s", output);
384 376
        printf("result is OK \n");
385

  
377
        delete output;
386 378
    }
387 379
    fflush(stdout);
388
    delete output;
380

  
389 381
    delete input;
390 382
    delete executable;
391 383

  
......
619 611
    if (result != NULL) {
620 612
        cout << result << endl;
621 613
        sresult->success++;
614
        delete result;
622 615
    } else {
623 616
        cout << "Result is null ====== FAIL ====== " << endl;
624 617
        sresult->failure++;
......
632 625
    cout << "ExampleSimple1Err taken from PHP:" << endl;
633 626

  
634 627
    XsltExecutable * executable = proc->compileFromFile("err.xsl");
635
    if(proc->exceptionOccurred()) {
628
    if(executable == nullptr || proc->exceptionOccurred()) {
629
        if( proc->exceptionOccurred()) {
630
            cout << "Error Message= "<< proc->getErrorMessage() << endl;
631
        }
636 632
        cout << "Result expected as null " << endl;
637 633
        sresult->success++;
634
        return;
638 635
    } else {
639

  
640 636
        sresult->failure++;
641 637
        sresult->failureList.push_back("exampleSimple1Err");
642 638

  
639
        delete executable;
643 640
    }
644 641
    proc->clearParameters(true);
645
    delete executable;
642

  
646 643
}
647 644

  
648 645

  
......
660 657
        }
661 658
        return;
662 659
    }
663
    cout << "exampleSimple2 cp0" << endl;
660

  
664 661
    executable->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
665 662
    const char *filename = "output1.xml";
666 663
    executable->setOutputFile(filename);
......
712 709
    executable->clearParameters(true);
713 710

  
714 711
    sresult->success++;
712
    delete executable;
715 713

  
716 714
}
717 715

  
......
735 733
    cout << "Error: executable is not nullptr'" << endl;
736 734
    sresult->failure++;
737 735
    sresult->failureList.push_back("exampleSimple3a");
736
    delete executable;
738 737
    return;
739 738

  
740 739

  
......
923 922
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
924 923
    if (result != NULL) {
925 924
        cout << "XdmNode returned" << endl;
925
        delete result;
926 926
    } else {
927 927
        printf("result is null \nCheck For errors:");
928 928
        if (proc->exceptionOccurred() > 0) {
......
1052 1052
        sresult->failure++;
1053 1053
    }
1054 1054

  
1055
    executable->clearParameters(true);
1056
    delete result;
1057
    delete executable;
1058

  
1055 1059
}
1056 1060

  
1057 1061
void testResolveUri(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
......
1403 1407
        }
1404 1408
        return;
1405 1409
    }
1406
    //trans->setSourceFromFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/example.xml");
1410

  
1407 1411
    executable->setInitialMatchSelectionAsFile("../php/catalog-test/example.xml");
1408 1412
//trans->compileFromFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/test1.xsl");
1409 1413
    const char *result = executable->applyTemplatesReturningString();
......
1502 1506
        return -1;
1503 1507
    }
1504 1508
    //testValidation(trans,sresult);
1505
    std::cerr << "cp0" << std::endl;
1509

  
1506 1510
    testInitialTemplate(processor, trans, sresult);
1507
    std::cerr << "cp1" << std::endl;
1511

  
1508 1512
    exampleSimple1Err(trans, sresult);
1509
    std::cerr << "cp2" << std::endl;
1513

  
1510 1514
    exampleSimple1(trans, sresult);
1511
    std::cerr << "cp3" << std::endl;
1512 1515

  
1513 1516
    exampleSimple_xmark(trans, sresult);
1514
    std::cerr << "cp4" << std::endl;
1517

  
1515 1518
    exampleSimple2(trans, sresult);
1516
    std::cerr << "cp5" << std::endl;
1519

  
1517 1520
    exampleSimple3(processor, trans, sresult);
1518
    std::cerr << "cp6" << std::endl;
1521

  
1519 1522
    exampleSimple3a(processor, trans, sresult);
1520
    std::cerr << "cp7" << std::endl;
1523

  
1521 1524
    testApplyTemplatesString1(trans, sresult);
1522
    std::cerr << "cp8" << std::endl;
1525

  
1523 1526
    testApplyTemplatesString2(processor, trans, sresult);
1524 1527

  
1525 1528
    testApplyTemplates2a(processor, trans, sresult);
1526 1529

  
1527 1530
    testTransformToString4(processor, trans, sresult);
1531
    processor->release();
1532
    return 0;
1528 1533

  
1529 1534
    testCatalog(cwd, processor,  sresult);
1530 1535

  
1531
    /*testTransformToString2b(processor, trans, sresult);
1536
    testTransformToString2b(processor, trans, sresult);
1532 1537

  
1533 1538
    testTransformToString3(processor, trans, sresult);
1534 1539
	
1535 1540
    testTransformFromstring(processor, trans, sresult);
1536 1541

  
1537
    testTransformFromstring2Err(processor, trans, sresult);      */
1542
    testTransformFromstring2Err(processor, trans, sresult);
1538 1543

  
1539 1544
    testTrackingOfValueReference(processor, trans, sresult);
1540 1545

  
......
1563 1568

  
1564 1569
    delete trans;
1565 1570
    delete processor;
1566
    // processor->release();
1571
    //processor->release();
1567 1572

  
1568 1573

  
1569 1574
    SaxonProcessor *processor2 = new SaxonProcessor(true);

Also available in: Unified diff