MCPcopy Create free account
hub / github.com/SoarGroup/Soar / MyXMLEventHandler

Method MyXMLEventHandler

Tests/UnitTests/src/handlers.cpp:187–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187void Handlers::MyXMLEventHandler(sml::smlXMLEventId, void* pUserData, sml::Agent*, sml::ClientXML* pXML)
188{
189 // pXML should be some structured trace output.
190 // Let's examine it a bit.
191 // We'll start by turning it back into XML so we can look at it in the debugger.
192 char* pStr = pXML->GenerateXMLString(true) ;
193 CPPUNIT_ASSERT(pStr);
194
195 // This will always succeed. If this isn't really trace XML
196 // the methods checking on tag names etc. will just fail
197 sml::ClientTraceXML* pRootXML = pXML->ConvertToTraceXML() ;
198 CPPUNIT_ASSERT(pRootXML);
199
200 // The root object is just a <trace> tag. The substance is in the children
201 // so we'll get the first child which should exist.
202 sml::ClientTraceXML childXML ;
203 CPPUNIT_ASSERT(pRootXML->GetChild(&childXML, 0));
204 sml::ClientTraceXML* pTraceXML = &childXML ;
205
206 if (pTraceXML->IsTagState())
207 {
208 CPPUNIT_ASSERT(pTraceXML->GetDecisionCycleCount());
209 std::string count = pTraceXML->GetDecisionCycleCount() ;
210
211 CPPUNIT_ASSERT(pTraceXML->GetStateID());
212 std::string stateID = pTraceXML->GetStateID() ;
213
214 CPPUNIT_ASSERT(pTraceXML->GetImpasseObject());
215 std::string impasseObject = pTraceXML->GetImpasseObject() ;
216
217 CPPUNIT_ASSERT(pTraceXML->GetImpasseType());
218 std::string impasseType = pTraceXML->GetImpasseType() ;
219 }
220
221 // Make a copy of the object we've been passed which should remain valid
222 // after the event handler has completed. We only keep the last message
223 // in this test. This is a stress test for our memory allocation logic.
224 // We're not allowed to keep pXML that we're passed, but we can copy it and keep the copy.
225 // (The copy is very efficient, the underlying object is ref-counted).
226 sml::ClientXML** clientXMLStorage = static_cast< sml::ClientXML** >(pUserData);;
227 if (*clientXMLStorage != NULL)
228 {
229 delete *clientXMLStorage ;
230 }
231 *clientXMLStorage = new sml::ClientXML(pXML) ;
232
233 pXML->DeleteString(pStr) ;
234}
235
236void Handlers::MyInterruptHandler(sml::smlRunEventId, void* pUserData, sml::Agent* pAgent, sml::smlPhase)
237{

Callers

nothing calls this directly

Calls 8

IsTagStateMethod · 0.80
GetDecisionCycleCountMethod · 0.80
GetStateIDMethod · 0.80
GetImpasseObjectMethod · 0.80
GetImpasseTypeMethod · 0.80
GenerateXMLStringMethod · 0.45
GetChildMethod · 0.45
DeleteStringMethod · 0.45

Tested by

no test coverage detected