Project

Profile

Help

Revision 339c45ee

Added by Dave Delpratt 5 months ago

Saxon/C development - fixes for testXQuery

View differences:

src/main/c/Saxon.C.API/SaxonApiException.cpp
71 71
     * A destructor.
72 72
     */
73 73
	SaxonApiException::~SaxonApiException() noexcept {
74
	    std::cerr<<"SaxonApiException destructor called"<<std::endl;
75
        message.clear();
76
        errorCode.clear();
77
        systemId.clear();
74
          message.clear();
75
          errorCode.clear();
76
          systemId.clear();
78 77
	}
79 78

  
80 79
    /**
......
99 98
	const char * SaxonApiException::getMessage(){
100 99
	    return message.c_str();
101 100

  
102
	}
101
	}
src/main/c/Saxon.C.API/XsltExecutable.cpp
114 114
}
115 115

  
116 116
void XsltExecutable::setInitialMatchSelection(XdmValue *_selection) {
117
    if (_selection != nullptr) {
117
    if(selection) {
118
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
119
        selection = nullptr;
120
    }
121
    if(selectionV != nullptr) {
122
	selectionV->decrementRefCount();
123
    }
124
//    if (_selection != nullptr) {
118 125
        _selection->incrementRefCount();
119 126
        selectionV = _selection;
120 127
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(_selection->getUnderlyingValue());
121
    }
128
//    }
122 129
}
123 130

  
124 131

  
125 132
void XsltExecutable::setInitialMatchSelectionAsFile(const char *filename) {
133
    if(selection) {
134
        SaxonProcessor::sxn_environ->env->DeleteGlobalRef(selection);
135
        selection = nullptr;
136
    }
126 137
    if (filename != nullptr) {
127 138
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(SaxonProcessor::sxn_environ->env->NewStringUTF(filename));
128 139

  
......
744 755
XdmValue *XsltExecutable::callTemplateReturningValue(const char *templateName) {
745 756

  
746 757

  
758
    if(templateName == nullptr) {
759
	std::cerr<<"template name given as null"<<std::endl;
760
	return nullptr;
761
    }
747 762
    static jmethodID ctsvmID = nullptr;
748 763
    if (ctsvmID == nullptr) {
749 764
        ctsvmID = (jmethodID) SaxonProcessor::sxn_environ->env->GetStaticMethodID(cppClass,
......
783 798
            jclass nodeClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/s9api/XdmNode");
784 799
            jclass functionItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
785 800
                                                    "net/sf/saxon/s9api/XdmFunctionItem");
801
            jclass mapItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
802
                                                    "net/sf/saxon/s9api/XdmMap");
803
            jclass arrayItemClass = lookForClass(SaxonProcessor::sxn_environ->env,
804
                                               "net/sf/saxon/s9api/XdmArray");
786 805
            XdmValue *value = nullptr;
787 806

  
788 807
            XdmItem *xdmItem = nullptr;
......
799 818
                xdmItem = new XdmFunctionItem(result);
800 819
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
801 820
                return xdmItem;
821

  
822
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, mapItemClass) == JNI_TRUE) {
823
                xdmItem = new XdmMap(result);
824
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
825
                return xdmItem;
826
            } else if (SaxonProcessor::sxn_environ->env->IsInstanceOf(result, arrayItemClass) == JNI_TRUE) {
827
                xdmItem = new XdmArray(result);
828
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
829
                return xdmItem;
802 830
            } else {
803 831
                value = new XdmValue(result, true);
804 832
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
......
887 915
                SaxonProcessor::sxn_environ->env->DeleteLocalRef(result);
888 916
                return xdmItem;
889 917
            } else {
890
                value = new XdmValue(result, true);
918
                value = new XdmValue(result);
891 919
                return value;
892 920
            }
893 921
            value = new XdmValue();
src/main/c/samples/cppTests/build64-linux.sh
56 56

  
57 57
g++  -std=c++14 -m64 -fPIC  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 -lc $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2
58 58

  
59
g++  -std=c++14 -m64 -fPIC 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 -lc $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2
59
g++  -std=c++14 -m64 -fPIC -pthread 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 -lc $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2
60 60

  
61 61
g++  -std=c++14 -m64 -fPIC bin/SaxonCGlue.o bin/SaxonCXPath.o bin/SaxonProcessor.o bin/XQueryProcessor.o bin/XsltProcessor.o bin/Xslt30Processor.o bin/XsltExecutable.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 -lc $TURN_ERRORS_TO_WARNINGS $SAXON_ERRORS $1 $2
62 62

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

  
1 2
#include "../../Saxon.C.API/SaxonProcessor.h"
2 3
#include "../../Saxon.C.API/XdmValue.h"
3 4
#include "../../Saxon.C.API/XdmItem.h"
......
68 69
        cout<<"The file $filename does not exist"<<endl;
69 70

  
70 71
    }
71
    cerr<<"testXQuery1 cp0"<<endl;
72 72
    queryProc->clearParameters();
73
    cerr<<"testXQuery1 cp0"<<endl;
74 73
    queryProc->clearProperties();
75 74

  
76 75
}
......
378 377
		}
379 378
	
380 379
    }
381
	delete processor;
382 380
    delete queryProc;
383 381

  
384 382
}
......
418 416

  
419 417
    testXQueryError2(processor, query,sresult);
420 418

  
421

  
422
#ifdef MEM_DEBUG
423
    SaxonProcessor::getInfo();
424
#endif
425 419
    cout<<endl<<"============================================================="<<endl<<endl;
426
    /*testDefaultNamespace(processor, query,sresult);
420
    testDefaultNamespace(processor, query,sresult);
427 421

  
428 422
    cout<<endl<<"============================================================="<<endl<<endl;
429 423
    testReusability(processor, sresult);
430 424
    cout<<endl<<"============================================================="<<endl<<endl;
431 425
    testXQueryLineNumberError(query,sresult);
432 426
    cout<<endl<<"============================================================="<<endl<<endl;
433
    testXQueryLineNumber(processor, sresult);*/
434
cerr<<"testXquery cp0"<<endl;
427
    testXQueryLineNumber(processor, sresult);
428

  
435 429
    delete query;
436
    cerr<<"testXquery cp0"<<endl;
437 430

  
438 431
    delete processor;
439
    cerr<<"testXquery cp0"<<endl;
440 432
    processor->release();
441 433

  
442 434
#ifdef MEM_DEBUG
src/main/c/samples/cppTests/testXSLT30.cpp
565 565
        try {
566 566

  
567 567
            XdmValue *valuei = parMap.at(name1.str());
568
            if (valuei != NULL) {
568
            if (valuei != nullptr) {
569 569
                cout << name1.str();
570
                if (valuei->itemAt(0) != NULL)
570
                if (valuei->itemAt(0) != nullptr)
571 571
                    cout << "= " << valuei->itemAt(0)->getStringValue();
572 572
                cout << endl;
573 573
            }
......
595 595
    XsltExecutable * executable = trans->compileFromString(
596 596
            "<?xml version='1.0'?><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'                 xmlns:xs='http://www.w3.org/2001/XMLSchema' version='3.0' exclude-result-prefixes='#all'>     <xsl:import-schema><xs:schema><xs:element name='x' type='xs:int'/></xs:schema></xsl:import-schema> <xsl:template name='main'>          <xsl:result-document validation='strict'> <x>3</x>   </xsl:result-document>    </xsl:template>    </xsl:stylesheet>");
597 597

  
598

  
599
    if(executable== nullptr) {
600
        sresult->failure++;
601
        sresult->failureList.push_back("testValidation");
602
        if (trans->exceptionOccurred()) {
603
            cerr <<"Error message: "<< trans->getErrorMessage() << endl;
604
        }
605
        trans->exceptionClear();
606
        return;
607
    }
608

  
609

  
610

  
598 611
    const char *rootValue = executable->callTemplateReturningString("main");
599 612

  
600 613

  
......
617 630
    std::cout << "testXdmNodeOutput" << std::endl;
618 631
    XsltExecutable * executable = trans->compileFromString(
619 632
            "<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template name='go'><a/></xsl:template></xsl:stylesheet>");
633

  
634

  
635
    if(executable== nullptr) {
636
        sresult->failure++;
637
        sresult->failureList.push_back("testXdmNodeOutput");
638
        if (trans->exceptionOccurred()) {
639
            cerr <<"Error message: "<< trans->getErrorMessage() << endl;
640
        }
641
        trans->exceptionClear();
642
        return;
643
    }
644

  
620 645
    XdmValue *rootValue = executable->callTemplateReturningValue("go");
621 646
    if (rootValue== nullptr) {
622 647
        cout << "Result is null ====== FAIL ====== " << endl;
......
811 836
    if(executable == nullptr) {
812 837
        cout << "executable is NULL" <<endl;
813 838
        if(proc->exceptionOccurred()) {
814
            cout << proc->getErrorMessage() <<endl;
839
            cout << "Error : " << proc->getErrorMessage() <<endl;
815 840

  
816 841
        }
817 842
        sresult->failure++;
818 843
        sresult->failureList.push_back("exampleParam");
844
	proc->exceptionClear();
819 845
        return;
820 846

  
821 847
    }
......
979 1005

  
980 1006
    executable->clearProperties();
981 1007

  
982
    if(result2 != NULL) {
1008
    if(result2 != nullptr) {
983 1009
        cout<<result2<<endl;
984 1010
        sresult->success++;
985 1011

  
......
991 1017
    executable->setParameter("a-param", (XdmValue*)xdmValue2);
992 1018

  
993 1019
    const char *result3 = executable->applyTemplatesReturningString();
994
    if(result3 != NULL) {
1020
    if(result3 != nullptr) {
995 1021
        cout<<"Output ="<<result3<<endl;
996 1022

  
997 1023
        sresult->success++;
......
1010 1036
    proc->setJustInTimeCompilation(true);
1011 1037

  
1012 1038
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1013
    if (result != NULL) {
1039
    if (result != nullptr && !proc->exceptionOccurred()) {
1014 1040
        cout << "XdmNode returned" << endl;
1015 1041
        sresult->success++;
1016 1042
        delete result;
......
1018 1044
        printf("result is null \nCheck For errors:");
1019 1045
        sresult->failure++;
1020 1046
        sresult->failureList.push_back("xmarkTest1");
1021
        cerr << "xmarkTest1 cp0" << endl;
1022 1047
        if (proc->exceptionOccurred()) {
1023
            cerr << "xmarkTest1 cp1" << endl;
1024 1048
            const char * message = proc->getErrorMessage();
1025
            cerr << "xmarkTest1 cp2" << endl;
1026 1049
            if(message != nullptr) {
1027
                cerr << "xmarkTest1 cp2-1" << endl;
1028 1050
                cerr << proc->getErrorMessage() << endl;
1051
		proc->exceptionClear();
1029 1052
            } else {
1030 1053
                cerr << "Message is nullptr" << endl;
1031 1054
                SaxonProcessor::sxn_environ->env->ExceptionDescribe();
1055
		SaxonProcessor::sxn_environ->env->ExceptionClear();
1032 1056
            }
1033 1057
        }
1034
        cerr << "xmarkTest1 cp3" << endl;
1035 1058
    }
1036

  
1059
    proc->setJustInTimeCompilation(false);
1037 1060

  
1038 1061
}
1039 1062

  
......
1042 1065
void xmarkTest2(Xslt30Processor *proc, sResultCount *sresult) {
1043 1066
    cout << "Test: xmarkTest2 - XMarkbench mark test q12.xsl (JIT=true):" << endl;
1044 1067

  
1068
    proc->setJustInTimeCompilation(true);
1045 1069

  
1046 1070
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1047
    if (result != NULL) {
1071
    if (result != nullptr && !proc->exceptionOccurred()) {
1048 1072
        cout << "XdmNode returned" << endl;
1049 1073
        sresult->success++;
1050 1074
        delete result;
......
1058 1082
            if(exception != nullptr) {
1059 1083
                const char *message = exception->getMessage();
1060 1084
                if (message != nullptr) {
1061
                    cerr << "xmarkTest2 cp2-1" << endl;
1062 1085
                    cerr << message << endl;
1086
		    proc->exceptionClear();
1063 1087
                }
1064 1088
                delete exception;
1065 1089
            } else {
1066 1090
                cerr << "Exception object is nullptr" << endl;
1067 1091
                SaxonProcessor::sxn_environ->env->ExceptionDescribe();
1092
		SaxonProcessor::sxn_environ->env->ExceptionClear();
1068 1093
            }
1069 1094
        }
1070 1095
    }
1071 1096

  
1097
    proc->setJustInTimeCompilation(false);
1072 1098

  
1073 1099
}
1074 1100

  
......
1079 1105
    proc->setJustInTimeCompilation(true);
1080 1106

  
1081 1107
    XdmValue *result = proc->transformFileToValue("xmark100k.xml", "q12.xsl");
1082
    if (result != NULL) {
1108

  
1109
    if (result != nullptr && !proc->exceptionOccurred()) {
1083 1110
        cout << "XdmNode returned" << endl;
1084 1111
        sresult->success++;
1085 1112
        delete result;
......
1093 1120
        proc->exceptionClear();
1094 1121
    }
1095 1122
    proc->clearParameters();
1123
    proc->setJustInTimeCompilation(false);
1096 1124

  
1097 1125
}
1098 1126

  
......
1139 1167

  
1140 1168
    if(trans->exceptionOccurred()) {
1141 1169
        const char *message = trans->getErrorMessage();
1142
        if (message != NULL) {
1170
        if (message != nullptr) {
1143 1171
            cout << "Error message =" << message << endl;
1144 1172
        }
1145 1173
        sresult->failure++;
......
1151 1179

  
1152 1180

  
1153 1181
    XsltExecutable * executable = trans->compileFromFile("test1.sef");
1182

  
1183
    if(executable == nullptr) {
1184
	if(trans->exceptionOccurred()) {
1185
          const char *message = trans->getErrorMessage();
1186
          if (message != nullptr) {
1187
            cout << "Error message =" << message << endl;
1188
          }
1189
          sresult->failure++;
1190
          sresult->failureList.push_back("testPackage1a");
1191
          trans->exceptionClear();
1192
    	}
1193
	return;   
1194

  
1195

  
1196
    }
1197

  
1154 1198
    executable->setInitialMatchSelectionAsFile("cat.xml");
1155 1199
    const char * output = executable->applyTemplatesReturningString();
1156 1200
    if (output== nullptr) {
......
1185 1229

  
1186 1230
    trans->compileFromStringAndSave(stylesheet, "test2.sef");
1187 1231

  
1188
    if(trans->exceptionOccurred()) {
1232
    if(trans->exceptionOccurred() || trans->getException() != nullptr) {
1189 1233
        const char *message = trans->getErrorMessage();
1190
        if (message != NULL) {
1234
        if (message != nullptr) {
1191 1235
            cout << "Error message =" << message << endl;
1192 1236
        }
1193 1237
        sresult->success++;
......
1195 1239
        return;
1196 1240

  
1197 1241
    }
1198

  
1242
    trans->exceptionClear();
1199 1243
    sresult->failure++;
1200 1244
    sresult->failureList.push_back("testPackage2_Error");
1201 1245

  

Also available in: Unified diff