Skip to content

Commit

Permalink
Add an integration test that reads, writes and reads a variable. Fix …
Browse files Browse the repository at this point in the history
…a problem discovered in VariableBuilder::writable() after testing it.
  • Loading branch information
locka99 committed Dec 3, 2019
1 parent 1cdf346 commit a16c659
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions integration/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub fn new_server(port: u16) -> Server {
VariableBuilder::new(&node_id, &name, &name)
.data_type(DataTypeId::Int32)
.value(0i32)
.writable()
.organized_by(&folder_id)
.insert(&mut address_space);
});
Expand Down
25 changes: 22 additions & 3 deletions integration/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,38 @@ fn read_write_read() {
info!("Client will try to connect to endpoint {:?}", client_endpoint);
let session = client.connect_to_endpoint(client_endpoint, identity_token).unwrap();

let node_id = stress_node_id(1);

// Read the existing value
{
let mut session = session.write().unwrap();
// TODO read value
let results = session.read(&[
node_id.clone().into()
]).unwrap();
let value = &results[0];
debug!("value = {:?}", value);
assert_eq!(*value.value.as_ref().unwrap(), Variant::Int32(0))
}

{
let mut session = session.write().unwrap();
// TODO write value
let results = session.write(&[WriteValue {
node_id: node_id.clone(),
attribute_id: AttributeId::Value as u32,
index_range: UAString::null(),
value: Variant::Int32(1).into(),
}]).unwrap().unwrap();
let value = results[0];
assert_eq!(value, StatusCode::Good);
}

{
let mut session = session.write().unwrap();
// TODO read value
let results = session.read(&[
node_id.into()
]).unwrap();
let value = &results[0];
assert_eq!(*value.value.as_ref().unwrap(), Variant::Int32(1))
}

{
Expand Down
3 changes: 2 additions & 1 deletion server/src/address_space/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl VariableBuilder {

/// Makes the variable writable (by default it isn't)
pub fn writable(mut self) -> Self {
self.node.set_access_level(self.node.access_level() & AccessLevel::CURRENT_WRITE);
self.node.set_user_access_level(self.node.user_access_level() | UserAccessLevel::CURRENT_WRITE);
self.node.set_access_level(self.node.access_level() | AccessLevel::CURRENT_WRITE);
self
}

Expand Down
12 changes: 2 additions & 10 deletions server/src/services/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,12 @@ impl AttributeService {
}

fn read_node_value(address_space: &AddressSpace, node_to_read: &ReadValueId, max_age: f64, timestamps_to_return: TimestampsToReturn) -> DataValue {
let mut result_value = DataValue {
value: None,
status: None,
source_timestamp: None,
source_picoseconds: None,
server_timestamp: None,
server_picoseconds: None,
};
// Node node found
let mut result_value = DataValue::null();
if let Some(node) = address_space.find_node(&node_to_read.node_id) {
if let Ok(attribute_id) = AttributeId::from_u32(node_to_read.attribute_id) {
if let Some(attribute) = node.as_node().get_attribute_max_age(attribute_id, max_age) {
let is_readable = Self::is_readable(&node);
if !is_readable {
if !Self::is_readable(&node) {
result_value.status = Some(StatusCode::BadNotReadable)
} else if !node_to_read.index_range.is_null() {
// Index ranges are not supported
Expand Down

0 comments on commit a16c659

Please sign in to comment.