Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#203 Improve pattern support #602

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Macaw.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,15 @@
A74C8326229EB77B0085A832 /* masking-path-13-f-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = A74C8325229EB77B0085A832 /* masking-path-13-f-manual.reference */; };
A74C832C229FB7690085A832 /* color-prop-04-t-manual-osx.svg in Resources */ = {isa = PBXBuildFile; fileRef = A74C832B229FB7690085A832 /* color-prop-04-t-manual-osx.svg */; };
A74C832E229FBA4C0085A832 /* color-prop-04-t-manual-osx.reference in Resources */ = {isa = PBXBuildFile; fileRef = A74C832D229FBA4C0085A832 /* color-prop-04-t-manual-osx.reference */; };
A75A2F5922AE92B40056A89D /* pservers-pattern-03-f-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F5822AE92B40056A89D /* pservers-pattern-03-f-manual.svg */; };
A75A2F5B22AE96050056A89D /* pservers-pattern-03-f-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F5A22AE96050056A89D /* pservers-pattern-03-f-manual.reference */; };
A75A2F6122AF818B0056A89D /* pservers-pattern-02-f-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F6022AF818B0056A89D /* pservers-pattern-02-f-manual.svg */; };
A75A2F6322AF81D90056A89D /* pservers-pattern-02-f-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F6222AF81D80056A89D /* pservers-pattern-02-f-manual.reference */; };
A75A2F7522AFBD0C0056A89D /* pservers-pattern-09-f-manual.svg in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F7422AFBD0C0056A89D /* pservers-pattern-09-f-manual.svg */; };
A75A2F7722AFBD5C0056A89D /* pservers-pattern-09-f-manual.reference in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F7622AFBD5C0056A89D /* pservers-pattern-09-f-manual.reference */; };
A75A2F8522AFC6570056A89D /* pservers-pattern-02-f-manual.png in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F8222AFC6560056A89D /* pservers-pattern-02-f-manual.png */; };
A75A2F8622AFC6570056A89D /* pservers-pattern-03-f-manual.png in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F8322AFC6560056A89D /* pservers-pattern-03-f-manual.png */; };
A75A2F8722AFC6570056A89D /* pservers-pattern-09-f-manual.png in Resources */ = {isa = PBXBuildFile; fileRef = A75A2F8422AFC6560056A89D /* pservers-pattern-09-f-manual.png */; };
A7E675561EC4213500BD9ECB /* NodeBoundsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7E675551EC4213500BD9ECB /* NodeBoundsTests.swift */; };
C410148E1F834D290022EE44 /* style.svg in Resources */ = {isa = PBXBuildFile; fileRef = C410148D1F834D280022EE44 /* style.svg */; };
C4153A8F1F8793DE001BA5EE /* small-logo.png in Resources */ = {isa = PBXBuildFile; fileRef = C4153A8E1F8793DD001BA5EE /* small-logo.png */; };
Expand Down Expand Up @@ -1248,6 +1257,15 @@
A74C8325229EB77B0085A832 /* masking-path-13-f-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "masking-path-13-f-manual.reference"; sourceTree = "<group>"; };
A74C832B229FB7690085A832 /* color-prop-04-t-manual-osx.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "color-prop-04-t-manual-osx.svg"; sourceTree = "<group>"; };
A74C832D229FBA4C0085A832 /* color-prop-04-t-manual-osx.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "color-prop-04-t-manual-osx.reference"; sourceTree = "<group>"; };
A75A2F5822AE92B40056A89D /* pservers-pattern-03-f-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "pservers-pattern-03-f-manual.svg"; sourceTree = "<group>"; };
A75A2F5A22AE96050056A89D /* pservers-pattern-03-f-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "pservers-pattern-03-f-manual.reference"; sourceTree = "<group>"; };
A75A2F6022AF818B0056A89D /* pservers-pattern-02-f-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "pservers-pattern-02-f-manual.svg"; sourceTree = "<group>"; };
A75A2F6222AF81D80056A89D /* pservers-pattern-02-f-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "pservers-pattern-02-f-manual.reference"; sourceTree = "<group>"; };
A75A2F7422AFBD0C0056A89D /* pservers-pattern-09-f-manual.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "pservers-pattern-09-f-manual.svg"; sourceTree = "<group>"; };
A75A2F7622AFBD5C0056A89D /* pservers-pattern-09-f-manual.reference */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "pservers-pattern-09-f-manual.reference"; sourceTree = "<group>"; };
A75A2F8222AFC6560056A89D /* pservers-pattern-02-f-manual.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pservers-pattern-02-f-manual.png"; sourceTree = "<group>"; };
A75A2F8322AFC6560056A89D /* pservers-pattern-03-f-manual.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pservers-pattern-03-f-manual.png"; sourceTree = "<group>"; };
A75A2F8422AFC6560056A89D /* pservers-pattern-09-f-manual.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "pservers-pattern-09-f-manual.png"; sourceTree = "<group>"; };
A7E675551EC4213500BD9ECB /* NodeBoundsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NodeBoundsTests.swift; path = Bounds/NodeBoundsTests.swift; sourceTree = "<group>"; };
C410148D1F834D280022EE44 /* style.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = style.svg; sourceTree = "<group>"; };
C4153A8E1F8793DD001BA5EE /* small-logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "small-logo.png"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1410,6 +1428,9 @@
4295954322A0F7CE00869079 /* shapes-rect-06-f-manual.png */,
4295954422A0F7CE00869079 /* shapes-polyline-02-t-manual.png */,
4295954522A0F7CE00869079 /* shapes-polygon-01-t-manual.png */,
A75A2F8222AFC6560056A89D /* pservers-pattern-02-f-manual.png */,
A75A2F8322AFC6560056A89D /* pservers-pattern-03-f-manual.png */,
A75A2F8422AFC6560056A89D /* pservers-pattern-09-f-manual.png */,
);
path = png;
sourceTree = "<group>";
Expand Down Expand Up @@ -1979,6 +2000,12 @@
A74C82DB229E35D20085A832 /* pservers-grad-24-f-manual.svg */,
5B1AE1F020B6A669007EECCB /* pservers-grad-stops-01-f-manual.reference */,
5B1AE1EB20B6A669007EECCB /* pservers-grad-stops-01-f-manual.svg */,
A75A2F7622AFBD5C0056A89D /* pservers-pattern-09-f-manual.reference */,
A75A2F7422AFBD0C0056A89D /* pservers-pattern-09-f-manual.svg */,
A75A2F6222AF81D80056A89D /* pservers-pattern-02-f-manual.reference */,
A75A2F6022AF818B0056A89D /* pservers-pattern-02-f-manual.svg */,
A75A2F5A22AE96050056A89D /* pservers-pattern-03-f-manual.reference */,
A75A2F5822AE92B40056A89D /* pservers-pattern-03-f-manual.svg */,
5B1AE1A220B6A669007EECCB /* render-elems-01-t-manual.reference */,
5B1AE1E920B6A669007EECCB /* render-elems-01-t-manual.svg */,
5B1AE19020B6A669007EECCB /* render-elems-02-t-manual.reference */,
Expand Down Expand Up @@ -2281,6 +2308,7 @@
A74C822D2297D5350085A832 /* coords-trans-13-f-manual.reference in Resources */,
5B1AE26C20B6A669007EECCB /* painting-fill-05-b-manual.svg in Resources */,
429595AF22A0F7CE00869079 /* shapes-polyline-02-t-manual.png in Resources */,
A75A2F8622AFC6570056A89D /* pservers-pattern-03-f-manual.png in Resources */,
5B37139920BE95D7004BB6EE /* pservers-grad-02-b-manual.reference in Resources */,
4295955022A0F7CE00869079 /* painting-fill-02-t-manual.png in Resources */,
4295954622A0F7CE00869079 /* text-fonts-02-t-manual.png in Resources */,
Expand Down Expand Up @@ -2336,6 +2364,7 @@
42DAF9B022A6130D0095B936 /* color-prop-03-t-manual.svg in Resources */,
5B1AE2CD20B6A669007EECCB /* paths-data-10-t-manual.svg in Resources */,
42DAF9AE22A612EC0095B936 /* painting-control-01-f-manual.svg in Resources */,
A75A2F7522AFBD0C0056A89D /* pservers-pattern-09-f-manual.svg in Resources */,
5B1AE29C20B6A669007EECCB /* paths-data-01-t-manual.reference in Resources */,
4295955822A0F7CE00869079 /* shapes-ellipse-03-f-manual.png in Resources */,
4295959F22A0F7CE00869079 /* shapes-rect-07-f-manual.png in Resources */,
Expand All @@ -2356,6 +2385,7 @@
A74C82E5229E35D30085A832 /* pservers-grad-13-b-manual.svg in Resources */,
A74C8308229E9CCE0085A832 /* masking-mask-02-f-manual.svg in Resources */,
5B1AE2B220B6A669007EECCB /* types-basic-01-f-manual.svg in Resources */,
A75A2F7722AFBD5C0056A89D /* pservers-pattern-09-f-manual.reference in Resources */,
58944BDA20AC8A9A00657640 /* logo_base64.txt in Resources */,
5B1AE2C520B6A669007EECCB /* coords-trans-02-t-manual.svg in Resources */,
A74C81F12292B3940085A832 /* color-prop-05-t-manual.svg in Resources */,
Expand Down Expand Up @@ -2440,6 +2470,7 @@
429595A622A0F7CE00869079 /* pservers-grad-stops-01-f-manual.png in Resources */,
5B1AE25120B6A669007EECCB /* coords-trans-05-t-manual.reference in Resources */,
5B1AE29120B6A669007EECCB /* coords-transformattr-01-f-manual.svg in Resources */,
A75A2F8522AFC6570056A89D /* pservers-pattern-02-f-manual.png in Resources */,
6A616BFA2129560A006A07FA /* MacawTests.bundle in Resources */,
4295957F22A0F7CE00869079 /* metadata-example-01-t-manual.png in Resources */,
5B1AE2D320B6A669007EECCB /* shapes-rect-04-f-manual.reference in Resources */,
Expand All @@ -2460,6 +2491,7 @@
A74C81F32292B45E0085A832 /* color-prop-05-t-manual.reference in Resources */,
4295958922A0F7CE00869079 /* masking-path-02-b-manual.png in Resources */,
5B1AE23420B6A669007EECCB /* painting-control-03-f-manual.reference in Resources */,
A75A2F8722AFC6570056A89D /* pservers-pattern-09-f-manual.png in Resources */,
4295955F22A0F7CE00869079 /* coords-transformattr-05-f-manual.png in Resources */,
A74C82342297D8B40085A832 /* shapes-rect-03-t-manual.svg in Resources */,
5B1AE26820B6A669007EECCB /* shapes-polyline-01-t-manual.svg in Resources */,
Expand Down Expand Up @@ -2518,6 +2550,7 @@
5B1AE26020B6A669007EECCB /* shapes-polygon-02-t-manual.reference in Resources */,
4295959022A0F7CE00869079 /* painting-control-02-f-manual.png in Resources */,
5B1AE2AA20B6A669007EECCB /* struct-frag-03-t-manual.svg in Resources */,
A75A2F5922AE92B40056A89D /* pservers-pattern-03-f-manual.svg in Resources */,
5B1AE24720B6A669007EECCB /* painting-stroke-01-t-manual.reference in Resources */,
5B1AE29B20B6A669007EECCB /* shapes-line-01-t-manual.reference in Resources */,
429595A722A0F7CE00869079 /* paths-data-08-t-manual.png in Resources */,
Expand All @@ -2543,6 +2576,7 @@
5B1AE2B720B6A669007EECCB /* struct-frag-03-t-manual.reference in Resources */,
5B1AE25C20B6A669007EECCB /* shapes-intro-01-t-manual.svg in Resources */,
57CAB12E1D7832E000FD8E47 /* circle.svg in Resources */,
A75A2F6122AF818B0056A89D /* pservers-pattern-02-f-manual.svg in Resources */,
5B1AE2D820B6A669007EECCB /* metadata-example-01-t-manual.svg in Resources */,
4295957422A0F7CE00869079 /* paths-data-12-t-manual.png in Resources */,
5B1AE2C620B6A669007EECCB /* painting-fill-05-b-manual.reference in Resources */,
Expand All @@ -2554,6 +2588,7 @@
5B1AE2DE20B6A669007EECCB /* painting-control-03-f-manual.svg in Resources */,
5B1AE25520B6A669007EECCB /* paths-data-15-t-manual.reference in Resources */,
5B1AE24D20B6A669007EECCB /* paths-data-13-t-manual.svg in Resources */,
A75A2F6322AF81D90056A89D /* pservers-pattern-02-f-manual.reference in Resources */,
A74C82202297D4810085A832 /* coords-trans-14-f-manual.svg in Resources */,
5B270B5D214BBC27001AD741 /* clearColor.reference in Resources */,
57CAB1311D7832E000FD8E47 /* line.svg in Resources */,
Expand Down Expand Up @@ -2620,6 +2655,7 @@
5B1AE27C20B6A669007EECCB /* shapes-rect-04-f-manual.svg in Resources */,
5B1AE2DB20B6A669007EECCB /* color-prop-01-b-manual.reference in Resources */,
4295959122A0F7CE00869079 /* coords-coord-02-t-manual.png in Resources */,
A75A2F5B22AE96050056A89D /* pservers-pattern-03-f-manual.reference in Resources */,
4295958022A0F7CE00869079 /* coords-trans-04-t-manual.png in Resources */,
42DB451422A52A4200091DC6 /* pservers-grad-22-b-manual.png in Resources */,
5B1AE2BF20B6A669007EECCB /* shapes-ellipse-02-t-manual.reference in Resources */,
Expand Down
129 changes: 70 additions & 59 deletions MacawTests/MacawSVGTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class MacawSVGTests: XCTestCase {

private let testFolderName = "MacawTestOutputData"
private let shouldComparePNGImages = true
private let multipleTestsWillRun = false
private let shouldSaveFaildedTestImage = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have removed few options in tests. For example, there is no shouldSaveFaildedTestImage which means that tests can generate some data which is not a good default value.

I would recommend to remove all these changes from this PR to keep it only about pattern support and create another one especially for tests improvements where we can discuss these changes.

private let multipleTestsWillRun = true
private let shouldSaveFaildedTestImage = true

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
Expand Down Expand Up @@ -136,6 +136,65 @@ class MacawSVGTests: XCTestCase {
}
}

func getImage(from svgName: String) -> MImage {
let bundle = Bundle(for: type(of: TestUtils()))
do {
let node = try SVGParser.parse(resource: svgName, fromBundle: bundle)

var frame = node.bounds
if frame == nil, let group = node as? Group {
frame = Group(contents: group.contents).bounds
}

let image = node.toNativeImage(size: frame?.size() ?? Size(w: 100, h: 100))
return image
} catch {
XCTFail(error.localizedDescription)
}

XCTFail()
return MImage()
}

func saveImage(image: MImage, fileName: String) {
#if os(OSX)
guard let data = image.tiffRepresentation else {
return
}
#endif

#if os(iOS)
guard let data = image.pngData() else {
return
}
#endif

let _ = writeToFile(data: data, fileName: "\(fileName).png")
}

fileprivate func setupTestFolderDirectory() {
guard let myDocuments = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
return
}

let testDirectoryPath = myDocuments.appendingPathComponent("\(testFolderName)")

do {
if !multipleTestsWillRun {
try FileManager.default.removeItem(at: testDirectoryPath)
}

var isDirectory: ObjCBool = ObjCBool(true)
if !FileManager.default.fileExists(atPath: testDirectoryPath.absoluteString, isDirectory: &isDirectory) {
try FileManager.default.createDirectory(at: testDirectoryPath, withIntermediateDirectories: true, attributes: .none)
}
} catch {
XCTFail(error.localizedDescription)
return
}
}


func testViewBox() {
validate("viewBox")
}
Expand Down Expand Up @@ -194,17 +253,16 @@ class MacawSVGTests: XCTestCase {
if let path = bundle.path(forResource: referenceFile, ofType: "reference") {
let referenceContent = try String(contentsOfFile: path)

let nodeContent = String(data: getJSONData(node: node), encoding: String.Encoding.utf8)
let nodeContent = String(data: getJSONData(node: node), encoding: .utf8)

if nodeContent != referenceContent {
XCTFail("nodeContent is not equal to referenceContent")
}


#if os(OSX)
let nativeImage = getImage(from: referenceFile)

//To save new PNG image for test, uncomment this
//saveImage(image: nativeImage, fileName: referenceFile)
#if os(OSX)
if shouldComparePNGImages {
validateImage(nodeImage: nativeImage, referenceFile: referenceFile)
}
Expand Down Expand Up @@ -814,62 +872,15 @@ class MacawSVGTests: XCTestCase {
validateJSON("masking-mask-02-f-manual")
}

func getImage(from svgName: String) -> MImage {
let bundle = Bundle(for: type(of: TestUtils()))
do {
let node = try SVGParser.parse(resource: svgName, fromBundle: bundle)

var frame = node.bounds
if frame == nil, let group = node as? Group {
frame = Group(contents: group.contents).bounds
}

let image = node.toNativeImage(size: frame?.size() ?? Size.init(w: 100, h: 100))
return image
} catch {
XCTFail(error.localizedDescription)
}

XCTFail()
return MImage()
func testPserversPattern02() {
validateJSON("pservers-pattern-02-f-manual")
}

func saveImage(image: MImage, fileName: String) {
#if os(OSX)
guard let data = image.tiffRepresentation else {
return
}
#endif

#if os(iOS)
guard let data = image.pngData() else {
return
}
#endif

let _ = writeToFile(data: data, fileName: "\(fileName).png")
func testPserversPattern03() {
validateJSON("pservers-pattern-03-f-manual")
}

fileprivate func setupTestFolderDirectory() {
guard let myDocuments = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
return
}

let testDirectoryPath = myDocuments.appendingPathComponent("\(testFolderName)")

do {
if !multipleTestsWillRun {
try FileManager.default.removeItem(at: testDirectoryPath)
}

var isDirectory: ObjCBool = ObjCBool(true)
if !FileManager.default.fileExists(atPath: testDirectoryPath.absoluteString, isDirectory: &isDirectory) {
try FileManager.default.createDirectory(at: testDirectoryPath, withIntermediateDirectories: true, attributes: .none)
}
} catch {
XCTFail(error.localizedDescription)
return
}
func testPserversPattern09() {
validateJSON("pservers-pattern-09-f-manual")
}

}
Binary file added MacawTests/png/pservers-pattern-02-f-manual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MacawTests/png/pservers-pattern-03-f-manual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MacawTests/png/pservers-pattern-09-f-manual.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading