123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /*
- * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import 'dart:typed_data';
- import 'package:fis_lib_print/printing.dart';
- import 'package:fis_lib_print/src/interface.dart';
- import 'package:flutter/widgets.dart';
- import 'package:flutter_test/flutter_test.dart';
- import 'package:mockito/mockito.dart';
- import 'package:pdf/pdf.dart';
- import 'package:plugin_platform_interface/plugin_platform_interface.dart';
- void main() {
- setUp(() {
- TestWidgetsFlutterBinding.ensureInitialized();
- final mock = MockPrinting();
- PrintingPlatform.instance = mock;
- });
- test('info', () async {
- final info = await Printing.info();
- expect(info, isInstanceOf<PrintingInfo>());
- });
- test('layoutPdf', () async {
- expect(
- await Printing.layoutPdf(
- onLayout: (_) => Uint8List(0),
- name: 'doc',
- format: PdfPageFormat.letter,
- ),
- true);
- });
- test('sharePdf', () async {
- expect(
- await Printing.sharePdf(
- bytes: Uint8List(0),
- ),
- true,
- );
- });
- test('pickPrinter', () async {
- expect(
- await Printing.pickPrinter(context: MockContext()),
- null,
- );
- });
- test('directPrintPdf', () async {
- expect(
- await Printing.directPrintPdf(
- onLayout: (_) => Uint8List(0),
- printer: const Printer(url: 'test'),
- ),
- true,
- );
- });
- test('convertHtml', () async {
- expect(
- await Printing.convertHtml(html: '<html></html>'),
- isInstanceOf<Uint8List>(),
- );
- });
- test('raster', () async {
- expect(
- Printing.raster(Uint8List(0)),
- isInstanceOf<Stream>(),
- );
- });
- test('test image', () async {
- final bytes = Uint8List.fromList([
- 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 1, //
- 0, 0, 0, 1, 0, 1, 3, 0, 0, 0, 102, 188, 58, 37, 0, 0, 0, 3, 80, 76, 84,
- 69, 181, 208, 208, 99, 4, 22, 234, 0, 0, 0, 31, 73, 68, 65, 84, 104,
- 129, 237, 193, 1, 13, 0, 0, 0, 194, 160, 247, 79, 109, 14, 55, 160, 0, 0,
- 0, 0, 0, 0, 0, 0, 190, 13, 33, 0, 0, 1, 154, 96, 225, 213, 0, 0, 0, 0, 73,
- 69, 78, 68, 174, 66, 96, 130
- ]);
- final imageProvider = Image.memory(bytes).image;
- expect(await flutterImageProvider(imageProvider), isNotNull);
- });
- }
- class MockPrinting extends Mock
- with MockPlatformInterfaceMixin
- implements PrintingPlatform {
- @override
- Future<PrintingInfo> info() async => const PrintingInfo();
- @override
- Future<bool> layoutPdf(
- Printer? printer,
- LayoutCallback onLayout,
- String name,
- PdfPageFormat format,
- bool dynamicLayout,
- bool usePrinterSettings,
- ) async =>
- true;
- @override
- Future<bool> sharePdf(Uint8List bytes, String filename, Rect bounds,
- String? subject, String? body, List<String>? emails) async =>
- true;
- @override
- Future<Printer?> pickPrinter(Rect bounds) async => null;
- @override
- Stream<PdfRaster> raster(
- Uint8List document, List<int>? pages, double dpi) async* {}
- @override
- Future<Uint8List> convertHtml(
- String html, String? baseUrl, PdfPageFormat format) async =>
- Uint8List(0);
- }
- class MockContext extends Mock implements BuildContext {}
|