goonvif/device_test.go

231 lines
4.5 KiB
Go
Raw Normal View History

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-11-06 19:58:33 +08:00
"os"
2024-10-31 18:22:47 +08:00
"git.pyer.club/kingecg/goonvif/onvif"
2024-10-30 18:51:51 +08:00
)
2024-11-06 19:58:33 +08:00
func TestMain(m *testing.M) {
os.Setenv("DEBUG", "DEBUG")
result := m.Run()
os.Unsetenv("DEBUG")
os.Exit(result)
}
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",
},
}
2024-11-06 19:58:33 +08:00
uri, err := d.GetStreamUriUdp("Profile_1")
2024-10-31 18:22:47 +08:00
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)
}
}
2024-11-06 19:58:33 +08:00
func TestGetProfiles(t *testing.T) {
d := NewDevice(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)
profiles, err := d.GetProfiles()
if err != nil {
t.Fatal(err)
}
t.Log(profiles)
}
func TestGetVideoSource(t *testing.T) {
d := NewDevice(onvif.DeviceParams{
Xaddr: "192.168.12.52",
Username: "dctdev",
Password: "dacenT2017",
})
videoSource, err := d.GetVideoSources()
if err != nil {
t.Fatal(err)
}
t.Log(videoSource) //"VideoSource_1"
}
func TestGetVideoSourceConfigurations(t *testing.T) {
d := NewDevice(onvif.DeviceParams{
Xaddr: "192.168.12.52",
Username: "dctdev",
Password: "dacenT2017",
})
videoSource, err := d.GetVideoSourceConfigurations()
if err != nil {
t.Fatal(err)
}
t.Log(videoSource)
}
func TestRelateVideoSource(t *testing.T) {
d := NewDevice(onvif.DeviceParams{
Xaddr: "192.168.12.52",
Username: "dctdev",
Password: "dacenT2017",
})
if err := d.RelateVideoSource("Profile_1", "VideoSource_1"); err != nil {
t.Fatal(err)
}
p, err := d.GetProfiles()
if err != nil {
t.Fatal(err)
}
t.Log(p)
}
func TestGetVideoEncoders(t *testing.T) {
d := NewDevice(onvif.DeviceParams{
Xaddr: "192.168.12.52",
Username: "dctdev",
Password: "dacenT2017",
})
encoders, err := d.GetVideoEncoderConfigurations()
if err != nil {
t.Fatal(err)
}
t.Log(encoders)
}