#include "xml/XmlParser.h"#include "xml/Dom.h"#include "xmlUtil/Substitute.h"#include "xmlUtil/id/DictValidVisitor.h"#include "xmlUtil/id/IdDict.h"#include "xmlUtil/id/NamedId.h"#include "xmlUtil/id/IdDictMan.h"#include "xmlUtil/id/IdConverter.h"#include "xmlUtil/id/IdConversion.h"#include <dom/DOM_Element.hpp>#include <dom/DOM_DocumentType.hpp>#include <iostream>#include <string>Go to the source code of this file.
Functions | |
| std::ostream * | openOut (char *outfile) |
| void | testQuery (xmlUtil::IdDict *dict) |
| int | testConverter (xmlUtil::IdConverter *converter) |
| int | main (int argc, char *argv[]) |
|
||||||||||||
|
Main program for the eval application.
Definition at line 32 of file testId.cxx. References xmlUtil::IdConverter::displayConversions(), xmlUtil::IdDictMan::DUPLICATE, xmlUtil::Substitute::execute(), xmlUtil::IdDictMan::findDict(), xmlUtil::IdDict::getDictName(), xmlUtil::IdDict::isValid(), xmlUtil::IdDictMan::registerDict(), xmlUtil::IdDictMan::RetCode, xmlUtil::IdDictMan::SUCCESS, testConverter(), and testQuery().
00032 {
00033 char* xmlInput = "../xml/test-dict.xml";
00034 if (argc >= 2) {
00035 xmlInput = argv[1];
00036 if (!(strcmp(xmlInput, "-help"))) { // instructions
00037 std::cout <<
00038 "First argument is xml file (id dictionary) to be parsed; defaults to test-dict.xml"
00039 << std::endl;
00040 exit(0);
00041 }
00042 }
00043
00044 xml::XmlParser* parser = new xml::XmlParser();
00045 DOM_Document doc = parser->parse(xmlInput);
00046 DOM_Element docElt = doc.getDocumentElement();
00047
00048 if (doc == 0) {
00049 std::cout << "Document failed to parse correctly" << std::endl;
00050 exit(0);
00051 }
00052
00053 std::cout << "Document was parsed" << std::endl;
00054
00055 // Evaluate and substitute in case constants were used
00056 xmlUtil::Substitute* sub = new xmlUtil::Substitute(doc);
00057
00058 // Look for IdDict element
00059 DOM_Element dictElt = xml::Dom::findFirstChildByName(docElt, "idDict");
00060 if (dictElt == DOM_Element()) {
00061 std::cout << "No identifier dictionary found " << std::endl;
00062 exit(0);
00063 }
00064 std::cout << "Dictionary element found" << std::endl;
00065
00066 int nSub = sub->execute(dictElt);
00067 std::cout << " # elements substituted: " << nSub << std::endl;
00068
00069 // Make the dictionary
00070 xmlUtil::IdDict *dict = new xmlUtil::IdDict(dictElt);
00071 std::cout << "Dictionary " << dict->getDictName() << " made" << std::endl;
00072
00073
00074 // Attempt to verify it
00075 bool valid = dict->isValid();
00076 std::cout << "Dictionary is " << ( (valid) ? "VALID" : "INVALID" );
00077 std::cout << std::endl;
00078
00079 // Test query functions
00080 testQuery(dict);
00081
00082 // Register dictionary
00083 xmlUtil::IdDictMan *man = xmlUtil::IdDictMan::getPointer();
00084 xmlUtil::IdDictMan::RetCode ret = man->registerDict(dict);
00085
00086 switch(ret) {
00087 case xmlUtil::IdDictMan::SUCCESS:
00088 std::cout << "Dictionary successfully registered" << std::endl;
00089 break;
00090 case xmlUtil::IdDictMan::DUPLICATE:
00091 std::cout << "Duplicate dictionary registration" << std::endl;
00092 break;
00093 default:
00094 std::cout << "Dictionary registration failed" << std::endl;
00095 exit(ret);
00096 }
00097
00098 // Check that we can find it again
00099 xmlUtil::IdDict *dictAgain = man->findDict(dict->getDictName());
00100 std::cout << ((dictAgain == dict) ? "Found dict" : "Failed to find dict") <<
00101 std::endl;
00102
00103 // Look for IdConverter
00104 DOM_Element converterElt =
00105 xml::Dom::findFirstChildByName(docElt, "idConverter");
00106 if (converterElt == DOM_Element()) {
00107 std::cout << "No id converter found " << std::endl;
00108 exit(0);
00109 }
00110 std::cout << "Id converter found" << std::endl;
00111
00112 // Build representation
00113 xmlUtil::IdConverter *converter = new xmlUtil::IdConverter(converterElt);
00114
00115 // What's it got?
00116 converter->displayConversions(std::cout);
00117
00118 // Check it out
00119 return (testConverter(converter));
00120 }
|
|
|
Open specified output file (may be standard output if "-" is given as input argument) Definition at line 134 of file makeXmlForDoc.cxx.
00135 {
00136 char *hyphen = "-";
00137 std::ostream* out;
00138
00139 if (*outfile == *hyphen) {
00140 out = &std::cout;
00141 }
00142 else { // try to open file as ostream
00143 out = new std::ofstream(outfile);
00144 }
00145 return out;
00146 }
|
|
|
Definition at line 184 of file testId.cxx. References xmlUtil::NamedId::addField(), xmlUtil::IdConverter::convert(), xmlUtil::IdConverter::isConsistent(), xmlUtil::NamedId::popField(), and xmlUtil::NamedId::stripNames(). Referenced by main().
00184 {
00185
00186 using namespace xmlUtil; // to get diagnostic output functions
00187
00188 if (!(converter->isConsistent()) ) {
00189 std::cout << "Converter is inconsistent" << std::endl;
00190 return (0);
00191 }
00192 std::cout << "Converter OK" << std::endl;
00193
00194 // Check out some particular Identifier and NamedId objects
00195 xmlUtil::NamedId nId;
00196 nId.addField("fLATObjects", 0); // Towers
00197 nId.addField("fTowerY", 3);
00198
00199 std::cout << "Before conversion:" << std::endl << nId;
00200
00201 std::cout << "After conversion (shouldn't change):" << std::endl;
00202
00203 std::cout << (*(converter->convert(&nId)));
00204
00205 nId.addField("fTowerX", 2);
00206 nId.addField("fTowerObjects", 0); // CAL
00207 nId.addField("fLayer", 3);
00208 nId.addField("fMeasure", 0);
00209 nId.addField("fCALLog", 4);
00210 nId.addField("fCALLogCmp", 2);
00211
00212 std::cout << "Before conversion:" << std::endl << nId;
00213
00214 std::cout << "After conversion (should truncate):" << std::endl;
00215
00216 std::cout << (*(converter->convert(&nId)));
00217
00218 nId.popField(5);
00219 nId.addField("fTowerObjects", 1); //TKR
00220 nId.addField("fTKRTray", 6);
00221 nId.addField("fMeasure", 1);
00222 nId.addField("fTKRTrayCmp", 3);
00223
00224 std::cout << "Before conversion:" << std::endl << nId;
00225
00226 std::cout << "After conversion (should compress):" << std::endl;
00227
00228 std::cout << (*(converter->convert(&nId)));
00229
00230 nId.popField(7);
00231 nId.addField("fLATObjects", 1); // ACD
00232 nId.addField("fACDFace", 3);
00233 nId.addField("fRow", 2);
00234 nId.addField("fCol", 3);
00235
00236 std::cout << "Before conversion:" << std::endl << nId;
00237
00238 std::cout << "After conversion (should disappear):" << std::endl;
00239
00240 std::cout << (*(converter->convert(&nId)));
00241
00242 // Try last one again, but on Identifier rather than named id
00243 xmlUtil::Identifier *id = nId.stripNames();
00244
00245 std::cout << "Before conversion (Identifier):" << std::endl << (*id);
00246 std::cout << "After conversion (should disappear):" << std::endl;
00247 std::cout << (*(converter->convert(id)));
00248
00249 return 1;
00250 }
|
|
|
Definition at line 122 of file testId.cxx. Referenced by main().
00122 {
00123
00124 using namespace xmlUtil; // for diagnostic output operators
00125
00126 xmlUtil::Identifier okId(3);
00127 xmlUtil::Identifier badId(4);
00128
00129 okId[0] = 0;
00130 okId[1] = 1;
00131 okId[2] = 1;
00132
00133 badId[0] = 0;
00134 badId[1] = 0;
00135 badId[2] = 27;
00136 badId[3] = 1;
00137
00138 bool valid = dict->idOk(okId);
00139 std::cout << "okId is " << ( (valid) ? "VALID" : "INVALID" );
00140 std::cout << std::endl;
00141
00142 std::cout << "Original: " << okId << std::endl;
00143 std::cout << "Reconstituted: " << std::endl << (*(dict->getNamedId(okId)));
00144
00145 valid = dict->idOk(badId);
00146 std::cout << "badId is " << ( (valid) ? "VALID" : "INVALID" );
00147 std::cout << std::endl;
00148
00149 xmlUtil::NamedId nIdBadVal(4);
00150 xmlUtil::NamedId nIdOk(2);
00151 xmlUtil::NamedId nIdBadName(3);
00152
00153 nIdBadVal.addField("fLATObjects", 0);
00154 nIdBadVal.addField("fTowerY", 2);
00155 nIdBadVal.addField("fTowerX", 14);
00156 nIdBadVal.addField("fTowerObjects", 0);
00157
00158 nIdOk.addField("fLATObjects", 0);
00159 nIdOk.addField("fTowerY", 2);
00160
00161 nIdBadName.addField("fLATObjects", 0);
00162 nIdBadName.addField("fTower", 2);
00163 nIdBadName.addField("fTowerX", 1);
00164
00165 valid = dict->idOk(nIdBadVal);
00166 std::cout << "nIdBadVal is " << ( (valid) ? "VALID" : "INVALID" );
00167 std::cout << std::endl;
00168
00169 valid = dict->idOk(nIdOk);
00170 std::cout << "nIdOk is " << ( (valid) ? "VALID" : "INVALID" );
00171 std::cout << std::endl;
00172
00173 std::cout << "Original named Id: " << nIdOk;
00174 Identifier *stripped = nIdOk.stripNames();
00175 std::cout << "..stripped: " << (*stripped);
00176 std::cout << "..reconstitued: " << std::endl
00177 << (*(dict->getNamedId(*stripped)));
00178
00179 valid = dict->idOk(nIdBadName);
00180 std::cout << "nIdBadName is " << ( (valid) ? "VALID" : "INVALID" );
00181 std::cout << std::endl;
00182 }
|
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001