Project

Profile

Help

How to connect?
Download (24.5 KB) Statistics
| Branch: | Tag: | Revision:

he / latest9.9 / hec / samples / cppTests / testXSLT.cpp @ 5401a5ae

1
#include <sstream>
2
#include <stdio.h>
3
#include <cstdlib>
4
#include <pthread.h>
5
#include <unistd.h>
6
#include <thread>
7
#include "../../Saxon.C.API/SaxonProcessor.h"
8
#include "../../Saxon.C.API/XdmValue.h"
9
#include "../../Saxon.C.API/XdmItem.h"
10
#include "../../Saxon.C.API/XdmNode.h"
11
#include "cppExtensionFunction.cpp"
12
#include <string>
13

    
14
// TODO: write test case for checking parameters which are null
15

    
16

    
17
using namespace std;
18
char fname[] = "_nativeCall";
19
char funcParameters[] = "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;";
20

    
21
JNINativeMethod cppMethods[] =
22
{
23
    {
24
         fname,
25
         funcParameters,
26
         (void *)&cppNativeCall
27
    }
28
};
29

    
30

    
31
/*
32
* Test transform to String. Source and stylesheet supplied as arguments
33
*/
34
void testTransformToString1(XsltProcessor * trans){
35
        
36
  cout<<endl<<"Test: TransformToString1:"<<endl;
37

    
38
    const char * output = trans->transformFileToString("cat.xml", "test.xsl");
39
   if(output == NULL) {
40
      printf("result is null \n");
41

    
42
    }else {
43
      printf("%s", output);
44
      printf("result is OK \n");
45
    }
46
      fflush(stdout);
47
        delete output;
48

    
49
}
50

    
51
/*
52
* Test transform to String. Source and stylesheet supplied as arguments
53
*/
54
void testTransformToStringExtensionFunc(SaxonProcessor * processor, XsltProcessor * trans){
55
        
56
  cout<<endl<<"Test: TransformToStringExtensionFunc:"<<endl;
57
trans->setProperty("extc", "home/ond1/work/svn/latest9.9-saxonc/samples/cppTests/cppExtensionFunction");
58

    
59
bool nativeFound = processor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/NativeCall",
60
    cppMethods, sizeof(cppMethods) / sizeof(cppMethods[0]));
61
if(nativeFound) {
62
    const char * output = trans->transformFileToString("cat.xml", "testExtension.xsl");
63
//XdmValue* output = trans->transformFileToValue("cat.xml", "testExtension.xsl");
64
   if(output == NULL) {
65
        SaxonProcessor::sxn_environ->env->ExceptionDescribe();
66
      printf("result is null \n");
67

    
68
    }else {
69
      //printf("%s", output);
70
      printf("result is OK \n");
71
    }
72
      fflush(stdout);
73
        delete output;
74
} else{
75
    printf("native Class not foun");
76
}
77
}
78

    
79

    
80

    
81
/*
82
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
83
*/
84
void testTransformToString2(SaxonProcessor * processor, XsltProcessor * trans){
85

    
86
  cout<<endl<<"Test: TransformToString2:"<<endl;
87
  trans->clearParameters(true);
88
  trans->clearProperties();
89
    XdmNode * input = processor->parseXmlFromFile("cat.xml");
90

    
91
   if(input == NULL) {
92
        cout<<"Source document is null."<<endl;
93

    
94
    }
95

    
96
     trans->setSourceFromXdmNode((XdmNode*)input);
97
    const char * output = trans->transformFileToString(NULL, "test.xsl");
98
   if(output == NULL) {
99
      printf("result is null \n");
100

    
101
    }else {
102
      printf("%s", output);
103
      printf("result is OK \n");
104
    }
105
      fflush(stdout);
106
    delete output;
107
}
108

    
109
/*
110
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
111
Should be error. Stylesheet file does not exist
112
*/
113
void testTransformToString2a(SaxonProcessor * processor, XsltProcessor * trans){
114

    
115
  cout<<endl<<"Test: TransformToString2a:"<<endl;
116
  trans->clearParameters(true);
117
  trans->clearProperties();
118
    XdmNode * input = processor->parseXmlFromFile("cat.xml");
119

    
120
   if(input == NULL) {
121
        cout<<"Source document is null."<<endl;
122

    
123
    }
124

    
125
     trans->setSourceFromXdmNode((XdmNode*)input);
126
    const char * output = trans->transformFileToString(NULL, "test-error.xsl");
127
   if(output == NULL) {
128
      printf("result is null \n");
129

    
130
    }else {
131
      printf("%s", output);
132
      printf("result is OK \n");
133
    }
134
      fflush(stdout);
135
    delete output;
136
        
137
        
138

    
139
}
140

    
141
/*
142
* Test transform to String. stylesheet supplied as argument. Source supplied as XdmNode
143
Should be error. Source file does not exist
144
*/
145
void testTransformToString2b(SaxonProcessor * processor, XsltProcessor * trans){
146

    
147
  cout<<endl<<"Test: TransformToString2b:"<<endl;
148
  trans->clearParameters(true);
149
  trans->clearProperties();
150
    XdmNode * input = processor->parseXmlFromFile("cat-error.xml");
151

    
152
   if(input == NULL) {
153
        cout<<"Source document is null."<<endl;
154

    
155
    }
156

    
157
     trans->setSourceFromXdmNode((XdmNode*)input);
158
    const char * output = trans->transformFileToString(NULL, "test-error.xsl");
159
   if(output == NULL) {
160
      printf("result is null \nCheck For errors:");
161
      if(trans->exceptionCount()>0) {
162
        cout<<trans->getErrorMessage(0)<<endl;
163
      }        
164
    }else {
165
      printf("%s", output);
166
      printf("result is OK \n");
167
    }
168
      fflush(stdout);
169
    delete output;
170
        
171
    trans->exceptionClear();
172

    
173
}
174

    
175

    
176
/*
177
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
178
and integer parmater created and supplied
179
*/
180
void testTransformToString3(SaxonProcessor * processor, XsltProcessor * trans){
181

    
182
  cout<<endl<<"Test: TransformToString3:"<<endl;
183
  trans->clearParameters(true);
184
  trans->clearProperties();
185
    XdmNode * inputi = processor->parseXmlFromString("<out><person>text1</person><person>text2</person><person>text3</person></out>");
186

    
187
   XdmAtomicValue * value1 = processor->makeIntegerValue(10);
188

    
189
   trans->setParameter("numParam",(XdmValue *)value1);
190

    
191
   if(inputi == NULL) {
192
        cout<<"Source document inputi is null."<<endl;
193

    
194
    }
195

    
196
    trans->setSourceFromXdmNode((XdmNode*)inputi);
197
    const char * output = trans->transformFileToString(NULL, "test.xsl");
198
   if(output == NULL) {
199
      printf("result is null \n");
200

    
201
    }else {
202
      printf("%s", output);
203
      printf("result is OK \n");
204
    }
205
      fflush(stdout);
206
   delete output;
207

    
208
}
209

    
210
/*
211
* Test transform to String. stylesheet supplied as argument. Source supplied as xml string
212
and integer parmater created and supplied
213
*/
214
void testTransformToString4(SaxonProcessor * processor, XsltProcessor * trans){
215

    
216
  cout<<endl<<"Test: TransformToString4:"<<endl;
217
  trans->clearParameters(true);
218
  trans->clearProperties();
219
    XdmNode * input = processor->parseXmlFromString("<out><person>text1</person><person>text2</person><person>text3</person></out>");
220

    
221
   XdmValue * values = new XdmValue(processor);
222
   values->addXdmItem((XdmItem*)processor->makeIntegerValue(10));
223
  values->addXdmItem((XdmItem*)processor->makeIntegerValue(5));
224
  values->addXdmItem((XdmItem*)processor->makeIntegerValue(6));
225
  values->addXdmItem((XdmItem*)processor->makeIntegerValue(7));
226
   
227
   trans->setParameter("values",(XdmValue *)values);
228

    
229
   if(input == NULL) {
230
        cout<<"Source document is null."<<endl;
231

    
232
    }
233

    
234
    trans->setSourceFromXdmNode((XdmNode*)input);
235
    const char * output = trans->transformFileToString(NULL, "test2.xsl");
236
   if(output == NULL) {
237
      printf("result is null \n");
238

    
239
    }else {
240
      printf("%s", output);
241
      printf("result is OK \n");
242
    }
243
      fflush(stdout);
244
    delete output;
245

    
246
}
247

    
248
void testTransformFromstring(SaxonProcessor * processor, XsltProcessor * trans){
249
cout<<endl<<"Test: testTransfromFromstring:"<<endl;
250
  trans->clearParameters(true);
251
  trans->clearProperties();
252
    XdmNode * input = processor->parseXmlFromString("<out><person>text1</person><person>text2</person><person>text3</person></out>");
253

    
254
   trans->compileFromString("<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>");
255
trans->setSourceFromXdmNode((XdmNode*)input);
256
 const char * output = trans->transformToString();
257
   if(output == NULL) {
258
      printf("result is null \n");
259

    
260
    }else {
261
      printf("%s", output);
262
      printf("result is OK \n");
263

    
264
    }
265
      fflush(stdout);
266
    delete output;
267

    
268

    
269
}
270

    
271
//Test case has error in the stylesheet
272
void testTransformFromstring2Err(SaxonProcessor * processor, XsltProcessor * trans){
273
cout<<endl<<"Test: testTransfromFromstring2-Error:"<<endl;
274
  trans->clearParameters(true);
275
  trans->clearProperties();
276
    XdmNode * input = processor->parseXmlFromString("<out><person>text1</person><person>text2</person><person>text3</person></out>");
277

    
278
   trans->compileFromString("<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>");
279
trans->setSourceFromXdmNode((XdmNode*)input);
280
 const char * output = trans->transformToString();
281
  if(output == NULL) {
282
      printf("result is null \nCheck For errors:\n");
283
      if(trans->exceptionCount()>0) {
284
        cout<<"Error count="<<trans->exceptionCount()<<", "<<trans->getErrorMessage(0)<<endl;
285
     }        
286
    }else {
287
      printf("%s", output);
288
      printf("result is OK \n");
289
    }
290
    fflush(stdout);
291
    delete output;
292

    
293
   trans->exceptionClear();
294

    
295

    
296
}
297

    
298
void testTrackingOfValueReference(SaxonProcessor * processor, XsltProcessor * trans){
299
  trans->clearParameters(true);
300
  trans->clearProperties();
301
 cout<<endl<<"Test: TrackingOfValueReference:"<<endl;
302
ostringstream test;
303
ostringstream valStr;
304
ostringstream name;
305
        for(int i=0; i<10; i++){
306
                test<<"v"<<i;
307
                valStr<<"<out><person>text1</person><person>text2</person><person>text3</person><value>"<<test.str()<<"</value></out>";
308
                name<<"value"<<i;
309
                
310
                XdmValue * values = (XdmValue*)processor->parseXmlFromString(valStr.str().c_str()); 
311
                //cout<<"Name:"<<name.str()<<", Value:"<<values->getHead()->getStringValue()<<endl;
312
                trans->setParameter(name.str().c_str(), values);
313
                test.str("");
314
                valStr.str("");
315
                name.str("");
316
        }
317
        
318
        std::map<std::string,XdmValue*> parMap = trans->getParameters();
319
        if(parMap.size()>0) {
320
cout<<"Parameter size: "<<parMap.size()<<endl;
321
        cout<<"Parameter size: "<<parMap.size()<<endl;//", Value:"<<trans->getParameters()["value0"]->getHead()->getStringValue()<<endl;
322
ostringstream name1;
323
        for(int i =0; i < 10;i++){
324
                name1<<"param:value"<<i;
325
                cout<<" i:"<<i<<" Map size:"<<parMap.size()<<", ";
326
                XdmValue * valuei = parMap[name1.str()];
327
                if(valuei != NULL ){
328
                        cout<<name1.str();
329
                        if(valuei->itemAt(0) != NULL)
330
                                cout<<"= "<<valuei->itemAt(0)->getStringValue();
331
                        cout<<endl;
332
                }
333
                name1.str("");
334
        }
335
        }
336
}
337

    
338
/*Test case should be error.*/
339
void testTrackingOfValueReferenceError(SaxonProcessor * processor, XsltProcessor * trans){
340
  trans->clearParameters(true);
341
  trans->clearProperties();
342
 cout<<endl<<"Test: TrackingOfValueReference-Error:"<<endl;
343
cout<<"Parameter Map size: "<<(trans->getParameters().size())<<endl;
344
ostringstream test;
345
ostringstream valStr;
346
ostringstream name;
347
        for(int i=0; i<10; i++){
348
                test<<"v"<<i;
349
                valStr<<"<out><person>text1</person><person>text2</person><person>text3</person><value>"<<test.str()<<"<value></out>";
350
                name<<"value"<<i;
351
                
352
                XdmValue * values = (XdmValue*)processor->parseXmlFromString(valStr.str().c_str());
353
                trans->setParameter(name.str().c_str(), values);
354
                test.str("");
355
                valStr.str("");
356
                name.str("");
357
        }
358
        std::map<std::string,XdmValue*> parMap = trans->getParameters();
359
cout<<"Parameter Map size: "<<parMap.size()<<endl;
360
        
361
ostringstream name1;
362
        for(int i =0; i < 10;i++){
363
                name1<<"param:value"<<i;
364
                cout<<" i:"<<i<<" Map size:"<<parMap.size()<<", ";
365
                 try {
366
                XdmValue * valuei = parMap.at(name1.str());
367
                if(valuei != NULL ){
368
                        cout<<name1.str();
369
                        if(valuei->itemAt(0) != NULL)
370
                                cout<<"= "<<valuei->itemAt(0)->getStringValue();
371
                        cout<<endl;
372
                }
373
                } catch(const std::out_of_range& oor) {
374
                        cout<< "Out of range exception occurred. Exception no. "<<endl;        
375
                }
376
                name1.str("");
377
        }
378
}
379

    
380

    
381
void testXdmNodeOutput(XsltProcessor * trans){
382
 trans->clearParameters(true);
383
  trans->clearProperties();
384

    
385

    
386
  trans->compileFromString("<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template name='go'><a/></xsl:template></xsl:stylesheet>");
387
            trans->setProperty("it","go");
388
            XdmNode * root = (XdmNode*)(trans->transformToValue());
389
             if(root == NULL) {  
390
                             
391
                        cout<<"Result is null"<<endl;
392
                        return;
393
                } 
394
               if(root->getNodeKind() == DOCUMENT){
395
                   cout<<"Result is a Document"<<endl;
396
                } else {
397
                        cout<<"Node is of kind:"<<root->getNodeKind()<<endl;
398
                }
399

    
400
  trans->clearProperties();
401

    
402
}
403

    
404
void exampleSimple1(XsltProcessor  *proc){
405
                cout<<"ExampleSimple1 taken from PHP:"<<endl;
406
                proc->setSourceFromFile("../php/xml/foo.xml");
407
                proc->compileFromFile("../php/xsl/foo.xsl");
408
                        
409
                const char *result = proc->transformToString();               
410
                if(result != NULL) {               
411
                        cout<<result<<endl;
412
                } else {
413
                        cout<<"Result is null"<<endl;
414
                }
415
                proc->clearParameters(true);
416
                proc->clearProperties();            
417
            }
418

    
419
void exampleSimple1Err(XsltProcessor  *proc){
420
                cout<<"ExampleSimple1 taken from PHP:"<<endl;
421
                proc->setSourceFromFile("cat.xml");
422
                proc->compileFromFile("err.xsl");
423
                        
424
                const char *result = proc->transformToString();               
425
                if(result != NULL) {               
426
                        cout<<result<<endl;
427
                } else {
428
                        cout<<"Result is null"<<endl;
429
                }
430
                proc->clearParameters(true);
431
                proc->clearProperties();            
432
            }
433

    
434
int exists(const char *fname)
435
{
436
    FILE *file;
437
    file = fopen(fname, "r");
438
    if (file)
439
    {
440
        fclose(file);
441
        return 1;
442
    }
443
    return 0;
444
}
445

    
446

    
447
  void exampleSimple2(XsltProcessor  *proc){
448
                cout<<"<b>exampleSimple2:</b><br/>"<<endl;
449
                proc->setSourceFromFile("../php/xml/foo.xml");
450
                proc->compileFromFile("../php/xsl/foo.xsl");
451
                const char * filename = "output1.xml";
452
                proc->setOutputFile(filename);
453
                proc->transformToFile();
454
                                
455
                if (exists(filename)) {
456
                    cout<<"The file $filename exists"<<endl;;
457
                } else {
458
                    cout<<"The file $filename does not exist"<<endl;
459
                }
460
                       proc->clearParameters(true);
461
                proc->clearProperties();
462
            }
463

    
464
void exampleSimple3(SaxonProcessor * saxonProc, XsltProcessor  *proc){
465
                cout<<"<b>exampleSimple3:</b><br/>"<<endl;
466
                proc->clearParameters(true);
467
                proc->clearProperties();
468
                XdmNode * xdmNode = saxonProc->parseXmlFromString("<doc><b>text value of out</b></doc>");
469
                if(xdmNode == NULL) {
470
                        cout<<"xdmNode is null'"<<endl;
471
                        return;        
472
                }            
473
                proc->setSourceFromXdmNode((XdmNode*)xdmNode);
474
                cout<<"end of exampleSimple3"<<endl;
475
                proc->clearParameters(true);
476
                proc->clearProperties();
477
}
478

    
479
void exampleParam(SaxonProcessor * saxonProc, XsltProcessor  *proc){
480
                cout<< "\nExampleParam:</b><br/>"<<endl;
481
                proc->setSourceFromFile("../php/xml/foo.xml");
482
                proc->compileFromFile("../php/xsl/foo.xsl");
483
            
484
                XdmAtomicValue * xdmvalue = saxonProc->makeStringValue("Hello to you");
485
                if(xdmvalue !=NULL){
486
                        
487
                        proc->setParameter("a-param", (XdmValue*)xdmvalue);
488
                } else {
489
                        cout<< "Xdmvalue is null"<<endl;
490
                }
491
                const char * result = proc->transformToString();
492
                if(result != NULL) {                
493
                        cout<<"Output:"<<result<<endl;
494
                } else {
495
                        cout<<"Result is NULL<br/>"<<endl;
496
                }
497
               
498
                //proc->clearParameters();                
499
                //unset($result);
500
                //echo 'again with a no parameter value<br/>';
501
                
502
                proc->setProperty("!indent", "yes"); 
503
                const char *result2 = proc->transformToString();
504
               
505
                proc->clearProperties();
506
                if(result2 != NULL) {                
507
                        cout<<result2<<endl;
508
                }
509
               
510
              //  unset($result);
511
               // echo 'again with no parameter and no properties value set. This should fail as no contextItem set<br/>';
512
                XdmAtomicValue * xdmValue2 = saxonProc->makeStringValue("goodbye to you");
513
                proc->setParameter("a-param", (XdmValue*)xdmValue2);
514
                
515
                const char *result3 = proc->transformToString();   
516
                if(result3 != NULL) {             
517
                        cout<<"Output ="<<result3<<endl;
518
                } else {
519
                        cout<<"Error in result"<<endl;
520
                }
521
                proc->clearParameters();
522
                proc->clearProperties(); 
523
                        
524
            }
525

    
526
// test parameter and properties maps where we update key, value pair.
527
void exampleParam2(SaxonProcessor * saxonProc, XsltProcessor  *proc){
528
                cout<< "\nExampleParam:</b><br/>"<<endl;
529
                proc->setSourceFromFile("../php/xml/foo.xml");
530
                proc->compileFromFile("../php/xsl/foo.xsl");
531

    
532
                XdmAtomicValue * xdmvalue = saxonProc->makeStringValue("Hello to you");
533
                XdmAtomicValue * xdmvalue2i = saxonProc->makeStringValue("Hello from me");
534
                if(xdmvalue !=NULL){
535

    
536
                        proc->setParameter("a-param", (XdmValue*)xdmvalue);
537
                        proc->setParameter("a-param", (XdmValue*)xdmvalue2i);
538
                } else {
539
                        cout<< "Xdmvalue is null"<<endl;
540
                }
541
                const char * result = proc->transformToString();
542
                if(result != NULL) {
543
                        cout<<"Output:"<<result<<endl;
544
                } else {
545
                        cout<<"Result is NULL<br/>"<<endl;
546
                }
547

    
548
                //proc->clearParameters();
549
                //unset($result);
550
                //echo 'again with a no parameter value<br/>';
551

    
552
                proc->setProperty("!indent", "no");
553
                proc->setProperty("!indent", "yes");
554
                const char *result2 = proc->transformToString();
555

    
556
                proc->clearProperties();
557
                if(result2 != NULL) {
558
                        cout<<result2<<endl;
559
                }
560

    
561
              //  unset($result);
562
               // echo 'again with no parameter and no properties value set. This should fail as no contextItem set<br/>';
563
                XdmAtomicValue * xdmValue2 = saxonProc->makeStringValue("goodbye to you");
564
                proc->setParameter("a-param", (XdmValue*)xdmValue2);
565

    
566
                const char *result3 = proc->transformToString();
567
                if(result3 != NULL) {
568
                        cout<<"Output ="<<result3<<endl;
569
                } else {
570
                        cout<<"Error in result"<<endl;
571
                }
572
                proc->clearParameters();
573
                proc->clearProperties();
574

    
575
            }
576

    
577

    
578
/* XMarkbench mark test q12.xsl with just-in-time=true*/
579
void xmarkTest1(XsltProcessor  *proc){
580
                cout<<"XMarkbench mark test q12.xsl (JIT=true):"<<endl;
581

    
582
        proc->setJustInTimeCompilation(true);
583

    
584
        XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
585
                if(result != NULL) {
586
                        cout<<"XdmNode returned"<<endl;
587
                } else {
588
                         printf("result is null \nCheck For errors:");
589
             if(proc->exceptionCount()>0) {
590
                    cout<<proc->getErrorMessage(0)<<endl;
591
             }
592
                }
593
                proc->clearParameters(true);
594
                proc->clearProperties();
595

    
596
 }
597

    
598

    
599

    
600
 /* XMarkbench mark test q12.xsl with just-in-time=true*/
601
 void xmarkTest2(XsltProcessor  *proc){
602
                 cout<<"XMarkbench mark test q12.xsl (JIT=true):"<<endl;
603

    
604

    
605
         XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
606
                 if(result != NULL) {
607
                         cout<<"XdmNode returned"<<endl;
608
                 } else {
609
                          printf("result is null \nCheck For errors:");
610
              if(proc->exceptionCount()>0) {
611
                     cout<<proc->getErrorMessage(0)<<endl;
612
              }
613
                 }
614
                 proc->clearParameters(true);
615
                 proc->clearProperties();
616

    
617
  }
618

    
619
/* XMarkbench mark test q12.xsl with just-in-time=true*/
620
void exampleSimple_xmark(XsltProcessor  *proc){
621
                cout<<"XMarkbench mark test q12.xsl:"<<endl;
622

    
623
        proc->setJustInTimeCompilation(true);
624

    
625
        XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
626
                if(result != NULL) {
627
                        cout<<"XdmNode returned"<<endl;
628
                } else {
629
                         printf("result is null \nCheck For errors:");
630
             if(proc->exceptionCount()>0) {
631
                    cout<<proc->getErrorMessage(0)<<endl;
632
             }
633
                }
634
                proc->clearParameters(true);
635
                proc->clearProperties();
636

    
637
 }
638

    
639

    
640
/*
641
* Test saving nd loading a Xslt package
642
*/
643
void testPackage1(XsltProcessor * trans){
644

    
645
  cout<<endl<<"Test: Saving and loading Packages:"<<endl;
646
  trans->clearParameters(true);
647
  trans->clearProperties();
648

    
649
    trans->compileFromFileAndSave("test.xsl", "test1.sef");
650
     const char * output = trans->transformFileToString("cat.xml","test1.sef");        
651
   if(output == NULL) {
652
      printf("result is null \n");
653
        const char * message = trans->checkException();
654
        if(message != NULL) {
655
                cout<<"Error message =" << message<< endl;
656
        }
657

    
658
    }else {
659
      printf("%s", output);
660
      printf("result is OK \n");
661
    }
662
      fflush(stdout);
663
    delete output;
664
}
665

    
666

    
667
/*
668
* Test saving and loading a Xslt package
669
*/
670
void testPackage2(XsltProcessor * trans){
671

    
672
  cout<<endl<<"Test: Saving and loading Packages2:"<<endl;
673
  trans->clearParameters(true);
674
  trans->clearProperties();
675

    
676
        const char * stylesheet = "<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>";
677

    
678
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
679
     const char * output = trans->transformFileToString("cat.xml","test2.sef");        
680
   if(output == NULL) {
681
      printf("result is null \n");
682
        const char * message = trans->checkException();
683
        if(message != NULL) {
684
                cout<<"Error message =" << message<< endl;
685
        }
686
    }else {
687
      printf("%s", output);
688
      printf("result is OK \n");
689
    }
690
      fflush(stdout);
691
    delete output;
692
}
693

    
694
void testCatalog(SaxonProcessor * proc) {
695

    
696
Xslt30Processor * trans = proc->newXslt30Processor();
697
  bool trace = false;
698
    
699
 proc->setCatalog("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/catalog.xml", trace); 
700

    
701

    
702
 //trans->setSourceFromFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/example.xml");
703
trans->setInitialMatchSelectionAsFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/example.xml"); 
704
//trans->compileFromFile("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/test1.xsl");
705
 const char *result = trans->applyTemplatesReturningString("/home/ond1/work/svn/latest9.9-saxonc/samples/php/catalog-test/test1.xsl");//transformToString();
706

    
707
if(result != NULL)
708
std::cerr<<"testCatalog result= "<<result<<std::endl;
709

    
710
}
711

    
712

    
713
void *RunThread(void *args) {
714

    
715
    struct arg_struct *argsi = (struct arg_struct *)args;
716
    int threadid = argsi->id;
717
    Xslt30Processor * trans = argsi->trans;
718
    long tid;
719
    tid = (long)threadid;
720

    
721
    trans->attachThread();
722

    
723
   trans->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
724

    
725
    const char *result = trans->applyTemplatesReturningString();
726
    cout<<" Result from THREAD ID: "<< tid << ", " << result<<endl;
727
    delete result;
728
    //pthread_exit(NULL);
729
    trans->detachThread();
730
}
731

    
732
void testThreads (SaxonProcessor * processor) {
733
    pthread_t threads[NUM_THREADS];
734
    int rc;
735
    int i;
736

    
737
    Xslt30Processor *  trans = processor->newXslt30Processor();
738

    
739
    trans->compileFromFile("../php/xsl/foo.xsl");
740
    struct arg_struct args;
741
    args.trans = trans;
742

    
743
    for( i = 0; i < NUM_THREADS; i++ ) {
744
        cout << "main() : creating thread, " << i << endl;
745
        args.id = i;
746
        rc = pthread_create(&threads[i], NULL, RunThread, (void *)&args);
747

    
748
        if (rc) {
749
            cout << "Error:unable to create thread," << rc << endl;
750
            exit(-1);
751
        }
752
        (void) pthread_join(threads[i], NULL);
753
    }
754
  //  pthread_exit(NULL);
755
}
756

    
757

    
758

    
759
int main()
760
{
761
SaxonProcessor::jvmCreatedCPP = 1;
762

    
763
    SaxonProcessor * processor = new SaxonProcessor(true);
764
    cout<<"Test: XsltProcessor with Saxon version="<<processor->version()<<endl<<endl; 
765
    //processor->setcwd("/home");
766
   processor->setConfigurationProperty("http://saxon.sf.net/feature/generateByteCode","false");
767
testCatalog(processor);
768
  
769
    XsltProcessor * trans = processor->newXsltProcessor();
770
   exampleSimple1Err(trans);
771
    exampleSimple1(trans);
772
    exampleSimple_xmark(trans);
773
    exampleSimple2(trans);
774
    exampleSimple3(processor, trans);
775

    
776
    testTransformToString1(trans);
777

    
778
    testTransformToString2(processor, trans);
779

    
780
    testTransformToString2a(processor, trans);
781

    
782
    testTransformToString2b(processor, trans);
783

    
784
    testTransformToString3(processor, trans);
785
        
786
    testTransformToString4(processor, trans);
787

    
788
    testTransformFromstring(processor, trans);
789

    
790
    testTransformFromstring2Err(processor, trans);
791

    
792
    testTrackingOfValueReference(processor, trans);
793

    
794
    testTrackingOfValueReferenceError(processor, trans);
795

    
796
    testPackage1(trans);
797

    
798
   testPackage2(trans);
799

    
800
    testXdmNodeOutput(trans);
801

    
802
    exampleParam(processor, trans);
803

    
804
    exampleParam2(processor, trans);
805

    
806
    xmarkTest1(trans);
807

    
808
    xmarkTest2(trans);
809

    
810
   //Available in PE and EE
811
   //testTransformToStringExtensionFunc(processor, trans);
812

    
813
    delete trans;
814
delete processor;
815
    // processor->release();
816
SaxonProcessor::jvmCreatedCPP = 1;
817

    
818
 SaxonProcessor * processor2 = new SaxonProcessor(true);
819
    cout<<"Test2: XsltProcessor with Saxon version="<<processor2->version()<<endl<<endl; 
820
    //processor->setcwd("/home");
821
    
822

    
823
    XsltProcessor * trans2 = processor2->newXsltProcessor();
824
testTransformToString1(trans2);
825
  delete trans2;
826
     processor2->release();
827

    
828
    return 0;
829
}
(23-23/25)