summaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording--get-sink-index.el
blob: dffb1cd662e57a0a82d7121ada53b5cb3775d48a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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