package goonvif import ( "fmt" "testing" "time" "os" "git.pyer.club/kingecg/goonvif/onvif" ) func TestMain(m *testing.M) { os.Setenv("DEBUG", "DEBUG") result := m.Run() os.Unsetenv("DEBUG") os.Exit(result) } 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) } 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("Profile_1") if err != nil { t.Errorf("Expected no error, got %v", err) return } fmt.Println(uri) } 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) } } 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) }