fordon_greeman / voidfiles

Branch: main
Switch branches/tags
main
theidioticdev add emacs 2079ec5 23h ago
57 lines · 2.4 KB Raw Blame History
1 ;;; emms-info-native-flac-tests.el --- Test suite for emms-info-native-flac -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2023 Free Software Foundation, Inc.
4
5 ;; Author: Petteri Hintsanen <petterih@iki.fi>
6
7 ;; This file is part of EMMS.
8
9 ;; EMMS is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
13
14 ;; EMMS is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 ;; License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with EMMS; see the file COPYING. If not, write to the Free
21 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 ;; MA 02110-1301, USA.
23
24 ;;; Code:
25
26 (require 'emms-info-native-flac)
27 (require 'ert)
28
29 (defmacro emms-test-flac-make-data-func (name bytes)
30 "Macro for defining test data generator.
31 This macro defines a suitable function with NAME that outputs
32 BYTES after FLAC signature. The function NAME can then be passed
33 for `emms-info-native-flac--decode-meta-blocks'."
34 `(defun ,name (offset end)
35 (let ((bytes (concat "fLaC" ,bytes)))
36 (erase-buffer)
37 (insert (substring bytes offset end)))))
38
39 (emms-test-flac-make-data-func emms-test-invalid-flac-block-length "\x01\xff\xff\xff\x00\x01\x02\x03")
40 (emms-test-flac-make-data-func emms-test-invalid-flac-block-type "\x09\x00\x00\x00\x00\x01\x02\x03")
41 (emms-test-flac-make-data-func emms-test-valid-flac-block "\x00\x00\x00\x08\x10\x11\x12\x13\x14\x15\x16\x17\x84\x00\x00\x04\x01\x02\x03\x04")
42
43 (ert-deftest emms-test-flac-meta-blocks ()
44 (should-error (emms-info-native-flac--decode-meta-blocks
45 #'emms-test-invalid-flac-block-length))
46 (should-error (emms-info-native-flac--decode-meta-blocks
47 #'emms-test-invalid-flac-block-type))
48 (should (equal (emms-info-native-flac--decode-meta-blocks
49 #'emms-test-valid-flac-block)
50 (list "\x01\x02\x03\x04"
51 "\x10\x11\x12\x13\x14\x15\x16\x17"))))
52
53 (ert-deftest emms-test-flac-decode-duration ()
54 ;; The corresponding sample metadata bytes are [10 196 66 240 1 8 36 0].
55 (should (= (emms-info-native-flac--decode-duration 775818634391462912) 392)))
56
57 ;;; emms-info-native-flac-tests.el ends here