Project

Profile

Help

Revision a69dd173

Added by O'Neil Delpratt 6 months ago

Saxon/C update

View differences:

src/main/c/Saxon.C.API/.idea/Saxon.C.API.iml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2
<module classpath="External" external.linked.project.id="Saxon.C.API" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="Makefile" type="CPP_MODULE" version="4" />
2
<module classpath="External" type="CPP_MODULE" version="4" />
src/main/c/Saxon.C.API/XdmAtomicValue.cpp
17 17
    }
18 18

  
19 19
    XdmAtomicValue::XdmAtomicValue(jobject obj, const char* ty):XdmItem(obj){
20
	valType = std::string(ty);
20
	    valType = std::string(ty);
21
    }
22

  
23
    XdmAtomicValue::~XdmAtomicValue(){
24
        std::cerr<<"XdmAtomicValue destructor called"<<std::endl;
25
        if(!valType.empty()) {
26
            valType.clear();
27
        }
21 28
    }
22 29

  
23 30
    void XdmAtomicValue::setType(const char * ty){
src/main/c/Saxon.C.API/XdmAtomicValue.h
26 26
    XdmAtomicValue(const XdmAtomicValue &d);
27 27

  
28 28

  
29
    virtual ~XdmAtomicValue(){
30
	//std::cerr<<"destructor called fpr XdmAtomicValue"<<std::endl;
31
	    if(!valType.empty()) {
32
		    valType.clear();
33
	    }
34
    }
29
    virtual ~XdmAtomicValue();
35 30

  
36 31
    XdmAtomicValue(jobject);
37 32

  
src/main/c/Saxon.C.API/XdmItem.cpp
16 16
XdmItem::XdmItem(jobject obj){
17 17
	value = obj;
18 18
	xdmSize =1;
19
	refCount =1;
19
	refCount =0;
20 20
}
21 21

  
22 22
bool XdmItem::isAtomic(){
......
63 63
	return value;
64 64
}
65 65

  
66
    const char * XdmItem::getStringValue(){
66
    const char * XdmItem:: getStringValue(){
67 67
        if(stringValue.empty()) {
68 68
    		jclass xdmItemClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmItem");
69 69
    		jmethodID sbmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetMethodID(xdmItemClass,
......
95 95
	}
96 96

  
97 97
XdmItem::~XdmItem() {
98
    //std::cerr<<std::endl<<"XdmItem destructor called, refCount"<<getRefCount()<<std::endl;
98
    decrementRefCount();
99
    std::cerr<<std::endl<<"XdmItem destructor called, refCount"<<getRefCount()<<std::endl;
99 100
    if(getRefCount()<1){
100 101
        if(value !=nullptr && SaxonProcessor::jvmCreatedCPP>0) {
101 102
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(value);
102 103
        }
103
        free(value);
104

  
104 105
        if(stringValue.empty()) {
105 106
            stringValue.clear();
106 107
        }
src/main/c/Saxon.C.API/XdmNode.h
36 36
	XdmNode(XdmNode *parent, jobject, XDM_NODE_KIND);
37 37

  
38 38
	virtual ~XdmNode() {
39
        std::cerr<<"XdmNode destructor called"<<std::endl;
39 40
		if (getRefCount() <1){
40
				delete baseURI;
41
		    delete baseURI;
41 42
			delete nodeName;
42 43
		}
43 44

  
src/main/c/Saxon.C.API/XdmValue.cpp
9 9
XdmValue::XdmValue(const XdmValue &other) {
10 10
	//SaxonProcessor *proc = other.proc; //TODO
11 11
	valueType = other.valueType;
12
	refCount = 1;
12
	refCount = 0;
13 13
	xdmSize = other.xdmSize;
14 14
	jValues = other.jValues;
15 15
	toStringValue = other.toStringValue;
......
62 62

  
63 63
XdmValue::XdmValue(jobject val) {
64 64
	XdmItem * value = new XdmItem(val);
65
	values.resize(0);//TODO memory issue might occur here
65
	values.resize(0);//TODO memory issue might occur here. Need to delete XdmItems
66 66
	values.push_back(value);
67 67
	xdmSize++;
68 68
	jValues = nullptr;
......
127 127

  
128 128
XdmValue::~XdmValue() {
129 129
	bool safeToClear = false;
130
	std::cout<<"xdmValue destructor size= "<<values.size()<<" ref="<<getRefCount()<<std::endl;
130 131
    if(getRefCount()<1){
132
        std::cout<<"xdmValue destructor refCount="<<getRefCount()<<" values.size="<<values.size()<<std::endl;
131 133
	//proc->env->ReleaseObject
132 134
	for (size_t i = 0; i < values.size(); i++) {
135
	    values[i]->decrementRefCount();
136
        std::cout<<"xdmItem (XdmValue destructor) refCount="<<values[i]->getRefCount()<<std::endl;
133 137
		if (values[i] != nullptr && values[i]->getRefCount() < 1) {
134 138
			delete values[i];
135 139
			safeToClear = true;
......
142 146
	}
143 147
	if (valueType != nullptr) { delete valueType; }
144 148
	if (jValues) {
149
        std::cout<<"xdmValue jni"<<getRefCount()<<std::endl;
145 150
		SaxonProcessor::sxn_environ->env->DeleteLocalRef(jValues);  //TODO check - this maybe should be DeleteGlobalRef  - check where it is created
146 151
	}
147 152
	xdmSize = 0;
148
	if(!toStringValue.empty()) {
149
		toStringValue.clear();
150
	}
153

  
154
    }
155

  
156
    if(!toStringValue.empty()) {
157
        toStringValue.clear();
151 158
    }
159
    std::cout<<"end - xdmValue destructor refCount="<<getRefCount()<<std::endl;
152 160

  
153 161
}
154 162

  
155 163
void XdmValue::addXdmItem(XdmItem* val) {
156 164
	if (val != nullptr) {
157 165
		values.push_back(val);
166
        val->incrementRefCount();
158 167
		xdmSize++;
159 168
		jValues = nullptr; //TODO clear jni array from memory if needed
160 169
	}
......
163 172

  
164 173
void XdmValue::addUnderlyingValue(jobject val) {
165 174
	XdmItem * valuei = new XdmItem(val);
175
	valuei->incrementRefCount();
166 176
	values.push_back(valuei);
167 177
	xdmSize++;
168 178
	jValues = nullptr; //TODO clear jni array from memory if needed
......
171 181

  
172 182
void XdmValue::incrementRefCount() {
173 183
		refCount++;
174
		//std::cerr<<"refCount-inc-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
184
		std::cerr<<"refCount-inc-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
175 185
	}
176 186

  
177 187
void XdmValue::decrementRefCount() {
178 188
		if (refCount > 0)
179 189
			refCount--;
180
		//std::cerr<<"refCount-dec-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
190
		std::cerr<<"refCount-dec-xdmVal="<<refCount<<" ob ref="<<(this)<<std::endl;
181 191
	}
182 192

  
183 193

  
src/main/c/Saxon.C.API/XdmValue.h
178 178
protected:
179 179
   inline void initialize() noexcept {
180 180
    jValues   = nullptr;
181
       refCount  = 1;
181
    refCount  = 0;
182 182
    valueType = nullptr;
183 183
    xdmSize   = 0;
184 184
  }
src/main/c/Saxon.C.API/Xslt30Processor.cpp
132 132

  
133 133

  
134 134
void Xslt30Processor::clearParameters(bool delValues) {
135

  
135 136
	if(delValues){
136 137
       		for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
137 138
			
......
323 324
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
324 325
						node->getUnderlyingValue(), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
325 326
		if (!executableObject) {
326
			proc->checkAndCreateException(cppClass);
327
			exception = proc->checkAndCreateException(cppClass);
327 328
			return nullptr;
328 329
		}
329 330
		if (comboArrays.stringArray != nullptr) {
......
363 364
						SaxonProcessor::sxn_environ->env->NewStringUTF(cwdXT.c_str()),
364 365
						SaxonProcessor::sxn_environ->env->NewStringUTF(source), jitCompilation, comboArrays.stringArray, comboArrays.objectArray));
365 366
		if (!executableObject) {
366
			proc->checkAndCreateException(cppClass);
367
			exception = proc->checkAndCreateException(cppClass);
367 368
     		return nullptr;
368 369
		}
369 370
		if (comboArrays.stringArray != nullptr) {
......
407 408
                                                                           stylesheet), jitCompilation,
408 409
                                                                   comboArrays.stringArray, comboArrays.objectArray));
409 410
        if (!executableObject) {
410
            proc->checkAndCreateException(cppClass);
411
            exception = proc->checkAndCreateException(cppClass);
411 412
            return nullptr;
412 413

  
413 414
        }
src/main/c/Saxon.C.API/XsltExecutable.cpp
49 49
        if (selectionV->getRefCount() == 0) {
50 50
            delete selectionV;
51 51
        }
52
    } else {
53
        if (selection) {
54
            SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
55
        }
52 56
    }
53 57
    SaxonProcessor::sxn_environ->env->DeleteGlobalRef(executableObject);
54 58

  
......
129 133

  
130 134
void XsltExecutable::setInitialMatchSelectionAsFile(const char *filename) {
131 135
    if (filename != nullptr) {
132
        selection = SaxonProcessor::sxn_environ->env->NewStringUTF(filename);
136
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
137

  
133 138
    }
134 139
}
135 140

  
......
169 174
void XsltExecutable::setInitialTemplateParameters(std::map<std::string, XdmValue *> _itparameters, bool _tunnel) {
170 175
    for (std::map<std::string, XdmValue *>::iterator itr = _itparameters.begin(); itr != _itparameters.end(); itr++) {
171 176
        parameters["itparam:" + std::string(itr->first)] = itr->second;
177
        itr->second->incrementRefCount();
172 178
    }
173 179
    tunnel = _tunnel;
174 180
    if (tunnel) {
......
246 252
            }
247 253
        }
248 254

  
249
        SaxonProcessor::sxn_environ->env->DeleteLocalRef(selection);
255
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
250 256
        selection = nullptr;
251 257
    } else {
252 258
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
......
1026 1032
    if (tftMID == nullptr) {
1027 1033
        tftMID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
1028 1034
                                                                                 "transformToString",
1029
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;");
1035
                                                                                 "(Ljava/lang/String;Lnet/sf/saxon/option/cpp/Xslt30Processor;Lnet/sf/saxon/s9api/XsltExecutable;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/Object;)[B");
1030 1036
    }
1031 1037
    if (!tftMID) {
1032
        std::cerr << "Error: " << getDllname() << "transformFileToString" << " not found\n"
1038
        std::cerr << "Error: " << getDllname() << "transformToString" << " not found\n"
1033 1039
                  << std::endl;
1034 1040

  
1035 1041
    } else {
1036 1042
        JParameters comboArrays;
1037 1043
        comboArrays = SaxonProcessor::createParameterJArray(parameters, properties);
1038 1044

  
1039
        jstring result = nullptr;
1045
        jbyteArray result = nullptr;
1040 1046
        jobject obj = SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(cppClass, tftMID,
1041 1047
                                                                               SaxonProcessor::sxn_environ->env->NewStringUTF(
1042 1048
                                                                                       cwdXE.c_str()), nullptr,
......
1044 1050
                                                                               (source != nullptr
1045 1051
                                                                                ? SaxonProcessor::sxn_environ->env->NewStringUTF(
1046 1052
                                                                                               source) : nullptr),
1053
                                                                               nullptr,
1047 1054
                                                                               comboArrays.stringArray,
1048 1055
                                                                               comboArrays.objectArray);
1049 1056
        if (comboArrays.stringArray != nullptr) {
......
1051 1058
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(comboArrays.objectArray);
1052 1059
        }
1053 1060
        if (obj) {
1054
            result = (jstring) obj;
1061
            result = (jbyteArray) obj;
1055 1062
        }
1056 1063
        if (result) {
1057
            const char *str = SaxonProcessor::sxn_environ->env->GetStringUTFChars(result,
1058
                                                                                  nullptr);
1064

  
1065
            jboolean isCopy = false;
1066
            jbyte* b = SaxonProcessor::sxn_environ->env->GetByteArrayElements(result, &isCopy);
1067
            jsize num_bytes = SaxonProcessor::sxn_environ->env->GetArrayLength(result);
1068

  
1069
            const char *str = new char[num_bytes];
1070
            memcpy ((void *) str, b , num_bytes );
1071

  
1059 1072
            SaxonProcessor::sxn_environ->env->DeleteLocalRef(obj);
1060 1073
            return str;
1061 1074
        }
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