aboutsummaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording--build-audio-command.el
blob: 54e5f56c8016256847f998f38632b7714729dae6 (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
73
74
75
76
;;; test-video-audio-recording--build-audio-command.el --- Tests for audio command builder -*- lexical-binding: t; -*-

;;; Commentary:
;; Unit tests for cj/recording--build-audio-command.
;; Verifies correct ffmpeg command construction for audio-only recording
;; (mic + system monitor mixed to M4A/AAC), including shell quoting of
;; device names and output paths.

;;; 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--build-audio-command-normal-uses-ffmpeg-pulse ()
  "Normal: audio command uses ffmpeg with two PulseAudio inputs mixed to AAC."
  (let ((cj/recording-mic-boost 2.0)
        (cj/recording-system-volume 1.0))
    (let ((cmd (cj/recording--build-audio-command "mic" "sys" "/tmp/out.m4a")))
      (should (string-match-p "ffmpeg" cmd))
      (should (string-match-p "-f pulse -i" cmd))
      (should (string-match-p "amix=inputs=2" cmd))
      (should (string-match-p "-c:a aac" cmd)))))

(ert-deftest test-video-audio-recording--build-audio-command-normal-devices-in-command ()
  "Normal: both mic and system device names appear in the command."
  (let ((cj/recording-mic-boost 1.0)
        (cj/recording-system-volume 1.0))
    (let ((cmd (cj/recording--build-audio-command
                "alsa_input.usb-Jabra-00.mono"
                "alsa_output.usb-JDS-00.monitor"
                "/tmp/out.m4a")))
      (should (string-match-p "alsa_input.usb-Jabra-00.mono" cmd))
      (should (string-match-p "alsa_output.usb-JDS-00.monitor" cmd)))))

(ert-deftest test-video-audio-recording--build-audio-command-normal-volume-in-filter ()
  "Normal: volume settings appear in the filter_complex expression."
  (let ((cj/recording-mic-boost 1.5)
        (cj/recording-system-volume 0.7))
    (let ((cmd (cj/recording--build-audio-command "mic" "sys" "/tmp/out.m4a")))
      (should (string-match-p "volume=1\\.5" cmd))
      (should (string-match-p "volume=0\\.7" cmd)))))

;;; Boundary Cases

(ert-deftest test-video-audio-recording--build-audio-command-boundary-device-quoted ()
  "Boundary: device names with spaces are shell-quoted."
  (let ((cj/recording-mic-boost 1.0)
        (cj/recording-system-volume 1.0))
    (let ((cmd (cj/recording--build-audio-command
                "device with spaces" "sys" "/tmp/out.m4a")))
      (should (string-match-p "device\\\\ with\\\\ spaces" cmd)))))

(ert-deftest test-video-audio-recording--build-audio-command-boundary-filename-quoted ()
  "Boundary: output filename with spaces is shell-quoted."
  (let ((cj/recording-mic-boost 1.0)
        (cj/recording-system-volume 1.0))
    (let ((cmd (cj/recording--build-audio-command
                "mic" "sys" "/tmp/my recording.m4a")))
      (should (string-match-p "my\\\\ recording\\.m4a" cmd)))))

(ert-deftest test-video-audio-recording--build-audio-command-boundary-zero-volume ()
  "Boundary: zero volume values produce 0.0 in the command."
  (let ((cj/recording-mic-boost 0.0)
        (cj/recording-system-volume 0.0))
    (let ((cmd (cj/recording--build-audio-command "mic" "sys" "/tmp/out.m4a")))
      (should (string-match-p "volume=0\\.0" cmd)))))

(provide 'test-video-audio-recording--build-audio-command)
;;; test-video-audio-recording--build-audio-command.el ends here