blob: c964b2465628c888b5e4fbf89eb030ce8e090b14 (
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
;;; test-video-audio-recording-command-structure.el --- Tests for recording command string structure -*- lexical-binding: t; -*-
;;; Commentary:
;; Tests that validate the structure and syntax of shell commands generated
;; for video and audio recording. These tests catch issues like invalid flags,
;; wrong encoder names, and incorrect output syntax that behavioral tests miss.
;;; Code:
(require 'ert)
;; Stub dependencies before loading the module
(defvar cj/custom-keymap (make-sparse-keymap)
"Stub keymap for testing.")
(defvar video-recordings-dir "/tmp/video-recordings/")
(defvar audio-recordings-dir "/tmp/audio-recordings/")
;; Now load the actual production module
(require 'video-audio-recording)
;;; Setup and Teardown
(defun test-command-structure-setup ()
"Reset all variables before each test."
(setq cj/video-recording-ffmpeg-process nil)
(setq cj/audio-recording-ffmpeg-process nil)
(setq cj/recording-mic-device "test-mic-device")
(setq cj/recording-system-device "test-monitor-device")
(setq cj/recording-mic-boost 2.0)
(setq cj/recording-system-volume 1.0))
(defun test-command-structure-teardown ()
"Clean up after each test."
(when cj/video-recording-ffmpeg-process
(ignore-errors (delete-process cj/video-recording-ffmpeg-process)))
(when cj/audio-recording-ffmpeg-process
(ignore-errors (delete-process cj/audio-recording-ffmpeg-process)))
(setq cj/video-recording-ffmpeg-process nil)
(setq cj/audio-recording-ffmpeg-process nil)
(setq cj/recording-mic-device nil)
(setq cj/recording-system-device nil))
;;; Wayland Video Recording - Command Structure
(ert-deftest test-video-recording-wayland-command-contains-wf-recorder ()
"Test that Wayland video recording uses wf-recorder."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "wf-recorder" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-wayland-command-has-auto-confirm-flag ()
"Test that wf-recorder command includes -y flag to auto-confirm overwrite."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "wf-recorder -y" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-wayland-command-has-correct-encoder ()
"Test that wf-recorder uses libx264 encoder (not h264)."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
;; Should use libx264, not h264
(should (string-match-p "-c libx264" command))
(should-not (string-match-p "-c h264[^a-z]" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-wayland-command-has-muxer-format ()
"Test that wf-recorder specifies matroska muxer with -m flag."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "-m matroska" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-wayland-command-outputs-to-stdout ()
"Test that wf-recorder outputs to stdout using -f /dev/stdout."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
;; Should use -f /dev/stdout, not -o -
(should (string-match-p "-f /dev/stdout" command))
(should-not (string-match-p " -o -" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-wayland-command-no-invalid-flags ()
"Test that wf-recorder command doesn't contain invalid flags."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
;; These flags don't exist in wf-recorder
(should-not (string-match-p "--no-audio" command))
(should-not (string-match-p "--noaudio" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-wayland-command-pipes-to-ffmpeg ()
"Test that wf-recorder output is piped to ffmpeg."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
;; Should pipe wf-recorder to ffmpeg
(should (string-match-p "wf-recorder.*|.*ffmpeg" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-wayland-ffmpeg-reads-from-pipe ()
"Test that ffmpeg reads from pipe input."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "ffmpeg -i pipe:0" command))))
(test-command-structure-teardown)))
;;; X11 Video Recording - Command Structure
(ert-deftest test-video-recording-x11-command-uses-x11grab ()
"Test that X11 video recording uses ffmpeg x11grab."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () nil))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "x11grab" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-x11-command-no-wf-recorder ()
"Test that X11 video recording doesn't use wf-recorder."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () nil))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should-not (string-match-p "wf-recorder" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-x11-command-captures-display ()
"Test that X11 video recording captures from display :0."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () nil))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "-i :0" command))))
(test-command-structure-teardown)))
;;; Audio Recording - Command Structure
(ert-deftest test-audio-recording-command-uses-ffmpeg ()
"Test that audio recording uses ffmpeg directly."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-audio" :command '("sleep" "1000")))))
(cj/ffmpeg-record-audio audio-recordings-dir)
(should (string-match-p "^ffmpeg " command))))
(test-command-structure-teardown)))
(ert-deftest test-audio-recording-command-uses-pulse-input ()
"Test that audio recording uses pulse audio input."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-audio" :command '("sleep" "1000")))))
(cj/ffmpeg-record-audio audio-recordings-dir)
(should (string-match-p "-f pulse" command))))
(test-command-structure-teardown)))
(ert-deftest test-audio-recording-command-outputs-m4a ()
"Test that audio recording outputs to .m4a file."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-audio" :command '("sleep" "1000")))))
(cj/ffmpeg-record-audio audio-recordings-dir)
(should (string-match-p "\\.m4a" command))))
(test-command-structure-teardown)))
;;; Common Command Structure (Both Video and Audio)
(ert-deftest test-video-recording-command-has-audio-filter-complex ()
"Test that video recording includes audio filter for mixing mic and system."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "-filter_complex" command))
(should (string-match-p "amerge" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-command-maps-video-and-audio ()
"Test that video recording maps both video and audio streams."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "-map 0:v" command))
(should (string-match-p "-map.*\\[out\\]" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-command-copies-video-codec ()
"Test that video recording copies video codec (no re-encoding)."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "-c:v copy" command))))
(test-command-structure-teardown)))
(ert-deftest test-video-recording-command-outputs-mkv ()
"Test that video recording outputs to .mkv file."
(test-command-structure-setup)
(unwind-protect
(let ((command nil))
(cl-letf (((symbol-function 'cj/recording--wayland-p) (lambda () t))
((symbol-function 'start-process-shell-command)
(lambda (_name _buffer cmd)
(setq command cmd)
(make-process :name "fake-video" :command '("sleep" "1000")))))
(cj/ffmpeg-record-video video-recordings-dir)
(should (string-match-p "\\.mkv" command))))
(test-command-structure-teardown)))
(provide 'test-video-audio-recording-command-structure)
;;; test-video-audio-recording-command-structure.el ends here
|