Skip to content

Commit

Permalink
fix EnumValueType value initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 2, 2023
1 parent 4c64a14 commit 408db1d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/node-opcua-address-space/src/namespace_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ export class NamespaceImpl implements NamespacePrivate {
return new EnumValueType({
description: coerceLocalizedText(enumItem.description),
displayName: coerceLocalizedText(enumItem.displayName),
value: [0, enumItem.value]
value: coerceInt64(enumItem.value)
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @module node-opcua-address-space
*/
import { assert } from "node-opcua-assert";
Expand Down Expand Up @@ -54,7 +54,7 @@ const hasFalseSubState_ReferenceTypeNodeId = resolveNodeId("HasFalseSubState");
// TwoStateVariableType
// <StateIdentifier> Defined in Clause 5.4.3 Optional

function _updateTransitionTime(node: UATwoStateVariableEx) {
function _updateTransitionTime(node: UATwoStateVariableEx, _subState?: UAVariable) {
// TransitionTime specifies the time when the current state was entered.
if (node.transitionTime) {
node.transitionTime.setValueFromSource({ dataType: DataType.DateTime, value: new Date() });
Expand Down Expand Up @@ -370,7 +370,7 @@ export class UATwoStateVariableImpl extends UAVariableImplT<LocalizedText, DataT
const addressSpace = this.addressSpace;
// add event handle
const subState = addressSpace.findNode(reference.nodeId) as UAVariable;
subState.on("value_changed", _updateEffectiveTransitionTime.bind(null, this, subState));
subState.on("value_changed", _updateEffectiveTransitionTime.bind(null, this));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/node-opcua-basic-types/test/test_coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("coerceUInt64", () => {
["1", [0x0, 0x1]],
["-1", [0xffffffff, 0xffffffff]],
["-2", [0xffffffff, 0xfffffffe]],
[-32768, [0xffffffff, 0xffff8000]],
["0x1000000000", [0x10, 0x0]],
["-100000000000000", [4294944012, 4018520064]],
].forEach(([input, output]) =>
Expand Down Expand Up @@ -93,7 +94,7 @@ describe("check coerce various types", () => {

const types = ["Byte", "SByte", "UInt8", "UInt16", "UInt32", "Int8", "Int16", "Int32", "Float", "Double", "Int64", "UInt64"];

types.forEach(function (type) {
types.forEach(function(type) {
it("should have a coerce method for " + type, () => {
const coerceFunc = ec["coerce" + type];
const randomFunc = ec["random" + type];
Expand Down
37 changes: 37 additions & 0 deletions packages/node-opcua-types/test/test_enum_value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const should = require("should");
const { BinaryStream } = require("node-opcua-binary-stream");
const { EnumValueType } = require("../dist"); // node-opcua-types"

function doTest(r) {
const binaryStream = new BinaryStream();

r.encode(binaryStream);

binaryStream.rewind();

const r2 = new EnumValueType();
r2.decode(binaryStream);

r2.toString().should.eql(r.toString());
console.log(r2.toString());
}

describe("Issue 688", () => {
it("EnumValue with empty constructor", () => {
const r = new EnumValueType({});
doTest(r);
});
it("EnumValue with value=10", () => {
const r = new EnumValueType({
value: 10
});
doTest(r);
});
it("EnumValue with value=-10", () => {
const r = new EnumValueType({
value: -32168,

});
doTest(r);
});
});

0 comments on commit 408db1d

Please sign in to comment.