Skip to content

Commit

Permalink
Added some commented out tests that don't work due to undoManager bei…
Browse files Browse the repository at this point in the history
…ng nil when testing.
  • Loading branch information
dehli committed Mar 29, 2016
1 parent 9f02622 commit 806e8e6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
12 changes: 8 additions & 4 deletions TouchDraw.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
89F60F6F1BC9580000BCDD93 /* TouchDraw.h in Headers */ = {isa = PBXBuildFile; fileRef = 89F60F6E1BC9580000BCDD93 /* TouchDraw.h */; settings = {ATTRIBUTES = (Public, ); }; };
89F60F761BC9580000BCDD93 /* TouchDraw.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 89F60F6B1BC9580000BCDD93 /* TouchDraw.framework */; };
89F60F7B1BC9580000BCDD93 /* TouchDrawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F60F7A1BC9580000BCDD93 /* TouchDrawTests.swift */; };
89F70C161CA729BA00133F03 /* TouchDrawViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F70C151CA729BA00133F03 /* TouchDrawViewController.swift */; };
89F70C161CA729BA00133F03 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89F70C151CA729BA00133F03 /* ViewController.swift */; };
89F70C181CA80BDB00133F03 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 89F70C171CA80BDB00133F03 /* Main.storyboard */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -32,7 +33,8 @@
89F60F751BC9580000BCDD93 /* TouchDrawTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TouchDrawTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
89F60F7A1BC9580000BCDD93 /* TouchDrawTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchDrawTests.swift; sourceTree = "<group>"; };
89F60F7C1BC9580000BCDD93 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
89F70C151CA729BA00133F03 /* TouchDrawViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchDrawViewController.swift; sourceTree = "<group>"; };
89F70C151CA729BA00133F03 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
89F70C171CA80BDB00133F03 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -85,9 +87,10 @@
89F60F791BC9580000BCDD93 /* TouchDrawTests */ = {
isa = PBXGroup;
children = (
89F70C151CA729BA00133F03 /* TouchDrawViewController.swift */,
89F70C151CA729BA00133F03 /* ViewController.swift */,
89F60F7A1BC9580000BCDD93 /* TouchDrawTests.swift */,
89F60F7C1BC9580000BCDD93 /* Info.plist */,
89F70C171CA80BDB00133F03 /* Main.storyboard */,
);
path = TouchDrawTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -190,6 +193,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
89F70C181CA80BDB00133F03 /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -208,7 +212,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
89F70C161CA729BA00133F03 /* TouchDrawViewController.swift in Sources */,
89F70C161CA729BA00133F03 /* ViewController.swift in Sources */,
89F60F7B1BC9580000BCDD93 /* TouchDrawTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
26 changes: 26 additions & 0 deletions TouchDrawTests/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="IvS-c1-OG4">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="WsG-zX-zCM">
<objects>
<viewController storyboardIdentifier="ViewController" id="IvS-c1-OG4" customClass="ViewController" customModule="TouchDrawTests" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="ugb-kF-rv3"/>
<viewControllerLayoutGuide type="bottom" id="F0p-bu-bMn"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="6C4-EP-23z" customClass="TouchDrawView" customModule="TouchDraw">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hJn-03-tdx" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="131" y="334"/>
</scene>
</scenes>
</document>
26 changes: 24 additions & 2 deletions TouchDrawTests/TouchDrawTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import XCTest

class TouchDrawTests: XCTestCase {

var viewController: TouchDrawViewController!
var viewController: ViewController!

override func setUp() {
super.setUp()

// Put setup code here. This method is called before the invocation of each test method in the class.
viewController = TouchDrawViewController()
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))

viewController = storyboard.instantiateInitialViewController() as! ViewController
viewController.viewDidLoad()
viewController.viewDidAppear(false)

// Test and Load the View at the Same Time!
XCTAssertNotNil(viewController.view)
}

override func tearDown() {
Expand All @@ -35,6 +43,7 @@ class TouchDrawTests: XCTestCase {
XCTAssertTrue(viewController.undoIsEnabled, "Undo should be enabled")
}

/*
/// Tests whether you clearing empties the strokes
func testClearing() {
var touches = Set<UITouch>()
Expand All @@ -48,4 +57,17 @@ class TouchDrawTests: XCTestCase {
XCTAssert(viewController.touchDrawView.stack.count == 0, "Should not have strokes on view")
}

/// Tests undoing functionality
func testUndo() {
var touches = Set<UITouch>()
touches.insert(UITouch())

viewController.touchDrawView.touchesBegan(touches, withEvent: nil)
viewController.touchDrawView.touchesEnded(touches, withEvent: nil)

XCTAssert(viewController.touchDrawView.stack.count == 1, "Should have one stroke")
viewController.touchDrawView.undo()
XCTAssert(viewController.touchDrawView.stack.count == 0, "Should not have any strokes")
}*/

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TouchDrawViewController.swift
// ViewController.swift
// TouchDraw
//
// Created by Christian Paul Dehli on 3/26/16.
Expand All @@ -8,35 +8,23 @@

@testable import TouchDraw

class TouchDrawViewController: UIViewController, TouchDrawViewDelegate {
class ViewController: UIViewController, TouchDrawViewDelegate {

internal var undoIsEnabled: Bool!
internal var redoIsEnabled: Bool!
internal var clearIsEnabled: Bool!

internal var touchDrawView: TouchDrawView!

init() {
super.init(nibName: nil, bundle: nil)
self.addTouchDrawView()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.addTouchDrawView()
}

private func addTouchDrawView() {
self.touchDrawView = TouchDrawView(frame: self.view.frame)
self.view.addSubview(touchDrawView)
touchDrawView.delegate = self
override func viewDidLoad() {
super.viewDidLoad()

self.undoIsEnabled = false
self.redoIsEnabled = false
self.clearIsEnabled = false

print(self.touchDrawView.undoManager)

touchDrawView = self.view as! TouchDrawView
touchDrawView.delegate = self
}

// MARK: - TouchDrawViewDelegate
Expand Down

0 comments on commit 806e8e6

Please sign in to comment.