testDataSemantics.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename testDataSemantics.cpp
00024  * @Description Tests the DataSemantics framework implementation
00025  * @Status unknown
00026  * @Version $Id: testDataSemantics.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer Marco Barbosa + Nelson Ramos
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   //cout << indent << t << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << endl;
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   //cout << indent << t << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;
00076   
00077 };
00078 
00079 
00080 int main (int argc, char * const argv[])
00081 {
00082   ACE_Trace::stop_tracing();
00083   
00084   // insert code here...
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 }; // main
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3