48 lines
1.7 KiB
Racket
48 lines
1.7 KiB
Racket
#lang racket/base
|
|
|
|
(require rackunit
|
|
racket/file
|
|
racket/path
|
|
"../flac-48khz-manager.rkt")
|
|
|
|
(define tmp (make-temporary-file "alm-test-~a" 'directory))
|
|
(define hi (build-path tmp "hires.flac"))
|
|
(define cd (build-path tmp "cd.flac"))
|
|
(call-with-output-file hi #:exists 'replace (lambda (out) (display "hires" out)))
|
|
(call-with-output-file cd #:exists 'replace (lambda (out) (display "cd" out)))
|
|
|
|
(define convert-count 0)
|
|
|
|
(define (mock-inspect p)
|
|
(define s (file->string p))
|
|
(cond [(regexp-match? #rx"converted" s) 48000]
|
|
[(regexp-match? #rx"hires" s) 96000]
|
|
[else 44100]))
|
|
|
|
(define (mock-convert p rate compression)
|
|
(set! convert-count (add1 convert-count))
|
|
(call-with-output-file p #:exists 'replace
|
|
(lambda (out) (fprintf out "converted to ~a compression ~a" rate compression)))
|
|
(list (cons 'mock #t) (cons 'target-sample-rate rate)))
|
|
|
|
(define first-summary
|
|
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:convert-proc mock-convert))
|
|
(check-equal? (assoc 'seen first-summary) '(seen . 2))
|
|
(check-equal? (assoc 'new first-summary) '(new . 2))
|
|
(check-equal? (assoc 'converted first-summary) '(converted . 1))
|
|
(check-equal? convert-count 1)
|
|
|
|
(define second-summary
|
|
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:convert-proc mock-convert))
|
|
(check-equal? (assoc 'seen second-summary) '(seen . 2))
|
|
(check-equal? (assoc 'unchanged second-summary) '(unchanged . 2))
|
|
(check-equal? convert-count 1)
|
|
|
|
(delete-file cd)
|
|
(define third-summary
|
|
(manage-flac-tree tmp #:inspect-flac-proc mock-inspect #:convert-proc mock-convert))
|
|
(check-equal? (assoc 'removed third-summary) '(removed . 1))
|
|
(check-equal? (assoc 'unchanged third-summary) '(unchanged . 1))
|
|
|
|
(delete-directory/files tmp)
|