|
| 1 | +import 'dart:convert'; |
| 2 | +import 'dart:typed_data'; |
| 3 | + |
| 4 | +import 'package:bb_mobile/core/urqr/urqr.dart'; |
| 5 | +import 'package:cbor/cbor.dart'; |
| 6 | +import 'package:flutter_test/flutter_test.dart'; |
| 7 | +import 'package:ur/ur.dart'; |
| 8 | +import 'package:ur/ur_encoder.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + group('UrQrReader', () { |
| 12 | + // Animated URs are fountain-coded (BCR-2020-005): once the pure |
| 13 | + // fragments 1..N have played, the stream keeps emitting mixed parts |
| 14 | + // N+1, N+2, ... The reader must accept them, or any scan that joins |
| 15 | + // the animation mid-stream fails immediately. |
| 16 | + test('decodes a stream the camera joins mid-animation', () { |
| 17 | + final payload = cbor.encode(CborBytes(utf8.encode('x' * 100))); |
| 18 | + final encoder = UREncoder(UR('bytes', Uint8List.fromList(payload)), 20); |
| 19 | + final pureParts = <String>[]; |
| 20 | + while (!encoder.isComplete) { |
| 21 | + pureParts.add(encoder.nextPart()); |
| 22 | + } |
| 23 | + final mixedPart = encoder.nextPart(); // seqNum N+1 of N |
| 24 | + |
| 25 | + final reader = UrQrReader(); |
| 26 | + reader.receive(mixedPart); // first captured frame is a mixed part |
| 27 | + for (final part in pureParts) { |
| 28 | + reader.receive(part); |
| 29 | + } |
| 30 | + |
| 31 | + expect(reader.isComplete, isTrue); |
| 32 | + }); |
| 33 | + }); |
| 34 | +} |
0 commit comments