From d0bfccb040dddb9c237a133a93668ce78b5db622 Mon Sep 17 00:00:00 2001 From: Steve Ayerhart Date: Tue, 29 Nov 2022 22:03:58 -0500 Subject: [PATCH] add tests to autotools --- Makefile.am | 2 +- configure.ac | 3 +- src/flac/metadata.scm | 1 - tests/Makefile.am | 30 ++++++ tests/ietf-decoding-examples.scm | 163 +++++++++++++++++++++++++++++++ tests/rcf-examples.scm | 119 ---------------------- 6 files changed, 196 insertions(+), 122 deletions(-) create mode 100644 tests/Makefile.am create mode 100644 tests/ietf-decoding-examples.scm delete mode 100644 tests/rcf-examples.scm diff --git a/Makefile.am b/Makefile.am index d11281e..9e390e2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,7 @@ ACLOCAL_AMFLAGS = -I build-aux -SUBDIRS = build-aux src +SUBDIRS = build-aux src tests EXTRA_DIST = \ build-aux/config.rpath \ diff --git a/configure.ac b/configure.ac index b2908f6..79e89e7 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ dnl Process this file with autoconf to produce configure. dnl define(GUILE_FLAC_CONFIGURE_COPYRIGHT, [[ -Copyright (C) 2017-2022 Artyom V. Poptsov +Copyright (C) 2022 Steve Ayerhart This file is part of Guile-FLAC. @@ -67,6 +67,7 @@ AC_CONFIG_FILES([ build-aux/m4/Makefile src/Makefile src/flac/Makefile + tests/Makefile ]) dnl Manual pages. diff --git a/src/flac/metadata.scm b/src/flac/metadata.scm index 06a30cc..27ff1c0 100644 --- a/src/flac/metadata.scm +++ b/src/flac/metadata.scm @@ -80,7 +80,6 @@ metadata) (define (read-flac-metadata) - (flac-read/assert-magic) (let metadata-loop ((metadata (%make-flac-metadata #f #f #f #f #f #f #f))) (receive (last-block? block-type block-length) (read-metadata-block-header) diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..ad2248d --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,30 @@ +SCM_TESTS = \ + ietf-decoding-examples.scm + +TESTS = ${SCM_TESTS} + +TEST_EXTENSIONS = .scm + +AM_TESTS_ENVIRONMENT = \ + abs_top_srcdir="$(abs_top_srcdir)"; export abs_top_srcdir; \ + abs_top_builddir="$(abs_top_builddir)"; export abs_top_builddir; \ + ORIGTERM=${TERM}; export ORIGTERM; \ + TERM=xterm; export TERM; \ + GUILE_AUTO_COMPILE=0; export GUILE_AUTO_COMPILE; + +# LOG_COMPILER was introduced in Automake 1.12; don't expect "make +# check" or "make distcheck" to work with earlier versions. +SCM_LOG_COMPILER = \ + $(GUILE) + +AM_SCM_LOG_FLAGS = \ + -L "$(abs_top_srcdir)/src" \ + -L "$(abs_top_builddir)/src" \ + -s + +EXTRA_DIST = \ + ${SCM_TESTS} + +CLEANFILES = \ + $(GOBJECTS) \ + *.log diff --git a/tests/ietf-decoding-examples.scm b/tests/ietf-decoding-examples.scm new file mode 100644 index 0000000..bdfa537 --- /dev/null +++ b/tests/ietf-decoding-examples.scm @@ -0,0 +1,163 @@ +;;; ietf-decoding-examples.scm -- Tests from the examples on the ietf document + +;; Copyright (C) 2022 Steve Ayerhart +;; +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. +;; +;; The program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with the program. If not, see . + + +;;; Commentary: + + +;;; Code: +(add-to-load-path (getenv "abs_top_srcdir")) + +(use-modules (flac reader) + (flac format) + (flac metadata) + (flac decoder) + + (rnrs bytevectors) + + (ice-9 binary-ports) + (ice-9 receive) + + (srfi srfi-64)) + +(test-begin "IETF Examples") + +(test-group "Example 1" + (define example-1 + #vu8(#x66 #x4c #x61 #x43 #x80 #x00 #x00 #x22 #x10 #x00 #x10 #x00 + #x00 #x00 #x0f #x00 #x00 #x0f #x0a #xc4 #x42 #xf0 #x00 #x00 + #x00 #x01 #x3e #x84 #xb4 #x18 #x07 #xdc #x69 #x03 #x07 #x58 + #x6a #x3d #xad #x1a #x2e #x0f #xff #xf8 #x69 #x18 #x00 #x00 + #xbf #x03 #x58 #xfd #x03 #x12 #x8b #xaa #x9a)) + + (define expected-streaminfo + (%make-metadata-stream-info + 4096 4096 15 15 44100 2 16 1 + #vu8(62 132 180 24 7 220 105 3 7 88 106 61 173 26 46 15))) + + (define expected-frame + (%make-frame + (%make-frame-header 'fixed 1 44100 'independent 16 0 191) + 43674 '((25588) (10416)))) + + + (receive (actual-metadata actual-frame) + (with-flac-input-port (open-bytevector-input-port example-1) + (λ () + (flac-read/assert-magic) + (let* ((metadata (read-flac-metadata)) + (stream-info (flac-metadata-stream-info metadata))) + (values metadata + (read-flac-frame stream-info))))) + (test-group "Metadata" + (test-equal "stream info" + (flac-metadata-stream-info actual-metadata) expected-streaminfo)) + (test-group "Frame" + (test-equal "first frame" expected-frame expected-frame)))) + +(test-group "Example 2" + (define example-2 + #vu8(#x66 #x4c #x61 #x43 #x00 #x00 #x00 #x22 #x00 #x10 #x00 #x10 + #x00 #x00 #x17 #x00 #x00 #x44 #x0a #xc4 #x42 #xf0 #x00 #x00 + #x00 #x13 #xd5 #xb0 #x56 #x49 #x75 #xe9 #x8b #x8d #x8b #x93 + #x04 #x22 #x75 #x7b #x81 #x03 #x03 #x00 #x00 #x12 #x00 #x00 + #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 + #x00 #x00 #x00 #x10 #x04 #x00 #x00 #x3a #x20 #x00 #x00 #x00 + #x72 #x65 #x66 #x65 #x72 #x65 #x6e #x63 #x65 #x20 #x6c #x69 + #x62 #x46 #x4c #x41 #x43 #x20 #x31 #x2e #x33 #x2e #x33 #x20 + #x32 #x30 #x31 #x39 #x30 #x38 #x30 #x34 #x01 #x00 #x00 #x00 + #x0e #x00 #x00 #x00 #x54 #x49 #x54 #x4c #x45 #x3d #xd7 #xa9 + #xd7 #x9c #xd7 #x95 #xd7 #x9d #x81 #x00 #x00 #x06 #x00 #x00 + #x00 #x00 #x00 #x00 #xff #xf8 #x69 #x98 #x00 #x0f #x99 #x12 + #x08 #x67 #x01 #x62 #x3d #x14 #x42 #x99 #x8f #x5d #xf7 #x0d + #x6f #xe0 #x0c #x17 #xca #xeb #x21 #x00 #x0e #xe7 #xa7 #x7a + #x24 #xa1 #x59 #x0c #x12 #x17 #xb6 #x03 #x09 #x7b #x78 #x4f + #xaa #x9a #x33 #xd2 #x85 #xe0 #x70 #xad #x5b #x1b #x48 #x51 + #xb4 #x01 #x0d #x99 #xd2 #xcd #x1a #x68 #xf1 #xe6 #xb8 #x10 + #xff #xf8 #x69 #x18 #x01 #x02 #xa4 #x02 #xc3 #x82 #xc4 #x0b + #xc1 #x4a #x03 #xee #x48 #xdd #x03 #xb6 #x7c #x13 #x30)) + + (define expected-stream-info + (%make-metadata-stream-info + 16 16 23 68 44100 2 16 19 + #vu8(213 176 86 73 117 233 139 141 139 147 4 34 117 123 129 3))) + + (define expected-vorbis-comment + (%make-metadata-vorbis-comment + "reference libFLAC 1.3.3 20190804" + (list '("TITLE" "שלום")))) + + (define expected-padding + (%make-metadata-padding 6)) + + (define expected-seek-table + (%make-metadata-seek-table + (list (%make-metadata-seek-point 0 0 16)))) + + (define expected-first-frame + (%make-frame + (%make-frame-header 'fixed 16 44100 'right 16 0 153) + 47120 + '((4302 7496 6199 7427 6484 7436 6740 7508 6984 7583 7182 -5990 -6306 -6032 -6299 -6165) + (6070 10545 8743 10449 9143 10463 9502 10569 9840 10680 10113 -8428 -8895 -8476 -8896 -8653)))) + + (define expected-second-frame + (%make-frame + (%make-frame-header 'fixed 3 44100 'independent 16 1 164) + 4912 + '((-15486 -15349 -16054) + (-9072 -8958 -9410)))) + + (receive (actual-metadata actual-first-frame actual-second-frame) + (with-flac-input-port (open-bytevector-input-port example-2) + (λ () + (flac-read/assert-magic) + (let* ((metadata (read-flac-metadata)) + (stream-info (flac-metadata-stream-info metadata))) + (values + metadata (read-flac-frame stream-info) (read-flac-frame stream-info))))) + (test-group "Metadata" + (test-equal "stream info" + (flac-metadata-stream-info actual-metadata) + expected-stream-info) + (test-equal "vorbis comment" + (flac-metadata-vorbis-comment actual-metadata) + expected-vorbis-comment) + (test-equal "padding" + (flac-metadata-padding actual-metadata) + expected-padding) + (test-equal "seek table" + (flac-metadata-seek-table actual-metadata) + expected-seek-table)) + (test-group "Frames" + (test-equal "frame 1" actual-first-frame expected-first-frame) + (test-equal "frame 2" actual-second-frame expected-second-frame)))) + +;;(define example-3 +;; #vu8(#x66 #x4c #x61 #x43 #x80 #x00 #x00 #x22 #x10 #x00 #x10 #x00 #x00 +;; #x00 #x1f #x00 #x00 #x1f #x07 #xd0 #x00 #x70 #x00 #x00 #x00 +;; #x18 #xf8 #xf9 #xe3 #x96 #xf5 #xcb #xcf #xc6 #xdc #x80 #x7f +;; #x99 #x77 #x90 #x6b #x32 #xff #xf8 #x68 #x02 #x00 #x17 #xe9 +;; #x44 #x00 #x4f #x6f #x31 #x3d #x10 #x47 #xd2 #x27 #xcb #x6d +;; #x09 #x08 #x31 #x45 #x2b #xdc #x28 #x22 #x22 #x80 #x57 #xa3)) + + +(define exit-status (test-runner-fail-count (test-runner-current))) + +(test-end "IETF Examples") + +(exit (= 0 exit-status)) diff --git a/tests/rcf-examples.scm b/tests/rcf-examples.scm deleted file mode 100644 index 402dbae..0000000 --- a/tests/rcf-examples.scm +++ /dev/null @@ -1,119 +0,0 @@ -(define-module (flac tests) - #:use-module (flac tests utils) - #:use-module (flac reader) - #:use-module (flac format) - #:use-module (flac metadata) - #:use-module (flac decoder) - - #:use-module (rnrs bytevectors) - #:use-module (ice-9 binary-ports) - - #:use-module (srfi srfi-64)) - -(define-syntax-rule (with-tests name body ...) - (begin - (test-begin name) - body ... - (test-end name))) - -(define-public example-1 - #vu8(#x66 #x4c #x61 #x43 #x80 #x00 #x00 #x22 #x10 #x00 #x10 #x00 - #x00 #x00 #x0f #x00 #x00 #x0f #x0a #xc4 #x42 #xf0 #x00 #x00 - #x00 #x01 #x3e #x84 #xb4 #x18 #x07 #xdc #x69 #x03 #x07 #x58 - #x6a #x3d #xad #x1a #x2e #x0f #xff #xf8 #x69 #x18 #x00 #x00 - #xbf #x03 #x58 #xfd #x03 #x12 #x8b #xaa #x9a)) - -(define-public example-2 - #vu8(#x66 #x4c #x61 #x43 #x00 #x00 #x00 #x22 #x00 #x10 #x00 #x10 - #x00 #x00 #x17 #x00 #x00 #x44 #x0a #xc4 #x42 #xf0 #x00 #x00 - #x00 #x13 #xd5 #xb0 #x56 #x49 #x75 #xe9 #x8b #x8d #x8b #x93 - #x04 #x22 #x75 #x7b #x81 #x03 #x03 #x00 #x00 #x12 #x00 #x00 - #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 #x00 - #x00 #x00 #x00 #x10 #x04 #x00 #x00 #x3a #x20 #x00 #x00 #x00 - #x72 #x65 #x66 #x65 #x72 #x65 #x6e #x63 #x65 #x20 #x6c #x69 - #x62 #x46 #x4c #x41 #x43 #x20 #x31 #x2e #x33 #x2e #x33 #x20 - #x32 #x30 #x31 #x39 #x30 #x38 #x30 #x34 #x01 #x00 #x00 #x00 - #x0e #x00 #x00 #x00 #x54 #x49 #x54 #x4c #x45 #x3d #xd7 #xa9 - #xd7 #x9c #xd7 #x95 #xd7 #x9d #x81 #x00 #x00 #x06 #x00 #x00 - #x00 #x00 #x00 #x00 #xff #xf8 #x69 #x98 #x00 #x0f #x99 #x12 - #x08 #x67 #x01 #x62 #x3d #x14 #x42 #x99 #x8f #x5d #xf7 #x0d - #x6f #xe0 #x0c #x17 #xca #xeb #x21 #x00 #x0e #xe7 #xa7 #x7a - #x24 #xa1 #x59 #x0c #x12 #x17 #xb6 #x03 #x09 #x7b #x78 #x4f - #xaa #x9a #x33 #xd2 #x85 #xe0 #x70 #xad #x5b #x1b #x48 #x51 - #xb4 #x01 #x0d #x99 #xd2 #xcd #x1a #x68 #xf1 #xe6 #xb8 #x10 - #xff #xf8 #x69 #x18 #x01 #x02 #xa4 #x02 #xc3 #x82 #xc4 #x0b - #xc1 #x4a #x03 #xee #x48 #xdd #x03 #xb6 #x7c #x13 #x30)) - -(define example-3 - #vu8(#x66 #x4c #x61 #x43 #x80 #x00 #x00 #x22 #x10 #x00 #x10 #x00 #x00 - #x00 #x1f #x00 #x00 #x1f #x07 #xd0 #x00 #x70 #x00 #x00 #x00 - #x18 #xf8 #xf9 #xe3 #x96 #xf5 #xcb #xcf #xc6 #xdc #x80 #x7f - #x99 #x77 #x90 #x6b #x32 #xff #xf8 #x68 #x02 #x00 #x17 #xe9 - #x44 #x00 #x4f #x6f #x31 #x3d #x10 #x47 #xd2 #x27 #xcb #x6d - #x09 #x08 #x31 #x45 #x2b #xdc #x28 #x22 #x22 #x80 #x57 #xa3)) - - ; (test-begin "RFC Examples") - ; - ; - -(with-tests - "RFC Examples" - (test-group "Example 1" - (with-flac-input-port - (open-bytevector-input-port example-1) - (λ () - (let* ((expected-streaminfo (%make-metadata-stream-info - 4096 4096 15 15 44100 2 16 1 - #vu8(62 132 180 24 7 220 105 3 7 88 106 61 173 26 46 15))) - (expected-frame (%make-frame - (%make-frame-header 'fixed 1 44100 'independent 16 0 191) - 43674 - '((25588) (10416)))) - - - (actual-metadata (read-flac-metadata)) - (actual-frame (read-flac-frame (flac-metadata-stream-info actual-metadata)))) - (test-group "Metadata" - (test-equal - "stream info" - (flac-metadata-stream-info actual-metadata) - expected-streaminfo)) - (test-group "Frame" - (test-equal "first frame" expected-frame expected-frame)))))) - (test-group "Example 2" - (with-flac-input-port - (open-bytevector-input-port example-2) - (λ () - (let* ((expected-stream-info (%make-metadata-stream-info - 16 16 23 68 44100 2 16 19 - #vu8(213 176 86 73 117 233 139 141 139 147 4 34 117 123 129 3))) - (expected-vorbis-comment (%make-metadata-vorbis-comment - "reference libFLAC 1.3.3 20190804" - (list '("TITLE" "שלום")))) - (expected-padding (%make-metadata-padding 6)) - (expected-seek-table (%make-metadata-seek-table - (list (%make-metadata-seek-point 0 0 16)))) - (expected-first-frame (%make-frame - (%make-frame-header 'fixed 16 44100 'right 16 0 153) - 47120 - '((4302 7496 6199 7427 6484 7436 6740 7508 6984 7583 7182 -5990 -6306 -6032 -6299 -6165) - (6070 10545 8743 10449 9143 10463 9502 10569 9840 10680 10113 -8428 -8895 -8476 -8896 -8653)))) - (expected-second-frame (%make-frame - (%make-frame-header 'fixed 3 44100 'independent 16 1 164) - 4912 - '((-15486 -15349 -16054) - (-9072 -8958 -9410)))) - - (actual-metadata (read-flac-metadata)) - (actual-stream-info (flac-metadata-stream-info actual-metadata)) - - (actual-first-frame (read-flac-frame actual-stream-info)) - (actual-second-frame (read-flac-frame actual-stream-info))) - (test-group "Metadata" - (test-equal "stream info" actual-stream-info expected-stream-info) - (test-equal "vorbis comment" (flac-metadata-vorbis-comment actual-metadata) expected-vorbis-comment) - (test-equal "padding" (flac-metadata-padding actual-metadata) expected-padding) - (test-equal "seek table" (flac-metadata-seek-table actual-metadata) expected-seek-table)) - (test-group "Frames" - (test-equal "frame 1" actual-first-frame expected-first-frame) - (test-equal "frame 2" actual-second-frame expected-second-frame)))))))