-
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve getComponent/Property/MethodByName
- Loading branch information
1 parent
a5855dd
commit 319556f
Showing
12 changed files
with
210 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
packages/node-opcua-address-space/test/test_get_xxx_by_name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { AddressSpace, UAObject } from ".."; | ||
import { getMiniAddressSpace } from "../testHelpers"; | ||
import * as should from "should"; | ||
|
||
describe("test component/property/method and method accessors", () => { | ||
let addressSpace: AddressSpace; | ||
let uaObject: UAObject; | ||
before(async () => { | ||
addressSpace = await getMiniAddressSpace(); | ||
const namespace1 = addressSpace.registerNamespace("urn:namespace1"); | ||
const namespace2 = addressSpace.registerNamespace("urn:namespace2"); | ||
const namespace3 = addressSpace.registerNamespace("urn:namespace3"); | ||
|
||
uaObject = namespace1.addObject({ | ||
browseName: "SomeObject" | ||
}); | ||
const cu1 = namespace1.addObject({ | ||
browseName: "SomeUniqueComponent", | ||
componentOf: uaObject | ||
}); | ||
const c1 = namespace1.addObject({ | ||
browseName: { namespaceIndex: namespace2.index, name: "SomeComponent" }, | ||
componentOf: uaObject | ||
}); | ||
const c12 = namespace1.addObject({ | ||
browseName: { namespaceIndex: namespace3.index, name: "SomeComponent" }, | ||
componentOf: uaObject | ||
}); | ||
const pu1 = namespace1.addVariable({ | ||
browseName: "SomeUniqueProperty", | ||
dataType: "Double", | ||
propertyOf: uaObject | ||
}); | ||
const p1 = namespace1.addVariable({ | ||
browseName: { namespaceIndex: namespace2.index, name: "SomeProperty" }, | ||
dataType: "Double", | ||
propertyOf: uaObject | ||
}); | ||
const p2 = namespace1.addVariable({ | ||
browseName: { namespaceIndex: namespace3.index, name: "SomeProperty" }, | ||
dataType: "Double", | ||
propertyOf: uaObject | ||
}); | ||
|
||
const mu1 = namespace1.addMethod(uaObject, { | ||
browseName: "SomeUniqueMethod" | ||
}); | ||
const m1 = namespace1.addMethod(uaObject, { | ||
browseName: { namespaceIndex: namespace2.index, name: "SomeMethod" } | ||
}); | ||
const m2 = namespace1.addMethod(uaObject, { | ||
browseName: { namespaceIndex: namespace3.index, name: "SomeMethod" } | ||
}); | ||
}); | ||
after(() => { | ||
addressSpace.dispose(); | ||
}); | ||
|
||
it("getComponentByName form 0", () => { | ||
const t1 = uaObject.getComponentByName("SomeUniqueComponent"); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 2, name: "SomeUniqueComponent" }); | ||
}); | ||
it("getComponentByName form 0 - should throw if multiple component exist with the same name (regardless of namespace)", () => { | ||
should.throws(() => { | ||
const t1 = uaObject.getComponentByName("SomeComponent"); | ||
}, "it should throw because 2 components exists with name SomeProperty in two different namespace => we need to provide a namespace "); | ||
}); | ||
it("getComponentByName form 1", () => { | ||
const t1 = uaObject.getComponentByName("SomeComponent", 3); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 3, name: "SomeComponent" }); | ||
}); | ||
it("getComponentByName form 3", () => { | ||
const t1 = uaObject.getComponentByName({ namespaceIndex: 3, name: "SomeComponent" }); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 3, name: "SomeComponent" }); | ||
}); | ||
|
||
it("getPropertyByName form 0", () => { | ||
const t1 = uaObject.getPropertyByName("SomeUniqueProperty"); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 2, name: "SomeUniqueProperty" }); | ||
}); | ||
it("getPropertyByName form 0 - should throw if multiple property exist with the same name (regardless of namespace)", () => { | ||
should.throws(() => { | ||
const t1 = uaObject.getPropertyByName("SomeProperty"); | ||
}, "it should throw because 2 components exists with name SomeProperty in two different namespace => we need to provide a namespace "); | ||
}); | ||
it("getPropertyByName form 1", () => { | ||
const t1 = uaObject.getPropertyByName("SomeProperty", 3); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 3, name: "SomeProperty" }); | ||
}); | ||
it("getPropertyByName form 3", () => { | ||
const t1 = uaObject.getPropertyByName({ namespaceIndex: 3, name: "SomeProperty" }); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 3, name: "SomeProperty" }); | ||
}); | ||
|
||
// -------------------------- | ||
it("getMethodByName form 0", () => { | ||
const t1 = uaObject.getMethodByName("SomeUniqueMethod"); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 2, name: "SomeUniqueMethod" }); | ||
}); | ||
it("getMethodByName form 0 - should throw if multiple Method exist with the same name (regardless of namespace)", () => { | ||
should.throws(() => { | ||
const t1 = uaObject.getMethodByName("SomeMethod"); | ||
}, "it should throw because 2 components exists with name SomeMethod in two different namespace => we need to provide a namespace "); | ||
}); | ||
it("getMethodByName form 1", () => { | ||
const t1 = uaObject.getMethodByName("SomeMethod", 3); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 3, name: "SomeMethod" }); | ||
}); | ||
it("getMethodByName form 3", () => { | ||
const t1 = uaObject.getMethodByName({ namespaceIndex: 3, name: "SomeMethod" }); | ||
should.exist(t1); | ||
t1?.browseName.toJSON().should.eql({ namespaceIndex: 3, name: "SomeMethod" }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.