fordon_greeman / voidfiles

Branch: 2079ec5
Switch branches/tags
main
theidioticdev add emacs 2079ec5 23h ago
130 lines · 6.7 KB Raw Blame History
1 ;;; emms-info-ogg-tests.el --- Test suite for emms-info-ogg -*- 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)
27 (require 'emms-info-native-ogg)
28 (require 'ert)
29
30 (ert-deftest emms-test-ogg-decode-page ()
31 (let* ((bytes "\x4f\x67\x67\x53\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x86\xd1\x9e\x17\x00\x00\x00\x00\x35\x52\xfb\x88\x01\x1e\x01\x76\x6f\x72\x62\x69\x73\x00\x00\x00\x00\x01\x44\xac\x00\x00\x00\x00\x00\x00\x80\x38\x01\x00\x00\x00\x00\x00\xb8\x01")
32 (page (bindat-unpack emms-info-native-ogg--page-bindat-spec bytes)))
33 (should (= (emms-info-native-ogg--num-packets page) 1))
34 (should (= (bindat-length emms-info-native-ogg--page-bindat-spec page) 58))
35 (should (equal (bindat-get-field page 'payload)
36 "\x01\x76\x6f\x72\x62\x69\x73\x00\x00\x00\x00\x01\x44\xac\x00\x00\x00\x00\x00\x00\x80\x38\x01\x00\x00\x00\x00\x00\xb8\x01"))))
37
38 (ert-deftest emms-test-ogg-decode-vorbis-headers ()
39 "Test `emms-info-ogg--decode-headers' with Vorbis data."
40 (let ((bytes "\x01\x76\x6f\x72\x62\x69\x73\x00\x00\x00\x00\x01\x44\xac\x00\x00\x00\x00\x00\x00\x80\x38\x01\x00\x00\x00\x00\x00\xb8\x01\x03\x76\x6f\x72\x62\x69\x73\x34\x00\x00\x00\x58\x69\x70\x68\x2e\x4f\x72\x67\x20\x6c\x69\x62\x56\x6f\x72\x62\x69\x73\x20\x49\x20\x32\x30\x32\x30\x30\x37\x30\x34\x20\x28\x52\x65\x64\x75\x63\x69\x6e\x67\x20\x45\x6e\x76\x69\x72\x6f\x6e\x6d\x65\x6e\x74\x29\x02\x00\x00\x00\x07\x00\x00\x00\x66\x6f\x6f\x3d\x62\x61\x72\x1b\x00\x00\x00\x4b\x65\x79\x3d\xce\x9f\xe1\xbd\x90\xcf\x87\xe1\xbd\xb6\x20\xce\xa4\xce\xb1\xe1\xbd\x90\xcf\x84\xe1\xbd\xb0\x01"))
41 (should
42 (emms-equal-lists
43 (emms-info-native-ogg--decode-headers bytes 'vorbis)
44 '((identification-header
45 (packet-type . 1)
46 (vorbis . "vorbis")
47 (vorbis-version . 0)
48 (channel-count . 1)
49 (sample-rate . 44100)
50 (bitrate-maximum . 0)
51 (bitrate-nominal . 80000)
52 (bitrate-minimum . 0)
53 (blocksize . 184)
54 (framing-flag . 1))
55 (comment-header
56 (packet-type . 3)
57 (vorbis . "vorbis")
58 (vendor-length . 52)
59 (vendor-string . "Xiph.Org libVorbis I 20200704 (Reducing Environment)")
60 (user-comments-list-length . 2)
61 (user-comments
62 ((length . 7)
63 (user-comment . "foo=bar"))
64 ((length . 27)
65 (user-comment . "Key=\316\237\341\275\220\317\207\341\275\266 \316\244\316\261\341\275\220\317\204\341\275\260")))
66 (framing-bit . 1)))))))
67
68 (ert-deftest emms-test-ogg-decode-opus-headers ()
69 "Test `emms-info-ogg--decode-headers' with Opus data."
70 (let ((bytes "\x4f\x70\x75\x73\x48\x65\x61\x64\x01\x01\x38\x01\x44\xac\x00\x00\x00\x00\x00\x4f\x70\x75\x73\x54\x61\x67\x73\x0d\x00\x00\x00\x6c\x69\x62\x6f\x70\x75\x73\x20\x31\x2e\x33\x2e\x31\x03\x00\x00\x00\x26\x00\x00\x00\x45\x4e\x43\x4f\x44\x45\x52\x3d\x6f\x70\x75\x73\x65\x6e\x63\x20\x66\x72\x6f\x6d\x20\x6f\x70\x75\x73\x2d\x74\x6f\x6f\x6c\x73\x20\x30\x2e\x31\x2e\x31\x30\x07\x00\x00\x00\x66\x6f\x6f\x3d\x62\x61\x72\x1b\x00\x00\x00\x4b\x65\x79\x3d\xce\x9f\xe1\xbd\x90\xcf\x87\xe1\xbd\xb6\x20\xce\xa4\xce\xb1\xe1\xbd\x90\xcf\x84\xe1\xbd\xb0"))
71 (emms-equal-lists
72 (emms-info-native-ogg--decode-headers bytes 'opus)
73 '((identification-header
74 (opus-head . "OpusHead")
75 (opus-version . 1)
76 (channel-count . 1)
77 (pre-skip . 312)
78 (sample-rate . 44100)
79 (output-gain . 0)
80 (channel-mapping-family . 0))
81 (comment-header
82 (opus-tags . "OpusTags")
83 (vendor-length . 13)
84 (vendor-string . "libopus 1.3.1")
85 (user-comments-list-length . 3)
86 (user-comments
87 ((length . 38)
88 (user-comment . "ENCODER=opusenc from opus-tools 0.1.10"))
89 ((length . 7)
90 (user-comment . "foo=bar"))
91 ((length . 27)
92 (user-comment . "Key=\316\237\341\275\220\317\207\341\275\266 \316\244\316\261\341\275\220\317\204\341\275\260"))))))))
93
94 (defun emms-test-ogg--decode-last-page (bytes)
95 "Call `emms-info-ogg--decode-last-page' with BYTES input.
96
97 This is a helper function for `emms-test-ogg-decode-last-page'."
98 (with-temp-buffer
99 (set-buffer-multibyte nil)
100 (insert (concat bytes))
101 (emms-info-native-ogg--decode-last-page)))
102
103 (ert-deftest emms-test-ogg-decode-last-page()
104 (let ((valid "\x01\x02\x03\x04\x4f\x67\x67\x53\x00\x04\x00\x24\x08\x01\x00\x00\x00\x00\x9c\x39\x6e\x47\x40\x08\x00\x00\x19\x4e\xac\xa3\x01\x0a\x4f\x67\x67\x53\x31\x32\x33\x34\x35\x36")
105 (notlast "\x01\x02\x03\x04\x4f\x67\x67\x53\x00\x00\x00\x24\x08\x01\x00\x00\x00\x00\x9c\x39\x6e\x47\x40\x08\x00\x00\x19\x4e\xac\xa3\x01\x0a\x4f\x67\x67\x53\x31\x32\x33\x34\x35\x36")
106 (invalid "\x01\x02\x03\x04\x4f\x67\x67\x53\x00\x04\x00\x24\x08\x01\x00\x00\x00\x00\x9c\x39\x6e\x47\x40\x08\x00\x00\x01\x02\x03\x04\x01\x0a\x4f\x67\x67\x53\x31\x32\x33\x34\x35\x36")
107 (valid-result
108 (quote
109 ((capture-pattern . "OggS")
110 (stream-structure-version . 0)
111 (header-type-flag . 4)
112 (granule-position . 17310720)
113 (stream-serial-number . 1198406044)
114 (page-sequence-no . 2112)
115 (page-checksum . 2745978393)
116 (page-segments . 1)
117 (segment-table . [10])
118 (payload . "OggS123456")))))
119 (unless (eval-when-compile (fboundp 'bindat-type))
120 (push (cons 'granule-position-bytes [0 36 8 1 0 0 0 0]) valid-result))
121 (should (emms-equal-lists (emms-test-ogg--decode-last-page valid)
122 valid-result))
123 (should (equal (emms-test-ogg--decode-last-page notlast) nil))
124 (should (equal (emms-test-ogg--decode-last-page invalid) nil))))
125
126 (ert-deftest emms-test-ogg-calculate-checksum ()
127 (let ((bytes "\x01\x02\x03\x04\x4f\x67\x67\x53\x00\x04\x00\x24\x08\x01\x00\x00\x00\x00\x9c\x39\x6e\x47\x40\x08\x00\x00\x19\x4e\xac\xa3\x01\x0a\x4f\x67\x67\x53\x31\x32\x33\x34\x35\x36"))
128 (should (= (emms-info-native-ogg--checksum bytes) 445885580))))
129
130 ;;; emms-info-native-ogg-tests.el ends here