From d617826c21a20f2c8ce6cb9babaca4d8cf3229e6 Mon Sep 17 00:00:00 2001 From: tanjiancheng <562575412@qq.com> Date: Thu, 28 Nov 2024 15:42:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E6=9E=90=E8=B7=AF=E5=BE=84demo?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tanjiancheng <562575412@qq.com> --- ohos/path_parsing_test/lib/main.dart | 29 ++ .../lib/pages/parse_path_test.dart | 248 ++++++++++++++++++ .../lib/pages/s_PathProxy_test.dart | 75 ++++++ .../lib/pages/s_PathSegmentData_test.dart | 134 ++++++++++ .../lib/pages/s_SvgPathNormalizer_test.dart | 59 +++++ .../lib/pages/s_SvgPathStringSource_test.dart | 67 +++++ 6 files changed, 612 insertions(+) create mode 100644 ohos/path_parsing_test/lib/pages/parse_path_test.dart create mode 100644 ohos/path_parsing_test/lib/pages/s_PathProxy_test.dart create mode 100644 ohos/path_parsing_test/lib/pages/s_PathSegmentData_test.dart create mode 100644 ohos/path_parsing_test/lib/pages/s_SvgPathNormalizer_test.dart create mode 100644 ohos/path_parsing_test/lib/pages/s_SvgPathStringSource_test.dart diff --git a/ohos/path_parsing_test/lib/main.dart b/ohos/path_parsing_test/lib/main.dart index fce7e4ce..b7a6e29b 100644 --- a/ohos/path_parsing_test/lib/main.dart +++ b/ohos/path_parsing_test/lib/main.dart @@ -20,10 +20,20 @@ import 'common/test_route.dart'; import 'pages/example.dart'; import 'pages/function_list.dart'; import 'pages/parse_path_deep_test.dart'; +import 'pages/parse_path_test.dart'; +import 'pages/s_PathProxy_test.dart'; +import 'pages/s_PathSegmentData_test.dart'; +import 'pages/s_SvgPathNormalizer_test.dart'; +import 'pages/s_SvgPathStringSource_test.dart'; void main() { final items = [ MainItem('functions', "", route: "FunctionList"), + // MainItem('excample_test', "", route: "PathParsingPage"), + MainItem('s_PathProxy_test', "", route: "SPathProxyTestPage"), + MainItem('s_PathSegmentData_test', "", route: "SPathSegmentDataTestPage"), + MainItem('s_SvgPathNormalizer_test', "", route: "SSvgPathNormalizerTestPage"), + MainItem('s_SvgPathStringSource_test', "", route: "SSvgPathStringSourceTestPage"), //SSvgPathStringSourceTestPage MainItem('parse_path_deep_test', "", route: "ParsePathDeepTestPage"), @@ -38,10 +48,29 @@ void main() { "FunctionList": (context) { return FunctionList(); }, + // "PathParsingPage": (context) { + // return PathParsingPage(); + // }, + "SPathProxyTestPage": (context) { + return SPathProxyTestPage('SPathProxyTestPage'); + }, + "SPathSegmentDataTestPage": (context) { + return SPathSegmentDataTestPage('SPathSegmentDataTestPage'); + }, + "SSvgPathNormalizerTestPage": (context) { + return SSvgPathNormalizerTestPage('SSvgPathNormalizerTestPage'); + }, + "SSvgPathStringSourceTestPage": (context) { + return SSvgPathStringSourceTestPage('SSvgPathStringSourceTestPage'); + }, + //SSvgPathStringSourceTestPage "ParsePathDeepTestPage": (context) { return ParsePathDeepTestPage("ParsePathDeepTestPage"); }, + "ParsePathTestPage": (context) { + return ParsePathTestPage("ParsePathTestPage"); + }, }, //PathParsingExamp ))); //BuilderTestPage diff --git a/ohos/path_parsing_test/lib/pages/parse_path_test.dart b/ohos/path_parsing_test/lib/pages/parse_path_test.dart new file mode 100644 index 00000000..bdeefe9a --- /dev/null +++ b/ohos/path_parsing_test/lib/pages/parse_path_test.dart @@ -0,0 +1,248 @@ +// Test paths taken from: +// * https://github.com/chromium/chromium/blob/master/third_party/blink/renderer/core/svg/svg_path_parser_test.cc + +import 'package:flutter/cupertino.dart'; +import 'package:path_parsing/path_parsing.dart'; +import 'package:path_parsing/src/path_segment_type.dart'; + +import '../common/test_page.dart'; + +// TODO(dnfield): a bunch of better tests could be written to track that commands are actually called with expected values/order +// For now we just want to know that something gets emitted and no exceptions are thrown (that's all the legacy tests really did anyway). +class TestPathProxy extends PathProxy { + bool called = false; + @override + void close() { + called = true; + } + + @override + void cubicTo( + double x1, + double y1, + double x2, + double y2, + double x3, + double y3, + ) { + called = true; + } + + @override + void lineTo(double x, double y) { + called = true; + } + + @override + void moveTo(double x, double y) { + called = true; + } +} + +class ParsePathTestPage extends TestPage { + ParsePathTestPage(String title, {Key? key}) : super(title, key: key) { + void assertValidPath(String input) { + final TestPathProxy proxy = TestPathProxy(); + // these shouldn't throw or assert + writeSvgPathDataToPath(input, proxy); + expect(proxy.called, true); + } + + void assertInvalidPath(String input) { + final TestPathProxy proxy = TestPathProxy(); + writeSvgPathDataToPath(input, proxy); + expect(proxy.called, true); + } + + test('Valid Paths', () { + assertValidPath('M1,2'); + assertValidPath('m1,2'); + assertValidPath('M100,200 m3,4'); + assertValidPath('M100,200 L3,4'); + assertValidPath('M100,200 l3,4'); + assertValidPath('M100,200 H3'); + assertValidPath('M100,200 h3'); + assertValidPath('M100,200 V3'); + assertValidPath('M100,200 v3'); + assertValidPath('M100,200 Z'); + assertValidPath('M100,200 z'); + assertValidPath('M100,200 C3,4,5,6,7,8'); + assertValidPath('M100,200 c3,4,5,6,7,8'); + assertValidPath('M100,200 S3,4,5,6'); + assertValidPath('M100,200 s3,4,5,6'); + assertValidPath('M100,200 Q3,4,5,6'); + assertValidPath('M100,200 q3,4,5,6'); + assertValidPath('M100,200 T3,4'); + assertValidPath('M100,200 t3,4'); + assertValidPath('M100,200 A3,4,5,0,0,6,7'); + assertValidPath('M100,200 A3,4,5,1,0,6,7'); + assertValidPath('M100,200 A3,4,5,0,1,6,7'); + assertValidPath('M100,200 A3,4,5,1,1,6,7'); + assertValidPath('M100,200 a3,4,5,0,0,6,7'); + assertValidPath('M100,200 a3,4,5,0,1,6,7'); + assertValidPath('M100,200 a3,4,5,1,0,6,7'); + assertValidPath('M100,200 a3,4,5,1,1,6,7'); + assertValidPath('M100,200 a3,4,5,006,7'); + assertValidPath('M100,200 a3,4,5,016,7'); + assertValidPath('M100,200 a3,4,5,106,7'); + assertValidPath('M100,200 a3,4,5,116,7'); + assertValidPath( + '''M19.0281,19.40466 20.7195,19.40466 20.7195,15.71439 24.11486,15.71439 24.11486,14.36762 20.7195,14.36762 +20.7195,11.68641 24.74134,11.68641 24.74134,10.34618 19.0281,10.34618 z'''); + + assertValidPath('M100,200 a0,4,5,0,0,10,0 a4,0,5,0,0,0,10 a0,0,5,0,0,-10,0 z'); + + assertValidPath('M1,2,3,4'); + assertValidPath('m100,200,3,4'); + + assertValidPath('M 100-200'); + assertValidPath('M 0.6.5'); + + assertValidPath(' M1,2'); + assertValidPath(' M1,2'); + assertValidPath('\tM1,2'); + assertValidPath('\nM1,2'); + assertValidPath('\rM1,2'); + assertValidPath('M1,2 '); + assertValidPath('M1,2\t'); + assertValidPath('M1,2\n'); + assertValidPath('M1,2\r'); + assertValidPath('M.1 .2 L.3 .4 .5 .6'); + assertValidPath('M1,1h2,3'); + assertValidPath('M1,1H2,3'); + assertValidPath('M1,1v2,3'); + assertValidPath('M1,1V2,3'); + assertValidPath('M1,1c2,3 4,5 6,7 8,9 10,11 12,13'); + assertValidPath('M1,1C2,3 4,5 6,7 8,9 10,11 12,13'); + assertValidPath('M1,1s2,3 4,5 6,7 8,9'); + assertValidPath('M1,1S2,3 4,5 6,7 8,9'); + assertValidPath('M1,1q2,3 4,5 6,7 8,9'); + assertValidPath('M1,1Q2,3 4,5 6,7 8,9'); + assertValidPath('M1,1t2,3 4,5'); + assertValidPath('M1,1T2,3 4,5'); + assertValidPath('M1,1a2,3,4,0,0,5,6 7,8,9,0,0,10,11'); + assertValidPath('M1,1A2,3,4,0,0,5,6 7,8,9,0,0,10,11'); + assertValidPath('M22.1595 3.80852C19.6789 1.35254 16.3807 -4.80966e-07 12.8727 ' + '-4.80966e-07C9.36452 -4.80966e-07 6.06642 1.35254 3.58579 3.80852C1.77297 5.60333 ' + '0.53896 7.8599 0.0171889 10.3343C-0.0738999 10.7666 0.206109 11.1901 0.64265 11.2803' + 'C1.07908 11.3706 1.50711 11.0934 1.5982 10.661C2.05552 8.49195 3.13775 6.51338 4.72783 ' + '4.9391C9.21893 0.492838 16.5262 0.492728 21.0173 4.9391C25.5082 9.38548 25.5082 16.6202 ' + '21.0173 21.0667C16.5265 25.5132 9.21893 25.5133 4.72805 21.0669C3.17644 19.5307 2.10538 ' + '17.6035 1.63081 15.4937C1.53386 15.0627 1.10252 14.7908 0.66697 14.887C0.231645 14.983 ' + '-0.0427272 15.4103 0.0542205 15.8413C0.595668 18.2481 1.81686 20.4461 3.5859 22.1976' + 'C6.14623 24.7325 9.50955 26 12.8727 26C16.236 26 19.5991 24.7326 22.1595 22.1976C27.2802 ' + '17.1277 27.2802 8.87841 22.1595 3.80852Z'); + assertValidPath('m18 11.8a.41.41 0 0 1 .24.08l.59.43h.05.72a.4.4 0 0 1 .39.28l.22.69a.08.08 0 ' + '0 0 0 0l.58.43a.41.41 0 0 1 .15.45l-.22.68a.09.09 0 0 0 0 .07l.22.68a.4.4 0 0 1 ' + '-.15.46l-.58.42a.1.1 0 0 0 0 0l-.22.68a.41.41 0 0 1 -.38.29h-.79l-.58.43a.41.41 0 ' + '0 1 -.24.08.46.46 0 0 1 -.24-.08l-.58-.43h-.06-.72a.41.41 0 0 1 -.39-.28l-.22-.68' + 'a.1.1 0 0 0 0 0l-.58-.43a.42.42 0 0 1 -.15-.46l.23-.67v-.02l-.29-.68a.43.43 0 0 1 ' + '.15-.46l.58-.42a.1.1 0 0 0 0-.05l.27-.69a.42.42 0 0 1 .39-.28h.78l.58-.43a.43.43 0 ' + '0 1 .25-.09m0-1a1.37 1.37 0 0 0 -.83.27l-.34.25h-.43a1.42 1.42 0 0 0 -1.34 1l-.13.4' + '-.35.25a1.42 1.42 0 0 0 -.51 1.58l.13.4-.13.4a1.39 1.39 0 0 0 .52 1.59l.34.25.13.4' + 'a1.41 1.41 0 0 0 1.34 1h.43l.34.26a1.44 1.44 0 0 0 .83.27 1.38 1.38 0 0 0 .83-.28' + 'l.35-.24h.43a1.4 1.4 0 0 0 1.33-1l.13-.4.35-.26a1.39 1.39 0 0 0 .51-1.57l-.13-.4.13-.41' + 'a1.4 1.4 0 0 0 -.51-1.56l-.35-.25-.13-.41a1.4 1.4 0 0 0 -1.34-1h-.42l-.34-.26a1.43 1.43 ' + '0 0 0 -.84-.28z'); + }); + + test('Malformed Paths, 此处应该为X', () { + assertInvalidPath('M100,200 a3,4,5,2,1,6,7'); + assertInvalidPath('M100,200 a3,4,5,1,2,6,7'); + + assertInvalidPath('\vM1,2'); + assertInvalidPath('xM1,2'); + assertInvalidPath('M1,2\v'); + assertInvalidPath('M1,2x'); + assertInvalidPath('M1,2 L40,0#90'); + + assertInvalidPath('x'); + assertInvalidPath('L1,2'); + + assertInvalidPath('M'); + assertInvalidPath('M\0'); + + assertInvalidPath('M1,1Z0'); + assertInvalidPath('M1,1z0'); + + assertInvalidPath('M1,1c2,3 4,5 6,7 8'); + assertInvalidPath('M1,1C2,3 4,5 6,7 8'); + assertInvalidPath('M1,1s2,3 4,5 6'); + assertInvalidPath('M1,1S2,3 4,5 6'); + assertInvalidPath('M1,1q2,3 4,5 6'); + assertInvalidPath('M1,1Q2,3 4,5 6'); + assertInvalidPath('M1,1t2,3 4'); + assertInvalidPath('M1,1T2,3 4'); + assertInvalidPath('M1,1a2,3,4,0,0,5,6 7'); + assertInvalidPath('M1,1A2,3,4,0,0,5,6 7'); + }); + + test('Missing commands/numbers/flags, 此处应该为X', () { + // Missing initial moveto. + assertInvalidPath(' 10 10'); + assertInvalidPath('L 10 10'); + // Invalid command letter. + assertInvalidPath('M 10 10 #'); + assertInvalidPath('M 10 10 E 100 100'); + // Invalid number. + assertInvalidPath('M 10 10 L100 '); + assertInvalidPath('M 10 10 L100 #'); + assertInvalidPath('M 10 10 L100#100'); + assertInvalidPath('M0,0 A#,10 0 0,0 20,20'); + assertInvalidPath('M0,0 A10,# 0 0,0 20,20'); + assertInvalidPath('M0,0 A10,10 # 0,0 20,20'); + assertInvalidPath('M0,0 A10,10 0 0,0 #,20'); + assertInvalidPath('M0,0 A10,10 0 0,0 20,#'); + // Invalid arc-flag. + assertInvalidPath('M0,0 A10,10 0 #,0 20,20'); + assertInvalidPath('M0,0 A10,10 0 0,# 20,20'); + assertInvalidPath('M0,0 A10,10 0 0,2 20,20'); + }); + + test('Check character constants', () { + expect(AsciiConstants.slashT, '\t'.codeUnitAt(0)); + expect(AsciiConstants.slashN, '\n'.codeUnitAt(0)); + expect(AsciiConstants.slashF, '\f'.codeUnitAt(0)); + expect(AsciiConstants.slashR, '\r'.codeUnitAt(0)); + expect(AsciiConstants.space, ' '.codeUnitAt(0)); + expect(AsciiConstants.period, '.'.codeUnitAt(0)); + expect(AsciiConstants.plus, '+'.codeUnitAt(0)); + expect(AsciiConstants.comma, ','.codeUnitAt(0)); + expect(AsciiConstants.minus, '-'.codeUnitAt(0)); + expect(AsciiConstants.number0, '0'.codeUnitAt(0)); + expect(AsciiConstants.number1, '1'.codeUnitAt(0)); + expect(AsciiConstants.number2, '2'.codeUnitAt(0)); + expect(AsciiConstants.number3, '3'.codeUnitAt(0)); + expect(AsciiConstants.number4, '4'.codeUnitAt(0)); + expect(AsciiConstants.number5, '5'.codeUnitAt(0)); + expect(AsciiConstants.number6, '6'.codeUnitAt(0)); + expect(AsciiConstants.number7, '7'.codeUnitAt(0)); + expect(AsciiConstants.number8, '8'.codeUnitAt(0)); + expect(AsciiConstants.number9, '9'.codeUnitAt(0)); + expect(AsciiConstants.upperA, 'A'.codeUnitAt(0)); + expect(AsciiConstants.upperC, 'C'.codeUnitAt(0)); + expect(AsciiConstants.upperE, 'E'.codeUnitAt(0)); + expect(AsciiConstants.upperH, 'H'.codeUnitAt(0)); + expect(AsciiConstants.upperL, 'L'.codeUnitAt(0)); + expect(AsciiConstants.upperM, 'M'.codeUnitAt(0)); + expect(AsciiConstants.upperQ, 'Q'.codeUnitAt(0)); + expect(AsciiConstants.upperS, 'S'.codeUnitAt(0)); + expect(AsciiConstants.upperT, 'T'.codeUnitAt(0)); + expect(AsciiConstants.upperV, 'V'.codeUnitAt(0)); + expect(AsciiConstants.upperZ, 'Z'.codeUnitAt(0)); + expect(AsciiConstants.lowerA, 'a'.codeUnitAt(0)); + expect(AsciiConstants.lowerC, 'c'.codeUnitAt(0)); + expect(AsciiConstants.lowerE, 'e'.codeUnitAt(0)); + expect(AsciiConstants.lowerH, 'h'.codeUnitAt(0)); + expect(AsciiConstants.lowerL, 'l'.codeUnitAt(0)); + expect(AsciiConstants.lowerM, 'm'.codeUnitAt(0)); + expect(AsciiConstants.lowerQ, 'q'.codeUnitAt(0)); + expect(AsciiConstants.lowerS, 's'.codeUnitAt(0)); + expect(AsciiConstants.lowerT, 't'.codeUnitAt(0)); + expect(AsciiConstants.lowerV, 'v'.codeUnitAt(0)); + expect(AsciiConstants.lowerX, 'x'.codeUnitAt(0)); + expect(AsciiConstants.lowerZ, 'z'.codeUnitAt(0)); + expect(AsciiConstants.tilde, '~'.codeUnitAt(0)); + }); + } +} diff --git a/ohos/path_parsing_test/lib/pages/s_PathProxy_test.dart b/ohos/path_parsing_test/lib/pages/s_PathProxy_test.dart new file mode 100644 index 00000000..3d2a304c --- /dev/null +++ b/ohos/path_parsing_test/lib/pages/s_PathProxy_test.dart @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* 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 'package:flutter/cupertino.dart'; +import 'package:path_parsing/path_parsing.dart'; +import '../common/test_page.dart'; +import 'example.dart'; + +class SPathProxyTestPage extends TestPage { + SPathProxyTestPage(String title, {Key? key}) : super(title, key: key) { + PathPrinter path = PathPrinter(); +//-------------构造方法---------------------- + group('Constructors', () { + test('PathProxy()', () { + expect('PathProxy为抽象类,不能直接创建', null); + }); + }); + +//-------------属性---------------------- + group('Properties', () { + test('.hashCode → int', () { + expect(path.hashCode, null); + }); + test('.runtimeType → Type', () { + expect(path.runtimeType, null); + }); + }); + +//-------------对象方法---------------------- + group('Methods', () { + test('close() → void', () { + path.close(); + expect('', null); + }); + + test('cubicTo(double x1, double y1, double x2, double y2, double x3, double y3) → void', () { + path.cubicTo(1, 2, 3, 4, 5, 6); + expect('', null); + }); + + test(' lineTo(double x, double y) → void', () { + path.lineTo( + 1, + 2, + ); + expect('', null); + }); + + test('moveTo(double x, double y) → void', () { + path.moveTo( + 1, + 2, + ); + expect('', null); + }); + + test('toString() → String', () { + expect(path.toString.runtimeType, null); + expect(path.toString, null); + }); + }); + } +} diff --git a/ohos/path_parsing_test/lib/pages/s_PathSegmentData_test.dart b/ohos/path_parsing_test/lib/pages/s_PathSegmentData_test.dart new file mode 100644 index 00000000..1974fd78 --- /dev/null +++ b/ohos/path_parsing_test/lib/pages/s_PathSegmentData_test.dart @@ -0,0 +1,134 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* 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 'package:flutter/cupertino.dart'; +import 'package:path_parsing/path_parsing.dart'; +import '../common/test_page.dart'; + +class SPathSegmentDataTestPage extends TestPage { + SPathSegmentDataTestPage(String title, {Key? key}) : super(title, key: key) { + String svg = 'M50 0 Q70 20, 50 40, Q30 20, 50 0 M50 0 Q70 -20, 50 -40, Q30 -20, 50 0 M50 40 V100'; + final SvgPathStringSource parser = SvgPathStringSource(svg); + PathSegmentData pathSD = parser.parseSegments().first; + +//-------------构造方法---------------------- + group('Constructors', () { + test('PathSegmentData()', () { + expect(PathSegmentData().runtimeType, null); + expect(PathSegmentData(), null); + }); + }); + +//-------------属性---------------------- + group('Properties', () { + test('.arcAngle ↔ double', () { + expect(pathSD.arcAngle.runtimeType, null); + expect(pathSD.arcAngle, null); + }); + + test('.arcLarge ↔ bool', () { + expect(pathSD.arcLarge.runtimeType, null); + expect(pathSD.arcLarge, null); + }); + + test('.arcRadii → _PathOffset', () { + expect(pathSD.arcRadii.runtimeType, null); + expect(pathSD.arcRadii, null); + }); + + test('.arcSweep ↔ bool', () { + expect(pathSD.arcSweep.runtimeType, null); + expect(pathSD.arcSweep, null); + }); + + test('.command ↔ SvgPathSegType', () { + expect(pathSD.command.runtimeType, null); + expect(pathSD.command, null); + }); + + test('.largeArcFlag → bool', () { + expect(pathSD.largeArcFlag.runtimeType, null); + expect(pathSD.largeArcFlag, null); + }); + + test('.point1 ↔ _PathOffset', () { + expect(pathSD.point1.runtimeType, null); + expect(pathSD.point1, null); + }); + + test('.point2 ↔ _PathOffset', () { + expect(pathSD.point2.runtimeType, null); + expect(pathSD.point2, null); + }); + + test('.r1 → double', () { + expect(pathSD.r1.runtimeType, null); + expect(pathSD.r1, null); + }); + + test('.r2 → double', () { + expect(pathSD.r2.runtimeType, null); + expect(pathSD.r2, null); + }); + + test('.sweepFlag → bool', () { + expect(pathSD.sweepFlag.runtimeType, null); + expect(pathSD.sweepFlag, null); + }); + + test('.targetPoint ↔ _PathOffset', () { + expect(pathSD.targetPoint.runtimeType, null); + expect(pathSD.targetPoint, null); + }); + + test('.x → double', () { + expect(pathSD.x.runtimeType, null); + expect(pathSD.x, null); + }); + + test('.x1 → double', () { + expect(pathSD.x1.runtimeType, null); + expect(pathSD.x1, null); + }); + + test('.x2 → double', () { + expect(pathSD.x2.runtimeType, null); + expect(pathSD.x2, null); + }); + + test('.y → double', () { + expect(pathSD.y.runtimeType, null); + expect(pathSD.y, null); + }); + + test('.y1 → double', () { + expect(pathSD.y1.runtimeType, null); + expect(pathSD.y1, null); + }); + + test('.y2 → double', () { + expect(pathSD.y2.runtimeType, null); + expect(pathSD.y2, null); + }); + }); + +//-------------对象方法---------------------- + group('Methods', () { + test('toString() → String', () { + expect(pathSD.toString(), null); + }); + }); + } +} diff --git a/ohos/path_parsing_test/lib/pages/s_SvgPathNormalizer_test.dart b/ohos/path_parsing_test/lib/pages/s_SvgPathNormalizer_test.dart new file mode 100644 index 00000000..c03f0ed3 --- /dev/null +++ b/ohos/path_parsing_test/lib/pages/s_SvgPathNormalizer_test.dart @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* 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 'package:flutter/cupertino.dart'; +import 'package:path_parsing/path_parsing.dart'; +import '../common/test_page.dart'; +import 'example.dart'; + +class SSvgPathNormalizerTestPage extends TestPage { + SSvgPathNormalizerTestPage(String title, {Key? key}) : super(title, key: key) { + SvgPathNormalizer pathNormalizer = SvgPathNormalizer(); +//-------------构造方法---------------------- + group('Constructors', () { + test('SvgPathNormalizer()', () { + expect(SvgPathNormalizer().runtimeType, null); + expect(SvgPathNormalizer(), null); + }); + }); + +//-------------属性---------------------- + group('Properties', () { + test('.runtimeType → Type', () { + expect(pathNormalizer.runtimeType, null); + }); + + test('.hashCode → int', () { + expect(pathNormalizer.hashCode.runtimeType, null); + expect(pathNormalizer.hashCode, null); + }); + }); + +//-------------对象方法---------------------- + group('Methods', () { + test('emitSegment(PathSegmentData segment, PathProxy path) → void', () { + String pathString = 'M100 100 L200 200 L300 100 Z'; + SvgPathStringSource source = SvgPathStringSource(pathString); + PathSegmentData pathSD = source.parseSegments().last; + print('它的值:${pathSD}--${source.parseSegments().length}'); + pathNormalizer.emitSegment(pathSD, PathPrinter()); + expect('', null); + }); + test('toString() → String', () { + expect(pathNormalizer.toString(), null); + }); + }); + } +} diff --git a/ohos/path_parsing_test/lib/pages/s_SvgPathStringSource_test.dart b/ohos/path_parsing_test/lib/pages/s_SvgPathStringSource_test.dart new file mode 100644 index 00000000..843f9bbc --- /dev/null +++ b/ohos/path_parsing_test/lib/pages/s_SvgPathStringSource_test.dart @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* 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 'package:flutter/cupertino.dart'; +import 'package:path_parsing/path_parsing.dart'; +import '../common/test_page.dart'; +import 'example.dart'; + +class SSvgPathStringSourceTestPage extends TestPage { + SSvgPathStringSourceTestPage(String title, {Key? key}) : super(title, key: key) { + String svg = 'M50 0 Q70 20, 50 40, Q30 20, 50 0 M50 0 Q70 -20, 50 -40, Q30 -20, 50 0 M50 40 V100'; + final SvgPathStringSource pathStringSource = SvgPathStringSource(svg); +//-------------构造方法---------------------- + group('Constructors', () { + test('SvgPathStringSource(String _string)', () { + expect( + SvgPathStringSource('M50 0 Q70 20, 50 40, Q30 20, 50 0 M50 0 Q70 -20, 50 -40, Q30 -20, 50 0 M50 40 V100').runtimeType, + null); + expect(SvgPathStringSource('M50 0 Q70 20, 50 40, Q30 20, 50 0 M50 0 Q70 -20, 50 -40, Q30 -20, 50 0 M50 40 V100'), null); + }); + }); + +//-------------属性--------------- + group('Properties', () { + test('.hasMoreData → bool', () { + expect(pathStringSource.hasMoreData.runtimeType, null); + expect(pathStringSource.hasMoreData, null); + }); + + test('.hashCode → int', () { + expect(pathStringSource.hashCode.runtimeType, null); + expect(pathStringSource.hashCode, null); + }); + }); + +//-------------对象方法---------------------- + group('Methods', () { + test('parseSegment() → PathSegmentData', () { + String svg = 'M50 0 Q70 20, 50 40, Q30 20, 50 0 M50 0 Q70 -20, 50 -40, Q30 -20, 50 0 M50 40 V100'; + final SvgPathStringSource pathStringSource = SvgPathStringSource(svg); + expect(pathStringSource.parseSegment(), null); + }); + test('parseSegments() → Iterable', () { + String svg = 'M50 0 Q70 20, 50 40, Q30 20, 50 0 M50 0 Q70 -20, 50 -40, Q30 -20, 50 0 M50 40 V100'; + final SvgPathStringSource pathStringSource = SvgPathStringSource(svg); + expect(pathStringSource.parseSegments(), null); + }); + + test('toString() → String', () { + expect(pathStringSource.toString.runtimeType, null); + expect(pathStringSource.toString, null); + }); + }); + } +} -- Gitee From 0fab43471fb8619973b588f9f2d58d2db7ef3bcf Mon Sep 17 00:00:00 2001 From: tanjiancheng <562575412@qq.com> Date: Thu, 28 Nov 2024 16:16:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E6=9E=90=E8=B7=AF=E5=BE=84demo?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tanjiancheng <562575412@qq.com> --- .../lib/pages/parse_path_test.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ohos/path_parsing_test/lib/pages/parse_path_test.dart b/ohos/path_parsing_test/lib/pages/parse_path_test.dart index bdeefe9a..cb46f2ea 100644 --- a/ohos/path_parsing_test/lib/pages/parse_path_test.dart +++ b/ohos/path_parsing_test/lib/pages/parse_path_test.dart @@ -1,5 +1,17 @@ -// Test paths taken from: -// * https://github.com/chromium/chromium/blob/master/third_party/blink/renderer/core/svg/svg_path_parser_test.cc +/* +* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. +* 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 'package:flutter/cupertino.dart'; import 'package:path_parsing/path_parsing.dart'; -- Gitee