mirror of
https://gitee.com/energye/energy.git
synced 2024-12-16 02:11:35 +08:00
d9f14c6a46
代码授权注释修改
128 lines
4.2 KiB
Go
128 lines
4.2 KiB
Go
//----------------------------------------
|
|
//
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
//
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
//----------------------------------------
|
|
|
|
package ipc
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/energye/energy/common"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// emit方式发送到render
|
|
func TestRenderOnEmit(t *testing.T) {
|
|
common.Args.SetArgs("type", "render")
|
|
UseNetIPCChannel = false
|
|
IPC.render.SetOnEvent(func(event IEventOn) {
|
|
event.On("renderOnTest", func(context IIPCContext) {
|
|
args := NewArgumentList()
|
|
fmt.Println("renderOnTest:", context.Arguments().Size())
|
|
defer args.Clear()
|
|
args.SetInt8(0, 1)
|
|
args.SetInt16(1, 122)
|
|
args.SetInt(2, 256)
|
|
args.SetString(3, "字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串")
|
|
args.SetString(4, "render on test")
|
|
time.Sleep(time.Second / 1000)
|
|
IPC.render.Emit("browserOnTest", args)
|
|
})
|
|
event.On("renderOnTest2", func(context IIPCContext) {
|
|
args := NewArgumentList()
|
|
fmt.Println("renderOnTest2:", context.Arguments().Size())
|
|
defer args.Clear()
|
|
args.SetInt8(0, 1)
|
|
args.SetInt16(1, 122)
|
|
args.SetInt(2, 256)
|
|
args.SetString(3, "字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串")
|
|
args.SetString(4, "render on test")
|
|
args.SetString(5, "render on test")
|
|
time.Sleep(time.Second / 1000)
|
|
IPC.render.Emit("browserOnTest2", args)
|
|
})
|
|
})
|
|
IPC.CreateRenderIPC(1, 20)
|
|
IPC.render.emitConnect()
|
|
IPC.render.Emit("browserOnTest", nil)
|
|
IPC.render.Emit("browserOnTest2", nil)
|
|
for {
|
|
time.Sleep(time.Second)
|
|
}
|
|
}
|
|
|
|
// 响应的方式返回给render
|
|
func TestRenderOnResponse(t *testing.T) {
|
|
common.Args.SetArgs("type", "render")
|
|
UseNetIPCChannel = false
|
|
IPC.CreateRenderIPC(1, 20)
|
|
IPC.render.emitConnect()
|
|
IPC.render.EmitAndCallback("browserOnTest", nil, func(context IIPCContext) {
|
|
fmt.Println("响应renderOnTest:", context.Arguments().Size())
|
|
})
|
|
IPC.render.EmitAndCallback("browserOnTest2", nil, func(context IIPCContext) {
|
|
fmt.Println("响应renderOnTest2:", context.Arguments().Size())
|
|
})
|
|
for {
|
|
time.Sleep(time.Second)
|
|
}
|
|
}
|
|
|
|
// render 1
|
|
func TestRender1OnEmit(t *testing.T) {
|
|
common.Args.SetArgs("type", "render")
|
|
UseNetIPCChannel = false
|
|
IPC.render.SetOnEvent(func(event IEventOn) {
|
|
event.On("testRender1OnEmit", func(context IIPCContext) {
|
|
args := NewArgumentList()
|
|
fmt.Println("testRender1OnEmit:", context.Arguments().Size())
|
|
defer args.Clear()
|
|
args.SetInt8(0, 1)
|
|
args.SetInt16(1, 122)
|
|
args.SetInt(2, 256)
|
|
args.SetString(3, "字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串")
|
|
args.SetString(4, "render on test")
|
|
time.Sleep(time.Second / 1000)
|
|
//IPC.render.Emit("browserOnTest", args)
|
|
})
|
|
})
|
|
IPC.CreateRenderIPC(1, 20)
|
|
IPC.render.emitConnect()
|
|
IPC.render.Emit("TestBrowserOnByRender", nil)
|
|
for {
|
|
time.Sleep(time.Second)
|
|
}
|
|
}
|
|
|
|
// render 2
|
|
func TestRender2OnEmit(t *testing.T) {
|
|
common.Args.SetArgs("type", "render")
|
|
UseNetIPCChannel = false
|
|
IPC.render.SetOnEvent(func(event IEventOn) {
|
|
event.On("testRender2OnEmit", func(context IIPCContext) {
|
|
args := NewArgumentList()
|
|
fmt.Println("testRender2OnEmit:", context.Arguments().Size())
|
|
defer args.Clear()
|
|
args.SetInt8(0, 1)
|
|
args.SetInt16(1, 122)
|
|
args.SetInt(2, 256)
|
|
args.SetString(3, "字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串")
|
|
args.SetString(4, "render on test")
|
|
time.Sleep(time.Second / 1000)
|
|
//IPC.render.Emit("browserOnTest", args)
|
|
})
|
|
})
|
|
IPC.CreateRenderIPC(1, 20)
|
|
IPC.render.emitConnect()
|
|
IPC.render.Emit("TestBrowserOnByRender", nil)
|
|
for {
|
|
time.Sleep(time.Second)
|
|
}
|
|
}
|