Updating tests to new API

parent f26607f7
...@@ -7,87 +7,101 @@ ...@@ -7,87 +7,101 @@
using namespace std; using namespace std;
class TestObject : public CVAObject { class TestObject : public CVAObject
{
public: public:
TestObject() : CVAObject("TestObject") { inline TestObject() : CVAObject( "TestObject" )
{
};
} inline CVAStruct CallObject( const CVAStruct& ) { return CVAStruct(); };
int HandleMessage(const CVAStruct* pArgumentMessage, CVAStruct* pReturnMessage) { inline int HandleMessage( const CVAStruct* pArgumentMessage, CVAStruct* pReturnMessage )
{
// No arguments => Do nothing // No arguments => Do nothing
if (!pArgumentMessage) return 0; if( !pArgumentMessage )
return 0;
const CVAStructValue* pCommand = pArgumentMessage->GetValue("command"); const CVAStructValue* pCommand = pArgumentMessage->GetValue( "command" );
// No command => Do nothing // No command => Do nothing
if (!pCommand) return 0; if( !pCommand )
return 0;
// Command must be a string // Command must be a string
if (!pCommand->IsString()) return -1; if( !pCommand->IsString() )
return -1;
std::string sCommand = *pCommand; std::string sCommand = *pCommand;
for( auto & c : sCommand ) c = toupper( c ); for( auto & c : sCommand )
c = char( toupper( c ) );
if (sCommand == "SAYHELLO") { if( sCommand == "SAYHELLO" )
{
cout << "Object \"" << GetObjectName() << "\" says hello!" << endl; cout << "Object \"" << GetObjectName() << "\" says hello!" << endl;
// No return values // No return values
return 0; return 0;
} }
if (sCommand == "PRINTID") { if( sCommand == "PRINTID" )
cout << "Object \"" << GetObjectName() << "\" has ID " << GetObjectID() << endl; {
cout << "Object \"" << GetObjectName() << "\" has ID " << GetObjectID() << endl;
// No return values // No return values
return 0; return 0;
} }
if (sCommand == "TEST") { if( sCommand == "TEST" )
{
cout << "Object \"" << GetObjectName() << "\" was called >test< " << endl; cout << "Object \"" << GetObjectName() << "\" was called >test< " << endl;
pReturnMessage->Clear(); pReturnMessage->Clear();
(*pReturnMessage)["Number"] = 4711; ( *pReturnMessage )[ "Number" ] = 4711;
return pReturnMessage->Size(); return pReturnMessage->Size();
} }
// Invalid command // Invalid command
return -1; return -1;
} };
}; };
int main() { int main( int, char** )
{
try { try
{
CVAObjectRegistry reg; CVAObjectRegistry reg;
TestObject obj; TestObject obj;
reg.RegisterObject(&obj); reg.RegisterObject( &obj );
cout << "Test object registered. Got ID " << obj.GetObjectID() << endl; cout << "Test object registered. Got ID " << obj.GetObjectID() << endl;
// Search for object // Search for object
CVAObject* pObj = reg.GetObjectByName("TestObject"); CVAObject* pObj = reg.GetObjectByName( "TestObject" );
cout << pObj << endl;
CVAStruct in, out; CVAStruct in, out;
int result; int result;
in["command"] = "SayHello"; in[ "command" ] = "SayHello";
result = obj.HandleMessage(&in, &out); result = obj.HandleMessage( &in, &out );
cout << "Result = " << result << endl; cout << "Result = " << result << endl;
if (result != 0) if( result != 0 )
cout << "Return message = " << out << endl; cout << "Return message = " << out << endl;
in["command"] = "PrintID"; in[ "command" ] = "PrintID";
result = obj.HandleMessage(&in, &out); result = obj.HandleMessage( &in, &out );
cout << "Result = " << result << endl; cout << "Result = " << result << endl;
if (result != 0) if( result != 0 )
cout << "Return message = " << out << endl; cout << "Return message = " << out << endl;
in["command"] = "Test"; in[ "command" ] = "Test";
result = obj.HandleMessage(&in, &out); result = obj.HandleMessage( &in, &out );
cout << "Result = " << result << endl; cout << "Result = " << result << endl;
if (result != 0) if( result != 0 )
cout << "Return message = " << out << endl; cout << "Return message = " << out << endl;
} catch(CVAException& e) { }
catch( CVAException& e ) {
cerr << "Error: " << e << endl; cerr << "Error: " << e << endl;
return e.GetErrorCode(); return e.GetErrorCode();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment