computer_view.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 View : public ::testing::Test
00022 {
00023 protected:
00024   View()
00025   {
00026     Query.Description.NodeToBrowse.Encoding = EV_TWO_BYTE;
00027     Query.Description.NodeToBrowse.TwoByteData.Identifier = static_cast<uint8_t>(ObjectId::RootFolder); // TODO automatic cast
00028     Query.Description.Direction = BrowseDirection::Forward;
00029     Query.Description.ReferenceTypeId.Encoding = EV_TWO_BYTE;
00030 //    Params.Description.ReferenceTypeId.TwoByteData.Identifier = 33;
00031     Query.Description.IncludeSubtypes = true;
00032     Query.Description.NodeClasses = NodeClass::Unspecified;
00033     Query.Description.ResultMask = BrowseResultMask::All;
00034     Query.MaxReferenciesCount = 1;
00035   }
00036 
00037   virtual void SetUp()
00038   {
00039     Server = Connect(GetEndpoint());
00040 
00041     RemoteSessionParameters session;
00042     session.ClientDescription.Name.Text = "opcua view service test";
00043     session.SessionName = "opua test";
00044     session.EndpointUrl = GetEndpoint();
00045     session.Timeout = 1000;
00046 
00047     Server->CreateSession(session);
00048     Server->ActivateSession();
00049 
00050     Service = Server->Views();
00051   }
00052 
00053   virtual void TearDown()
00054   {
00055     Service = std::unique_ptr<ViewServices>();
00056     if (Server)
00057     {
00058       Server->CloseSession();
00059     }
00060     Server.reset();
00061   }
00062 
00063 protected:
00064   OpcUa::NodesQuery Query;
00065   std::unique_ptr<Services> Server;
00066   std::shared_ptr<ViewServices> Service;
00067 };
00068 
00069 
00070 
00071 TEST_F(View, Browse)
00072 {
00073   using namespace OpcUa;
00074   ASSERT_TRUE(static_cast<bool>(Service));
00075 
00076   const std::vector<ReferenceDescription> refs =  Service->Browse(Query);
00077   ASSERT_EQ(refs.size(), 1);
00078 }
00079 
00080 TEST_F(View, BrowseNext)
00081 {
00082   using namespace OpcUa;
00083   ASSERT_TRUE(static_cast<bool>(Service));
00084 
00085   Service->Browse(Query);
00086   const std::vector<ReferenceDescription> refs =  Service->BrowseNext();
00087   ASSERT_EQ(refs.size(), 1);
00088 }
00089 
00090 TEST_F(View, BrowseFinishes)
00091 {
00092   using namespace OpcUa;
00093   ASSERT_TRUE(static_cast<bool>(Service));
00094 
00095   Service->Browse(Query);
00096   std::vector<ReferenceDescription> browsedRefs;
00097   unsigned count = 0;
00098   while (true)
00099   {
00100     const std::vector<ReferenceDescription> refs = Service->BrowseNext();
00101     if (refs.empty())
00102     {
00103       break;
00104     }
00105     browsedRefs.insert(browsedRefs.end(), refs.begin(), refs.end());
00106     ++count;
00107   }
00108   EXPECT_TRUE(count > 0);
00109   EXPECT_EQ(browsedRefs.size(), count);
00110 }
00111 


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