Updating tests to new API

parent f26607f7
......@@ -7,87 +7,101 @@
using namespace std;
class TestObject : public CVAObject {
class TestObject : public CVAObject
{
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
if (!pArgumentMessage) return 0;
if( !pArgumentMessage )
return 0;
const CVAStructValue* pCommand = pArgumentMessage->GetValue("command");
const CVAStructValue* pCommand = pArgumentMessage->GetValue( "command" );
// No command => Do nothing
if (!pCommand) return 0;
if( !pCommand )
return 0;
// Command must be a string
if (!pCommand->IsString()) return -1;
if( !pCommand->IsString() )
return -1;
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;
// No return values
return 0;
}
if (sCommand == "PRINTID") {
cout << "Object \"" << GetObjectName() << "\" has ID " << GetObjectID() << endl;
if( sCommand == "PRINTID" )
{
cout << "Object \"" << GetObjectName() << "\" has ID " << GetObjectID() << endl;
// No return values
return 0;
}
if (sCommand == "TEST") {
if( sCommand == "TEST" )
{
cout << "Object \"" << GetObjectName() << "\" was called >test< " << endl;
pReturnMessage->Clear();
(*pReturnMessage)["Number"] = 4711;
( *pReturnMessage )[ "Number" ] = 4711;
return pReturnMessage->Size();
}
// Invalid command
return -1;
}
};
};
int main() {
try {
int main( int, char** )
{
try
{
CVAObjectRegistry reg;
TestObject obj;
reg.RegisterObject(&obj);
reg.RegisterObject( &obj );
cout << "Test object registered. Got ID " << obj.GetObjectID() << endl;
// Search for object
CVAObject* pObj = reg.GetObjectByName("TestObject");
CVAObject* pObj = reg.GetObjectByName( "TestObject" );
cout << pObj << endl;
CVAStruct in, out;
int result;
in["command"] = "SayHello";
result = obj.HandleMessage(&in, &out);
in[ "command" ] = "SayHello";
result = obj.HandleMessage( &in, &out );
cout << "Result = " << result << endl;
if (result != 0)
if( result != 0 )
cout << "Return message = " << out << endl;
in["command"] = "PrintID";
result = obj.HandleMessage(&in, &out);
in[ "command" ] = "PrintID";
result = obj.HandleMessage( &in, &out );
cout << "Result = " << result << endl;
if (result != 0)
if( result != 0 )
cout << "Return message = " << out << endl;
in["command"] = "Test";
result = obj.HandleMessage(&in, &out);
in[ "command" ] = "Test";
result = obj.HandleMessage( &in, &out );
cout << "Result = " << result << endl;
if (result != 0)
if( result != 0 )
cout << "Return message = " << out << endl;
} catch(CVAException& e) {
}
catch( CVAException& e ) {
cerr << "Error: " << e << endl;
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