model_variable_ut.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  *   Copyright (C) 2013-2014 by Alexander Rykovanov                        *
00003  *   rykovanov.as@gmail.com                                                   *
00004  *                                                                            *
00005  *   This library is free software; you can redistribute it and/or modify     *
00006  *   it under the terms of the GNU Lesser General Public License as           *
00007  *   published by the Free Software Foundation; version 3 of the License.     *
00008  *                                                                            *
00009  *   This library is distributed in the hope that it will be useful,          *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00012  *   GNU Lesser General Public License for more details.                      *
00013  *                                                                            *
00014  *   You should have received a copy of the GNU Lesser General Public License *
00015  *   along with this library; if not, write to the                            *
00016  *   Free Software Foundation, Inc.,                                          *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                *
00018  ******************************************************************************/
00019 
00020 
00021 #include <opc/ua/model.h>
00022 
00023 #include <opc/common/addons_core/addon_manager.h>
00024 #include <opc/ua/protocol/attribute_ids.h>
00025 #include <opc/ua/protocol/status_codes.h>
00026 #include <opc/ua/services/services.h>
00027 #include <opc/ua/server/address_space.h>
00028 #include <opc/ua/server/standard_address_space.h>
00029 
00030 #include "address_space_registry_test.h"
00031 #include "services_registry_test.h"
00032 #include "standard_namespace_test.h"
00033 
00034 #include <gmock/gmock.h>
00035 #include <gtest/gtest.h>
00036 
00037 using namespace testing;
00038 
00039 
00040 class ModelVariable : public Test
00041 {
00042 protected:
00043   virtual void SetUp()
00044   {
00045     const bool debug = false;
00046     Addons = Common::CreateAddonsManager();
00047 
00048     OpcUa::Test::RegisterServicesRegistry(*Addons);
00049     OpcUa::Test::RegisterAddressSpace(*Addons);
00050     OpcUa::Test::RegisterStandardNamespace(*Addons);
00051     Addons->Start();
00052 
00053     OpcUa::Server::ServicesRegistry::SharedPtr addon = Addons->GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
00054     Services = addon->GetServer();
00055   }
00056 
00057   virtual void TearDown()
00058   {
00059     Services.reset();
00060     Addons->Stop();
00061     Addons.reset();
00062   }
00063 
00064 protected:
00065   Common::AddonsManager::UniquePtr Addons;
00066   OpcUa::Services::SharedPtr Services;
00067 };
00068 
00069 
00070 TEST_F(ModelVariable, CanSetVariableValue_ByVariant)
00071 {
00072   OpcUa::Model::Server server(Services);
00073   OpcUa::Model::Object rootObject = server.RootObject();
00074   OpcUa::QualifiedName name("new_variable");
00075   OpcUa::Variant value = 8;
00076   OpcUa::Model::Variable variable = rootObject.CreateVariable(name, value);
00077 
00078   ASSERT_NE(variable.GetId(), OpcUa::ObjectId::Null);
00079   ASSERT_EQ(variable.GetBrowseName(), name);
00080   ASSERT_EQ(variable.GetDisplayName(), OpcUa::LocalizedText(name.Name));
00081   ASSERT_EQ(variable.GetValue(), value);
00082 
00083   variable.SetValue(10);
00084   OpcUa::DataValue data = variable.GetValue();
00085   ASSERT_TRUE(data.Encoding & (OpcUa::DATA_VALUE));
00086   ASSERT_TRUE(data.Encoding & (OpcUa::DATA_VALUE_SOURCE_TIMESTAMP));
00087   EXPECT_EQ(data.Value, 10);
00088   EXPECT_NE(data.SourceTimestamp, 0);
00089 }
00090 
00091 TEST_F(ModelVariable, CanSetVariableValue_DataValue)
00092 {
00093   OpcUa::Model::Server server(Services);
00094   OpcUa::Model::Object rootObject = server.RootObject();
00095   OpcUa::QualifiedName name("new_variable");
00096   OpcUa::Variant value = 8;
00097   OpcUa::Model::Variable variable = rootObject.CreateVariable(name, value);
00098 
00099   ASSERT_NE(variable.GetId(), OpcUa::ObjectId::Null);
00100   ASSERT_EQ(variable.GetBrowseName(), name);
00101   ASSERT_EQ(variable.GetDisplayName(), OpcUa::LocalizedText(name.Name));
00102   ASSERT_EQ(variable.GetValue(), value);
00103 
00104   OpcUa::DataValue data(10);
00105   data.SetSourceTimestamp(OpcUa::DateTime(12345));
00106   variable.SetValue(data);
00107   OpcUa::DataValue result = variable.GetValue();
00108   ASSERT_NE(result.Encoding & (OpcUa::DATA_VALUE), 0);
00109   ASSERT_NE(result.Encoding & (OpcUa::DATA_VALUE_SOURCE_TIMESTAMP), 0);
00110   EXPECT_EQ(result.Value, 10);
00111   EXPECT_EQ(result.SourceTimestamp, 12345);
00112 }
00113 
00114 TEST_F(ModelVariable, CanSetListSubVariables)
00115 {
00116   OpcUa::Model::Variable variable(OpcUa::ObjectId::Server_ServerStatus_BuildInfo, Services);
00117   std::vector<OpcUa::Model::Variable> vars = variable.Variables();
00118   EXPECT_FALSE(vars.empty());
00119 }


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