David PHAM-VAN

Add more widget tests

... ... @@ -32,3 +32,8 @@ printing/ios/Runner
.pana
pedantic_analyis_options_*.yaml
.dartfix
node_modules
pdf/lcov.info
pdf/coverage.json
.coverage
package-lock.json
... ...
... ... @@ -16,6 +16,7 @@
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')
SWFT_SRC=$(shell find . -name '*.swift')
FONTS=pdf/open-sans.ttf pdf/open-sans-bold.ttf pdf/roboto.ttf pdf/noto-sans.ttf pdf/genyomintw.ttf
COV_PORT=9292
all: $(FONTS) format
... ... @@ -45,12 +46,22 @@ format-clang: $(CLNG_SRC)
format-swift: $(SWFT_SRC)
swiftformat --swiftversion 4.2 $^
test: $(FONTS)
.coverage:
pub global activate coverage
touch $@
node_modules:
npm install lcov-summary
test: $(FONTS) .coverage node_modules
cd pdf; pub get
cd pdf; pub run test
cd pdf; pub global run coverage:collect_coverage --port=$(COV_PORT) -o coverage.json --resume-isolates --wait-paused &\
dart --enable-asserts --disable-service-auth-codes --enable-vm-service=$(COV_PORT) --pause-isolates-on-exit test/all_tests.dart
cd pdf; pub global run coverage:format_coverage --packages=.packages -i coverage.json --report-on lib --lcov --out lcov.info
cd pdf; for EXAMPLE in $(shell cd pdf; find example -name '*.dart'); do dart $$EXAMPLE; done
cd printing/example; flutter packages get
cd printing/example; flutter test
node_modules/.bin/lcov-summary pdf/lcov.info
clean:
git clean -fdx -e .vscode
... ... @@ -72,8 +83,8 @@ publish-printing: format clean
analyze: .pana
@find pdf -name pubspec.yaml -exec sed -i -e 's/^dependency_overrides:/_dependency_overrides:/g' '{}' ';'
@find printing -name pubspec.yaml -exec sed -i -e 's/^dependency_overrides:/_dependency_overrides:/g' '{}' ';'
@pana --no-warning --source path pdf 2> /dev/null | python pana_report.py
@pana --no-warning --source path printing 2> /dev/null | python pana_report.py
@pub global run pana --no-warning --source path pdf 2> /dev/null | python pana_report.py
@pub global run pana --no-warning --source path printing 2> /dev/null | python pana_report.py
@find pdf -name pubspec.yaml -exec sed -i -e 's/^_dependency_overrides:/dependency_overrides:/g' '{}' ';'
@find printing -name pubspec.yaml -exec sed -i -e 's/^_dependency_overrides:/dependency_overrides:/g' '{}' ';'
... ... @@ -83,8 +94,8 @@ analyze: .pana
fix: .dartfix
cd pdf; pub get
cd pdf; dartfix --overwrite .
cd pdf; pub global run dartfix:fix --overwrite .
cd printing; flutter packages get
cd printing; dartfix --overwrite .
cd printing; pub global run dartfix:fix --overwrite .
.PHONY: test format format-dart format-clang clean publish-pdf publish-printing analyze
... ...
/*
* 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.
*/
library pdf.all_tests;
import '../example/main.dart' as example;
import 'annotations_test.dart' as annotations;
import 'colors_test.dart' as colors;
import 'complex_test.dart' as complex;
import 'jpeg_test.dart' as jpeg;
import 'metrics_test.dart' as metrics;
import 'minimal_test.dart' as minimal;
import 'ttf_test.dart' as ttf;
import 'type1_test.dart' as type1;
import 'widget_basic_test.dart' as widget_basic;
import 'widget_clip_test.dart' as widget_clip;
import 'widget_container_test.dart' as widget_container;
import 'widget_test.dart' as widget;
void main() {
annotations.main();
colors.main();
complex.main();
jpeg.main();
metrics.main();
minimal.main();
ttf.main();
type1.main();
widget_basic.main();
widget_clip.main();
widget_container.main();
widget.main();
example.main();
}
... ...
/*
* 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:io';
import 'package:test/test.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
Document pdf;
void main() {
setUpAll(() {
Document.debug = true;
pdf = Document();
});
test('Basic Widgets Align', () {
pdf.addPage(Page(
build: (Context context) => Align(
alignment: Alignment.bottomRight,
child: SizedBox(width: 100, height: 100, child: PdfLogo()),
)));
});
test('Basic Widgets AspectRatio', () {
pdf.addPage(Page(
build: (Context context) => AspectRatio(
aspectRatio: 1.618,
child: Placeholder(),
)));
});
test('Basic Widgets Center', () {
pdf.addPage(Page(
build: (Context context) => Center(
child: SizedBox(width: 100, height: 100, child: PdfLogo()),
)));
});
test('Basic Widgets ConstrainedBox', () {
pdf.addPage(Page(
build: (Context context) => ConstrainedBox(
constraints: const BoxConstraints.tightFor(height: 300),
child: Placeholder()),
));
});
test('Basic Widgets CustomPaint', () {
pdf.addPage(Page(
build: (Context context) => CustomPaint(
size: const PdfPoint(200, 200),
painter: (PdfGraphics canvas, PdfPoint size) {
canvas
..drawEllipse(size.x / 2, size.y / 2, size.x / 2, size.y / 2)
..setFillColor(PdfColors.blue)
..fillPath();
},
)));
pdf.addPage(Page(
build: (Context context) => CustomPaint(
size: const PdfPoint(200, 200),
painter: (PdfGraphics canvas, PdfPoint size) {
canvas
..drawEllipse(size.x / 2, size.y / 2, size.x / 2, size.y / 2)
..setFillColor(PdfColors.blue)
..fillPath();
},
child: PdfLogo(),
)));
});
test('Basic Widgets FittedBox', () {
pdf.addPage(Page(
build: (Context context) => Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
SizedBox(
height: 100,
width: 100,
child: FittedBox(
fit: BoxFit.contain,
child: SizedBox(
width: 100, height: 50, child: Placeholder()))),
SizedBox(
height: 100,
width: 100,
child: FittedBox(
fit: BoxFit.cover,
child: SizedBox(
width: 100, height: 50, child: Placeholder()))),
SizedBox(
height: 100,
width: 100,
child: FittedBox(
fit: BoxFit.fill,
child: SizedBox(
width: 100, height: 50, child: Placeholder()))),
SizedBox(
height: 100,
width: 100,
child: FittedBox(
fit: BoxFit.fitWidth,
child: SizedBox(
width: 100, height: 50, child: Placeholder()))),
SizedBox(
height: 100,
width: 100,
child: FittedBox(
fit: BoxFit.fitHeight,
child: SizedBox(
width: 100, height: 50, child: Placeholder()))),
SizedBox(
height: 100,
width: 100,
child: FittedBox(
fit: BoxFit.none,
child: SizedBox(
width: 100, height: 50, child: Placeholder()))),
SizedBox(
height: 100,
width: 100,
child: FittedBox(
fit: BoxFit.scaleDown,
child: SizedBox(
width: 100, height: 50, child: Placeholder()))),
])));
});
test('Basic Widgets LimitedBox', () {
pdf.addPage(Page(
build: (Context context) => ListView(
children: <Widget>[
LimitedBox(
maxHeight: 40,
child: Placeholder(),
),
],
)));
});
test('Basic Widgets Padding', () {
pdf.addPage(Page(
build: (Context context) => Center(
child: Padding(
padding: const EdgeInsets.all(20),
child: PdfLogo(),
),
)));
});
test('Basic Widgets SizedBox', () {
pdf.addPage(Page(
build: (Context context) => SizedBox(
width: 200,
height: 100,
child: Placeholder(),
)));
});
test('Basic Widgets Transform', () {
pdf.addPage(Page(
build: (Context context) => Transform.scale(
scale: 0.5,
child: Transform.rotate(
angle: 0.1,
child: Placeholder(),
),
)));
});
tearDownAll(() {
final File file = File('widgets-basic.pdf');
file.writeAsBytesSync(pdf.save());
});
}
... ...
/*
* 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:io';
import 'package:test/test.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
Document pdf;
void main() {
setUpAll(() {
Document.debug = true;
pdf = Document();
});
test('Clip Widgets ClipRect', () {
pdf.addPage(Page(
build: (Context context) => ClipRect(
child: Transform.rotate(
angle: 0.1,
child: Container(
decoration: const BoxDecoration(
color: PdfColors.blue,
),
),
),
),
));
});
test('Clip Widgets ClipRRect', () {
pdf.addPage(Page(
build: (Context context) => ClipRRect(
horizontalRadius: 30,
verticalRadius: 30,
child: Container(
decoration: const BoxDecoration(
color: PdfColors.blue,
),
),
),
));
});
test('Clip Widgets ClipOval', () {
pdf.addPage(Page(
build: (Context context) => ClipOval(
child: Container(
decoration: const BoxDecoration(
color: PdfColors.blue,
),
),
),
));
});
tearDownAll(() {
final File file = File('widgets-clip.pdf');
file.writeAsBytesSync(pdf.save());
});
}
... ...
/*
* 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:io';
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
Document pdf;
Uint32List generateBitmap(int w, int h) {
final Uint32List bm = Uint32List(w * h);
final double dw = w.toDouble();
final double dh = h.toDouble();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
bm[y * w + x] = (math.sin(x / dw) * 256).toInt() |
(math.sin(y / dh) * 256).toInt() << 8 |
(math.sin(x / dw * y / dh) * 256).toInt() << 16 |
0xff000000;
}
}
return bm;
}
void main() {
setUpAll(() {
Document.debug = true;
pdf = Document();
});
test('Container Widgets Flat', () {
pdf.addPage(Page(
build: (Context context) => Container(
alignment: Alignment.center,
margin: const EdgeInsets.all(30),
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: PdfColors.blue,
borderRadius: 20,
border: BoxBorder(
color: PdfColors.blue800,
top: true,
left: true,
right: true,
bottom: true,
width: 2,
)),
width: 200,
height: 400,
// child: Placeholder(),
),
));
});
test('Container Widgets Image', () {
final Uint32List img = generateBitmap(100, 100);
final PdfImage image = PdfImage(pdf.document,
image: img.buffer.asUint8List(), width: 100, height: 100);
pdf.addPage(Page(
build: (Context context) => Container(
alignment: Alignment.center,
margin: const EdgeInsets.all(30),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
image: DecorationImage(image: image, fit: BoxFit.cover),
),
width: 200,
height: 400,
// child: Placeholder(),
),
));
});
tearDownAll(() {
final File file = File('widgets-container.pdf');
file.writeAsBytesSync(pdf.save());
});
}
... ...