Showing
2 changed files
with
64 additions
and
0 deletions
| @@ -76,6 +76,7 @@ test-pdf: $(FONTS) get-pdf .coverage | @@ -76,6 +76,7 @@ test-pdf: $(FONTS) get-pdf .coverage | ||
| 76 | test/compare-pdf.sh pdf test/golden | 76 | test/compare-pdf.sh pdf test/golden |
| 77 | 77 | ||
| 78 | test-printing: $(FONTS) get-printing .coverage | 78 | test-printing: $(FONTS) get-printing .coverage |
| 79 | + cd printing; flutter test --coverage --coverage-path lcov.info | ||
| 79 | cd printing/example; flutter test --coverage --coverage-path ../lcov.info | 80 | cd printing/example; flutter test --coverage --coverage-path ../lcov.info |
| 80 | 81 | ||
| 81 | test-readme: $(FONTS) get-readme | 82 | test-readme: $(FONTS) get-readme |
printing/test/printing_test.dart
0 → 100644
| 1 | +import 'dart:io'; | ||
| 2 | +import 'dart:typed_data'; | ||
| 3 | + | ||
| 4 | +import 'package:flutter/services.dart'; | ||
| 5 | +import 'package:flutter/widgets.dart'; | ||
| 6 | +import 'package:flutter_test/flutter_test.dart'; | ||
| 7 | +import 'package:pdf/pdf.dart'; | ||
| 8 | +import 'package:pdf/widgets.dart' as pdf; | ||
| 9 | +import 'package:printing/printing.dart'; | ||
| 10 | + | ||
| 11 | +pdf.Document doc; | ||
| 12 | +pdf.Font ttf; | ||
| 13 | + | ||
| 14 | +void main() { | ||
| 15 | + final String path = | ||
| 16 | + Directory.current.path.split('/').last == 'test' ? '..' : '.'; | ||
| 17 | + const MethodChannel channel = MethodChannel('net.nfet.printing'); | ||
| 18 | + TestWidgetsFlutterBinding.ensureInitialized(); | ||
| 19 | + | ||
| 20 | + setUp(() { | ||
| 21 | + channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
| 22 | + print(methodCall); | ||
| 23 | + return '1'; | ||
| 24 | + }); | ||
| 25 | + }); | ||
| 26 | + | ||
| 27 | + tearDown(() { | ||
| 28 | + channel.setMockMethodCallHandler(null); | ||
| 29 | + }); | ||
| 30 | + | ||
| 31 | + test('convertHtml', () async { | ||
| 32 | + // expect(await Printing.platformVersion, '42'); | ||
| 33 | + }); | ||
| 34 | + | ||
| 35 | + test('pdfImageFromImageProvider(FileImage)', () async { | ||
| 36 | + final PdfImage image = await pdfImageFromImageProvider( | ||
| 37 | + pdf: doc.document, image: FileImage(File('$path/example.png'))); | ||
| 38 | + | ||
| 39 | + doc.addPage( | ||
| 40 | + pdf.Page( | ||
| 41 | + build: (pdf.Context context) => pdf.Center( | ||
| 42 | + child: pdf.Container( | ||
| 43 | + child: pdf.Image(image), | ||
| 44 | + ), | ||
| 45 | + ), | ||
| 46 | + ), | ||
| 47 | + ); | ||
| 48 | + }); | ||
| 49 | + | ||
| 50 | + setUpAll(() { | ||
| 51 | + pdf.Document.debug = true; | ||
| 52 | + pdf.RichText.debug = true; | ||
| 53 | + final Uint8List fontData = | ||
| 54 | + File('$path/../pdf/open-sans.ttf').readAsBytesSync(); | ||
| 55 | + ttf = pdf.Font.ttf(fontData.buffer.asByteData()); | ||
| 56 | + doc = pdf.Document(); | ||
| 57 | + }); | ||
| 58 | + | ||
| 59 | + tearDownAll(() { | ||
| 60 | + final File file = File('printing.pdf'); | ||
| 61 | + file.writeAsBytesSync(doc.save()); | ||
| 62 | + }); | ||
| 63 | +} |
-
Please register or login to post a comment