當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript node-opcua-leak-detector.describeWithLeakDetector函數代碼示例

本文整理匯總了TypeScript中node-opcua-leak-detector.describeWithLeakDetector函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript describeWithLeakDetector函數的具體用法?TypeScript describeWithLeakDetector怎麽用?TypeScript describeWithLeakDetector使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了describeWithLeakDetector函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: require

        );
        // console.log(e.toString());
    }
}

// tslint:disable-next-line:no-var-requires
const describe = require("node-opcua-leak-detector").describeWithLeakDetector;
describe("Testing server with alternate names", () => {

    before(async () => {
        await startServer();
    });
    after(async () => {
        await stopServer();
    });

    it("should expose all end points", async () => {

        const endpointUrl = `opc.tcp://localhost:${port1}`;
        const endpoints = await extractEndpoints(endpointUrl);
        dumpEndpoints(endpoints);
        endpoints.length.should.eql(3 * 7);
    });
});

describe("Testing server with several endpoints on different TCP/IP port1", () => {

    before(async () => {
        await startMultiHeadServer();
    });
    after(async () => {
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:31,代碼來源:test_server_with_alternate_names.ts

示例2: getBrowseName

describe("Testing Boiler System", () => {

    function getBrowseName(x: BaseNode): string {
        return x.browseName.toString();
    }

    const nodesetFilename = nodesets.standard_nodeset_file;

    let addressSpace: AddressSpace;
    let namespace: Namespace;
    before(async () => {
        addressSpace = AddressSpace.create();
        await generateAddressSpace(addressSpace, nodesetFilename);
        namespace = addressSpace.registerNamespace("Private");
        namespace.index.should.eql(1);
    });
    after(async () => {
        addressSpace.dispose();
    });

    it("should handle StateMachine derived from ProgramStateMachine", () => {

        const programStateMachine = addressSpace.findObjectType("ProgramStateMachineType")!;

        const psm = programStateMachine.instantiate({
            browseName: "MyStateMachine#2"
        }) as ProgramFiniteStateMachine;
        promoteToStateMachine(psm);

        psm.getStates().map(getBrowseName).sort().should.eql(["Halted", "Ready", "Running", "Suspended"]);

    });

    it("should handle StateMachine derived from ProgramStateMachine", () => {

        const myProgramStateMachine = namespace.addObjectType({
            browseName: "MyProgramStateMachine",
            subtypeOf: "ProgramStateMachineType"
        });

        const psm = myProgramStateMachine.instantiate({
            browseName: "MyStateMachine#2"
        }) as ProgramFiniteStateMachine;

        promoteToStateMachine(psm);

        psm.getStates().map(getBrowseName).sort().should.eql(["Halted", "Ready", "Running", "Suspended"]);

        psm.getTransitions().map(getBrowseName).should.eql([
            "HaltedToReady",
            "ReadyToRunning",
            "RunningToHalted",
            "RunningToReady",
            "RunningToSuspended",
            "SuspendedToRunning",
            "SuspendedToHalted",
            "SuspendedToReady",
            "ReadyToHalted"
        ]);
    });

    it("should create a boiler system", async () => {

        const context = SessionContext.defaultContext;

        const boilerType = createBoilerType(addressSpace);
        boilerType.getNotifiers().length.should.eql(3);
        boilerType.getEventSources().length.should.eql(1);

        const boiler = makeBoiler(addressSpace, {
            browseName: "Boiler#1",
            organizedBy: addressSpace.rootFolder
        });

        boiler.pipeX001.browseName.toString().should.eql("1:PipeX001");
        boiler.pipeX002.browseName.toString().should.eql("1:PipeX002");
        boiler.drumX001.browseName.toString().should.eql("1:DrumX001");
        boiler.simulation.browseName.toString().should.eql("1:Simulation");

        // xx boiler.pipeX001.displayName.text.toString().should.eql("Pipe1001");

        boiler.pipeX001.modellingRule!.should.eql("Mandatory");
        boiler.pipeX002.modellingRule!.should.eql("Mandatory");
        boiler.drumX001.modellingRule!.should.eql("Mandatory");
        boiler.simulation.modellingRule!.should.eql("Mandatory");

        boiler.getNotifiers().length.should.eql(3);
        boiler.getEventSources().length.should.eql(1);

        boiler.getNotifiers().map((x: BaseNode) => {
            return x.browseName.name!.toString();
        }).join(" ").should.eql("PipeX001 DrumX001 PipeX002");
        // xx boiler.pipeX001.notifierOf.nodeId.toString().should.eql(boiler.nodeId.toString());
        // xx boiler.pipeX001.notifierOf.nodeId.toString().should.eql(boiler.nodeId.toString());

        const haltMethod = boiler.simulation.getMethodByName("Halt")!;
        const resetMethod = boiler.simulation.getMethodByName("Reset")!;
        const startMethod = boiler.simulation.getMethodByName("Start")!;
        const suspendMethod = boiler.simulation.getMethodByName("Suspend")!;

//.........這裏部分代碼省略.........
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:101,代碼來源:test_boiler.ts

示例3: generateAddressSpace

describe("Issue 162 : demonstrate how to modify an instantiate object variable", function(this: any) {

    this.timeout(Math.max(300000, this._timeout));

    let addressSpace: AddressSpace;

    before(async () => {
        addressSpace = AddressSpace.create();

        const xml_file = nodesets.standard_nodeset_file;

        fs.existsSync(xml_file).should.be.eql(true);

        await generateAddressSpace(addressSpace, xml_file);
        const namespace = addressSpace.registerNamespace("Private");
        namespace.index.should.eql(1);

    });

    after(() => {
        addressSpace.dispose();
    });

    it("example from 162 - way 1 : using setValueFromSource", () => {

        const myCustomObjectType = findOrCreateCustomObjectType(addressSpace);

        const myObject = myCustomObjectType.instantiate({
            browseName: "MyObject",
            organizedBy: "RootFolder",
        })  as MyCustomObject;

        should(myObject).hasOwnProperty("customProperty");
        // the first method consist of accessing the customProperty and
        // setting the value when ever it change from the outside.
        myObject.customProperty.setValueFromSource({ dataType: DataType.Double, value: -32 });

        // verification
        // xx console.log(myObject.customProperty.readValue().toString());
        myObject.customProperty.readValue().value.value.should.eql(-32);

    });

    it("example from 162 - way 2 : rebinding variable ", () => {

        const myCustomObjectType = findOrCreateCustomObjectType(addressSpace);

        const myObject = myCustomObjectType.instantiate({
            browseName: "MyObject2",
            organizedBy: "RootFolder",
        }) as MyCustomObject;

        // the  method consist of setting a getter and a setter
        let value = 3;

        const options = {
            get: () => {
                return new Variant({
                    dataType: DataType.Double,
                    value
                });
            },
            set: undefined
        };

        myObject.customProperty.bindVariable(options, true/*overwrite existing binding ? Yes !*/);

        myObject.customProperty.readValue().value.value.should.eql(3);

        value = 30;
        myObject.customProperty.readValue().value.value.should.eql(30);
    });

});
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:74,代碼來源:test_issue_162.ts

示例4: generateAddressSpace

describe("testing add TwoStateVariable ", function(this: any) {

    this.timeout(Math.max(this._timeout, 10000));

    let addressSpace: AddressSpace;
    let namespace: Namespace;

    before(async () => {
        addressSpace = AddressSpace.create();
        const xml_file = require("node-opcua-nodesets").standard_nodeset_file;
        fs.existsSync(xml_file).should.be.eql(true);

        await generateAddressSpace(addressSpace, xml_file);
        namespace = addressSpace.registerNamespace("MyPrivateNamespace");
        namespace.namespaceUri.should.eql("MyPrivateNamespace");
        namespace.index.should.eql(1);
    });
    after(async () => {
        addressSpace.dispose();
    });

    beforeEach(function(this: any) {
        clock = sinon.useFakeTimers();
    });
    afterEach(function(this: any) {
        clock.restore();
        clock = null;
    });

    it("should add a TwoStateVariableType", () => {

        const node = namespace.addTwoStateVariable({
            browseName: "TwoStateVariable1"
        });

        node.browseName.toString().should.eql("1:TwoStateVariable1");
        node.typeDefinitionObj.browseName.toString().should.eql("TwoStateVariableType");
        node.dataTypeObj.browseName.toString().should.eql("LocalizedText");
        node.valueRank.should.eql(-1);

        should.not.exist(node.transitionTime);

        node.readValue().statusCode.should.eql(StatusCodes.UncertainInitialValue);

        node.setValue(true);
        node.readValue().value.value.text.should.eql("TRUE");

        node.setValue(false);
        node.readValue().value.value.text.should.eql("FALSE");

    });

    it("TwoStateVariableType should add an uncertain value after creation", () => {

        const node = namespace.addTwoStateVariable({
            browseName: "TwoStateVariable1"
        });

        node.readValue().statusCode.should.eql(StatusCodes.UncertainInitialValue);

        node.id!.readValue().statusCode.should.eql(StatusCodes.UncertainInitialValue);

        node.setValue(true);
        node.readValue().statusCode.should.eql(StatusCodes.Good);
        node.id.readValue().statusCode.should.eql(StatusCodes.Good);

    });

    it("should add a TwoStateVariableType with trueState and falseState as String", () => {
        const node = namespace.addTwoStateVariable({
            browseName: "TwoStateVariable1",
            falseState: "Disabled",
            trueState: "Enabled"
        });

        node.browseName.toString().should.eql("1:TwoStateVariable1");
        node.typeDefinitionObj.browseName.toString().should.eql("TwoStateVariableType");
        node.dataTypeObj.browseName.toString().should.eql("LocalizedText");
        node.valueRank.should.eql(-1);

        should.not.exist(node.transitionTime);

        node.setValue(true);
        node.readValue().value.value.text.should.eql("Enabled");

        node.setValue(false);
        node.readValue().value.value.text.should.eql("Disabled");
    });

    it("should add a TwoStateVariableType with transitionTime", function(this: any) {

        const node = namespace.addTwoStateVariable({
            browseName: "TwoStateVariable2",
            optionals: ["TransitionTime"]
        });
        should.exist(node.transitionTime);

        clock.tick(100);
        node.setValue(true);
        node.transitionTime!.readValue().value.value.getTime().should.eql(100);
//.........這裏部分代碼省略.........
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:101,代碼來源:test_address_space_add_two_state_variable.ts

示例5: generateAddressSpace

describe("Testing automatic string nodeid assignment", () => {

    const nodesetFilename = nodesets.standard_nodeset_file;

    let addressSpace: AddressSpace;
    let boilerType: BoilerType;

    before(async () => {
        addressSpace = AddressSpace.create();
        await generateAddressSpace(addressSpace, nodesetFilename);

        const namespace = addressSpace.registerNamespace("private");
        namespace.index.should.eql(1);

        const someNamespace1 = addressSpace.registerNamespace("SomeOtherNamespace1");
        someNamespace1.index.should.eql(2);

        const someNamespace2 = addressSpace.registerNamespace("SomeOtherNamespace2");
        someNamespace2.index.should.eql(3);

        boilerType = createBoilerType(addressSpace);
    });

    after(async () => {
        addressSpace.dispose();
    });

    it("should automatically assign string nodeId in same namespace as parent object", () => {

        const someNamespace1 = addressSpace.getNamespace("SomeOtherNamespace1");

        const boiler = boilerType.instantiate({
            browseName: "Boiler#1",
            nodeId: "s=MyBoiler"
        });

        boiler.nodeId.toString().should.eql("ns=1;s=MyBoiler");

        boiler.pipeX001.nodeId.namespace.should.eql(boiler.nodeId.namespace, "expecting namespace index to match");
        boiler.pipeX001.nodeId.toString().should.eql("ns=1;s=MyBoiler-1:PipeX001");

        //  console.log(boiler.toString());

    });

    it("should be possible to specify a custom separator for construction string nodeid " +
      "during object instantiation", () => {

        const old_nodeIdNameSeparator = NamespaceOptions.nodeIdNameSeparator;

        old_nodeIdNameSeparator.should.have.type("string");

        NamespaceOptions.nodeIdNameSeparator = "#";

        const boiler = boilerType.instantiate({
            browseName: "Boiler2",
            nodeId: "s=MyBoiler2"
        });

        boiler.nodeId.toString().should.eql("ns=1;s=MyBoiler2");

        boiler.pipeX001.nodeId.namespace.should.eql(boiler.nodeId.namespace, "expecting namespace index to match");
        boiler.pipeX001.nodeId.toString().should.eql("ns=1;s=MyBoiler2#1:PipeX001");

        NamespaceOptions.nodeIdNameSeparator = old_nodeIdNameSeparator;

    });

});
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:69,代碼來源:test_issue_343.ts

示例6: beforeEach

describe("testing Variables ", () => {

    let addressSpace: AddressSpace;
    let namespace: Namespace;

    beforeEach(async () => {
        addressSpace = await getMiniAddressSpace();
        namespace = addressSpace.getOwnNamespace();
    });

    afterEach(() =>  {
        addressSpace.dispose();
    });

    it("accessLevel: CurrentRead | CurrentWrite\tuserAccessLevel: CurrentRead | CurrentWrite", () => {

        const v = namespace.addVariable({
            accessLevel: "CurrentRead | CurrentWrite",
            arrayDimensions: [1, 2, 3],
            browseName: "some variable",
            dataType: "Int32",
            minimumSamplingInterval: 10,
            userAccessLevel: "CurrentRead | CurrentWrite"
        });

        v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
        v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);

       });

    it("accessLevel: CurrentRead | CurrentWrite\tuserAccessLevel: CurrentRead", () => {

        const v = namespace.addVariable({
            accessLevel: "CurrentRead",
            arrayDimensions: [1, 2, 3],
            browseName: "some variable",
            dataType: "Int32",
            minimumSamplingInterval: 10,
            userAccessLevel: "CurrentRead | CurrentWrite"
        });

        v.accessLevel.should.eql(AccessLevelFlag.CurrentRead);
        v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead);

    });

    it("accessLevel: CurrentRead | CurrentWrite\tuserAccessLevel: CurrentWrite", () => {

        const v = namespace.addVariable({
            accessLevel: "CurrentRead | CurrentWrite",
            arrayDimensions: [1, 2, 3],
            browseName: "some variable",
            dataType: "Int32",
            minimumSamplingInterval: 10,
            userAccessLevel: "CurrentWrite"
        });

        v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
        v.userAccessLevel.should.eql(AccessLevelFlag.CurrentWrite);

    });

    it("accessLevel: CurrentRead | CurrentWrite\tuserAccessLevel: undefined", () => {

        const v = namespace.addVariable({
            accessLevel: "CurrentRead | CurrentWrite",
            arrayDimensions: [1, 2, 3],
            browseName: "some variable",
            dataType: "Int32",
            minimumSamplingInterval: 10,
        });

        v.accessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);
        v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead | AccessLevelFlag.CurrentWrite);

    });

    // accessLevel CurrentRead
    it("accessLevel: CurrentRead \tuserAccessLevel: CurrentRead | CurrentWrite", () => {

        const v = namespace.addVariable({
            accessLevel: "CurrentRead",
            arrayDimensions: [1, 2, 3],
            browseName: "some variable",
            dataType: "Int32",
            minimumSamplingInterval: 10,
            userAccessLevel: "CurrentRead | CurrentWrite"
        });

        v.accessLevel.should.eql(AccessLevelFlag.CurrentRead);
        v.userAccessLevel.should.eql(AccessLevelFlag.CurrentRead);

    });

    it("accessLevel: CurrentRead \tuserAccessLevel: CurrentRead", () => {

        const v = namespace.addVariable({
            accessLevel: "CurrentRead",
            arrayDimensions: [1, 2, 3],
            browseName: "some variable",
//.........這裏部分代碼省略.........
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:101,代碼來源:test_accessLevel_userAccessLevel_pullrequest.ts

示例7: before

describe("PseudoSession", () => {
    let addressSpace: AddressSpace;
    let session: PseudoSession;
    before(async () => {
        addressSpace = await getMiniAddressSpace();
        session = new PseudoSession(addressSpace);
    });
    after(() => {
        addressSpace.dispose();
    });

    it("should browse a single node ", async () => {

        const nodeToBrowse = /*BrowseDescription*/ {
            browseDirection: BrowseDirection.Forward,
            includeSubtypes: false,
            nodeClassMask: makeNodeClassMask("Object"),
            nodeId: "i=84",
            referenceTypeId: null,
            resultMask: makeResultMask("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition")
        };

        const browseResult = await session.browse(nodeToBrowse);

        browseResult.constructor.name.should.eql("BrowseResult");

        browseResult.references!.length.should.eql(3);
        browseResult.references![0].browseName.toString().should.eql("Objects");
        browseResult.references![1].browseName.toString().should.eql("Types");
        browseResult.references![2].browseName.toString().should.eql("Views");
    });

    it("should browse multiple nodes ", async () => {

        const nodeToBrowse = /*BrowseDescription*/ {
            browseDirection: BrowseDirection.Forward,
            includeSubtypes: false,
            nodeClassMask: makeNodeClassMask("Object"),
            nodeId: "i=84",
            referenceTypeId: null,
            resultMask: makeResultMask("ReferenceType | IsForward | BrowseName | NodeClass | TypeDefinition")
        };

        const browseResults = await session.browse([nodeToBrowse, nodeToBrowse]);

        browseResults.should.be.instanceOf(Array);
        browseResults[0].constructor.name.should.eql("BrowseResult");
        browseResults[0].references!.length.should.eql(3);

        browseResults[0].references![0].browseName.toString().should.eql("Objects");
        browseResults[0].references![1].browseName.toString().should.eql("Types");
        browseResults[0].references![2].browseName.toString().should.eql("Views");

        browseResults[1].constructor.name.should.eql("BrowseResult");
        browseResults[1].references!.length.should.eql(3);
        browseResults[1].references![0].browseName.toString().should.eql("Objects");
        browseResults[1].references![1].browseName.toString().should.eql("Types");
        browseResults[1].references![2].browseName.toString().should.eql("Views");
    });

    it("should read a single node", async () => {

        const nodeToRead = /*ReadValue*/ {
            attributeId: AttributeIds.BrowseName,
            nodeId: "i=84"
        };

        const dataValue = await session.read(nodeToRead);

        dataValue.statusCode.should.eql(StatusCodes.Good);
        dataValue.value.value.toString().should.eql("Root");
    });

    it("should read multiple nodes", async () => {

        const nodesToRead: ReadValueIdOptions[] = [
            {
                attributeId: AttributeIds.BrowseName,
                nodeId: "i=84"
            },
            {
                attributeId: AttributeIds.BrowseName,
                nodeId: "i=85"
            }
        ];

        const dataValues = await session.read(nodesToRead);

        dataValues[0].statusCode.should.eql(StatusCodes.Good);
        dataValues[0].value.value.toString().should.eql("Root");

        dataValues[1].statusCode.should.eql(StatusCodes.Good);
        dataValues[1].value.value.toString().should.eql("Objects");
    });
});
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:95,代碼來源:test_pseudo_session.ts

示例8: before

describe("AddressSpace : add event type ", () => {

    let addressSpace: AddressSpace;
    let namespace: Namespace;
    before(async () => {
        addressSpace = await getMiniAddressSpace();
        namespace = addressSpace.getOwnNamespace();

        const eventType = namespace.addEventType({
            browseName: "MyCustomEvent",
            // isAbstract:false,
            subtypeOf: "BaseEventType" // should be implicit
        });
    });

    after(() => {
        addressSpace.dispose();
    });

    it("#generateEventId should generate event id sequentially", () => {

        const id1 = addressSpace.generateEventId();
        const id2 = addressSpace.generateEventId();
        const id3 = addressSpace.generateEventId();
        // xx console.log(id1.value.toString("hex"));
        // xx console.log(id2.value.toString("hex"));
        // xx console.log(id3.value.toString("hex"));
        id1.value.toString("hex").should.not.eql(id2.value.toString("hex"));
        id1.value.toString("hex").should.not.eql(id3.value.toString("hex"));
    });

    it("should find BaseEventType", () => {
        addressSpace.findEventType("BaseEventType")!.nodeId.toString().should.eql("ns=0;i=2041");
    });

    it("BaseEventType should be abstract ", () => {
        const baseEventType = addressSpace.findEventType("BaseEventType")!;
        baseEventType.nodeId.toString().should.eql("ns=0;i=2041");
        baseEventType.isAbstract.should.eql(true);
    });

    it("should find AuditEventType", () => {
        const auditEventType = addressSpace.findEventType("AuditEventType")!;
        auditEventType.nodeId.toString().should.eql("ns=0;i=2052");
        auditEventType.isAbstract.should.eql(true);
    });

    it("should verify that AuditEventType is a superType of BaseEventType", () => {

        const baseEventType = addressSpace.findObjectType("BaseEventType")!;
        const auditEventType = addressSpace.findObjectType("AuditEventType")!;
        auditEventType.isSupertypeOf(baseEventType).should.eql(true);
        baseEventType.isSupertypeOf(auditEventType).should.eql(false);
    });

    it("should find a newly added EventType", () => {

        should(addressSpace.findEventType("__EventTypeForTest1")).eql(null);

        const eventType = namespace.addEventType({
            browseName: "__EventTypeForTest1",
            subtypeOf: "BaseEventType" // should be implicit
        });
        eventType.browseName.toString().should.eql("1:__EventTypeForTest1");

        const privateNamespace = addressSpace.getOwnNamespace();

        const reloaded = addressSpace.findEventType("__EventTypeForTest1", privateNamespace.index)!;

        should(reloaded).not.eql(null, "cannot findEventType " + "__EventTypeForTest1");
        reloaded.nodeId.should.eql(eventType.nodeId);

    });

    it("should retrieve EventType in several ways", () => {

        const namespaceIndex = addressSpace.getOwnNamespace().index;
        namespaceIndex.should.eql(1);

        const eventType1 = addressSpace.findEventType("MyCustomEvent", namespaceIndex)!;
        const eventType2 = addressSpace.getOwnNamespace().findObjectType("MyCustomEvent")!;
        const eventType3 = addressSpace.findEventType("1:MyCustomEvent")!;

        eventType1.should.eql(eventType2);
        eventType1.should.eql(eventType3);

    });

    it("added EventType should be abstract by default", () => {

        const namespaceIndex = addressSpace.getOwnNamespace().index;
        const eventType = addressSpace.findEventType("MyCustomEvent", namespaceIndex)!;
        eventType.isAbstract.should.eql(true);

        eventType.browseName.toString().should.eql("1:MyCustomEvent");
    });

    it("should be possible to add a non-abstract event type", () => {

        const eventType = namespace.addEventType({
//.........這裏部分代碼省略.........
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:101,代碼來源:test_address_space_add_event_type.ts

示例9: generateAddressSpace

describe("FileTransfer", () => {

    let addressSpace: AddressSpace;

    before(async () => {
        const xmlFiles = [
            nodesets.standard
        ];
        addressSpace = AddressSpace.create();
        await generateAddressSpace(addressSpace, xmlFiles);
        addressSpace.registerNamespace("Own");
    });
    after(() => {
        addressSpace.dispose();
    });

    let opcuaFile: UAFileType;
    let opcuaFile2: UAFileType;

    before(async () => {
        const namespace = addressSpace.getOwnNamespace();

        const fileType = addressSpace.findObjectType("FileType")!;
        should.exists(fileType);

        // install file 1
        opcuaFile = fileType.instantiate({
            browseName: "FileTransferObj",
            organizedBy: addressSpace.rootFolder.objects.server
        }) as UAFileType;

        const tempFolder = await promisify(fs.mkdtemp)(path.join(os.tmpdir(), "test-"));

        const filename = path.join(tempFolder, "tempFile1.txt");
        await promisify(fs.writeFile)(filename, "content", "utf8");

        installFileType(opcuaFile, { filename });

        // install file 2
        opcuaFile2 = fileType.instantiate({
            browseName: "FileTransferObj2",
            organizedBy: addressSpace.rootFolder.objects.server
        }) as UAFileType;
        const filename2 = path.join(tempFolder, "tempFile2.txt");
        installFileType(opcuaFile2, { filename: filename2 });

    });
    after(() => {
        /* empty */
    });

    it("should expose a File Transfer node and open/close", async () => {

        const session = new PseudoSession(addressSpace);

        const clientFile = new ClientFile(session, opcuaFile.nodeId);

        const handle = await clientFile.open(1);
        handle.should.not.eql(0);
        /// clientFile.handle.should.eql(handle);

        await clientFile.close();
        // clientFile.handle.should.eql(0);

    });

    it("should expose a File Transfer node", async () => {

        const session = new PseudoSession(addressSpace);
        const clientFile = new ClientFile(session, opcuaFile.nodeId);

        await clientFile.open(1);

        const curPos = await clientFile.getPosition();
        curPos.should.eql([0, 0]);

        await clientFile.setPosition([0, 1]);
        const curPos1 = await clientFile.getPosition();
        curPos1.should.eql([0, 1]);

        await clientFile.close();

    });

    it("should read a file ", async () => {

        const session = new PseudoSession(addressSpace);
        const clientFile = new ClientFile(session, opcuaFile.nodeId);

        await clientFile.open(1);

        const buf = await clientFile.read(1000);
        await clientFile.close();

        buf.toString("ascii").should.eql("content");

    });

    it("should increase openCount when a file is opened and decrease it when it's closed", async () => {

//.........這裏部分代碼省略.........
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:101,代碼來源:test_file_transfer.ts

示例10: before

describe("testing address space", () => {

    let addressSpace: AddressSpace;
    before(async () => {
        addressSpace = await getMiniAddressSpace();
    });
    after(async () => {
        addressSpace.dispose();
    });

    it("should dump references", (done: any) => {

        const hr = addressSpace.findReferenceType("HierarchicalReferences")!;

        redirectToFile("dumpReferences.log", () => {
            dumpReferences(addressSpace, _.map((hr as any)._references, (x: any) => x));
        }, done);

    });

    it("should dump a browseDescription", (done: any) => {

        const browseDescription: BrowseDescriptionOptions = {
            browseDirection: BrowseDirection.Both,
            includeSubtypes: true,
            nodeClassMask: 0, // 0 = all nodes
            referenceTypeId: resolveNodeId("HierarchicalReferences"),
            resultMask: 0x3F
        };

        const hr = addressSpace.findReferenceType("HierarchicalReferences")!;

        redirectToFile("dumpBrowseDescription.log", () => {
            dumpBrowseDescription(hr, browseDescription);
        }, done);

    });

    it("should provide a convenient a way to construct the node full name ", () => {

        const obj = addressSpace.findNode("Server_ServerStatus_BuildInfo")!;
        obj.fullName().should.eql("Server.ServerStatus.BuildInfo");

    });

});
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:46,代碼來源:test_browse_node.ts


注:本文中的node-opcua-leak-detector.describeWithLeakDetector函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。