summaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording--get-sink-index.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-05 07:07:04 -0500
committerCraig Jennings <c@cjennings.net>2026-04-05 07:07:04 -0500
commita303c1c8274fc86383365c9de94e7975fb4b0a23 (patch)
tree2ec83b8090c5684797cc2fd617d06230eaad12d8 /tests/test-video-audio-recording--get-sink-index.el
parent4fa136a0f8bfde7852655a9fce2c44422bd32b3a (diff)
test(recording): add direct tests for device-sort-key, device-status-label, get-sink-index
Previously tested only indirectly via label-devices and sink-has-active-audio-p.
Diffstat (limited to 'tests/test-video-audio-recording--get-sink-index.el')
-rw-r--r--tests/test-video-audio-recording--get-sink-index.el72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/test-video-audio-recording--get-sink-index.el b/tests/test-video-audio-recording--get-sink-index.el
new file mode 100644
index 00000000..dffb1cd6
--- /dev/null
+++ b/tests/test-video-audio-recording--get-sink-index.el
@@ -0,0 +1,72 @@
+;;; test-video-audio-recording--get-sink-index.el --- Tests for sink index lookup -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Unit tests for cj/recording--get-sink-index.
+;; Verifies numeric index extraction from `pactl list sinks short' output.
+
+;;; Code:
+
+(require 'ert)
+
+;; Stub dependencies before loading the module
+(defvar cj/custom-keymap (make-sparse-keymap)
+ "Stub keymap for testing.")
+
+(require 'video-audio-recording)
+
+(defconst test--sinks-output
+ "47\talsa_output.usb-Jabra_SPEAK_510-00.analog-stereo\tmodule-alsa-card.c\ts16le 1ch 16000Hz\tSUSPENDED
+82\talsa_output.pci-0000_00_1f.3.analog-stereo\tmodule-alsa-card.c\ts32le 2ch 48000Hz\tRUNNING
+135\talsa_output.usb-JDS_Labs_Element_IV-00.analog-stereo\tmodule-alsa-card.c\ts32le 2ch 96000Hz\tIDLE"
+ "Sample pactl list sinks short output for tests.")
+
+;;; Normal Cases
+
+(ert-deftest test-video-audio-recording--get-sink-index-normal-returns-index ()
+ "Returns the numeric index for a matching sink name."
+ (should (equal "82" (cj/recording--get-sink-index
+ "alsa_output.pci-0000_00_1f.3.analog-stereo"
+ test--sinks-output))))
+
+(ert-deftest test-video-audio-recording--get-sink-index-normal-first-sink ()
+ "Returns index for the first sink in the list."
+ (should (equal "47" (cj/recording--get-sink-index
+ "alsa_output.usb-Jabra_SPEAK_510-00.analog-stereo"
+ test--sinks-output))))
+
+(ert-deftest test-video-audio-recording--get-sink-index-normal-last-sink ()
+ "Returns index for the last sink in the list."
+ (should (equal "135" (cj/recording--get-sink-index
+ "alsa_output.usb-JDS_Labs_Element_IV-00.analog-stereo"
+ test--sinks-output))))
+
+;;; Boundary Cases
+
+(ert-deftest test-video-audio-recording--get-sink-index-boundary-not-found ()
+ "Returns nil when sink name is not in the output."
+ (should (null (cj/recording--get-sink-index
+ "nonexistent.sink"
+ test--sinks-output))))
+
+(ert-deftest test-video-audio-recording--get-sink-index-boundary-empty-output ()
+ "Returns nil for empty output string."
+ (should (null (cj/recording--get-sink-index
+ "alsa_output.pci-0000_00_1f.3.analog-stereo"
+ ""))))
+
+(ert-deftest test-video-audio-recording--get-sink-index-boundary-substring-no-match ()
+ "Does not match when sink name is a substring of another sink."
+ (should (null (cj/recording--get-sink-index
+ "alsa_output.pci-0000_00_1f.3"
+ test--sinks-output))))
+
+;;; Error Cases
+
+(ert-deftest test-video-audio-recording--get-sink-index-error-malformed-lines ()
+ "Returns nil when output has no tab-separated fields."
+ (should (null (cj/recording--get-sink-index
+ "some-sink"
+ "this is not valid pactl output\nneither is this"))))
+
+(provide 'test-video-audio-recording--get-sink-index)
+;;; test-video-audio-recording--get-sink-index.el ends here