Skip to content

Commit b434fa1

Browse files
committed
adding image tests
1 parent 6e3bf65 commit b434fa1

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

Samples/invalid.svg

Lines changed: 3 additions & 0 deletions
Loading

SwiftDraw.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@
169169
D9F3AD5B219E9DF400BAFA55 /* XML.SAXParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9F3AD59219E9DF400BAFA55 /* XML.SAXParserTests.swift */; };
170170
D9F3AD5E21A218CF00BAFA55 /* ImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9F3AD5D21A218CF00BAFA55 /* ImageTests.swift */; };
171171
D9F3AD5F21A218CF00BAFA55 /* ImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9F3AD5D21A218CF00BAFA55 /* ImageTests.swift */; };
172+
D9F3AD6121A21B7800BAFA55 /* Bundle+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9F3AD6021A21B7800BAFA55 /* Bundle+Extensions.swift */; };
173+
D9F3AD6221A21B7800BAFA55 /* Bundle+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9F3AD6021A21B7800BAFA55 /* Bundle+Extensions.swift */; };
174+
D9F3AD6421A21CD200BAFA55 /* invalid.svg in Resources */ = {isa = PBXBuildFile; fileRef = D9F3AD6321A21CD100BAFA55 /* invalid.svg */; };
175+
D9F3AD6521A21CD200BAFA55 /* invalid.svg in Resources */ = {isa = PBXBuildFile; fileRef = D9F3AD6321A21CD100BAFA55 /* invalid.svg */; };
172176
D9F3EBBB1DFF5BA3006691A1 /* SwiftDraw.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9F3EBB11DFF5BA3006691A1 /* SwiftDraw.framework */; };
173177
D9F3EBC21DFF5BA3006691A1 /* SwiftDraw.h in Headers */ = {isa = PBXBuildFile; fileRef = D9F3EBB41DFF5BA3006691A1 /* SwiftDraw.h */; settings = {ATTRIBUTES = (Public, ); }; };
174178
/* End PBXBuildFile section */
@@ -276,6 +280,8 @@
276280
D9C47AC11ED54FA100178D06 /* viewbox.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = viewbox.svg; sourceTree = "<group>"; };
277281
D9F3AD59219E9DF400BAFA55 /* XML.SAXParserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XML.SAXParserTests.swift; sourceTree = "<group>"; };
278282
D9F3AD5D21A218CF00BAFA55 /* ImageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageTests.swift; sourceTree = "<group>"; };
283+
D9F3AD6021A21B7800BAFA55 /* Bundle+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Extensions.swift"; sourceTree = "<group>"; };
284+
D9F3AD6321A21CD100BAFA55 /* invalid.svg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = invalid.svg; sourceTree = "<group>"; };
279285
D9F3EBB11DFF5BA3006691A1 /* SwiftDraw.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftDraw.framework; sourceTree = BUILT_PRODUCTS_DIR; };
280286
D9F3EBB41DFF5BA3006691A1 /* SwiftDraw.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftDraw.h; sourceTree = "<group>"; };
281287
D9F3EBB51DFF5BA3006691A1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -405,6 +411,7 @@
405411
isa = PBXGroup;
406412
children = (
407413
D90DB3FC219CCF9200D374D2 /* StackTests.swift */,
414+
D9F3AD6021A21B7800BAFA55 /* Bundle+Extensions.swift */,
408415
);
409416
name = Utilities;
410417
sourceTree = "<group>";
@@ -534,6 +541,7 @@
534541
D9C47ABF1ED54FA100178D06 /* mask.svg */,
535542
D9C47AC01ED54FA100178D06 /* transform.svg */,
536543
D9C47AC11ED54FA100178D06 /* viewbox.svg */,
544+
D9F3AD6321A21CD100BAFA55 /* invalid.svg */,
537545
);
538546
path = Samples;
539547
sourceTree = "<group>";
@@ -754,6 +762,7 @@
754762
isa = PBXResourcesBuildPhase;
755763
buildActionMask = 2147483647;
756764
files = (
765+
D9F3AD6521A21CD200BAFA55 /* invalid.svg in Resources */,
757766
D9C47AC71ED54FA100178D06 /* viewbox.svg in Resources */,
758767
D9A843961E8611D7002A804B /* curves.svg in Resources */,
759768
D9778E5C1E6ED66300FF6EBB /* shapes.svg in Resources */,
@@ -775,6 +784,7 @@
775784
isa = PBXResourcesBuildPhase;
776785
buildActionMask = 2147483647;
777786
files = (
787+
D9F3AD6421A21CD200BAFA55 /* invalid.svg in Resources */,
778788
D9C47AC61ED54FA100178D06 /* viewbox.svg in Resources */,
779789
D9A843951E8611D6002A804B /* curves.svg in Resources */,
780790
D965B5821E3C48C6003E859E /* shapes.svg in Resources */,
@@ -864,6 +874,7 @@
864874
D9F3AD5B219E9DF400BAFA55 /* XML.SAXParserTests.swift in Sources */,
865875
D90DB47E219CD2C300D374D2 /* AttributeParserTests.swift in Sources */,
866876
D90DB492219CD2C300D374D2 /* Parser.SVGTests.swift in Sources */,
877+
D9F3AD6221A21B7800BAFA55 /* Bundle+Extensions.swift in Sources */,
867878
D90DB486219CD2C300D374D2 /* StyleTests.swift in Sources */,
868879
D90DB3D4219CCC8A00D374D2 /* LayerTree.LayerTests.swift in Sources */,
869880
D90DB476219CD2C300D374D2 /* CoordinateTests.swift in Sources */,
@@ -951,6 +962,7 @@
951962
D9F3AD5A219E9DF400BAFA55 /* XML.SAXParserTests.swift in Sources */,
952963
D90DB47D219CD2C300D374D2 /* AttributeParserTests.swift in Sources */,
953964
D90DB491219CD2C300D374D2 /* Parser.SVGTests.swift in Sources */,
965+
D9F3AD6121A21B7800BAFA55 /* Bundle+Extensions.swift in Sources */,
954966
D90DB485219CD2C300D374D2 /* StyleTests.swift in Sources */,
955967
D90DB3CC219CCC8100D374D2 /* LayerTree.ColorTests.swift in Sources */,
956968
D90DB475219CD2C300D374D2 /* CoordinateTests.swift in Sources */,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// Bundle+Extensions.swift
3+
// SwiftDraw
4+
//
5+
// Created by Simon Whitty on 19/11/18.
6+
// Copyright 2018 Simon Whitty
7+
//
8+
// Distributed under the permissive zlib license
9+
// Get the latest version from here:
10+
//
11+
// https://github.com/swhitty/SwiftDraw
12+
//
13+
// This software is provided 'as-is', without any express or implied
14+
// warranty. In no event will the authors be held liable for any damages
15+
// arising from the use of this software.
16+
//
17+
// Permission is granted to anyone to use this software for any purpose,
18+
// including commercial applications, and to alter it and redistribute it
19+
// freely, subject to the following restrictions:
20+
//
21+
// 1. The origin of this software must not be misrepresented; you must not
22+
// claim that you wrote the original software. If you use this software
23+
// in a product, an acknowledgment in the product documentation would be
24+
// appreciated but is not required.
25+
//
26+
// 2. Altered source versions must be plainly marked as such, and must not be
27+
// misrepresented as being the original software.
28+
//
29+
// 3. This notice may not be removed or altered from any source distribution.
30+
//
31+
32+
33+
import Foundation
34+
35+
extension Bundle {
36+
37+
static var test: Bundle {
38+
return Bundle(for: ImageTests.self)
39+
}
40+
41+
func url(forResource named: String) throws -> URL {
42+
guard let url = self.url(forResource: named, withExtension: nil) else {
43+
throw Error.invalid
44+
}
45+
return url
46+
}
47+
48+
private enum Error: Swift.Error {
49+
case invalid
50+
}
51+
52+
}

SwiftDrawTests/ImageTests.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ import XCTest
3434

3535
final class ImageTests: XCTestCase {
3636

37-
func testIsEOF() throws {
37+
func testValidSVGLoads() {
38+
XCTAssertNotNil(Image(named: "shapes.svg", in: .test))
3839
}
40+
41+
func testInvalidSVGReturnsNil() {
42+
XCTAssertNil(Image(named: "invalid.svg", in: .test))
43+
}
44+
45+
func testMissingSVGReturnsNil() {
46+
XCTAssertNil(Image(named: "missing.svg", in: .test))
47+
}
48+
3949
}

0 commit comments

Comments
 (0)