2024-10-30 18:51:51 +08:00
|
|
|
package goonvif
|
|
|
|
|
|
|
|
import (
|
2024-10-31 18:22:47 +08:00
|
|
|
"fmt"
|
2024-10-30 18:51:51 +08:00
|
|
|
"testing"
|
2024-10-31 18:22:47 +08:00
|
|
|
"time"
|
2024-10-30 18:51:51 +08:00
|
|
|
|
2024-10-31 18:22:47 +08:00
|
|
|
"git.pyer.club/kingecg/goonvif/onvif"
|
2024-10-30 18:51:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestListInterfaces(t *testing.T) {
|
|
|
|
ifaces, err := listLocalNetworkInterfaces()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Log(ifaces)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDiscovery(t *testing.T) {
|
|
|
|
devices, err := Discovery()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, device := range devices {
|
|
|
|
t.Log(device)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetCapabilities(t *testing.T) {
|
|
|
|
// 创建一个模拟的 Device 对象
|
|
|
|
d := &Device{
|
|
|
|
DeviceParams: onvif.DeviceParams{
|
|
|
|
Xaddr: "192.168.12.52",
|
|
|
|
Username: "dctdev",
|
|
|
|
Password: "dacenT2017",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// 测试正常情况
|
|
|
|
response, err := d.GetCapabilities()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log(response)
|
|
|
|
// 模拟 check 函数返回错误
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetEndpoints(t *testing.T) {
|
|
|
|
// 创建一个模拟的 Device 对象
|
|
|
|
d := &Device{
|
|
|
|
DeviceParams: onvif.DeviceParams{
|
|
|
|
Xaddr: "192.168.12.52",
|
|
|
|
Username: "dctdev",
|
|
|
|
Password: "dacenT2017",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
response, err := d.GetEndpoints()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
t.Log(response)
|
|
|
|
}
|
|
|
|
func TestGetRecordingSummary(t *testing.T) {
|
|
|
|
// 创建一个模拟的 Device 对象
|
|
|
|
d := &Device{
|
|
|
|
DeviceParams: onvif.DeviceParams{
|
|
|
|
Xaddr: "192.168.12.52",
|
|
|
|
Username: "dctdev",
|
|
|
|
Password: "dacenT2017",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
response, err := d.GetRecordingSummary()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", err)
|
|
|
|
}
|
|
|
|
t.Log(response)
|
|
|
|
}
|
2024-10-31 18:22:47 +08:00
|
|
|
|
|
|
|
func TestFindRecording(t *testing.T) {
|
|
|
|
// 创建一个模拟的 Device 对象
|
|
|
|
d := &Device{
|
|
|
|
DeviceParams: onvif.DeviceParams{
|
|
|
|
Xaddr: "192.168.12.52",
|
|
|
|
Username: "dctdev",
|
|
|
|
Password: "dacenT2017",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
// 模拟时间 三小时之前
|
|
|
|
start := time.Now().Add(-time.Hour * 3)
|
|
|
|
end := time.Now().Add(-time.Hour * 2)
|
|
|
|
response, err := d.FindRecording(start, end)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, recordingToken := range response {
|
|
|
|
uri, uerr := d.GetReplayUri(recordingToken, UdpUnicastStreamSetup)
|
|
|
|
if uerr != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", uerr)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(recordingToken, uri)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetStreamUri(t *testing.T) {
|
|
|
|
d := &Device{
|
|
|
|
DeviceParams: onvif.DeviceParams{
|
|
|
|
Xaddr: "192.168.12.52",
|
|
|
|
Username: "dctdev",
|
|
|
|
Password: "dacenT2017",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
uri, err := d.GetStreamUriUdp("")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected no error, got %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(uri)
|
|
|
|
}
|
2024-11-01 16:53:22 +08:00
|
|
|
|
|
|
|
func TestGetPtzNodes(t *testing.T) {
|
|
|
|
d := NewDevice(onvif.DeviceParams{
|
|
|
|
Xaddr: "192.168.12.52",
|
|
|
|
Username: "dctdev",
|
|
|
|
Password: "dacenT2017",
|
|
|
|
})
|
|
|
|
nodes, err := d.PTZNodes()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Log(nodes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestZoom(t *testing.T) {
|
|
|
|
d := NewDevice(onvif.DeviceParams{
|
|
|
|
Xaddr: "192.168.12.52",
|
|
|
|
Username: "dctdev",
|
|
|
|
Password: "dacenT2017",
|
|
|
|
})
|
|
|
|
err := d.Zoom(-0.5)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|