David PHAM-VAN

Add more widget tests

@@ -32,3 +32,8 @@ printing/ios/Runner @@ -32,3 +32,8 @@ printing/ios/Runner
32 .pana 32 .pana
33 pedantic_analyis_options_*.yaml 33 pedantic_analyis_options_*.yaml
34 .dartfix 34 .dartfix
  35 +node_modules
  36 +pdf/lcov.info
  37 +pdf/coverage.json
  38 +.coverage
  39 +package-lock.json
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 CLNG_SRC=$(shell find printing/ios -name '*.java' -o -name '*.m' -o -name '*.h') $(shell find printing/android -name '*.java' -o -name '*.m' -o -name '*.h') 16 CLNG_SRC=$(shell find printing/ios -name '*.java' -o -name '*.m' -o -name '*.h') $(shell find printing/android -name '*.java' -o -name '*.m' -o -name '*.h')
17 SWFT_SRC=$(shell find . -name '*.swift') 17 SWFT_SRC=$(shell find . -name '*.swift')
18 FONTS=pdf/open-sans.ttf pdf/open-sans-bold.ttf pdf/roboto.ttf pdf/noto-sans.ttf pdf/genyomintw.ttf 18 FONTS=pdf/open-sans.ttf pdf/open-sans-bold.ttf pdf/roboto.ttf pdf/noto-sans.ttf pdf/genyomintw.ttf
  19 + COV_PORT=9292
19 20
20 all: $(FONTS) format 21 all: $(FONTS) format
21 22
@@ -45,12 +46,22 @@ format-clang: $(CLNG_SRC) @@ -45,12 +46,22 @@ format-clang: $(CLNG_SRC)
45 format-swift: $(SWFT_SRC) 46 format-swift: $(SWFT_SRC)
46 swiftformat --swiftversion 4.2 $^ 47 swiftformat --swiftversion 4.2 $^
47 48
48 -test: $(FONTS) 49 +.coverage:
  50 + pub global activate coverage
  51 + touch $@
  52 +
  53 +node_modules:
  54 + npm install lcov-summary
  55 +
  56 +test: $(FONTS) .coverage node_modules
49 cd pdf; pub get 57 cd pdf; pub get
50 - cd pdf; pub run test 58 + cd pdf; pub global run coverage:collect_coverage --port=$(COV_PORT) -o coverage.json --resume-isolates --wait-paused &\
  59 + dart --enable-asserts --disable-service-auth-codes --enable-vm-service=$(COV_PORT) --pause-isolates-on-exit test/all_tests.dart
  60 + cd pdf; pub global run coverage:format_coverage --packages=.packages -i coverage.json --report-on lib --lcov --out lcov.info
51 cd pdf; for EXAMPLE in $(shell cd pdf; find example -name '*.dart'); do dart $$EXAMPLE; done 61 cd pdf; for EXAMPLE in $(shell cd pdf; find example -name '*.dart'); do dart $$EXAMPLE; done
52 cd printing/example; flutter packages get 62 cd printing/example; flutter packages get
53 cd printing/example; flutter test 63 cd printing/example; flutter test
  64 + node_modules/.bin/lcov-summary pdf/lcov.info
54 65
55 clean: 66 clean:
56 git clean -fdx -e .vscode 67 git clean -fdx -e .vscode
@@ -72,8 +83,8 @@ publish-printing: format clean @@ -72,8 +83,8 @@ publish-printing: format clean
72 analyze: .pana 83 analyze: .pana
73 @find pdf -name pubspec.yaml -exec sed -i -e 's/^dependency_overrides:/_dependency_overrides:/g' '{}' ';' 84 @find pdf -name pubspec.yaml -exec sed -i -e 's/^dependency_overrides:/_dependency_overrides:/g' '{}' ';'
74 @find printing -name pubspec.yaml -exec sed -i -e 's/^dependency_overrides:/_dependency_overrides:/g' '{}' ';' 85 @find printing -name pubspec.yaml -exec sed -i -e 's/^dependency_overrides:/_dependency_overrides:/g' '{}' ';'
75 - @pana --no-warning --source path pdf 2> /dev/null | python pana_report.py  
76 - @pana --no-warning --source path printing 2> /dev/null | python pana_report.py 86 + @pub global run pana --no-warning --source path pdf 2> /dev/null | python pana_report.py
  87 + @pub global run pana --no-warning --source path printing 2> /dev/null | python pana_report.py
77 @find pdf -name pubspec.yaml -exec sed -i -e 's/^_dependency_overrides:/dependency_overrides:/g' '{}' ';' 88 @find pdf -name pubspec.yaml -exec sed -i -e 's/^_dependency_overrides:/dependency_overrides:/g' '{}' ';'
78 @find printing -name pubspec.yaml -exec sed -i -e 's/^_dependency_overrides:/dependency_overrides:/g' '{}' ';' 89 @find printing -name pubspec.yaml -exec sed -i -e 's/^_dependency_overrides:/dependency_overrides:/g' '{}' ';'
79 90
@@ -83,8 +94,8 @@ analyze: .pana @@ -83,8 +94,8 @@ analyze: .pana
83 94
84 fix: .dartfix 95 fix: .dartfix
85 cd pdf; pub get 96 cd pdf; pub get
86 - cd pdf; dartfix --overwrite . 97 + cd pdf; pub global run dartfix:fix --overwrite .
87 cd printing; flutter packages get 98 cd printing; flutter packages get
88 - cd printing; dartfix --overwrite . 99 + cd printing; pub global run dartfix:fix --overwrite .
89 100
90 .PHONY: test format format-dart format-clang clean publish-pdf publish-printing analyze 101 .PHONY: test format format-dart format-clang clean publish-pdf publish-printing analyze
  1 +/*
  2 + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +library pdf.all_tests;
  18 +
  19 +import '../example/main.dart' as example;
  20 +import 'annotations_test.dart' as annotations;
  21 +import 'colors_test.dart' as colors;
  22 +import 'complex_test.dart' as complex;
  23 +import 'jpeg_test.dart' as jpeg;
  24 +import 'metrics_test.dart' as metrics;
  25 +import 'minimal_test.dart' as minimal;
  26 +import 'ttf_test.dart' as ttf;
  27 +import 'type1_test.dart' as type1;
  28 +import 'widget_basic_test.dart' as widget_basic;
  29 +import 'widget_clip_test.dart' as widget_clip;
  30 +import 'widget_container_test.dart' as widget_container;
  31 +import 'widget_test.dart' as widget;
  32 +
  33 +void main() {
  34 + annotations.main();
  35 + colors.main();
  36 + complex.main();
  37 + jpeg.main();
  38 + metrics.main();
  39 + minimal.main();
  40 + ttf.main();
  41 + type1.main();
  42 + widget_basic.main();
  43 + widget_clip.main();
  44 + widget_container.main();
  45 + widget.main();
  46 + example.main();
  47 +}
  1 +/*
  2 + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +import 'dart:io';
  18 +
  19 +import 'package:test/test.dart';
  20 +import 'package:pdf/pdf.dart';
  21 +import 'package:pdf/widgets.dart';
  22 +
  23 +Document pdf;
  24 +
  25 +void main() {
  26 + setUpAll(() {
  27 + Document.debug = true;
  28 + pdf = Document();
  29 + });
  30 +
  31 + test('Basic Widgets Align', () {
  32 + pdf.addPage(Page(
  33 + build: (Context context) => Align(
  34 + alignment: Alignment.bottomRight,
  35 + child: SizedBox(width: 100, height: 100, child: PdfLogo()),
  36 + )));
  37 + });
  38 +
  39 + test('Basic Widgets AspectRatio', () {
  40 + pdf.addPage(Page(
  41 + build: (Context context) => AspectRatio(
  42 + aspectRatio: 1.618,
  43 + child: Placeholder(),
  44 + )));
  45 + });
  46 +
  47 + test('Basic Widgets Center', () {
  48 + pdf.addPage(Page(
  49 + build: (Context context) => Center(
  50 + child: SizedBox(width: 100, height: 100, child: PdfLogo()),
  51 + )));
  52 + });
  53 +
  54 + test('Basic Widgets ConstrainedBox', () {
  55 + pdf.addPage(Page(
  56 + build: (Context context) => ConstrainedBox(
  57 + constraints: const BoxConstraints.tightFor(height: 300),
  58 + child: Placeholder()),
  59 + ));
  60 + });
  61 +
  62 + test('Basic Widgets CustomPaint', () {
  63 + pdf.addPage(Page(
  64 + build: (Context context) => CustomPaint(
  65 + size: const PdfPoint(200, 200),
  66 + painter: (PdfGraphics canvas, PdfPoint size) {
  67 + canvas
  68 + ..drawEllipse(size.x / 2, size.y / 2, size.x / 2, size.y / 2)
  69 + ..setFillColor(PdfColors.blue)
  70 + ..fillPath();
  71 + },
  72 + )));
  73 + pdf.addPage(Page(
  74 + build: (Context context) => CustomPaint(
  75 + size: const PdfPoint(200, 200),
  76 + painter: (PdfGraphics canvas, PdfPoint size) {
  77 + canvas
  78 + ..drawEllipse(size.x / 2, size.y / 2, size.x / 2, size.y / 2)
  79 + ..setFillColor(PdfColors.blue)
  80 + ..fillPath();
  81 + },
  82 + child: PdfLogo(),
  83 + )));
  84 + });
  85 +
  86 + test('Basic Widgets FittedBox', () {
  87 + pdf.addPage(Page(
  88 + build: (Context context) => Column(
  89 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
  90 + mainAxisSize: MainAxisSize.max,
  91 + children: <Widget>[
  92 + SizedBox(
  93 + height: 100,
  94 + width: 100,
  95 + child: FittedBox(
  96 + fit: BoxFit.contain,
  97 + child: SizedBox(
  98 + width: 100, height: 50, child: Placeholder()))),
  99 + SizedBox(
  100 + height: 100,
  101 + width: 100,
  102 + child: FittedBox(
  103 + fit: BoxFit.cover,
  104 + child: SizedBox(
  105 + width: 100, height: 50, child: Placeholder()))),
  106 + SizedBox(
  107 + height: 100,
  108 + width: 100,
  109 + child: FittedBox(
  110 + fit: BoxFit.fill,
  111 + child: SizedBox(
  112 + width: 100, height: 50, child: Placeholder()))),
  113 + SizedBox(
  114 + height: 100,
  115 + width: 100,
  116 + child: FittedBox(
  117 + fit: BoxFit.fitWidth,
  118 + child: SizedBox(
  119 + width: 100, height: 50, child: Placeholder()))),
  120 + SizedBox(
  121 + height: 100,
  122 + width: 100,
  123 + child: FittedBox(
  124 + fit: BoxFit.fitHeight,
  125 + child: SizedBox(
  126 + width: 100, height: 50, child: Placeholder()))),
  127 + SizedBox(
  128 + height: 100,
  129 + width: 100,
  130 + child: FittedBox(
  131 + fit: BoxFit.none,
  132 + child: SizedBox(
  133 + width: 100, height: 50, child: Placeholder()))),
  134 + SizedBox(
  135 + height: 100,
  136 + width: 100,
  137 + child: FittedBox(
  138 + fit: BoxFit.scaleDown,
  139 + child: SizedBox(
  140 + width: 100, height: 50, child: Placeholder()))),
  141 + ])));
  142 + });
  143 +
  144 + test('Basic Widgets LimitedBox', () {
  145 + pdf.addPage(Page(
  146 + build: (Context context) => ListView(
  147 + children: <Widget>[
  148 + LimitedBox(
  149 + maxHeight: 40,
  150 + child: Placeholder(),
  151 + ),
  152 + ],
  153 + )));
  154 + });
  155 +
  156 + test('Basic Widgets Padding', () {
  157 + pdf.addPage(Page(
  158 + build: (Context context) => Center(
  159 + child: Padding(
  160 + padding: const EdgeInsets.all(20),
  161 + child: PdfLogo(),
  162 + ),
  163 + )));
  164 + });
  165 +
  166 + test('Basic Widgets SizedBox', () {
  167 + pdf.addPage(Page(
  168 + build: (Context context) => SizedBox(
  169 + width: 200,
  170 + height: 100,
  171 + child: Placeholder(),
  172 + )));
  173 + });
  174 +
  175 + test('Basic Widgets Transform', () {
  176 + pdf.addPage(Page(
  177 + build: (Context context) => Transform.scale(
  178 + scale: 0.5,
  179 + child: Transform.rotate(
  180 + angle: 0.1,
  181 + child: Placeholder(),
  182 + ),
  183 + )));
  184 + });
  185 +
  186 + tearDownAll(() {
  187 + final File file = File('widgets-basic.pdf');
  188 + file.writeAsBytesSync(pdf.save());
  189 + });
  190 +}
  1 +/*
  2 + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +import 'dart:io';
  18 +
  19 +import 'package:test/test.dart';
  20 +import 'package:pdf/pdf.dart';
  21 +import 'package:pdf/widgets.dart';
  22 +
  23 +Document pdf;
  24 +
  25 +void main() {
  26 + setUpAll(() {
  27 + Document.debug = true;
  28 + pdf = Document();
  29 + });
  30 +
  31 + test('Clip Widgets ClipRect', () {
  32 + pdf.addPage(Page(
  33 + build: (Context context) => ClipRect(
  34 + child: Transform.rotate(
  35 + angle: 0.1,
  36 + child: Container(
  37 + decoration: const BoxDecoration(
  38 + color: PdfColors.blue,
  39 + ),
  40 + ),
  41 + ),
  42 + ),
  43 + ));
  44 + });
  45 +
  46 + test('Clip Widgets ClipRRect', () {
  47 + pdf.addPage(Page(
  48 + build: (Context context) => ClipRRect(
  49 + horizontalRadius: 30,
  50 + verticalRadius: 30,
  51 + child: Container(
  52 + decoration: const BoxDecoration(
  53 + color: PdfColors.blue,
  54 + ),
  55 + ),
  56 + ),
  57 + ));
  58 + });
  59 +
  60 + test('Clip Widgets ClipOval', () {
  61 + pdf.addPage(Page(
  62 + build: (Context context) => ClipOval(
  63 + child: Container(
  64 + decoration: const BoxDecoration(
  65 + color: PdfColors.blue,
  66 + ),
  67 + ),
  68 + ),
  69 + ));
  70 + });
  71 +
  72 + tearDownAll(() {
  73 + final File file = File('widgets-clip.pdf');
  74 + file.writeAsBytesSync(pdf.save());
  75 + });
  76 +}
  1 +/*
  2 + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +import 'dart:io';
  18 +import 'dart:math' as math;
  19 +import 'dart:typed_data';
  20 +
  21 +import 'package:test/test.dart';
  22 +import 'package:pdf/pdf.dart';
  23 +import 'package:pdf/widgets.dart';
  24 +
  25 +Document pdf;
  26 +
  27 +Uint32List generateBitmap(int w, int h) {
  28 + final Uint32List bm = Uint32List(w * h);
  29 + final double dw = w.toDouble();
  30 + final double dh = h.toDouble();
  31 + for (int y = 0; y < h; y++) {
  32 + for (int x = 0; x < w; x++) {
  33 + bm[y * w + x] = (math.sin(x / dw) * 256).toInt() |
  34 + (math.sin(y / dh) * 256).toInt() << 8 |
  35 + (math.sin(x / dw * y / dh) * 256).toInt() << 16 |
  36 + 0xff000000;
  37 + }
  38 + }
  39 +
  40 + return bm;
  41 +}
  42 +
  43 +void main() {
  44 + setUpAll(() {
  45 + Document.debug = true;
  46 + pdf = Document();
  47 + });
  48 +
  49 + test('Container Widgets Flat', () {
  50 + pdf.addPage(Page(
  51 + build: (Context context) => Container(
  52 + alignment: Alignment.center,
  53 + margin: const EdgeInsets.all(30),
  54 + padding: const EdgeInsets.all(20),
  55 + decoration: const BoxDecoration(
  56 + color: PdfColors.blue,
  57 + borderRadius: 20,
  58 + border: BoxBorder(
  59 + color: PdfColors.blue800,
  60 + top: true,
  61 + left: true,
  62 + right: true,
  63 + bottom: true,
  64 + width: 2,
  65 + )),
  66 + width: 200,
  67 + height: 400,
  68 + // child: Placeholder(),
  69 + ),
  70 + ));
  71 + });
  72 +
  73 + test('Container Widgets Image', () {
  74 + final Uint32List img = generateBitmap(100, 100);
  75 + final PdfImage image = PdfImage(pdf.document,
  76 + image: img.buffer.asUint8List(), width: 100, height: 100);
  77 +
  78 + pdf.addPage(Page(
  79 + build: (Context context) => Container(
  80 + alignment: Alignment.center,
  81 + margin: const EdgeInsets.all(30),
  82 + padding: const EdgeInsets.all(20),
  83 + decoration: BoxDecoration(
  84 + image: DecorationImage(image: image, fit: BoxFit.cover),
  85 + ),
  86 + width: 200,
  87 + height: 400,
  88 + // child: Placeholder(),
  89 + ),
  90 + ));
  91 + });
  92 +
  93 + tearDownAll(() {
  94 + final File file = File('widgets-container.pdf');
  95 + file.writeAsBytesSync(pdf.save());
  96 + });
  97 +}