blob: f062ac0fc5472474f755bd847fb2225bbdf70900 (
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
|
;;; test-video-audio-recording--source-exists-p.el --- Tests for cj/recording--source-exists-p -*- lexical-binding: t; -*-
;;; Commentary:
;; Unit tests for cj/recording--source-exists-p function.
;; Tests checking whether a PulseAudio source exists in pactl 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)
;;; Test Fixtures Helper
(defun test-load-fixture (filename)
"Load fixture file FILENAME from tests/fixtures directory."
(let ((fixture-path (expand-file-name
(concat "tests/fixtures/" filename)
user-emacs-directory)))
(with-temp-buffer
(insert-file-contents fixture-path)
(buffer-string))))
;;; Normal Cases
(ert-deftest test-source-exists-p-normal-existing-device-returns-t ()
"Test that an existing device returns non-nil."
(let ((output (test-load-fixture "pactl-output-normal.txt")))
(should (cj/recording--source-exists-p
"alsa_output.pci-0000_00_1f.3.analog-stereo.monitor" output))))
(ert-deftest test-source-exists-p-normal-input-device-returns-t ()
"Test that an existing input device returns non-nil."
(let ((output (test-load-fixture "pactl-output-normal.txt")))
(should (cj/recording--source-exists-p
"alsa_input.pci-0000_00_1f.3.analog-stereo" output))))
(ert-deftest test-source-exists-p-normal-bluetooth-device-returns-t ()
"Test that a Bluetooth device returns non-nil."
(let ((output (test-load-fixture "pactl-output-normal.txt")))
(should (cj/recording--source-exists-p
"bluez_input.00:1B:66:C0:91:6D" output))))
;;; Boundary Cases
(ert-deftest test-source-exists-p-boundary-nonexistent-device-returns-nil ()
"Test that a non-existent device returns nil."
(let ((output (test-load-fixture "pactl-output-normal.txt")))
(should-not (cj/recording--source-exists-p
"nonexistent_device.monitor" output))))
(ert-deftest test-source-exists-p-boundary-empty-output-returns-nil ()
"Test that empty pactl output returns nil."
(should-not (cj/recording--source-exists-p "any-device" "")))
(ert-deftest test-source-exists-p-boundary-partial-name-no-match ()
"Test that partial device name does not match."
(let ((output (test-load-fixture "pactl-output-normal.txt")))
(should-not (cj/recording--source-exists-p
"alsa_output.pci-0000_00_1f.3.analog-stereo" output))))
(provide 'test-video-audio-recording--source-exists-p)
;;; test-video-audio-recording--source-exists-p.el ends here
|