1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-08-16 00:20:23 +03:00

Svg tests added

This commit is contained in:
Victor Sukochev 2016-09-01 16:03:48 +06:00
parent 872ca49bdb
commit 0e03d39365
12 changed files with 153 additions and 106 deletions

View File

@ -12,6 +12,16 @@
57CAB11C1D78177900FD8E47 /* SWXMLHash.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57CAB11B1D78177900FD8E47 /* SWXMLHash.framework */; };
57CAB11D1D78178000FD8E47 /* SWXMLHash.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 57CAB11B1D78177900FD8E47 /* SWXMLHash.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
57CAB1211D781F0000FD8E47 /* CAAnimation+Closure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57CAB1201D781F0000FD8E47 /* CAAnimation+Closure.swift */; };
57CAB1231D782DFC00FD8E47 /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57CAB1221D782DFC00FD8E47 /* TestUtils.swift */; };
57CAB12E1D7832E000FD8E47 /* circle.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB1251D7832E000FD8E47 /* circle.svg */; };
57CAB12F1D7832E000FD8E47 /* ellipse.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB1261D7832E000FD8E47 /* ellipse.svg */; };
57CAB1301D7832E000FD8E47 /* group.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB1271D7832E000FD8E47 /* group.svg */; };
57CAB1311D7832E000FD8E47 /* line.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB1281D7832E000FD8E47 /* line.svg */; };
57CAB1321D7832E000FD8E47 /* polygon.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB1291D7832E000FD8E47 /* polygon.svg */; };
57CAB1331D7832E000FD8E47 /* polyline.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB12A1D7832E000FD8E47 /* polyline.svg */; };
57CAB1341D7832E000FD8E47 /* rect.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB12B1D7832E000FD8E47 /* rect.svg */; };
57CAB1351D7832E000FD8E47 /* roundRect.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB12C1D7832E000FD8E47 /* roundRect.svg */; };
57CAB1361D7832E000FD8E47 /* triangle.svg in Resources */ = {isa = PBXBuildFile; fileRef = 57CAB12D1D7832E000FD8E47 /* triangle.svg */; };
57FCD2771D76EA4600CC0FB6 /* Macaw.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57FCD26C1D76EA4600CC0FB6 /* Macaw.framework */; };
57FCD27C1D76EA4600CC0FB6 /* MacawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57FCD27B1D76EA4600CC0FB6 /* MacawTests.swift */; };
57FCD2E71D76EB8E00CC0FB6 /* AnimatableVariable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57FCD2881D76EB8E00CC0FB6 /* AnimatableVariable.swift */; };
@ -125,6 +135,16 @@
57CAB1181D78173F00FD8E47 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = RxSwift.framework; sourceTree = "<group>"; };
57CAB11B1D78177900FD8E47 /* SWXMLHash.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SWXMLHash.framework; path = iOS/SWXMLHash.framework; sourceTree = "<group>"; };
57CAB1201D781F0000FD8E47 /* CAAnimation+Closure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CAAnimation+Closure.swift"; sourceTree = "<group>"; };
57CAB1221D782DFC00FD8E47 /* TestUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = "<group>"; };
57CAB1251D7832E000FD8E47 /* circle.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = circle.svg; sourceTree = "<group>"; };
57CAB1261D7832E000FD8E47 /* ellipse.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = ellipse.svg; sourceTree = "<group>"; };
57CAB1271D7832E000FD8E47 /* group.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = group.svg; sourceTree = "<group>"; };
57CAB1281D7832E000FD8E47 /* line.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = line.svg; sourceTree = "<group>"; };
57CAB1291D7832E000FD8E47 /* polygon.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = polygon.svg; sourceTree = "<group>"; };
57CAB12A1D7832E000FD8E47 /* polyline.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = polyline.svg; sourceTree = "<group>"; };
57CAB12B1D7832E000FD8E47 /* rect.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = rect.svg; sourceTree = "<group>"; };
57CAB12C1D7832E000FD8E47 /* roundRect.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = roundRect.svg; sourceTree = "<group>"; };
57CAB12D1D7832E000FD8E47 /* triangle.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = triangle.svg; sourceTree = "<group>"; };
57FCD26C1D76EA4600CC0FB6 /* Macaw.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Macaw.framework; sourceTree = BUILT_PRODUCTS_DIR; };
57FCD2761D76EA4600CC0FB6 /* MacawTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MacawTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
57FCD27B1D76EA4600CC0FB6 /* MacawTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacawTests.swift; sourceTree = "<group>"; };
@ -249,6 +269,22 @@
path = "Swift-CAAnimation-Closure";
sourceTree = "<group>";
};
57CAB1241D7832E000FD8E47 /* svg */ = {
isa = PBXGroup;
children = (
57CAB1251D7832E000FD8E47 /* circle.svg */,
57CAB1261D7832E000FD8E47 /* ellipse.svg */,
57CAB1271D7832E000FD8E47 /* group.svg */,
57CAB1281D7832E000FD8E47 /* line.svg */,
57CAB1291D7832E000FD8E47 /* polygon.svg */,
57CAB12A1D7832E000FD8E47 /* polyline.svg */,
57CAB12B1D7832E000FD8E47 /* rect.svg */,
57CAB12C1D7832E000FD8E47 /* roundRect.svg */,
57CAB12D1D7832E000FD8E47 /* triangle.svg */,
);
path = svg;
sourceTree = "<group>";
};
57D2020D1D78044A00A90D4F /* Dependencies */ = {
isa = PBXGroup;
children = (
@ -312,6 +348,8 @@
57FCD27A1D76EA4600CC0FB6 /* MacawTests */ = {
isa = PBXGroup;
children = (
57CAB1241D7832E000FD8E47 /* svg */,
57CAB1221D782DFC00FD8E47 /* TestUtils.swift */,
57FCD27B1D76EA4600CC0FB6 /* MacawTests.swift */,
57FCD27D1D76EA4600CC0FB6 /* Info.plist */,
);
@ -626,6 +664,15 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
57CAB1361D7832E000FD8E47 /* triangle.svg in Resources */,
57CAB1301D7832E000FD8E47 /* group.svg in Resources */,
57CAB1351D7832E000FD8E47 /* roundRect.svg in Resources */,
57CAB12E1D7832E000FD8E47 /* circle.svg in Resources */,
57CAB1331D7832E000FD8E47 /* polyline.svg in Resources */,
57CAB1311D7832E000FD8E47 /* line.svg in Resources */,
57CAB1321D7832E000FD8E47 /* polygon.svg in Resources */,
57CAB12F1D7832E000FD8E47 /* ellipse.svg in Resources */,
57CAB1341D7832E000FD8E47 /* rect.svg in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -725,6 +772,7 @@
buildActionMask = 2147483647;
files = (
57FCD27C1D76EA4600CC0FB6 /* MacawTests.swift in Sources */,
57CAB1231D782DFC00FD8E47 /* TestUtils.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -3,108 +3,108 @@ import XCTest
class MacawTests: XCTestCase {
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
super.setUp()
}
override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
super.setUp()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testSVGTriangle() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("triangle", referenceObject: createTriangleReferenceObject()))
}
func testSVGTriangle() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("triangle", referenceObject: createTriangleReferenceObject()))
}
func testSVGLine() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("line", referenceObject: createLineReferenceObject()))
}
func testSVGLine() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("line", referenceObject: createLineReferenceObject()))
}
func testSVGRect() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("rect", referenceObject: createRectReferenceObject()))
}
func testSVGRect() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("rect", referenceObject: createRectReferenceObject()))
}
func testSVGRoundRect() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("roundRect", referenceObject: createRoundRectReferenceObject()))
}
func testSVGRoundRect() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("roundRect", referenceObject: createRoundRectReferenceObject()))
}
func testSVGPolygon() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("polygon", referenceObject: createPolygonReferenceObject()))
}
func testSVGPolygon() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("polygon", referenceObject: createPolygonReferenceObject()))
}
func testSVGPolyline() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("polyline", referenceObject: createPolylineReferenceObject()))
}
func testSVGPolyline() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("polyline", referenceObject: createPolylineReferenceObject()))
}
func testSVGCircle() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("circle", referenceObject: createCircleReferenceObject()))
}
func testSVGCircle() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("circle", referenceObject: createCircleReferenceObject()))
}
func testSVGEllipse() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("ellipse", referenceObject: createEllipseReferenceObject()))
}
func testSVGEllipse() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("ellipse", referenceObject: createEllipseReferenceObject()))
}
func testSVGGroup() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("group", referenceObject: createGroupReferenceObject()))
}
func testSVGGroup() {
XCTAssertTrue(TestUtils.compareWithReferenceObject("group", referenceObject: createGroupReferenceObject()))
}
func createTriangleReferenceObject() -> Group {
let path = Path(segments: [Move(x: 150, y: 0), PLine(x: 75, y: 200), PLine(x: 225, y: 200), Close()])
return Group(contents: [Shape(form: path, stroke: Stroke(fill: Color.black, width: 2, cap: .round, join: .round))])
}
func createTriangleReferenceObject() -> Group {
let path = MoveTo(x: 150, y: 0).lineTo(x: 75, y: 200).lineTo(x: 225, y: 200).close().build()
return Group(contents: [Shape(form: path, stroke: Stroke(fill: Color.black, width: 2, cap: .round, join: .round))])
}
func createLineReferenceObject() -> Group {
let line = Line(x1: 0, y1: 0, x2: 200, y2: 200)
return Group(contents: [Shape(form: line, stroke: Stroke(fill: Color.red, width: 2, cap: .round, join: .round))])
}
func createLineReferenceObject() -> Group {
let line = Line(x1: 0, y1: 0, x2: 200, y2: 200)
return Group(contents: [Shape(form: line, stroke: Stroke(fill: Color.red, width: 2, cap: .round, join: .round))])
}
func createRectReferenceObject() -> Group {
let rect = Rect(x: 50, w: 150, h: 150)
return Group(contents: [Shape(form: rect)])
}
func createRectReferenceObject() -> Group {
let rect = Rect(x: 50, w: 150, h: 150)
return Group(contents: [Shape(form: rect)])
}
func createRoundRectReferenceObject() -> Group {
let roundRect = RoundRect(rect: Rect(w: 150, h: 150), rx: 20, ry: 20)
return Group(contents: [Shape(form: roundRect)])
}
func createRoundRectReferenceObject() -> Group {
let roundRect = RoundRect(rect: Rect(w: 150, h: 150), rx: 20, ry: 20)
return Group(contents: [Shape(form: roundRect)])
}
func createPolygonReferenceObject() -> Group {
let polygon = Polygon(points: [200, 10, 250, 190, 160, 210])
return Group(contents: [Shape(form: polygon)])
}
func createPolygonReferenceObject() -> Group {
let polygon = Polygon(points: [200, 10, 250, 190, 160, 210])
return Group(contents: [Shape(form: polygon)])
}
func createPolylineReferenceObject() -> Group {
let polyline = Polyline(points: [0, 40, 40, 40, 40, 80, 80, 80, 80, 120, 120, 120, 120, 160])
func createPolylineReferenceObject() -> Group {
let polyline = Polyline(points: [0, 40, 40, 40, 40, 80, 80, 80, 80, 120, 120, 120, 120, 160])
return Group(contents: [Shape(form: polyline,
stroke: Stroke(fill: Color.red, width: 4, cap: .round, join: .round),
fill: Color.white)])
}
return Group(contents: [Shape(form: polyline,
stroke: Stroke(fill: Color.red, width: 4, cap: .round, join: .round),
fill: Color.white)])
}
func createCircleReferenceObject() -> Group {
let circle = Circle(cx: 50, cy: 50, r: 40)
func createCircleReferenceObject() -> Group {
let circle = Circle(cx: 50, cy: 50, r: 40)
return Group(contents: [Shape(form: circle,
stroke: Stroke(fill: Color.black, width: 3, cap: .round, join: .round),
fill: Color.red)])
}
return Group(contents: [Shape(form: circle,
stroke: Stroke(fill: Color.black, width: 3, cap: .round, join: .round),
fill: Color.red)])
}
func createEllipseReferenceObject() -> Group {
let ellipse = Ellipse(cx: 200, cy: 80, rx: 100, ry: 50)
func createEllipseReferenceObject() -> Group {
let ellipse = Ellipse(cx: 200, cy: 80, rx: 100, ry: 50)
return Group(contents: [Shape(form: ellipse,
stroke: Stroke(fill: Color.purple, width: 2, cap: .round, join: .round),
fill: Color.yellow)])
}
return Group(contents: [Shape(form: ellipse,
stroke: Stroke(fill: Color.purple, width: 2, cap: .round, join: .round),
fill: Color.yellow)])
}
func createGroupReferenceObject() -> Group {
let pathShape = Shape(form: Path(segments: [Move(x: 150, y: 0), PLine(x: 75, y: 200), PLine(x: 225, y: 200), Close()]),
stroke: Stroke(fill: Color.black, width: 2, cap: .round, join: .round))
func createGroupReferenceObject() -> Group {
let pathShape = Shape(form: MoveTo(x: 150, y: 0).lineTo(x: 75, y: 200).lineTo(x: 225, y: 200).close().build(),
stroke: Stroke(fill: Color.black, width: 2, cap: .round, join: .round))
let lineShape = Shape(form: Line(x1: 0, y1: 0, x2: 200, y2: 200),
stroke: Stroke(fill: Color.white, width: 2, cap: .round, join: .round))
let lineShape = Shape(form: Line(x1: 0, y1: 0, x2: 200, y2: 200),
stroke: Stroke(fill: Color.white, width: 2, cap: .round, join: .round))
return Group(contents: [Group(contents: [pathShape, lineShape])])
}
return Group(contents: [Group(contents: [pathShape, lineShape])])
}
}

View File

@ -3,32 +3,31 @@ import Macaw
class TestUtils {
class func compareWithReferenceObject(fileName: String, referenceObject: AnyObject) -> Bool {
let bundle = NSBundle(forClass: TestUtils().dynamicType)
if let path = bundle.pathForResource(fileName, ofType: "svg") {
let content = try? NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding)
if let svgString = content as? String {
let parser = SVGParser(svgString)
let group = parser.parse()
let referenceArray = TestUtils.prepareParametersList(Mirror(reflecting: referenceObject))
let parametersArray = TestUtils.prepareParametersList(Mirror(reflecting: group))
return referenceArray.elementsEqual(parametersArray, isEquivalent: { first, second in
return first.0 == second.0 && first.1 == second.1
})
}
}
return false
}
class func compareWithReferenceObject(fileName: String, referenceObject: AnyObject) -> Bool {
let bundle = NSBundle(forClass: TestUtils().dynamicType)
if let path = bundle.pathForResource(fileName, ofType: "svg") {
let content = try? NSString(contentsOfFile: path, encoding: NSUTF8StringEncoding)
if let svgString = content as? String {
let group = SVGParser.parse(text: svgString)
let referenceArray = TestUtils.prepareParametersList(Mirror(reflecting: referenceObject))
let parametersArray = TestUtils.prepareParametersList(Mirror(reflecting: group))
return referenceArray.elementsEqual(parametersArray, isEquivalent: { first, second in
return first.0 == second.0 && first.1 == second.1
})
}
}
return false
}
class func prepareParametersList(mirror: Mirror) -> [(String, String)] {
var result: [(String, String)] = []
for (_, attribute) in mirror.children.enumerate() {
if let label = attribute.label where label == "_value" || label.characters.first != "_" {
result.append((label, String(attribute.value)))
result.appendContentsOf(prepareParametersList(Mirror(reflecting: attribute.value)))
}
}
return result
}
class func prepareParametersList(mirror: Mirror) -> [(String, String)] {
var result: [(String, String)] = []
for (_, attribute) in mirror.children.enumerate() {
if let label = attribute.label where label == "_value" || label.characters.first != "_" {
result.append((label, String(attribute.value)))
result.appendContentsOf(prepareParametersList(Mirror(reflecting: attribute.value)))
}
}
return result
}
}

View File

Before

Width:  |  Height:  |  Size: 268 B

After

Width:  |  Height:  |  Size: 268 B

View File

Before

Width:  |  Height:  |  Size: 281 B

After

Width:  |  Height:  |  Size: 281 B

View File

Before

Width:  |  Height:  |  Size: 332 B

After

Width:  |  Height:  |  Size: 332 B

View File

Before

Width:  |  Height:  |  Size: 259 B

After

Width:  |  Height:  |  Size: 259 B

View File

Before

Width:  |  Height:  |  Size: 226 B

After

Width:  |  Height:  |  Size: 226 B

View File

Before

Width:  |  Height:  |  Size: 305 B

After

Width:  |  Height:  |  Size: 305 B

View File

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

View File

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 234 B

View File

Before

Width:  |  Height:  |  Size: 263 B

After

Width:  |  Height:  |  Size: 263 B