Project

Profile

Help

Revision 55b80284

Added by O'Neil Delpratt 5 months ago

Saxon/C added memory debugging and bug fixes

View differences:

src/main/c/samples/cppTests/testXSLT30.cpp
1

  
1 2
#include <sstream>
2 3
#include <stdio.h>
4

  
3 5
#include "../../Saxon.C.API/SaxonProcessor.h"
4 6
#include "../../Saxon.C.API/XdmValue.h"
5 7
#include "../../Saxon.C.API/XdmItem.h"
6 8
#include "../../Saxon.C.API/XdmNode.h"
7 9
#include "../../Saxon.C.API/XdmFunctionItem.h"
10
#include "../../Saxon.C.API/XdmMap.h"
11
#include "../../Saxon.C.API/XdmArray.h"
8 12
#include "cppExtensionFunction.h"
9 13
#include "CppTestUtils.h"
10 14
#include <string>
......
12 16

  
13 17

  
14 18

  
19

  
15 20
using namespace std;
21

  
22

  
23
#ifdef MEM_DEBUG
24
#define new new(__FILE__, __LINE__)
25
#endif
26

  
27

  
28

  
29

  
30

  
16 31
char fname[] = "_nativeCall";
17 32
char funcParameters[] = "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;";
18 33

  
......
247 262
*/
248 263
void testTransformToString3(SaxonProcessor *processor, Xslt30Processor *trans, sResultCount *sresult) {
249 264

  
250
    cout << endl << "Test: TransformToString3" << endl;
265
    cout << endl << "Test: testTransformToString3" << endl;
251 266

  
252 267
    XdmNode *inputi = processor->parseXmlFromString(
253 268
            "<out><person>text1</person><person>text2</person><person>text3</person></out>");
......
306 321

  
307 322
    delete value1;
308 323
    delete inputi;
324
    inputi = nullptr;
309 325
    delete executable;
310 326

  
311 327
}
......
690 706

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

  
695 710
    XsltExecutable * executable = proc->compileFromFile("../php/xsl/foo.xsl");
696 711
    if(executable== nullptr) {
......
1133 1148
        }
1134 1149
        sresult->failure++;
1135 1150
        sresult->failureList.push_back("testPackage1a");
1151
        trans->exceptionClear();
1136 1152

  
1137 1153
    } else {
1138 1154
        printf("%s", output);
1139 1155
        printf("result is OK \n");
1140 1156
        sresult->success++;
1157
        delete output;
1141 1158
    }
1142 1159
    fflush(stdout);
1143
    delete output;
1160
    delete executable;
1144 1161
}
1145 1162

  
1146 1163

  
......
1202 1219

  
1203 1220
    if (v != NULL && (v->getHead())->isAtomic() && ((XdmAtomicValue *) (v->getHead()))->getLongValue() == 5) {
1204 1221
        sresult->success++;
1222
        delete v;
1205 1223
    } else {
1206 1224
        if (v != NULL && !(v->getHead())->isAtomic()) {
1207 1225
            cout << "Value in callFunction is not atomic - but expected as atomic value" << endl;
......
1216 1234
        }
1217 1235
        sresult->failure++;
1218 1236
        sresult->failureList.push_back("testCallFunction");
1237
        executable->exceptionClear();
1238
        delete v;
1219 1239
    }
1220 1240
    delete valueArray[0];
1221 1241
    delete valueArray[1];
1222 1242
    delete [] valueArray;
1243
    delete executable;
1223 1244
}
1224 1245

  
1225 1246
void testInitialTemplate(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
......
1234 1255
        }
1235 1256
        return;
1236 1257
    }
1237
    XdmNode *node = proc->parseXmlFromString("<e/>");
1258
    XdmNode * node = proc->parseXmlFromString("<e/>");
1238 1259

  
1239 1260
    executable->setResultAsRawValue(false);
1240 1261
    std::map<std::string, XdmValue *> parameterValues;
......
1257 1278
    delete executable;
1258 1279
    delete a1;
1259 1280
    delete a2;
1281
    delete node;
1282
    parameterValues.clear();
1260 1283
}
1261 1284

  
1262 1285
void testResolveUri(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
......
1292 1315
        delete value;
1293 1316
    }
1294 1317

  
1295

  
1318
    delete executable;
1296 1319
}
1297 1320

  
1298 1321
void testContextNotRoot(SaxonProcessor *proc, Xslt30Processor *trans, sResultCount *sresult) {
......
1325 1348

  
1326 1349
                if (result == nullptr) {
1327 1350

  
1328
                    cout << "testCallFunction ======= FAIL ======" << endl;
1351
                    cout << "testContextNotRoot ======= FAIL ======" << endl;
1329 1352
                    if (executable->exceptionOccurred()) {
1330 1353
                        SaxonApiException *exception = executable->getException();
1331 1354
                        cerr << "Error: " << exception->getMessage() << endl;
......
1360 1383

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

  
1386
    if(node == nullptr) {
1387
        if(proc->exceptionOccurred()) {
1388
            const char * message = proc->getErrorMessage();
1389
            if(message != nullptr) {
1390
                cerr << "Error: " << message << endl;
1391
            }
1392
            proc->exceptionClear();
1393
        }
1394
        sresult->failure++;
1395
        sresult->failureList.push_back("testContextNotRootNamedTemplate");
1396
        return;
1397
    }
1398

  
1363 1399
    XsltExecutable * executable = trans->compileFromString(
1364 1400
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:variable name='x' select='.'/><xsl:template match='/'>errorA</xsl:template><xsl:template name='main'>[<xsl:value-of select='name($x)'/>]</xsl:template></xsl:stylesheet>");
1365 1401

  
......
1369 1405
        if(trans->exceptionOccurred()) {
1370 1406
            cout << "Error: "<< trans->getErrorMessage() << endl;
1371 1407
        }
1408
        delete node;
1372 1409
        return;
1373 1410
    }
1374 1411

  
......
1377 1414

  
1378 1415
    if (result== nullptr) {
1379 1416

  
1380
        cout << "testCallFunction ======= FAIL ======" << endl;
1417
        cout << "testContextNotRootNameTemplate ======= FAIL ======" << endl;
1381 1418
        if(executable->exceptionOccurred()) {
1382 1419
            SaxonApiException * exception = executable->getException();
1383 1420
            cerr<<"Error: " << exception->getMessage() <<endl;
......
1389 1426

  
1390 1427
        cout << "testContextNotRoot = " << result << endl;
1391 1428
        sresult->success++;
1429
        delete result;
1392 1430
    }
1431
    delete node;
1432
    delete executable;
1393 1433

  
1394 1434
}
1395 1435

  
......
1399 1439

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

  
1442
    if(node == nullptr) {
1443
        if(proc->exceptionOccurred()) {
1444
            const char * message = proc->getErrorMessage();
1445
            if(message != nullptr) {
1446
                cerr << "Error: " << message << endl;
1447
            }
1448
            proc->exceptionClear();
1449
        }
1450
        sresult->failure++;
1451
        sresult->failureList.push_back("testContextNotRootNamedTemplateValue");
1452
        return;
1453
    }
1454

  
1402 1455
    XsltExecutable * executable = trans->compileFromString(
1403 1456
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:variable name='x' select='.'/><xsl:template match='/'>errorA</xsl:template><xsl:template name='main'>[<xsl:value-of select='name($x)'/>]</xsl:template></xsl:stylesheet>");
1404 1457

  
......
1408 1461
        if(trans->exceptionOccurred()) {
1409 1462
            cout << "Error: "<< trans->getErrorMessage() << endl;
1410 1463
        }
1464
        delete node;
1411 1465
        return;
1412 1466
    }
1413 1467

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

  
1417
    if (result== nullptr) {
1471
    if (result == nullptr) {
1418 1472

  
1419 1473
        cout << "testCallFunction ======= FAIL ======" << endl;
1420 1474
        if(executable->exceptionOccurred()) {
......
1428 1482

  
1429 1483
        cout << "testContextNotRoot = " << result->getHead()->getStringValue() << endl;
1430 1484
        sresult->success++;
1485
        delete result;
1486
        result = nullptr;
1431 1487
    }
1432 1488

  
1489
    delete node;
1490
    delete executable;
1491

  
1492

  
1433 1493
}
1434 1494

  
1435 1495
void testCallSystemFunction(SaxonProcessor *proc, sResultCount *sresult) {
......
1466 1526
    cout << endl << "Test: testPipeline" << endl;
1467 1527

  
1468 1528
    Xslt30Processor * trans = proc->newXslt30Processor();
1529
    if(trans == nullptr) {
1530
        cout << "Error: Xslt30Processor is null - maybe unclean state of JNI" << endl;
1531
        sresult->failure++;
1532
        sresult->failureList.push_back("testPipeline");
1533
        return;
1534
    }
1469 1535
    XsltExecutable * stage1 = trans->compileFromString(
1470 1536
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1471 1537

  
......
1473 1539
        sresult->failure++;
1474 1540
        sresult->failureList.push_back("testPipeline");
1475 1541
        if(trans->exceptionOccurred()) {
1476
            cout << "stage 1 Error: "<< trans->getErrorMessage() << endl;
1542
            const char * message = trans->getErrorMessage();
1543
            cout << "stage 1 Error: " << message << endl;
1544

  
1477 1545
        }
1546
        cout << "Stage 1 Error - exit method " << endl;
1547
        delete trans;
1478 1548
        return;
1479 1549
    }
1480 1550

  
......
1487 1557
        sresult->failure++;
1488 1558
        sresult->failureList.push_back("testPipeline");
1489 1559
        if(trans->exceptionOccurred()) {
1490
            cout << "stage 2 Error: "<< trans->getErrorMessage() << endl;
1560
            const char * message = trans->getErrorMessage();
1561
            cout << "stage 2 Error: " << message << endl;
1562

  
1491 1563
        }
1564
        cout << "Stage 2 Error - exit method " << endl;
1565
        delete stage1;
1566
        delete trans;
1567
        delete inn;
1492 1568
        return;
1493 1569
    }
1570

  
1571

  
1494 1572
    XsltExecutable *stage3 = trans->compileFromString(
1495 1573
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1496 1574

  
......
1498 1576
        sresult->failure++;
1499 1577
        sresult->failureList.push_back("testPipeline");
1500 1578
        if(trans->exceptionOccurred()) {
1501
            cout << "stage 3 Error: "<< trans->getErrorMessage() << endl;
1579
            const char * message = trans->getErrorMessage();
1580
            cout << "stage 3 Error: " << message << endl;
1581

  
1582
        } else {
1583
            cout << "Stage 3 Error: testPipeline failed with exception" << endl;
1502 1584
        }
1585
        cout << "Stage 3 Error - exit method " << endl;
1586
        delete stage1;
1587
        delete stage2;
1588
        delete trans;
1589
        delete inn;
1503 1590
        return;
1504 1591
    }
1592

  
1505 1593
    XsltExecutable *stage4 = trans->compileFromString(
1506 1594
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='/'><a><xsl:copy-of select='.'/></a></xsl:template></xsl:stylesheet>");
1507 1595

  
1508
    if(stage3 == nullptr) {
1596
    if(stage4 == nullptr) {
1509 1597
        sresult->failure++;
1510 1598
        sresult->failureList.push_back("testPipeline");
1511 1599
        if(trans->exceptionOccurred()) {
1512
            cout << "stage 4 Error: "<< trans->getErrorMessage() << endl;
1513
        }
1600
            const char * message = trans->getErrorMessage();
1601
            cout << "stage 4 Error: " << message << endl;
1602

  
1603
        } else {
1604
            cout << "Stage 4 Error: testPipeline failed with exception" << endl;
1605
        }
1606
        cout << "Stage 4 Error - exit method " << endl;
1607
        delete stage1;
1608
        delete stage2;
1609
        delete stage3;
1610
        delete trans;
1611
        delete inn;
1514 1612
        return;
1515 1613
    }
1516 1614

  
......
1521 1619
        sresult->failure++;
1522 1620
        sresult->failureList.push_back("testPipeline");
1523 1621
        if(trans->exceptionOccurred()) {
1524
            cout << "stage 5 Error: "<< trans->getErrorMessage() << endl;
1525
        }
1622
            const char * message = trans->getErrorMessage();
1623
            cout << "stage 5 Error: " << message << endl;
1624

  
1625
        } else {
1626
            cout << "Stage 5 Error: testPipeline failed with exception" << endl;
1627
        }
1628
        cout << "Stage 5     Error - exit method " << endl;
1629
        delete stage1;
1630
        delete stage2;
1631
        delete stage3;
1632
        delete stage4;
1633
        delete trans;
1634
        delete inn;
1526 1635
        return;
1527 1636
    }
1528 1637

  
......
1530 1639
    stage1->setInitialMatchSelection(inn);
1531 1640

  
1532 1641
    XdmValue *d1 = stage1->applyTemplatesReturningValue();
1533
    if (stage1->exceptionOccurred()) {
1534
        sresult->failure++;
1535
        sresult->failureList.push_back("testPipeline");
1536
        if(stage1->exceptionOccurred()) {
1537
            SaxonApiException * exception = stage1->getException();
1538
            cerr<<"Error: " << exception->getMessage() <<endl;
1539
            delete exception;
1642
    if(d1 == nullptr) {
1643
        if (stage1->exceptionOccurred()) {
1644
            sresult->failure++;
1645
            sresult->failureList.push_back("testPipeline");
1646
            if (stage1->exceptionOccurred()) {
1647
                SaxonApiException *exception = stage1->getException();
1648
                if (exception != nullptr) {
1649
                    cerr << "Error: " << exception->getMessage() << endl;
1650
                    delete exception;
1651
                    exception = nullptr;
1652
                }
1653
            }
1654
            cout << "Stage d1 Error - exit method " << endl;
1655
            delete stage1;
1656
            delete stage2;
1657
            delete stage3;
1658
            delete stage4;
1659
            delete stage5;
1660
            delete trans;
1661
            delete inn;
1662
            return;
1540 1663
        }
1541
        return;
1542 1664
    }
1543 1665

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

  
1552 1669
        cout << "d11 is NULL\n" << endl;
1670
        sresult->failure++;
1671
        sresult->failureList.push_back("testPipeline-1");
1672
        delete stage1;
1673
        delete stage2;
1674
        delete stage3;
1675
        delete stage4;
1676
        delete stage5;
1677
        delete d1;
1678
        delete inn;
1679
        delete trans;
1680
        return;
1553 1681
    }
1554
    const char *data = d1->getHead()->toString();
1682
    const char *data = d11->toString();
1555 1683

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

  
1688
        cout << "d1 result Error - toString is NULL" << endl;
1689
        delete stage1;
1690
        delete stage2;
1691
        delete stage3;
1692
        delete stage4;
1693
        delete stage5;
1694
        delete d1;
1695
        delete inn;
1696
        delete trans;
1562 1697
        return;
1563 1698
    }
1564 1699
    stage2->setProperty("!indent", "no");
1565
    stage2->setInitialMatchSelection(d1->getHead());
1700
    stage2->setInitialMatchSelection(d11);
1566 1701
    XdmValue *d2 = stage2->applyTemplatesReturningValue();
1567 1702
    if (d2== nullptr) {
1568 1703
        cout << "ERROR-11\n" << endl;
1569
        if(stage2->exceptionOccurred()) {
1570
            SaxonApiException * exception = stage2->getException();
1571
            cerr<<"Error: " << exception->getMessage() <<endl;
1572
            delete exception;
1573
        }
1574 1704
        sresult->failure++;
1575 1705
        sresult->failureList.push_back("testPipeline-2");
1706
        if (stage2->exceptionOccurred()) {
1707
            SaxonApiException *exception = stage2->getException();
1708
            if (exception != nullptr) {
1709
                cerr << "Error: " << exception->getMessage() << endl;
1710
                delete exception;
1711
                exception = nullptr;
1712
            }
1713
        }
1714
        cout << "Stage d2 Error - exit method " << endl;
1715
        delete d1;
1716
        delete inn;
1717
        delete stage1;
1718
        delete stage2;
1719
        delete stage3;
1720
        delete stage4;
1721
        delete stage5;
1722
        delete trans;
1576 1723
        return;
1577 1724
    }
1578 1725
    stage3->setProperty("!indent", "no");
......
1581 1728
    if(d3 == nullptr){
1582 1729
        sresult->failure++;
1583 1730
        sresult->failureList.push_back("testPipeline-3");
1584
        if(stage3->exceptionOccurred()) {
1585
            SaxonApiException * exception = stage3->getException();
1586
            cerr<<"Error: " << exception->getMessage() <<endl;
1587
            delete exception;
1731
        if (stage3->exceptionOccurred()) {
1732
            SaxonApiException *exception = stage3->getException();
1733
            if (exception != nullptr) {
1734
                cerr << "Error: " << exception->getMessage() << endl;
1735
                delete exception;
1736
                exception = nullptr;
1737
            }
1588 1738
        }
1739
        cout << "Stage d3 Error - exit method " << endl;
1740
        delete d1;
1741
        delete d2;
1742
        delete inn;
1743

  
1744
        delete stage1;
1745
        delete stage2;
1746
        delete stage3;
1747
        delete stage4;
1748
        delete stage5;
1749
        delete trans;
1750
        return;
1589 1751
      }
1590 1752
    stage4->setProperty("!indent", "no");
1591 1753
    stage4->setInitialMatchSelection(d3);
1592 1754
    XdmValue * d4 = stage4->applyTemplatesReturningValue();
1593
    if(d3== nullptr){
1755
    if(d4== nullptr){
1594 1756
        sresult->failure++;
1595
        sresult->failureList.push_back("testPipeline-1");
1596
        if(stage4->exceptionOccurred()) {
1597
            SaxonApiException * exception = stage4->getException();
1598
            cerr<<"Error: " << exception->getMessage() <<endl;
1599
            delete exception;
1757
        sresult->failureList.push_back("testPipeline-4");
1758
        if (stage4->exceptionOccurred()) {
1759
            SaxonApiException *exception = stage4->getException();
1760
            if (exception != nullptr) {
1761
                cerr << "Error: " << exception->getMessage() << endl;
1762
                delete exception;
1763
                exception = nullptr;
1764
            }
1600 1765
        }
1766
        cout << "Stage d4 Error - exit method " << endl;
1767
        delete d3;
1768
        delete d2;
1769
        delete d1;
1770
        delete inn;
1771
        delete stage1;
1772
        delete stage2;
1773
        delete stage3;
1774
        delete stage4;
1775
        delete stage5;
1776
        delete trans;
1601 1777
        return;
1602 1778
      }
1603 1779
    stage5->setProperty("!indent", "no");
1604 1780
    stage5->setInitialMatchSelection(d4);
1605 1781
    const char * sw = stage5->applyTemplatesReturningString();
1606
    if(sw==NULL){
1782
    if(sw == nullptr){
1607 1783
        sresult->failure++;
1608
        sresult->failureList.push_back("testPipeline-1");
1609
        if(stage5->exceptionOccurred()) {
1610
            SaxonApiException * exception = stage5->getException();
1611
            cerr<<"Error: " << exception->getMessage() <<endl;
1612
            delete exception;
1784
        sresult->failureList.push_back("testPipeline-5");
1785
        if (stage5->exceptionOccurred()) {
1786
            SaxonApiException *exception = stage5->getException();
1787
            if (exception != nullptr) {
1788
                cerr << "Error: " << exception->getMessage() << endl;
1789
                delete exception;
1790
            }
1613 1791
        }
1792
        cout << "Stage sw Error - exit method " << endl;
1793
        delete stage1;
1794
        delete stage2;
1795
        delete stage3;
1796
        delete stage4;
1797
        delete stage5;
1798
        delete trans;
1799
        delete d4;
1800
        delete d3;
1801
        delete d2;
1802
        delete d1;
1803
        delete inn;
1614 1804
        return;
1615 1805
      }
1616 1806
    cout<<sw<<endl;
1617 1807
    cout << "testPipeline = " << sw << endl;
1618 1808
    sresult->success++;
1809
    delete stage1;
1810
    stage1 = nullptr;
1811

  
1812
    delete stage2;
1813
    stage2 = nullptr;
1814

  
1815

  
1816
    delete stage3;
1817
    stage3 = nullptr;
1818

  
1819
    delete stage4;
1820
    stage4 = nullptr;
1821

  
1822
    delete stage5;
1823
    stage5 = nullptr;
1824

  
1825
    delete trans;
1826
    trans = nullptr;
1827

  
1828
    delete sw;
1829
    sw = nullptr;
1619 1830

  
1831
    delete d4;
1832
    d4 = nullptr;
1833

  
1834
    delete d3;
1835
    d3 = nullptr;
1836

  
1837
    delete d2;
1838
    d2 = nullptr;
1839

  
1840
    delete d1;
1841
    d1 = nullptr;
1842

  
1843
    delete inn;
1844
    inn = nullptr;
1620 1845

  
1621 1846
}
1622 1847

  
......
1650 1875
        sresult->failure++;
1651 1876
        sresult->failureList.push_back("testCatalog");
1652 1877
        trans->exceptionClear();
1878
        delete trans;
1879
        trans= nullptr;
1653 1880
        return;
1654 1881
    }
1655 1882

  
......
1659 1886

  
1660 1887
    if(result != NULL) {
1661 1888
        std::cerr << "testCatalog result= " << result << std::endl;
1889
        delete result;
1890
        sresult->success++; // TODO - check the results more carefully
1891
    } else {
1892
        sresult->failure++;
1893
        sresult->failureList.push_back("testCatalog");
1662 1894
    }
1663
    sresult->success++; // TODO - check the results more carefully
1895

  
1664 1896

  
1665 1897
    delete executable;
1898
    executable = nullptr;
1899
    delete trans;
1900
    trans = nullptr;
1666 1901

  
1667 1902
}
1668 1903

  
1669 1904
static int NUM_THREADS = 10;
1670 1905

  
1671 1906
void RunThread(XsltExecutable * executable, int tid, const std::string filename) {
1907
    JavaVMAttachArgs att_arg;
1908
    att_arg.version = JNI_VERSION_1_2;
1909
    att_arg.name = NULL;
1910
    att_arg.group = NULL;
1911

  
1912
   // SaxonProcessor::sxn_environ->jvm->AttachCurrentThread((void**)&SaxonProcessor::sxn_environ->env, &att_arg);
1913
    cerr<<endl<<"RunThread cp0,  THEAD ID="<<tid<<endl;
1914
    fflush(stderr);
1915
    fflush(stdout);
1672 1916

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

  
1675
   executable->setInitialMatchSelectionAsFile(filename.c_str());
1917
    if(executable != nullptr) {
1918
       executable->setInitialMatchSelectionAsFile(filename.c_str());
1676 1919

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

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

  
1688
            if (exception != nullptr) {
1689
                const char *message = exception->getMessage();
1690
                if (message != nullptr) {
1691
                    cerr << "Error = " << message << endl;
1922
       const char *result = nullptr;
1923
        result = executable->applyTemplatesReturningString();
1924
        if (result != nullptr) {
1925
            cout << " Result from THREAD ID: " << tid << ", " << result << endl;
1926
            delete result;
1927
        } else {
1928
            cerr << " ===== Failed in THREAD ID: " << tid << endl;
1929
           /* if(executable->exceptionOccurred()) {
1930
                SaxonApiException *exception = executable->getException();
1931

  
1932
                if (exception != nullptr) {
1933
                    const char *message = exception->getMessage();
1934
                    if (message != nullptr) {
1935
                        cerr << "Error = " << message << endl;
1936
                    }
1937
                    delete exception;
1692 1938
                }
1693
            }
1694
        } else {*/
1695
            cerr<<"No exception found - result is nullptr"<<endl;
1696
        //}
1939
            } else {
1940
            cerr << "No exception found - result is nullptr" << endl;
1941
            }*/
1697 1942

  
1943
        }
1944
    delete executable;
1945
    } else {
1946
        cerr << "XsltExecutable is nullptr" << endl;
1698 1947
    }
1699 1948

  
1949
   // (   SaxonProcessor::sxn_environ->jvm)->DetachCurrentThread();
1700 1950

  
1701 1951
}
1702 1952

  
......
1712 1962
    std::vector<std::thread> threads;
1713 1963

  
1714 1964
    for (int i = 0; i < s.size(); i++) {
1965

  
1715 1966
        XsltExecutable * executable = trans->compileFromFile("q12.xsl");
1716
        if(executable != nullptr) {
1717 1967
            threads.push_back(std::thread(RunThread, executable, i, s[i]));
1718
        } else {
1719
            cerr<<"Error : Failed to create thread as executable is NULL"<<endl;
1720
        }
1968

  
1721 1969
    }
1722 1970
    cerr<<"testThreads cp0"<<endl;
1723 1971
    for (auto &th : threads) {
......
1827 2075
	
1828 2076
    testTransformFromstring(processor, trans, sresult);
1829 2077

  
2078

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

  
1832 2081
    testTransformFromstring2Err(processor, trans, sresult);
......
1889 2138

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

  
1892
    testPipeline(processor, sresult);
2141
   testPipeline(processor, sresult);
1893 2142

  
1894 2143

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

  
2146
    fflush(stdout);
2147

  
1897 2148

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

  
1901
    delete trans;
1902
    delete processor;
2152

  
2153

  
1903 2154
    //processor->release();
2155
    //return 0;
1904 2156

  
2157
    fflush(stdout);
1905 2158

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

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

  
1917 2171

  
1918
    testThreads (processor2, trans2, sresult);
1919 2172

  
2173
    //testThreads (processor, trans2, sresult);
1920 2174

  
1921 2175

  
2176
    delete trans;
1922 2177
    delete trans2;
1923
    delete processor2;
1924
    processor2->release();
2178
    processor->release();
2179
    delete processor;
2180

  
1925 2181

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

  
......
1937 2193

  
1938 2194
    }
1939 2195

  
2196
    delete sresult;
2197

  
2198
#ifdef MEM_DEBUG
2199
    SaxonProcessor::getInfo();
2200
#endif
1940 2201

  
1941 2202
    return 0;
1942 2203
}

Also available in: Unified diff