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/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
}

Also available in: Unified diff