Index: test/utility/CMakeLists.txt
===================================================================
RCS file: /sources/certi/certi/test/utility/CMakeLists.txt,v
retrieving revision 1.1
diff -u -r1.1 CMakeLists.txt
--- test/utility/CMakeLists.txt	25 Jul 2007 14:35:06 -0000	1.1
+++ test/utility/CMakeLists.txt	14 Feb 2008 11:53:26 -0000
@@ -14,3 +14,16 @@
     RUNTIME DESTINATION bin
     LIBRARY DESTINATION lib
     ARCHIVE DESTINATION lib)
+    
+SET(CertiParseTests_SRCS
+  CertiParseTests.cc 
+  )
+
+ADD_EXECUTABLE(CertiParseTests ${CertiParseTests_SRCS})
+
+TARGET_LINK_LIBRARIES(CertiParseTests ${SOCKET_LIBRARY} ${LIBXML2_LIBRARIES} RTI)
+
+INSTALL(TARGETS CertiParseTests
+    RUNTIME DESTINATION bin
+    LIBRARY DESTINATION lib
+    ARCHIVE DESTINATION lib)
\ No newline at end of file
Index: test/utility/CertiParseTests.cc
===================================================================
RCS file: test/utility/CertiParseTests.cc
diff -N test/utility/CertiParseTests.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test/utility/CertiParseTests.cc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,336 @@
+/**
+ * @file CertiParseTests.cc
+ *
+ * @brief This federate is a test federate which ay be used to validate Fed or XML parser.
+ *
+ * The federate will parse the specified fed or xml file and
+ * try to subscribe to each declared object in the file.
+ */
+
+#include <RTI.hh>
+#include <NullFederateAmbassador.hh>
+#include <iostream>
+#include <cstdlib>
+
+using std::cout;
+using std::cerr;
+using std::endl;
+
+/**
+ * The parse tests main class.
+ */
+class CertiParseTests : public NullFederateAmbassador {
+
+private:
+
+	std::string fedFileName;
+	std::string federationName;
+	std::string federateName;
+	bool fileIsXML;
+	RTI::RTIambassador rtiAmbassador;
+	RTI::ObjectClassHandle anOCHandle;
+	RTI::AttributeHandle anATTHandle;
+	std::string OCClassName;
+	std::string ATTName;
+	RTI::ObjectHandle    anObjectInstance;
+	double value;
+	std::auto_ptr<RTI::AttributeHandleSet> attrSet;
+	std::auto_ptr<RTI::AttributeHandleValuePairSet> attrVPSet;
+
+public:
+
+	/* constructor initializes private variables. */
+	CertiParseTests() :
+		NullFederateAmbassador() {
+		fedFileName = "";
+		federationName = "";
+		federationName = "";
+		OCClassName = "ObjectRoot.Unit";
+		ATTName     = "Timestamp";
+		fileIsXML = false;
+		value = 0.0;
+		attrSet = std::auto_ptr<RTI::AttributeHandleSet>(RTI::AttributeHandleSetFactory::create(1));
+		attrVPSet = std::auto_ptr<RTI::AttributeHandleValuePairSet>(RTI::AttributeSetFactory::create(1));
+	}
+	;
+
+	virtual ~CertiParseTests() throw (RTI::FederateInternalError) {
+	}
+	;
+	
+	virtual void reflectAttributeValues(RTI::ObjectHandle, const RTI::AttributeHandleValuePairSet &, 
+						const RTI::FedTime &, const char *, RTI::EventRetractionHandle) 
+		throw (RTI::ObjectNotKnown, RTI::AttributeNotKnown, RTI::FederateOwnsAttributes,
+		       RTI::InvalidFederationTime, RTI::FederateInternalError) { }
+	
+	virtual void
+	    reflectAttributeValues (RTI::ObjectHandle theObject,
+	                            const RTI::AttributeHandleValuePairSet&
+	                            theAttributes,
+	                            const char *theTag)
+	    throw ( RTI::ObjectNotKnown,
+	            RTI::AttributeNotKnown,
+	            RTI::FederateOwnsAttributes,
+	            RTI::FederateInternalError) {
+	        RTI::ULong length;
+	        char *attrValue;
+
+	        /*
+	        * common implementation scheme is to iterate through the
+	        * AttributeHandleValuePairSet.
+	        */
+	        for (unsigned int i=0; i<theAttributes.size(); i++) {
+
+	            RTI::AttributeHandle handle = theAttributes.getHandle(i);
+	            length = theAttributes.getValueLength(i);
+	            attrValue = new char[length];
+	            theAttributes.getValue(i, attrValue, length);
+
+	            if (!strcmp(theTag,ATTName.c_str())) {
+	                value = *(reinterpret_cast<double*>(attrValue));
+	                cout << "Got new value for " << ATTName.c_str() 
+	                << " =" << value << endl;
+	            }
+	            delete[] attrValue;
+	        }
+	    }
+
+	void setFederationName(std::string federationName) {
+		this->federationName = federationName;
+		cout << "Using FederationName <" << this->federationName <<">"<<endl;
+	}
+
+	void setFedFileName(std::string fedFile) {
+		this->fedFileName = fedFile;
+		cout << "Using FedFileName <" << this->fedFileName <<">"<<endl;
+	}
+
+	void setFederateName(std::string federateName) {
+		this->federateName = federateName;
+		cout << "Using FederateName <" << this->federateName <<">"<<endl;
+	}
+
+	void createFederation() {		
+		try {
+			rtiAmbassador.createFederationExecution(federationName.c_str(),fedFileName.c_str());
+		} catch ( RTI::FederationExecutionAlreadyExists ) {
+			cout << "Federation already created by another federate." << endl;
+		} catch ( RTI::Exception &e ) {
+			cerr << "RTI exception: " << e._name << " ["
+			<< (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+			cerr << "Error: unknown non-RTI exception." << endl;
+		}		
+		cout << "createFederation done." << endl;
+	}
+	;
+
+	void joinFederation() {		
+		try {
+			rtiAmbassador.joinFederationExecution(federateName.c_str(),
+					federationName.c_str(),
+					this);
+		} catch ( RTI::Exception &e ) {
+			cerr << "RTI exception: " << e._name << " ["
+			<< (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+			cerr << "Error: unknown non-RTI exception." << endl;
+		}
+		cout << "joinFederation done." << endl;
+	}
+	;
+
+	void getHandles() {		
+		try {
+			anOCHandle = rtiAmbassador.getObjectClassHandle(OCClassName.c_str());
+			cout << OCClassName << " handle is " << anOCHandle <<endl;
+			anATTHandle = rtiAmbassador.getAttributeHandle(ATTName.c_str(), anOCHandle);
+			cout << ATTName << " handle is " << anATTHandle <<endl;
+		} catch ( RTI::Exception &e ) {
+			cerr << "RTI exception: " << e._name << " ["
+			<< (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+			cerr << "Error: unknown non-RTI exception." << endl;
+		}
+		cout << "getHandles done." << endl;
+	}
+	;
+
+	void publish() {
+		cout << "PUBLISH side ..." << std::flush << endl;
+		attrSet->add(anATTHandle);
+		try {
+			rtiAmbassador.publishObjectClass(anOCHandle, *attrSet);
+		} catch ( RTI::Exception &e ) {
+			cerr << "RTI exception: " << e._name << " ["
+			<< (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+			cerr << "Error: unknown non-RTI exception." << endl;
+		}
+						
+	try {
+		anObjectInstance = rtiAmbassador.registerObjectInstance(anOCHandle,ATTName.c_str());
+		    } catch ( RTI::Exception &e ) {
+		        cerr << "RTI exception: " << e._name << " ["
+		        << (e._reason ? e._reason : "undefined") << "]." << endl;
+		    } catch ( ... ) {
+		        cerr << "Error: unknown non-RTI exception." << endl;
+		    }
+		    cout << "publish done." << endl;
+	}
+	;
+
+	void subscribe() {
+		cout << "SUBSCRIBE side ..." << std::flush << endl;
+		attrSet->add(anATTHandle);
+		try {
+			rtiAmbassador.subscribeObjectClassAttributes(anOCHandle, *attrSet);
+		} catch ( RTI::Exception &e ) {
+			cerr << "RTI exception: " << e._name << " ["
+			<< (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+			cerr << "Error: unknown non-RTI exception." << endl;
+		}
+		cout << "subscribe done." << endl;
+	}
+	;
+	
+	void update() {
+		value = value + 0.1;
+		attrVPSet->add(anATTHandle, (char*)&(value), sizeof(double));
+		try {
+		            rtiAmbassador.updateAttributeValues(anObjectInstance, *attrVPSet, ATTName.c_str());
+		        } catch ( RTI::Exception &e ) {
+		            cerr << "RTI exception: " << e._name << " ["
+		            << (e._reason ? e._reason : "undefined") << "]." << endl;
+		        } catch ( ... ) {
+		            cerr << "Error: unknown non-RTI exception." << endl;
+		        }
+
+	   attrVPSet -> empty ();
+	   cout << "update done." << endl;
+	};
+	
+	void reflect() {
+		try {					  
+			rtiAmbassador.tick();
+			rtiAmbassador.tick();
+			rtiAmbassador.tick();
+		} catch ( RTI::Exception &e ) {
+		                cerr << "RTI exception: " << e._name << " ["
+		                << (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+		                cerr << "Error: unknown non-RTI exception." << endl;
+		 }	   
+		cout << "reflect done." << endl;
+	}
+
+	void resignFederation() {
+		/* resign federation execution */
+		try {
+			rtiAmbassador.resignFederationExecution(
+					RTI::DELETE_OBJECTS_AND_RELEASE_ATTRIBUTES);
+		} catch ( RTI::Exception &e ) {
+			cerr << "RTI exception: " << e._name << " ["
+			<< (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+			cerr << "Error: unknown non-RTI exception." << endl;
+		}
+		cout << "resignFederation done." << endl;
+	}
+	;
+
+	void destroyFederation() {
+		/* destroy federation execution */
+		try {
+			rtiAmbassador.destroyFederationExecution(federationName.c_str());
+		} catch (RTI::FederatesCurrentlyJoined) {
+			cout << "Federates currently joined." << endl;
+		} catch ( RTI::Exception &e ) {
+			cerr << "RTI exception: " << e._name << " ["
+			<< (e._reason ? e._reason : "undefined") << "]." << endl;
+		} catch ( ... ) {
+			cerr << "Error: unknown non-RTI exception." << endl;
+		}
+		cout << "destroyFederation done." << endl;
+	}
+	;
+
+	RTI::RTIambassador& ambassador() {
+		return rtiAmbassador;
+	}
+	;
+
+	void wait(unsigned int nsec) {
+		unsigned int n = nsec;
+		cout << "Waiting ." << std::flush;
+		while (nsec--) {
+			cout << "." << std::flush;
+			rtiAmbassador.tick();
+			sleep(1);
+		}
+		cout << endl;
+	}
+	
+	void getKeyFromCmdLine(void) {
+	    std::cout << std::endl << ">> Press any key to continue <<" << std::endl;
+	    char pressedKey;
+	    std::cin.get(pressedKey);
+	}
+};
+
+/**
+ * main of CertiParseTests
+ */
+int main(int argc, char* argv[]) {
+
+	CertiParseTests tester;
+	bool subscribe;
+	;
+
+	if (argc < 4) {
+		cerr <<argv[0] <<"ERROR:: not enough arguments" << endl;
+		cerr <<"Usage: " << argv[0]
+				<< " <fedFileName> <federationName> <federateName>" << endl;
+		return (EXIT_FAILURE);
+	}
+
+	if (argc >4) {
+		subscribe = true;
+	} else {
+		subscribe = false;
+	}
+
+	tester.setFedFileName(argv[1]);
+	tester.setFederationName(argv[2]);
+	tester.setFederateName(argv[3]);
+
+	tester.createFederation();
+	tester.joinFederation();
+	tester.getHandles();
+	tester.getKeyFromCmdLine();
+	if (subscribe) {
+		tester.wait(3);
+		tester.subscribe();
+		tester.getKeyFromCmdLine();
+		tester.reflect();		
+		tester.wait(1);
+		tester.reflect();
+		tester.getKeyFromCmdLine();
+        tester.wait(1);
+	} else {
+		tester.publish();
+		tester.getKeyFromCmdLine();
+		tester.wait(2);
+		tester.update();
+		tester.getKeyFromCmdLine();
+		tester.wait(1);
+		tester.update();
+		tester.getKeyFromCmdLine();
+		tester.wait(1);
+	}
+	tester.resignFederation();
+	tester.destroyFederation();
+	tester.getKeyFromCmdLine();
+	return (EXIT_SUCCESS);
+}
