package onvif
import (
"context"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// TestGetProfiles tests GetProfiles operation.
func TestGetProfiles(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
Main Profile
H264
1920
1080
5.0
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
profiles, err := client.GetProfiles(ctx)
if err != nil {
t.Fatalf("GetProfiles() failed: %v", err)
}
if len(profiles) != 1 {
t.Errorf("Expected 1 profile, got %d", len(profiles))
}
if profiles[0].Token != "Profile1" {
t.Errorf("Expected token Profile1, got %s", profiles[0].Token)
}
if profiles[0].Name != "Main Profile" {
t.Errorf("Expected name 'Main Profile', got %s", profiles[0].Name)
}
}
// TestGetProfile tests GetProfile operation.
func TestGetProfile(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
Main Profile
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
profile, err := client.GetProfile(ctx, "Profile1")
if err != nil {
t.Fatalf("GetProfile() failed: %v", err)
}
if profile.Token != "Profile1" {
t.Errorf("Expected token Profile1, got %s", profile.Token)
}
}
// TestSetProfile tests SetProfile operation.
func TestSetProfile(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
profile := &Profile{
Token: "Profile1",
Name: "Updated Profile",
}
err = client.SetProfile(ctx, profile)
if err != nil {
t.Fatalf("SetProfile() failed: %v", err)
}
}
// TestGetStreamURI tests GetStreamURI operation.
func TestGetStreamURI(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
rtsp://192.168.1.100:554/stream1
false
true
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
uri, err := client.GetStreamURI(ctx, "Profile1")
if err != nil {
t.Fatalf("GetStreamURI() failed: %v", err)
}
if uri.URI != "rtsp://192.168.1.100:554/stream1" {
t.Errorf("Expected URI 'rtsp://192.168.1.100:554/stream1', got %s", uri.URI)
}
}
// TestGetSnapshotURI tests GetSnapshotURI operation.
func TestGetSnapshotURI(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
http://192.168.1.100/snapshot.jpg
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
uri, err := client.GetSnapshotURI(ctx, "Profile1")
if err != nil {
t.Fatalf("GetSnapshotURI() failed: %v", err)
}
if !strings.Contains(uri.URI, "snapshot") {
t.Errorf("Expected snapshot URI, got %s", uri.URI)
}
}
// TestGetVideoSources tests GetVideoSources operation.
func TestGetVideoSources(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
30.0
1920
1080
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
sources, err := client.GetVideoSources(ctx)
if err != nil {
t.Fatalf("GetVideoSources() failed: %v", err)
}
if len(sources) != 1 {
t.Errorf("Expected 1 video source, got %d", len(sources))
}
if sources[0].Token != "VideoSource1" {
t.Errorf("Expected token VideoSource1, got %s", sources[0].Token)
}
}
// TestGetAudioSources tests GetAudioSources operation.
func TestGetAudioSources(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
2
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
sources, err := client.GetAudioSources(ctx)
if err != nil {
t.Fatalf("GetAudioSources() failed: %v", err)
}
if len(sources) != 1 {
t.Errorf("Expected 1 audio source, got %d", len(sources))
}
}
// TestGetAudioOutputs tests GetAudioOutputs operation.
func TestGetAudioOutputs(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
outputs, err := client.GetAudioOutputs(ctx)
if err != nil {
t.Fatalf("GetAudioOutputs() failed: %v", err)
}
if len(outputs) != 1 {
t.Errorf("Expected 1 audio output, got %d", len(outputs))
}
}
// TestCreateProfile tests CreateProfile operation.
func TestCreateProfile(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
New Profile
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
profile, err := client.CreateProfile(ctx, "New Profile", "")
if err != nil {
t.Fatalf("CreateProfile() failed: %v", err)
}
if profile.Token != "NewProfile1" {
t.Errorf("Expected token NewProfile1, got %s", profile.Token)
}
}
// TestDeleteProfile tests DeleteProfile operation.
func TestDeleteProfile(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.DeleteProfile(ctx, "Profile1")
if err != nil {
t.Fatalf("DeleteProfile() failed: %v", err)
}
}
// TestGetVideoEncoderConfiguration tests GetVideoEncoderConfiguration operation.
func TestGetVideoEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
H264 Config
H264
1920
1080
5.0
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config, err := client.GetVideoEncoderConfiguration(ctx, "VideoEnc1")
if err != nil {
t.Fatalf("GetVideoEncoderConfiguration() failed: %v", err)
}
if config.Token != "VideoEnc1" {
t.Errorf("Expected token VideoEnc1, got %s", config.Token)
}
if config.Encoding != "H264" {
t.Errorf("Expected encoding H264, got %s", config.Encoding)
}
}
// TestSetVideoEncoderConfiguration tests SetVideoEncoderConfiguration operation.
func TestSetVideoEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config := &VideoEncoderConfiguration{
Token: "VideoEnc1",
Name: "H264 Config",
Encoding: "H264",
Resolution: &VideoResolution{
Width: 1920,
Height: 1080,
},
Quality: 5.0,
}
err = client.SetVideoEncoderConfiguration(ctx, config, true)
if err != nil {
t.Fatalf("SetVideoEncoderConfiguration() failed: %v", err)
}
}
// TestGetMediaServiceCapabilities tests GetMediaServiceCapabilities operation.
func TestGetMediaServiceCapabilities(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
caps, err := client.GetMediaServiceCapabilities(ctx)
if err != nil {
t.Fatalf("GetMediaServiceCapabilities() failed: %v", err)
}
if !caps.SnapshotURI {
t.Error("Expected SnapshotURI to be true")
}
if caps.MaximumNumberOfProfiles != 10 {
t.Errorf("Expected MaximumNumberOfProfiles 10, got %d", caps.MaximumNumberOfProfiles)
}
}
// TestGetVideoEncoderConfigurationOptions tests GetVideoEncoderConfigurationOptions operation.
func TestGetVideoEncoderConfigurationOptions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
1.0
10.0
1920
1080
Baseline
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
options, err := client.GetVideoEncoderConfigurationOptions(ctx, "VideoEnc1")
if err != nil {
t.Fatalf("GetVideoEncoderConfigurationOptions() failed: %v", err)
}
if options.QualityRange == nil {
t.Error("Expected QualityRange to be set")
}
if options.H264 == nil {
t.Error("Expected H264 options to be set")
}
}
// TestGetAudioEncoderConfiguration tests GetAudioEncoderConfiguration operation.
func TestGetAudioEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
AAC Config
AAC
128000
48000
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config, err := client.GetAudioEncoderConfiguration(ctx, "AudioEnc1")
if err != nil {
t.Fatalf("GetAudioEncoderConfiguration() failed: %v", err)
}
if config.Token != "AudioEnc1" {
t.Errorf("Expected token AudioEnc1, got %s", config.Token)
}
if config.Encoding != "AAC" {
t.Errorf("Expected encoding AAC, got %s", config.Encoding)
}
}
// TestSetAudioEncoderConfiguration tests SetAudioEncoderConfiguration operation.
func TestSetAudioEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config := &AudioEncoderConfiguration{
Token: "AudioEnc1",
Name: "AAC Config",
Encoding: "AAC",
Bitrate: 128000,
SampleRate: 48000,
}
err = client.SetAudioEncoderConfiguration(ctx, config, true)
if err != nil {
t.Fatalf("SetAudioEncoderConfiguration() failed: %v", err)
}
}
// TestGetMetadataConfiguration tests GetMetadataConfiguration operation.
func TestGetMetadataConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
Metadata Config
true
true
false
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config, err := client.GetMetadataConfiguration(ctx, "Metadata1")
if err != nil {
t.Fatalf("GetMetadataConfiguration() failed: %v", err)
}
if config.Token != "Metadata1" {
t.Errorf("Expected token Metadata1, got %s", config.Token)
}
if config.PTZStatus == nil {
t.Error("Expected PTZStatus to be set")
}
}
// TestSetMetadataConfiguration tests SetMetadataConfiguration operation.
func TestSetMetadataConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config := &MetadataConfiguration{
Token: "Metadata1",
Name: "Metadata Config",
Analytics: false,
PTZStatus: &PTZFilter{
Status: true,
Position: true,
},
}
err = client.SetMetadataConfiguration(ctx, config, true)
if err != nil {
t.Fatalf("SetMetadataConfiguration() failed: %v", err)
}
}
// TestGetVideoSourceModes tests GetVideoSourceModes operation.
func TestGetVideoSourceModes(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
true
1920
1080
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
modes, err := client.GetVideoSourceModes(ctx, "VideoSource1")
if err != nil {
t.Fatalf("GetVideoSourceModes() failed: %v", err)
}
if len(modes) != 1 {
t.Errorf("Expected 1 mode, got %d", len(modes))
}
if modes[0].Token != "Mode1" {
t.Errorf("Expected token Mode1, got %s", modes[0].Token)
}
}
// TestSetVideoSourceMode tests SetVideoSourceMode operation.
func TestSetVideoSourceMode(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.SetVideoSourceMode(ctx, "VideoSource1", "Mode1")
if err != nil {
t.Fatalf("SetVideoSourceMode() failed: %v", err)
}
}
// TestSetSynchronizationPoint tests SetSynchronizationPoint operation.
func TestSetSynchronizationPoint(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.SetSynchronizationPoint(ctx, "Profile1")
if err != nil {
t.Fatalf("SetSynchronizationPoint() failed: %v", err)
}
}
// TestGetOSDs tests GetOSDs operation.
func TestGetOSDs(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
osds, err := client.GetOSDs(ctx, "")
if err != nil {
t.Fatalf("GetOSDs() failed: %v", err)
}
if len(osds) != 2 {
t.Errorf("Expected 2 OSDs, got %d", len(osds))
}
}
// TestGetOSD tests GetOSD operation.
func TestGetOSD(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
osd, err := client.GetOSD(ctx, "OSD1")
if err != nil {
t.Fatalf("GetOSD() failed: %v", err)
}
if osd.Token != "OSD1" {
t.Errorf("Expected token OSD1, got %s", osd.Token)
}
}
// TestSetOSD tests SetOSD operation.
func TestSetOSD(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
osd := &OSDConfiguration{
Token: "OSD1",
}
err = client.SetOSD(ctx, osd)
if err != nil {
t.Fatalf("SetOSD() failed: %v", err)
}
}
// TestCreateOSD tests CreateOSD operation.
func TestCreateOSD(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
osd, err := client.CreateOSD(ctx, "VideoSourceConfig1", nil)
if err != nil {
t.Fatalf("CreateOSD() failed: %v", err)
}
if osd.Token != "NewOSD1" {
t.Errorf("Expected token NewOSD1, got %s", osd.Token)
}
}
// TestDeleteOSD tests DeleteOSD operation.
func TestDeleteOSD(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.DeleteOSD(ctx, "OSD1")
if err != nil {
t.Fatalf("DeleteOSD() failed: %v", err)
}
}
// TestStartMulticastStreaming tests StartMulticastStreaming operation.
func TestStartMulticastStreaming(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.StartMulticastStreaming(ctx, "Profile1")
if err != nil {
t.Fatalf("StartMulticastStreaming() failed: %v", err)
}
}
// TestStopMulticastStreaming tests StopMulticastStreaming operation.
func TestStopMulticastStreaming(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.StopMulticastStreaming(ctx, "Profile1")
if err != nil {
t.Fatalf("StopMulticastStreaming() failed: %v", err)
}
}
// TestAddVideoEncoderConfiguration tests AddVideoEncoderConfiguration operation.
func TestAddVideoEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.AddVideoEncoderConfiguration(ctx, "Profile1", "VideoEnc1")
if err != nil {
t.Fatalf("AddVideoEncoderConfiguration() failed: %v", err)
}
}
// TestRemoveVideoEncoderConfiguration tests RemoveVideoEncoderConfiguration operation.
func TestRemoveVideoEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.RemoveVideoEncoderConfiguration(ctx, "Profile1")
if err != nil {
t.Fatalf("RemoveVideoEncoderConfiguration() failed: %v", err)
}
}
// TestAddAudioEncoderConfiguration tests AddAudioEncoderConfiguration operation.
func TestAddAudioEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.AddAudioEncoderConfiguration(ctx, "Profile1", "AudioEnc1")
if err != nil {
t.Fatalf("AddAudioEncoderConfiguration() failed: %v", err)
}
}
// TestRemoveAudioEncoderConfiguration tests RemoveAudioEncoderConfiguration operation.
func TestRemoveAudioEncoderConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.RemoveAudioEncoderConfiguration(ctx, "Profile1")
if err != nil {
t.Fatalf("RemoveAudioEncoderConfiguration() failed: %v", err)
}
}
// TestAddAudioSourceConfiguration tests AddAudioSourceConfiguration operation.
func TestAddAudioSourceConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.AddAudioSourceConfiguration(ctx, "Profile1", "AudioSourceConfig1")
if err != nil {
t.Fatalf("AddAudioSourceConfiguration() failed: %v", err)
}
}
// TestRemoveAudioSourceConfiguration tests RemoveAudioSourceConfiguration operation.
func TestRemoveAudioSourceConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.RemoveAudioSourceConfiguration(ctx, "Profile1")
if err != nil {
t.Fatalf("RemoveAudioSourceConfiguration() failed: %v", err)
}
}
// TestAddVideoSourceConfiguration tests AddVideoSourceConfiguration operation.
func TestAddVideoSourceConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.AddVideoSourceConfiguration(ctx, "Profile1", "VideoSourceConfig1")
if err != nil {
t.Fatalf("AddVideoSourceConfiguration() failed: %v", err)
}
}
// TestRemoveVideoSourceConfiguration tests RemoveVideoSourceConfiguration operation.
func TestRemoveVideoSourceConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.RemoveVideoSourceConfiguration(ctx, "Profile1")
if err != nil {
t.Fatalf("RemoveVideoSourceConfiguration() failed: %v", err)
}
}
// TestAddPTZConfiguration tests AddPTZConfiguration operation.
func TestAddPTZConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.AddPTZConfiguration(ctx, "Profile1", "PTZConfig1")
if err != nil {
t.Fatalf("AddPTZConfiguration() failed: %v", err)
}
}
// TestRemovePTZConfiguration tests RemovePTZConfiguration operation.
func TestRemovePTZConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.RemovePTZConfiguration(ctx, "Profile1")
if err != nil {
t.Fatalf("RemovePTZConfiguration() failed: %v", err)
}
}
// TestAddMetadataConfiguration tests AddMetadataConfiguration operation.
func TestAddMetadataConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.AddMetadataConfiguration(ctx, "Profile1", "Metadata1")
if err != nil {
t.Fatalf("AddMetadataConfiguration() failed: %v", err)
}
}
// TestRemoveMetadataConfiguration tests RemoveMetadataConfiguration operation.
func TestRemoveMetadataConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
err = client.RemoveMetadataConfiguration(ctx, "Profile1")
if err != nil {
t.Fatalf("RemoveMetadataConfiguration() failed: %v", err)
}
}
// TestGetAudioEncoderConfigurationOptions tests GetAudioEncoderConfigurationOptions operation.
func TestGetAudioEncoderConfigurationOptions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
AAC
G711
64000
128000
44100
48000
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
options, err := client.GetAudioEncoderConfigurationOptions(ctx, "AudioEnc1", "")
if err != nil {
t.Fatalf("GetAudioEncoderConfigurationOptions() failed: %v", err)
}
if len(options.EncodingOptions) == 0 {
t.Error("Expected encoding options to be set")
}
}
// TestGetMetadataConfigurationOptions tests GetMetadataConfigurationOptions operation.
func TestGetMetadataConfigurationOptions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
true
true
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
options, err := client.GetMetadataConfigurationOptions(ctx, "Metadata1", "")
if err != nil {
t.Fatalf("GetMetadataConfigurationOptions() failed: %v", err)
}
if options.PTZStatusFilterOptions == nil {
t.Error("Expected PTZStatusFilterOptions to be set")
}
}
// TestGetAudioOutputConfiguration tests GetAudioOutputConfiguration operation.
func TestGetAudioOutputConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
Audio Output Config
AudioOutput1
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config, err := client.GetAudioOutputConfiguration(ctx, "AudioOutputConfig1")
if err != nil {
t.Fatalf("GetAudioOutputConfiguration() failed: %v", err)
}
if config.Token != "AudioOutputConfig1" {
t.Errorf("Expected token AudioOutputConfig1, got %s", config.Token)
}
}
// TestSetAudioOutputConfiguration tests SetAudioOutputConfiguration operation.
func TestSetAudioOutputConfiguration(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(``))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
config := &AudioOutputConfiguration{
Token: "AudioOutputConfig1",
Name: "Audio Output Config",
OutputToken: "AudioOutput1",
}
err = client.SetAudioOutputConfiguration(ctx, config, true)
if err != nil {
t.Fatalf("SetAudioOutputConfiguration() failed: %v", err)
}
}
// TestGetAudioOutputConfigurationOptions tests GetAudioOutputConfigurationOptions operation.
func TestGetAudioOutputConfigurationOptions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
AudioOutput1
AudioOutput2
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
options, err := client.GetAudioOutputConfigurationOptions(ctx, "")
if err != nil {
t.Fatalf("GetAudioOutputConfigurationOptions() failed: %v", err)
}
if len(options.OutputTokensAvailable) == 0 {
t.Error("Expected output tokens to be available")
}
}
// TestGetAudioDecoderConfigurationOptions tests GetAudioDecoderConfigurationOptions operation.
func TestGetAudioDecoderConfigurationOptions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
64000
128000
44100
48000
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
options, err := client.GetAudioDecoderConfigurationOptions(ctx, "")
if err != nil {
t.Fatalf("GetAudioDecoderConfigurationOptions() failed: %v", err)
}
if options.AACDecOptions == nil {
t.Error("Expected AACDecOptions to be set")
}
}
// TestGetGuaranteedNumberOfVideoEncoderInstances tests GetGuaranteedNumberOfVideoEncoderInstances operation.
func TestGetGuaranteedNumberOfVideoEncoderInstances(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
4
2
2
0
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
instances, err := client.GetGuaranteedNumberOfVideoEncoderInstances(ctx, "VideoEnc1")
if err != nil {
t.Fatalf("GetGuaranteedNumberOfVideoEncoderInstances() failed: %v", err)
}
if instances.TotalNumber != 4 {
t.Errorf("Expected TotalNumber 4, got %d", instances.TotalNumber)
}
if instances.H264 != 2 {
t.Errorf("Expected H264 2, got %d", instances.H264)
}
}
// TestGetOSDOptions tests GetOSDOptions operation.
func TestGetOSDOptions(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
response := `
10
`
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(response))
}))
defer server.Close()
client, err := NewClient(server.URL + "/onvif/media_service")
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
options, err := client.GetOSDOptions(ctx, "")
if err != nil {
t.Fatalf("GetOSDOptions() failed: %v", err)
}
if options.MaximumNumberOfOSDs != 10 {
t.Errorf("Expected MaximumNumberOfOSDs 10, got %d", options.MaximumNumberOfOSDs)
}
}