TEST_F(ModelObject, ObjectCanCreateVariable) { OpcUa::Model::Server server(Services); OpcUa::Model::Object rootObject = server.RootObject(); OpcUa::QualifiedName name("new_variable"); OpcUa::Variant value = 8; OpcUa::Model::Variable variable = rootObject.CreateVariable(name, value); ASSERT_NE(variable.GetId(), OpcUa::ObjectId::Null); ASSERT_EQ(variable.GetBrowseName(), name); ASSERT_EQ(variable.GetDisplayName(), OpcUa::LocalizedText(name.Name)); ASSERT_EQ(variable.GetValue(), value); }
TEST_F(ModelVariable, CanSetVariableValue_ByVariant) { OpcUa::Model::Server server(Services); OpcUa::Model::Object rootObject = server.RootObject(); OpcUa::QualifiedName name("new_variable"); OpcUa::Variant value = 8; OpcUa::Model::Variable variable = rootObject.CreateVariable(name, value); ASSERT_NE(variable.GetID(), OpcUa::ObjectID::Null); ASSERT_EQ(variable.GetBrowseName(), name); ASSERT_EQ(variable.GetDisplayName(), OpcUa::LocalizedText(name.Name)); ASSERT_EQ(variable.GetValue(), value); variable.SetValue(10); OpcUa::DataValue data = variable.GetValue(); ASSERT_TRUE(data.Encoding & (OpcUa::DATA_VALUE)); ASSERT_TRUE(data.Encoding & (OpcUa::DATA_VALUE_SOURCE_TIMESTAMP)); EXPECT_EQ(data.Value, 10); EXPECT_NE(data.SourceTimestamp, 0); }