TEST_F(ModelObject, ServerCanAccessToRootObject) { OpcUa::Model::Server server(Services); OpcUa::Model::Object rootObject = server.RootObject(); ASSERT_EQ(rootObject.GetId(), OpcUa::ObjectId::RootFolder); }
TEST_F(ModelObject, CanAccessVariableByBrowsePath) { OpcUa::Model::Server server(Services); OpcUa::Model::Object serverObject = server.GetObject(OpcUa::ObjectId::Server); OpcUa::RelativePath path; path.Elements.push_back(GetHierarchicalElement(OpcUa::Names::ServerStatus)); path.Elements.push_back(GetHierarchicalElement(OpcUa::Names::BuildInfo)); path.Elements.push_back(GetHierarchicalElement(OpcUa::Names::BuildNumber)); OpcUa::Model::Variable buildNumber = serverObject.GetVariable(path); EXPECT_EQ(buildNumber.GetBrowseName(), OpcUa::QualifiedName(OpcUa::Names::BuildNumber)); }
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(ModelObject, CanAccessVariableByQualifiedName) { std::cout << "1" << std::endl; OpcUa::Model::Server server(Services); std::cout << "2" << std::endl; OpcUa::Model::Object rootObject = server.RootObject(); std::cout << "3" << std::endl; OpcUa::Model::ObjectType serverType = server.GetObjectType(OpcUa::ObjectId::ServerType); std::cout << "4" << std::endl; OpcUa::Model::Object serverObject = rootObject.CreateObject(serverType, OpcUa::QualifiedName("Server")); std::cout << "5" << std::endl; OpcUa::Model::Variable serverStatus = serverObject.GetVariable(OpcUa::QualifiedName(OpcUa::Names::ServerStatus)); std::cout << "6" << std::endl; EXPECT_EQ(serverStatus.GetBrowseName(), OpcUa::QualifiedName(OpcUa::Names::ServerStatus)); std::cout << "7" << std::endl; }
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); }