Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 }