model_variable_ut.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2013-2014 by Alexander Rykovanov *
3  * rykovanov.as@gmail.com *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Lesser General Public License as *
7  * published by the Free Software Foundation; version 3 of the License. *
8  * *
9  * This library is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU Lesser General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Lesser General Public License *
15  * along with this library; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18  ******************************************************************************/
19 
20 
21 #include <opc/ua/model.h>
22 
29 
31 #include "services_registry_test.h"
33 
34 #include <gmock/gmock.h>
35 #include <gtest/gtest.h>
36 
37 using namespace testing;
38 
39 
40 class ModelVariable : public Test
41 {
42 protected:
43  virtual void SetUp()
44  {
46  Logger = spdlog::stderr_color_mt("test");
47  Logger->set_level(spdlog::level::info);
48  Addons = Common::CreateAddonsManager(Logger);
49 
53  Addons->Start();
54 
55  OpcUa::Server::ServicesRegistry::SharedPtr addon = Addons->GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
56  Services = addon->GetServer();
57  }
58 
59  virtual void TearDown()
60  {
61  Services.reset();
62  Addons->Stop();
63  Addons.reset();
64  }
65 
66 protected:
67  Common::Logger::SharedPtr Logger;
68  Common::AddonsManager::UniquePtr Addons;
69  OpcUa::Services::SharedPtr Services;
70 };
71 
72 
73 TEST_F(ModelVariable, CanSetVariableValue_ByVariant)
74 {
75  OpcUa::Model::Server server(Services);
76  OpcUa::Model::Object rootObject = server.RootObject();
77  OpcUa::QualifiedName name("new_variable");
78  OpcUa::Variant value = 8;
79  OpcUa::Model::Variable variable = rootObject.CreateVariable(name, value);
80 
82  ASSERT_EQ(variable.GetBrowseName(), name);
84  ASSERT_EQ(variable.GetValue(), value);
85 
86  variable.SetValue(10);
87  OpcUa::DataValue data = variable.GetValue();
90  EXPECT_EQ(data.Value, 10);
91  EXPECT_NE(data.SourceTimestamp, 0);
92 }
93 
94 TEST_F(ModelVariable, CanSetVariableValue_DataValue)
95 {
96  OpcUa::Model::Server server(Services);
97  OpcUa::Model::Object rootObject = server.RootObject();
98  OpcUa::QualifiedName name("new_variable");
99  OpcUa::Variant value = 8;
100  OpcUa::Model::Variable variable = rootObject.CreateVariable(name, value);
101 
103  ASSERT_EQ(variable.GetBrowseName(), name);
105  ASSERT_EQ(variable.GetValue(), value);
106 
107  OpcUa::DataValue data(10);
108  data.SetSourceTimestamp(OpcUa::DateTime(12345));
109  variable.SetValue(data);
110  OpcUa::DataValue result = variable.GetValue();
111  ASSERT_NE(result.Encoding & (OpcUa::DATA_VALUE), 0);
113  EXPECT_EQ(result.Value, 10);
114  EXPECT_EQ(result.SourceTimestamp, 12345);
115 }
116 
117 TEST_F(ModelVariable, CanSetListSubVariables)
118 {
120  std::vector<OpcUa::Model::Variable> vars = variable.Variables();
121  EXPECT_FALSE(vars.empty());
122 }
virtual void TearDown()
TEST_F(TestInfoTest, Names)
OpcUa::Services::SharedPtr Services
const char ServicesRegistryAddonId[]
Common::Logger::SharedPtr Logger
DataValue GetValue() const
name
Definition: setup.py:38
#define ASSERT_NE(val1, val2)
Variable CreateVariable(const QualifiedName &browseName, const Variant &value)
Create a new variable.
void RegisterStandardNamespace(Common::AddonsManager &addons)
void SetValue(const Variant &value)
#define EXPECT_FALSE(condition)
AddonsManager::UniquePtr CreateAddonsManager(const Common::Logger::SharedPtr &logger)
Get instance of addons core.
void RegisterServicesRegistry(Common::AddonsManager &addons)
void RegisterAddressSpace(Common::AddonsManager &addons)
const uint8_t DATA_VALUE_SOURCE_TIMESTAMP
Definition: data_value.h:20
#define EXPECT_NE(expected, actual)
QualifiedName GetBrowseName() const
Definition: model_node.cpp:48
#define ASSERT_TRUE(condition)
Object RootObject() const
#define ASSERT_EQ(val1, val2)
virtual std::shared_ptr< OpcUa::Services > GetServer() const =0
std::string Name
Definition: types.h:74
virtual void SetUp()
DateTime SourceTimestamp
Definition: data_value.h:31
const uint8_t DATA_VALUE
Definition: data_value.h:18
uint8_t Encoding
Definition: data_value.h:28
NodeId GetId() const
Definition: model_node.cpp:43
std::vector< Variable > Variables() const
#define EXPECT_EQ(expected, actual)
std::shared_ptr< logger > stderr_color_mt(const std::string &logger_name)
Definition: spdlog_impl.h:150
Common::AddonsManager::UniquePtr Addons
server
Definition: server.py:19
LocalizedText GetDisplayName() const
Definition: model_node.cpp:53
void drop_all()
Definition: spdlog_impl.h:260


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:06