computer_attribute.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "common.h"
00012 
00013 #include <opc/ua/client/remote_server.h>
00014 #include <opc/ua/object_ids.h>
00015 
00016 #include <stdexcept>
00017 
00018 using namespace OpcUa;
00019 
00020 
00021 class Attribute : public ::testing::Test
00022 {
00023 protected:
00024   Attribute()
00025   {
00026   }
00027 
00028   virtual void SetUp()
00029   {
00030     Server = Connect(GetEndpoint());
00031     if (!Server)
00032     {
00033       return;
00034     }
00035 
00036     RemoteSessionParameters session;
00037     session.ClientDescription.Name.Text = "opcua view service test";
00038     session.SessionName = "opua test";
00039     session.EndpointUrl = GetEndpoint();
00040     session.Timeout = 1000;
00041 
00042     Server->CreateSession(session);
00043     Server->ActivateSession();
00044 
00045     Service = Server->Attributes();
00046   }
00047 
00048   virtual void TearDown()
00049   {
00050     Service = std::unique_ptr<AttributeServices>();
00051     if (Server)
00052     {
00053       Server->CloseSession();
00054       Server.reset();
00055     }
00056   }
00057 
00058 protected:
00059   std::unique_ptr<Services> Server;
00060   std::shared_ptr<AttributeServices> Service;
00061 };
00062 
00063 
00064 
00065 TEST_F(Attribute, Read)
00066 {
00067   using namespace OpcUa;
00068   ASSERT_TRUE(static_cast<bool>(Service));
00069 
00070 
00071   ReadValueId id;
00072   id.Node.Encoding = EV_TWO_BYTE;
00073   id.Node.TwoByteData.Identifier = static_cast<uint8_t>(ObjectId::ObjectsFolder);
00074   id.Attribute = AttributeId::BrowseName;
00075 
00076   OpcUa::ReadParameters params;
00077   params.AttributesToRead.push_back(id);
00078 
00079   const std::vector<DataValue> values = Service->Read(params);
00080   ASSERT_EQ(values.size(), 1);
00081   EXPECT_TRUE(values.at(0).Encoding & DATA_VALUE);
00082 }
00083 
00084 TEST_F(Attribute, Write)
00085 {
00086   using namespace OpcUa;
00087   ASSERT_TRUE(static_cast<bool>(Service));
00088 
00089   WriteValue value;
00090   value.Node.Encoding = EV_TWO_BYTE;
00091   value.Node.TwoByteData.Identifier = static_cast<uint8_t>(ObjectId::ObjectsFolder);
00092   value.Attribute = AttributeId::BrowseName;
00093 
00094   const std::vector<StatusCode> codes = Service->Write(std::vector<WriteValue>(1, value));
00095   ASSERT_EQ(codes.size(), 1);
00096   EXPECT_NE(codes[0], StatusCode::Good);
00097 }
00098 
00099 


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:40