testDataSemantics.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "config.h"
00031
00032 #include <iostream>
00033 #include <string>
00034 #include <ace/Trace.h>
00035
00036 #include "SemanticTreeFactory.hpp"
00037 #include "SemanticTree.hpp"
00038 #include "SemanticNode.hpp"
00039
00040 #include <FilePathSearch.hpp>
00041
00042
00043 #include <Exception.hpp>
00044
00045 using namespace mermaid::support::data;
00046 using mermaid::support::errorhandling::Exception;
00047 using boost::shared_ptr;
00048 using mermaid::support::system::FilePathSearch;
00049 using std::string;
00050 using std::cout;
00051 using std::endl;
00052
00053 void printNode (shared_ptr<SemanticNode> node, int indent)
00054 {
00055 string t = "";
00056 for (int i = 0; i < indent; i++) {
00057 t = t + " ";
00058 }
00059
00060
00061 string name = node->getName();
00062
00063 cout << indent << t << " Name: " << name << endl;
00064
00065 SemanticNodeVector children = node->getChildren();
00066
00067 int numChild = children.size();
00068 cout << indent << t << " Children: " << numChild << endl;
00069
00070 SemanticNodeVector::iterator it;
00071 for (it = children.begin(); it != children.end(); it++) {
00072 shared_ptr<SemanticNode> n = *it;
00073 printNode (n, indent + 1);
00074 }
00075
00076
00077 };
00078
00079
00080 int main (int argc, char * const argv[])
00081 {
00082 ACE_Trace::stop_tracing();
00083
00084
00085
00086
00087 try {
00088 std::cerr << "DataSemantics framework test" << endl;
00089
00090 if (argc != 2) {
00091 cout << "Usage: test-DataSemantics [filename]" << endl;
00092 return (1);
00093 }
00094
00095 FilePathSearch::addSearchPath ("./");
00096 FilePathSearch::addSearchPath ("/");
00097
00098 XmlDocument doc;
00099
00100 doc.parseFile (string (argv[1]));
00101
00102 if (doc.isWellFormed()) {
00103 cout << "XML is WELL FORMED" << endl;
00104 }
00105 else {
00106 cout << "XML is NOT WELL FORMED" << endl;
00107 return (1);
00108 }
00109
00110
00111 if (doc.isValid()) {
00112 cout << "XML is VALID" << endl;
00113 }
00114 else {
00115 cout << "XML is NOT VALID" << endl;
00116 return (1);
00117 }
00118
00119 shared_ptr<SemanticTree> t;
00120 t = SemanticTreeFactory::buildSemanticTree (&doc);
00121 shared_ptr<SemanticNode> rootNode = t->getRootNode();
00122 printNode (rootNode, 0);
00123
00124
00125 if (t->aContainsB ("Universe", "Animals") == true) {
00126 cout << "Universe CONTAINS Animals" << endl;
00127 }
00128 else {
00129 cout << "Universe DOES NOT CONTAIN Animals" << endl;
00130 return (1);
00131 }
00132
00133 if (t->aContainsB ("Animals", "Universe") == true) {
00134 cout << "Animals CONTAINS Universe" << endl;
00135 return (1);
00136 }
00137 else {
00138 cout << "Animals DOES NOT CONTAIN Universe" << endl;
00139 }
00140 }
00141 catch (Exception &exception) {
00142 cout << "ERROR:" << endl;
00143 cout << "\t" << exception.what() << endl;
00144 return (1);
00145 }
00146 catch (...) {
00147 cout << "How the hell did I end up here?!" << endl;
00148 return (1);
00149 }
00150
00151 };