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/Saxon.C.API/CMakeLists.txt
46 46
        XsltExecutable.cpp
47 47
        XsltExecutable.h
48 48
        XsltProcessor.cpp
49
        XsltProcessor.h)
49
        XsltProcessor.h SaxoncNewDebug.h SaxoncNewDebug.cpp SaxoncNewDebug.cpp)
50 50

  
51 51
target_link_libraries(Saxon_C_API ${CMAKE_DL_LIBS})
src/main/c/Saxon.C.API/SaxonApiException.cpp
4 4
#include "SaxonApiException.h"
5 5

  
6 6

  
7
#ifdef MEM_DEBUG
8
#define new new(__FILE__, __LINE__)
9
#endif
7 10

  
8 11
  const char * SaxonApiException::what () {
9 12
        return message.c_str();
src/main/c/Saxon.C.API/SaxonApiException.h
12 12
#include <exception>
13 13

  
14 14

  
15

  
15 16
/*! <code>SaxonApiException</code>. An exception thrown by the Saxon s9api API (Java). This is always a C++ wrapper for some other underlying exception in Java
16 17
 * <p/>
17 18
 */
src/main/c/Saxon.C.API/SaxonCProcessor.c
188 188
	return str;
189 189
     }
190 190

  
191
    checkForException( *(environi.env), cpp);
191
    checkForException( *(environi.env));
192 192
    return 0;
193 193
}
194 194

  
src/main/c/Saxon.C.API/SaxonProcessor.cpp
14 14
#include "XdmArray.h"
15 15
#include "XdmAtomicValue.h"
16 16

  
17

  
17 18
//#define DEBUG
18 19
#ifdef DEBUG
19 20
#include <signal.h>
......
22 23
#include <stdio.h>
23 24

  
24 25

  
26
#if defined MEM_DEBUG
27

  
28
void* newImpl(std::size_t sz,char const* file, int line){
29
    static int counter{};
30
    void* ptr= std::malloc(sz);
31
    std::cerr << "Saxon/C Mem test: "<<file << ": " << line << " " <<  ptr << std::endl;
32
    myAlloc.push_back(ptr);
33
    return ptr;
34
}
35

  
36
void* operator new(std::size_t sz,char const* file, int line){
37
return newImpl(sz,file,line);
38
}
39

  
40
void* operator new [](std::size_t sz,char const* file, int line){
41
return newImpl(sz,file,line);
42
}
43

  
44
void operator delete(void* ptr) noexcept{
45
    auto ind= std::distance(myAlloc.begin(),std::find(myAlloc.begin(), myAlloc.end(),ptr));
46
    myAlloc[ind]= nullptr;
47
    std::free(ptr);
48
}
49

  
50
#define new new(__FILE__, __LINE__)
51

  
52
void SaxonProcessor::getInfo(){
53

  
54
    std::cout << std::endl;
55

  
56
    std::cout << "Allocation: " << std::endl;
57
    for (auto i: myAlloc){
58
        if (i != nullptr ) std::cout << " " << i << std::endl;
59
    }
60

  
61
    std::cout << std::endl;
62

  
63
}
64

  
65
#endif
66

  
25 67
//jobject cpp;
26 68
const char *failure;
27 69
sxnc_environment *SaxonProcessor::sxn_environ = 0;
......
37 79
    return message;
38 80
}
39 81

  
82

  
83

  
40 84
SaxonApiException *SaxonProcessor::checkAndCreateException(jclass cppClass) {
41 85
    if (SaxonProcessor::sxn_environ->env->ExceptionCheck()) {
42 86
        SaxonApiException *exception = checkForExceptionCPP(SaxonProcessor::sxn_environ->env, cppClass, nullptr);
......
62 106
        SaxonProcessor::sxn_environ->env->ExceptionClear();
63 107
    }
64 108
    if (exception != nullptr) {
109
        std::cerr<< "saxonProc exception= "<< exception <<std::endl;
65 110
        delete exception;
111
        exception = nullptr;
66 112
    }
67 113

  
68 114
}
......
79 125

  
80 126
void SaxonProcessor::createException(const char * message) {
81 127

  
82
    if(exceptionOccurred()) {
83
        delete exception;
84
        SaxonProcessor::sxn_environ->env->ExceptionClear();
85
    }
128
    exceptionClear();
86 129

  
87 130
    if(message == nullptr) {
88 131
        exception = checkAndCreateException(saxonCAPIClass);
......
302 345
    }
303 346
    if (versionStr != nullptr) {
304 347
        delete versionStr;
348
        versionStr = nullptr;
305 349
    }
306 350
    exceptionClear();
307 351
}
......
609 653
        int verLen = strlen(tempVersionStr) + 22 + strlen(CVERSION) + 1;
610 654
        versionStr = new char[verLen];
611 655
        snprintf(versionStr, verLen, "Saxon/C %s %s %s", CVERSION, "running with", tempVersionStr);
612
        delete tempVersionStr;
656
        SaxonProcessor::sxn_environ->env->ReleaseStringUTFChars(jstr, tempVersionStr);
657

  
613 658

  
614 659
    }
615 660

  
......
691 736
                                                                                SaxonProcessor::sxn_environ->env->NewStringUTF(
692 737
                                                                                        source));
693 738
    if (xdmNodei) {
694
        XdmNode *value = new XdmNode(xdmNodei);
739
        XdmNode *value = nullptr;
740
        value = new XdmNode(xdmNodei);
741
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(xdmNodei);
695 742
        return value;
696 743
    } else if (exceptionOccurred()) {
697 744
        createException();
......
811 858
        //std::cerr<<"SaxonProc: JVM finalized calling !"<<std::endl;
812 859
        finalizeJavaRT(SaxonProcessor::sxn_environ->jvm);
813 860

  
814
        //delete SaxonProcessor::sxn_environ;
861
        delete SaxonProcessor::sxn_environ;
815 862
        /*clearParameters();
816 863
        clearProperties();*/
817 864
    } else {
src/main/c/Saxon.C.API/SaxonProcessor.h
8 8
#ifndef SAXON_PROCESSOR_H
9 9
#define SAXON_PROCESSOR_H
10 10

  
11

  
11 12
#if defined __linux__ || defined __APPLE__
12 13

  
13 14
#include <stdlib.h>
......
25 26
#define CVERSION "1.3.0"
26 27
#define CVERSION_API_NO 130
27 28

  
29

  
30

  
31

  
28 32
#include <string>
29 33
#include <iostream>
30 34
#include <sstream>
......
44 48
//#include "com_saxonica_functions_extfn_PhpCall.h"
45 49
//#include "com_saxonica_functions_extfn_PhpCall_PhpFunctionCall.h"
46 50

  
51
#if defined MEM_DEBUG
52

  
53

  
54
#include <algorithm>
55
#include <cstdlib>
56
#include <new>
57

  
58
static std::vector<void*> myAlloc;
59

  
60
void* newImpl(std::size_t sz,char const* file, int line);
61

  
62
void* operator new(std::size_t sz,char const* file, int line);
63

  
64
void* operator new [](std::size_t sz,char const* file, int line);
65

  
66
void operator delete(void* ptr) noexcept;
67

  
68
#endif
69

  
70

  
47 71
class XsltProcessor;
48 72

  
49 73
class Xslt30Processor;
......
276 300
    */
277 301
    XdmAtomicValue *makeAtomicValue(const char *type, const char *value);
278 302

  
279
#if CVERSION_API_NO >= 123
280

  
281 303
    /**
282 304
        * Make an XdmArray whose members are from string representation
283 305
        * @param input the input array of booleans
......
319 341
    XdmMap *makeMap(std::map<XdmAtomicValue *, XdmValue *> dataMap);
320 342

  
321 343

  
322
#endif
323

  
324 344
    /**
325 345
    * Get the string representation of the XdmValue.
326 346
    * @return char array
......
494 514

  
495 515

  
496 516

  
517

  
518

  
497 519
//	XPathEngine
498 520
//	XQueryEngine
499 521
//	SchemaManager
......
504 526
    std::string cwd; /*!< current working directory */
505 527
    jobject proc; /*!< Java Processor object */
506 528

  
529

  
530

  
531
    static void getInfo();
532

  
507 533
    /*static JavaVM *jvm;*/
508 534

  
509 535
protected:
......
545 571
    static const char *checkException();
546 572
};
547 573

  
574

  
548 575
//===============================================================================================
549 576

  
577

  
578

  
550 579
#endif /* SAXON_PROCESSOR_H */
src/main/c/Saxon.C.API/SaxoncNewDebug.h
1
#ifndef MY_NEW5
2
#define MY_NEW5
3

  
4
#include <algorithm>
5
#include <cstdlib>
6
#include <iostream>
7
#include <new>
8
#include <vector>
9

  
10
std::vector<void*> myAlloc;
11

  
12
extern void* newImpl(std::size_t sz,char const* file, int line){
13
    static int counter{};
14
    void* ptr= std::malloc(sz);
15
    std::cerr << "Saxon/C Mem test: "<<file << ": " << line << " " <<  ptr << std::endl;
16
    myAlloc.push_back(ptr);
17
    return ptr;
18
}
19

  
20
void* operator new(std::size_t sz,char const* file, int line){
21
    return newImpl(sz,file,line);
22
}
23

  
24
void* operator new [](std::size_t sz,char const* file, int line){
25
    return newImpl(sz,file,line);
26
}
27

  
28
void operator delete(void* ptr) noexcept{
29
    auto ind= std::distance(myAlloc.begin(),std::find(myAlloc.begin(),myAlloc.end(),ptr));
30
    myAlloc[ind]= nullptr;
31
    std::free(ptr);
32
}
33

  
34
#define new new(__FILE__, __LINE__)
35

  
36
void dummyFunction(){
37
    int* dummy= new int;
38
}
39

  
40
void getInfo(){
41

  
42
    std::cout << std::endl;
43

  
44
    std::cout << "Allocation: " << std::endl;
45
    for (auto i: myAlloc){
46
        if (i != nullptr ) std::cout << " " << i << std::endl;
47
    }
48

  
49
    std::cout << std::endl;
50

  
51
}
52

  
53

  
54
#endif // MY_NEW5
src/main/c/Saxon.C.API/SchemaValidator.cpp
5 5

  
6 6
//#define DEBUG
7 7

  
8
#ifdef MEM_DEBUG
9
#define new new(__FILE__, __LINE__)
10
#endif
11

  
8 12
SchemaValidator::SchemaValidator() {
9 13
	SaxonProcessor *p = new SaxonProcessor(true);
10 14
	SchemaValidator(p, "");
src/main/c/Saxon.C.API/XPathProcessor.cpp
7 7
#include "XdmMap.h"
8 8
#include "XdmArray.h"
9 9

  
10
#ifdef MEM_DEBUG
11
#define new new(__FILE__, __LINE__)
12
#endif
13

  
10 14
XPathProcessor::XPathProcessor() {
11 15
	SaxonProcessor *p = new SaxonProcessor(false);
12 16
	XPathProcessor(p, "");
src/main/c/Saxon.C.API/XdmFunctionItem.cpp
3 3

  
4 4
#include "XdmFunctionItem.h"
5 5

  
6
#ifdef MEM_DEBUG
7
#define new new(__FILE__, __LINE__)
8
#endif
9

  
6 10
    XdmFunctionItem::XdmFunctionItem():XdmItem(), arity(-1){}
7 11

  
8 12

  
src/main/c/Saxon.C.API/XdmItem.cpp
94 94

  
95 95
XdmItem::~XdmItem() {
96 96
    //decrementRefCount();
97
    //std::cerr<<std::endl<<"XdmItem destructor called, refCount"<<getRefCount()<<std::endl;
98 97

  
99 98
    SaxonProcessor::sxn_environ->env->ExceptionDescribe();
100 99

  
src/main/c/Saxon.C.API/XdmMap.cpp
2 2
#include "XdmAtomicValue.h"
3 3
#include <map>
4 4

  
5
#ifdef MEM_DEBUG
6
#define new new(__FILE__, __LINE__)
7
#endif
8

  
5 9

  
6 10
XdmMap::XdmMap(): XdmFunctionItem() {
7 11

  
src/main/c/Saxon.C.API/XdmNode.cpp
2 2

  
3 3
#include "XdmNode.h"
4 4

  
5
#ifdef MEM_DEBUG
6
#define new new(__FILE__, __LINE__)
7
#endif
8

  
5 9
XdmNode::XdmNode(jobject obj): XdmItem(obj), baseURI(nullptr), nodeName(nullptr), children(nullptr), childCount(-1), parent(nullptr), typedValue(nullptr), attrValues(nullptr), attrCount(-1), nodeKind(UNKNOWN){
6 10

  
7 11
}
src/main/c/Saxon.C.API/XdmValue.cpp
6 6
#include "XdmMap.h"
7 7
#include "XdmArray.h"
8 8

  
9

  
10
#ifdef MEM_DEBUG
11
#define new new(__FILE__, __LINE__)
12
#endif
13

  
14

  
9 15
XdmValue::XdmValue(const XdmValue &other) {
10 16
	//SaxonProcessor *proc = other.proc; //TODO
11 17
	valueType = other.valueType;
......
127 133

  
128 134
XdmValue::~XdmValue() {
129 135
	//bool safeToClear = false;
130
	//std::cout<<"xdmValue destructor size= "<<values.size()<<" ref="<<getRefCount()<<" Pointer = "<<(this)<<std::endl;
131 136
	if(values.size() > 0) {
132 137
        for (size_t i = 0; i < values.size(); i++) {
133 138
            if (values[i] != nullptr) {
src/main/c/Saxon.C.API/XdmValue.h
19 19
#include "SaxonCXPath.h"
20 20

  
21 21

  
22

  
22 23
/*! <code>XdmValue</code>. Value in the XDM data model. A value is a sequence of zero or more items,
23 24
 * each item being either an atomic value or a node. This class is a wrapper of the the XdmValue object created in Java.
24 25
 * <p/>
......
30 31
class XdmNode;
31 32

  
32 33

  
34

  
33 35
typedef enum eXdmType { XDM_VALUE = 1, XDM_ITEM = 2, XDM_NODE = 3, XDM_ATOMIC_VALUE = 4, XDM_FUNCTION_ITEM = 5 } XDM_TYPE;
34 36

  
35 37
typedef enum saxonTypeEnum
......
54 56
        initialize();
55 57
    }
56 58

  
59
    /*void * operator new(size_t size)
60
    {
57 61

  
58
	/**
62
        void * p = ::new XdmValue();
63
        //void * p = malloc(size); will also work fine
64
        std::cerr<< "new called on XdmValue size= " << size << " p="<<p<<std::endl;
65
        return p;
66
    }*/
67

  
68

  
69
    /**
59 70
	 * A copy constructor.
60 71
	 * @param other - Xdmvalue
61 72
	 */
src/main/c/Saxon.C.API/Xslt30Processor.cpp
14 14
#include <typeinfo> //used for testing only
15 15
#endif
16 16

  
17
#ifdef MEM_DEBUG
18
#define new new(__FILE__, __LINE__)
19
#endif
20

  
17 21
Xslt30Processor::Xslt30Processor() {
18 22

  
19 23
	SaxonProcessor *p = new SaxonProcessor(false);
......
58 62
	    clearParameters();
59 63
	    SaxonProcessor::sxn_environ->env->DeleteLocalRef(cppXT);
60 64
	    cwdXT.erase();
65
	    exceptionClear();
61 66
    }
62 67

  
63 68

  
......
111 116
                XdmValue * valuei = it->second;
112 117
                if(valuei != nullptr) {
113 118
                    valuei->decrementRefCount();
114
                    if (valuei->getRefCount() < 1) {
119
                    //if (valuei->getRefCount() < 1) {
115 120
                        delete value;
116
                    }
121
                        value = nullptr;
122
                    //}
117 123
                    parameters.erase(skey);
118 124
                    parameters[skey] = value;
119 125
                    value->incrementRefCount();
......
149 155
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
150 156
#endif
151 157
                    delete value;
158
                    value = nullptr;
152 159

  
153 160
            }
154 161
        }
......
186 193
}
187 194

  
188 195
void Xslt30Processor::createException(const char * message) {
189

  
190

  
191
    if(exception != nullptr) {
192
        delete exception;
193
        SaxonProcessor::sxn_environ->env->ExceptionClear();
194
    }
195

  
196
    exceptionClear();
196 197
    if(message == nullptr) {
197 198
        exception = proc->checkAndCreateException(cppClass);
198 199
    } else {
src/main/c/Saxon.C.API/XsltExecutable.cpp
14 14
#include <typeinfo> //used for testing only
15 15
#endif
16 16

  
17
#ifdef MEM_DEBUG
18
#define new new(__FILE__, __LINE__)
19
#endif
17 20

  
18 21
XsltExecutable::XsltExecutable(jobject exObject, std::string curr) {
19 22

  
......
37 40
    selection = nullptr;
38 41
    selectionV = nullptr;
39 42
    saxonMessageListenerObj = nullptr;
40
    executableObject = exObject;
43
    executableObject = SaxonProcessor::sxn_environ->env->NewGlobalRef(exObject);
41 44
    cwdXE = curr;
42 45
}
43 46

  
......
235 238
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
236 239
#endif
237 240
                    delete value;
241
                    value = nullptr;
238 242
            }
239 243
        }
240 244
    }
......
945 949
                                                                                  "(Ljava/lang/String;Ljava/lang/String;)V");
946 950
        }
947 951
        if (!messageID) {
948
            std::cerr << "Error: "<<"SaxonCMessageListener" << " in " <<getDllname() << " not found\n"
952
            std::cerr << "Error: SaxonCMessageListener" << " in " <<getDllname() << " not found\n"
949 953
                      << std::endl;
950 954
            SaxonProcessor::sxn_environ->env->ExceptionClear();
951 955
        }
952 956

  
957
        jobject tempListenerObj;
953 958
        if (filename == nullptr) {
954
            saxonMessageListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
959
            tempListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
955 960
                                                                                           SaxonProcessor::sxn_environ->env->NewStringUTF("-:on"));
956 961
            //setProperty("m", "on");
957 962
        } else {
958
            saxonMessageListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
963
            tempListenerObj = (jobject)SaxonProcessor::sxn_environ->env->NewObject(messageListenerClass, messageID,
959 964
                                                                                           SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
960 965
        }
966
        if(tempListenerObj) {
967
            saxonMessageListenerObj = SaxonProcessor::sxn_environ->env->NewGlobalRef(tempListenerObj);
968
        } else {
969
            std::cerr << "Error: Failed to create SaxonCMessageListener" <<  std::endl;
970
        }
961 971
    } else {
962 972
        setProperty("m", "off");
963 973
    }
src/main/c/Saxon.C.API/XsltProcessor.cpp
12 12
#include <typeinfo> //used for testing only
13 13
#endif
14 14

  
15
#ifdef MEM_DEBUG
16
#define new new(__FILE__, __LINE__)
17
#endif
18

  
15 19
XsltProcessor::XsltProcessor() {
16 20

  
17 21
	SaxonProcessor *p = new SaxonProcessor(false);
src/main/c/samples/cppTests/build64-mac.sh
58 58

  
59 59
g++ -std=c++14  -m64 -fPIC -I$jdkdir   bin/SaxonCGlue.o bin/SaxonCXPath.o bin/SaxonProcessor.o bin/XQueryProcessor.o bin/XsltProcessor.o bin/XsltExecutable.o bin/Xslt30Processor.o bin/XPathProcessor.o bin/XdmValue.o bin/XdmItem.o bin/XdmNode.o bin/XdmAtomicValue.o bin/XdmArray.o bin/XdmMap.o bin/XdmFunctionItem.o bin/SchemaValidator.o bin/SaxonApiException.o testXSLT.cpp -o testXSLT -ldl  -L.  $1 $2
60 60

  
61
g++ -std=c++14  -m64 -fPIC -I$jdkdir   bin/SaxonCGlue.o bin/SaxonCXPath.o bin/SaxonProcessor.o bin/XQueryProcessor.o bin/XsltProcessor.o bin/XsltExecutable.o bin/Xslt30Processor.o bin/XPathProcessor.o bin/XdmValue.o bin/XdmItem.o bin/XdmNode.o bin/XdmAtomicValue.o bin/XdmArray.o bin/XdmMap.o bin/XdmFunctionItem.o bin/SchemaValidator.o bin/SaxonApiException.o bin/cppExtensionFunction.o testXSLT30.cpp -o testXSLT30 -ldl  -L.  $1 $2
61
g++ -std=c++14  -m64 -fPIC -pthread -I$jdkdir   bin/SaxonCGlue.o bin/SaxonCXPath.o bin/SaxonProcessor.o bin/XQueryProcessor.o bin/XsltProcessor.o bin/XsltExecutable.o bin/Xslt30Processor.o bin/XPathProcessor.o bin/XdmValue.o bin/XdmItem.o bin/XdmNode.o bin/XdmAtomicValue.o bin/XdmArray.o bin/XdmMap.o bin/XdmFunctionItem.o bin/SchemaValidator.o bin/SaxonApiException.o bin/cppExtensionFunction.o testXSLT30.cpp -o testXSLT30 -ldl  -L.  $1 $2
62 62

  
63 63
g++ -std=c++14   -m64 -fPIC -I$jdkdir   bin/SaxonCGlue.o bin/SaxonCXPath.o bin/SaxonProcessor.o bin/XQueryProcessor.o bin/XsltProcessor.o bin/XsltExecutable.o bin/Xslt30Processor.o bin/XPathProcessor.o bin/XdmValue.o bin/XdmItem.o bin/XdmNode.o bin/XdmAtomicValue.o bin/XdmArray.o bin/XdmFunctionItem.o bin/XdmMap.o bin/SchemaValidator.o bin/SaxonApiException.o testXQuery.cpp -o testXQuery -ldl  -L.  $1 $2
64 64

  
src/main/c/samples/cppTests/testXQuery.cpp
3 3
#include "../../Saxon.C.API/XdmItem.h"
4 4
#include "../../Saxon.C.API/XdmNode.h"
5 5
#include "../../Saxon.C.API/XdmAtomicValue.h"
6
#include "../../Saxon.C.API/XdmFunctionItem.h"
7
#include "../../Saxon.C.API/XdmMap.h"
8
#include "../../Saxon.C.API/XdmArray.h"
6 9
#include "CppTestUtils.h"
7 10
#include <string>
8 11

  
9 12
using namespace std;
10 13

  
11

  
14
#ifdef MEM_DEBUG
15
#define new new(__FILE__, __LINE__)
16
#endif
12 17

  
13 18

  
14 19
/*
15 20
* Test1: 
16 21
*/
17
void testxQuery1(SaxonProcessor * processor, XQueryProcessor * queryProc){
18
 cout<<endl<<"Test testXQuery1:"<<endl;
22
void testxQuery1(SaxonProcessor * processor, XQueryProcessor * queryProc, sResultCount *sresult){
23
    cout<<endl<<"Test testXQuery1:"<<endl;
19 24
	queryProc->clearProperties();
20 25
	queryProc->clearParameters(true);
21 26
   queryProc->setProperty("s", "cat.xml");
......
26 31
    if(result != NULL){
27 32
    	cout<<"Result :"<<result<<endl;
28 33
    } else {
34
        if(queryProc->exceptionOccurred()) {
35

  
36
            SaxonApiException *exception = queryProc->getException();
37
            cerr<< "Error: "<<exception->getMessage()<<endl;
38
            delete exception;
39
        }
29 40

  
30
	queryProc->checkException();
31 41
	
32 42
    }
33 43

  
34
return;
44

  
35 45
	queryProc->setcwd(".");
36 46
     queryProc->executeQueryToFile(NULL, "catOutput.xml", NULL);
37 47

  
......
43 53
		}
44 54
}
45 55

  
46
void testxQueryError(XQueryProcessor * queryProc){
56
void testxQueryError(XQueryProcessor * queryProc, sResultCount *sresult){
47 57
 cout<<endl<<"Test testXQueryError-Test:"<<endl;
48 58
	queryProc->clearProperties();
49 59
	queryProc->clearParameters(true);
......
64 74
		}
65 75
}
66 76

  
67
void testxQueryError2(SaxonProcessor * processor, XQueryProcessor * queryProc){
77
void testxQueryError2(SaxonProcessor * processor, XQueryProcessor * queryProc, sResultCount *sresult){
68 78
 cout<<endl<<"Test testXQueryError-test2:"<<endl;
69 79
	queryProc->clearProperties();
70 80
	queryProc->clearParameters(true);
......
88 98
}
89 99

  
90 100

  
91
void testDefaultNamespace(SaxonProcessor * processor, XQueryProcessor * queryProc) {
101
void testDefaultNamespace(SaxonProcessor * processor, XQueryProcessor * queryProc, sResultCount *sresult) {
92 102
 cout<<endl<<"Test testXQuery2:"<<endl;
93 103
	queryProc->clearProperties();
94 104
	queryProc->clearParameters(true);	
......
108 118
}
109 119

  
110 120
// Test that the XQuery compiler can compile two queries without interference
111
void testReusability(SaxonProcessor * processor, XQueryProcessor * queryProc){
121
void testReusability(SaxonProcessor * processor, XQueryProcessor * queryProc, sResultCount *sresult){
112 122
	cout<<endl<<"Test test XQuery reusability:"<<endl;
113 123
	XQueryProcessor * queryProc2 = processor->newXQueryProcessor();
114 124

  
......
169 179

  
170 180

  
171 181
//Test requirement of license file - Test should fail
172
void testXQueryLineNumberError(XQueryProcessor * queryProc){
182
void testXQueryLineNumberError(XQueryProcessor * queryProc, sResultCount *sresult){
173 183
 cout<<endl<<"Test testXQueryLineNumberError:"<<endl;
174 184
	queryProc->clearProperties();
175 185
	queryProc->clearParameters(true);
......
197 207
}
198 208

  
199 209
//Test requirement of license file - Test should succeed
200
void testXQueryLineNumber(){
210
void testXQueryLineNumber(sResultCount *sresult){
201 211
  SaxonProcessor * processor = new SaxonProcessor(true);
202 212
  processor->setConfigurationProperty("l", "on");
203 213
  XQueryProcessor * queryProc = processor->newXQueryProcessor();
......
234 244
    SaxonProcessor * processor = new SaxonProcessor(false);
235 245
    cout<<"Test: XQueryProcessor with Saxon version="<<processor->version()<<endl<<endl;
236 246
    XQueryProcessor * query = processor->newXQueryProcessor();
237
    
238 247

  
239
    testxQuery1(processor, query);
240
    testxQueryError(query);
241
    testxQueryError2(processor, query);
242
    testDefaultNamespace(processor, query);
243
    testReusability(processor, query);
244
    testXQueryLineNumberError(query);
245
    testXQueryLineNumber();
248
    sResultCount *sresult = new sResultCount();
249

  
250
    testxQuery1(processor, query, sresult);
251

  
252
    cout<<endl<<"============================================================="<<endl<<endl;
253

  
254
    testxQueryError(query,sresult);
255

  
256
    cout<<endl<<"============================================================="<<endl<<endl;
257

  
258
    testxQueryError2(processor, query,sresult);
259

  
260
    cout<<endl<<"============================================================="<<endl<<endl;
261
    testDefaultNamespace(processor, query,sresult);
262

  
263
    cout<<endl<<"============================================================="<<endl<<endl;
264
    testReusability(processor, query,sresult);
265
    cout<<endl<<"============================================================="<<endl<<endl;
266
    testXQueryLineNumberError(query,sresult);
267
    cout<<endl<<"============================================================="<<endl<<endl;
268
    testXQueryLineNumber(sresult);
269

  
246 270

  
247 271
    delete query;
248
     processor->release();
272
    processor->release();
273

  
274

  
275
    cout<<endl<<"======================== Test Results ========================"<<endl<<endl;
276

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

  
280
    std::list<std::string>::iterator it;
281
    std::cout << "Failed tests:" << std::endl;
282
    // Make iterate point to beginning and increment it one by one until it reaches the end of list.
283
    for (it = sresult->failureList.begin(); it != sresult->failureList.end(); it++) {
284
        //Print the contents
285
        std::cout << it->c_str() << std::endl;
286

  
287
    }
288

  
289
    delete sresult;
290

  
291
#ifdef MEM_DEBUG
292
    SaxonProcessor::getInfo();
293
#endif
249 294
    return 0;
250 295
}
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;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff