diff options
| -rw-r--r-- | tests/test-video-audio-recording--device-sort-key.el | 63 | ||||
| -rw-r--r-- | tests/test-video-audio-recording--device-status-label.el | 63 | ||||
| -rw-r--r-- | tests/test-video-audio-recording--get-sink-index.el | 72 |
3 files changed, 198 insertions, 0 deletions
diff --git a/tests/test-video-audio-recording--device-sort-key.el b/tests/test-video-audio-recording--device-sort-key.el new file mode 100644 index 00000000..97e67747 --- /dev/null +++ b/tests/test-video-audio-recording--device-sort-key.el @@ -0,0 +1,63 @@ +;;; test-video-audio-recording--device-sort-key.el --- Tests for device sort key -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for cj/recording--device-sort-key. +;; Verifies numeric sort key assignment: RUNNING=0, IDLE=1, SUSPENDED=2, muted=3. + +;;; Code: + +(require 'ert) + +;; Stub dependencies before loading the module +(defvar cj/custom-keymap (make-sparse-keymap) + "Stub keymap for testing.") + +(require 'video-audio-recording) + +;;; Normal Cases + +(ert-deftest test-video-audio-recording--device-sort-key-normal-running () + "RUNNING unmuted device returns 0 (highest priority)." + (should (= 0 (cj/recording--device-sort-key "RUNNING" "no")))) + +(ert-deftest test-video-audio-recording--device-sort-key-normal-idle () + "IDLE unmuted device returns 1." + (should (= 1 (cj/recording--device-sort-key "IDLE" "no")))) + +(ert-deftest test-video-audio-recording--device-sort-key-normal-suspended () + "SUSPENDED unmuted device returns 2." + (should (= 2 (cj/recording--device-sort-key "SUSPENDED" "no")))) + +(ert-deftest test-video-audio-recording--device-sort-key-normal-muted-overrides-state () + "Muted device returns 3 regardless of state." + (should (= 3 (cj/recording--device-sort-key "RUNNING" "yes"))) + (should (= 3 (cj/recording--device-sort-key "IDLE" "yes"))) + (should (= 3 (cj/recording--device-sort-key "SUSPENDED" "yes")))) + +;;; Boundary Cases + +(ert-deftest test-video-audio-recording--device-sort-key-boundary-nil-state () + "Nil state with unmuted returns 2 (default/available)." + (should (= 2 (cj/recording--device-sort-key nil "no")))) + +(ert-deftest test-video-audio-recording--device-sort-key-boundary-lowercase-state () + "Lowercase state is handled via upcase." + (should (= 0 (cj/recording--device-sort-key "running" "no"))) + (should (= 1 (cj/recording--device-sort-key "idle" "no")))) + +(ert-deftest test-video-audio-recording--device-sort-key-boundary-empty-state () + "Empty string state returns 2 (default)." + (should (= 2 (cj/recording--device-sort-key "" "no")))) + +;;; Error Cases + +(ert-deftest test-video-audio-recording--device-sort-key-error-unknown-state () + "Unknown state string returns 2 (falls through to default)." + (should (= 2 (cj/recording--device-sort-key "BOGUS" "no")))) + +(ert-deftest test-video-audio-recording--device-sort-key-error-muted-nil-state () + "Muted with nil state still returns 3 (muted check is first)." + (should (= 3 (cj/recording--device-sort-key nil "yes")))) + +(provide 'test-video-audio-recording--device-sort-key) +;;; test-video-audio-recording--device-sort-key.el ends here diff --git a/tests/test-video-audio-recording--device-status-label.el b/tests/test-video-audio-recording--device-status-label.el new file mode 100644 index 00000000..f64cc60b --- /dev/null +++ b/tests/test-video-audio-recording--device-status-label.el @@ -0,0 +1,63 @@ +;;; test-video-audio-recording--device-status-label.el --- Tests for device status label -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for cj/recording--device-status-label. +;; Verifies human-readable label mapping from PulseAudio state strings. + +;;; Code: + +(require 'ert) + +;; Stub dependencies before loading the module +(defvar cj/custom-keymap (make-sparse-keymap) + "Stub keymap for testing.") + +(require 'video-audio-recording) + +;;; Normal Cases + +(ert-deftest test-video-audio-recording--device-status-label-normal-running () + "RUNNING unmuted device returns [in use]." + (should (equal "[in use]" (cj/recording--device-status-label "RUNNING" "no")))) + +(ert-deftest test-video-audio-recording--device-status-label-normal-idle () + "IDLE unmuted device returns [ready]." + (should (equal "[ready]" (cj/recording--device-status-label "IDLE" "no")))) + +(ert-deftest test-video-audio-recording--device-status-label-normal-suspended () + "SUSPENDED unmuted device returns [available]." + (should (equal "[available]" (cj/recording--device-status-label "SUSPENDED" "no")))) + +(ert-deftest test-video-audio-recording--device-status-label-normal-muted-overrides-state () + "Muted device returns [muted] regardless of state." + (should (equal "[muted]" (cj/recording--device-status-label "RUNNING" "yes"))) + (should (equal "[muted]" (cj/recording--device-status-label "IDLE" "yes"))) + (should (equal "[muted]" (cj/recording--device-status-label "SUSPENDED" "yes")))) + +;;; Boundary Cases + +(ert-deftest test-video-audio-recording--device-status-label-boundary-nil-state () + "Nil state with unmuted falls through to [available]." + (should (equal "[available]" (cj/recording--device-status-label nil "no")))) + +(ert-deftest test-video-audio-recording--device-status-label-boundary-lowercase-state () + "Lowercase state is handled via upcase." + (should (equal "[in use]" (cj/recording--device-status-label "running" "no"))) + (should (equal "[ready]" (cj/recording--device-status-label "idle" "no")))) + +(ert-deftest test-video-audio-recording--device-status-label-boundary-empty-state () + "Empty string state falls through to [available]." + (should (equal "[available]" (cj/recording--device-status-label "" "no")))) + +;;; Error Cases + +(ert-deftest test-video-audio-recording--device-status-label-error-unknown-state () + "Unknown state string falls through to [available]." + (should (equal "[available]" (cj/recording--device-status-label "BOGUS" "no")))) + +(ert-deftest test-video-audio-recording--device-status-label-error-muted-nil-state () + "Muted with nil state still returns [muted]." + (should (equal "[muted]" (cj/recording--device-status-label nil "yes")))) + +(provide 'test-video-audio-recording--device-status-label) +;;; test-video-audio-recording--device-status-label.el ends here 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 |
