Files
mediadevices/pkg/driver/camera/camera_stubs_test.go
T
sean yu 03900dcb1b Add darwin runtime device observer support (#670)
* wip

* wip

* Organize

* Remove unnecessary change in camera_darwin.go filtering

* wip

* Make observer stop safe during startup

* wip IsAvailable impl

* Fix non-darwin builds

* Lock bg loop to main thread and add comment

* Remove fmt prints

* Simplify isAvailable; Add timeout for Read darwin

* Match comment with code

* Change to singleton pattern; Add clearer safer state machine states; Change language from Stop to Destroy; Add new error for when observer is unavailable;

* Add stubs for linux

* Move cancel() up so its not dead code sometimes

* Add stubs for Windows too

* Remove StopObserver usage

* Add camera tests

* Add device observer tests

* Fix multiple destroy calls bug; Call setup in start

* Improve isAvailable

* Improve string handling in device observer c

* Add error handling in example

* Add comment about setup vs start

* Rename and organize device observer darwin

* Explicitly case initial state for setup

* Fix potential destroy goroutine leak; Use only modern build tag; Return err not nil for stubs; Improve comments

* Close startDone channel on device observer stop not wait
2025-12-28 13:33:36 -08:00

53 lines
1.7 KiB
Go

//go:build linux || windows
package camera
import (
"errors"
"testing"
"github.com/pion/mediadevices/pkg/driver/availability"
)
// TestSetupObserver tests the stub implementation of SetupObserver.
func TestSetupObserver(t *testing.T) {
err := SetupObserver()
if !errors.Is(err, availability.ErrUnimplemented) {
t.Errorf("SetupObserver() should return ErrUnimplemented for stub implementation, got: %v", err)
}
}
// TestStartObserver tests the stub implementation of StartObserver.
func TestStartObserver(t *testing.T) {
err := StartObserver()
if !errors.Is(err, availability.ErrUnimplemented) {
t.Errorf("StartObserver() should return ErrUnimplemented for stub implementation, got: %v", err)
}
}
// TestDestroyObserver tests the stub implementation of DestroyObserver.
func TestDestroyObserver(t *testing.T) {
err := DestroyObserver()
if !errors.Is(err, availability.ErrUnimplemented) {
t.Errorf("DestroyObserver() should return ErrUnimplemented for stub implementation, got: %v", err)
}
}
// TestObserverFunctionsIdempotent tests that observer functions can be called multiple times safely.
func TestObserverFunctionsIdempotent(t *testing.T) {
for i := 0; i < 3; i++ {
if err := SetupObserver(); !errors.Is(err, availability.ErrUnimplemented) {
t.Errorf("SetupObserver() call %d should return ErrUnimplemented, got: %v", i+1, err)
}
if err := StartObserver(); !errors.Is(err, availability.ErrUnimplemented) {
t.Errorf("StartObserver() call %d should return ErrUnimplemented, got: %v", i+1, err)
}
}
for i := 0; i < 3; i++ {
if err := DestroyObserver(); !errors.Is(err, availability.ErrUnimplemented) {
t.Errorf("DestroyObserver() call %d should return ErrUnimplemented, got: %v", i+1, err)
}
}
}