fix(replaygain): report decoder failures and reject incomplete scans

This commit is contained in:
zarzet
2026-09-07 16:36:50 +07:00
parent e3f7817b29
commit c27dc7c1b6
7 changed files with 147 additions and 13 deletions
+51
View File
@@ -0,0 +1,51 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:spotiflac_android/services/ffmpeg_service.dart';
void main() {
test('missing decoder reports unsupported and rejects a default summary', () {
var unsupported = false;
final result = FFmpegService.parseReplayGainScan(
FFmpegResult(
success: false,
returnCode: 1,
output:
'Decoder (codec ac4) not found for input stream #0:0\n'
'I: -70.0 LUFS\nPeak: -120.0 dBFS',
),
onUnsupportedDecoder: () => unsupported = true,
);
expect(result, isNull);
expect(unsupported, isTrue);
});
test('failed decoding cannot use a partial loudness measurement', () {
var unsupported = false;
final result = FFmpegService.parseReplayGainScan(
FFmpegResult(
success: false,
returnCode: 1,
output:
'Error while decoding stream #0:0: Invalid data\n'
'I: -12.0 LUFS\nPeak: -1.0 dBFS',
),
onUnsupportedDecoder: () => unsupported = true,
);
expect(result, isNull);
expect(unsupported, isFalse);
});
test('completed analysis uses the final summary and highest peak', () {
final result = FFmpegService.parseReplayGainScan(
FFmpegResult(
success: true,
returnCode: 0,
output:
'I: -70.0 LUFS\nI: -12.0 LUFS\n'
'Peak: -2.0 dBFS\nPeak: -1.0 dBFS',
),
);
expect(result, isNotNull);
expect(result!.trackGain, '-6.00 dB');
expect(result.truePeakLinear, closeTo(0.891251, 0.000001));
});
}