Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Add async test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Jun 4, 2015
1 parent e5b178a commit 14c09f7
Show file tree
Hide file tree
Showing 10 changed files with 686 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
/* Begin PBXBuildFile section */
1401EC2A1B15141B000D8737 /* ExampleFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 1401EC291B15141B000D8737 /* ExampleFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
1401EC301B15141B000D8737 /* ExampleFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1401EC241B15141B000D8737 /* ExampleFramework.framework */; };
1401EC371B15141B000D8737 /* ExampleFrameworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1401EC361B15141B000D8737 /* ExampleFrameworkTests.swift */; };
1401EC371B15141B000D8737 /* CalculatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1401EC361B15141B000D8737 /* CalculatorTests.swift */; };
1401EC411B151494000D8737 /* Calculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1401EC401B151494000D8737 /* Calculator.swift */; };
1499139D1B20F7E90079325B /* Networking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1499139C1B20F7E90079325B /* Networking.swift */; };
1499139E1B20F7E90079325B /* Networking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1499139C1B20F7E90079325B /* Networking.swift */; };
149913A01B20F92B0079325B /* NetworkingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1499139F1B20F92B0079325B /* NetworkingTests.swift */; };
149913A11B20F92B0079325B /* NetworkingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1499139F1B20F92B0079325B /* NetworkingTests.swift */; };
14DE827C1B1B586E00E1BAA4 /* ExampleFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 14DE82711B1B586D00E1BAA4 /* ExampleFramework.framework */; };
14DE828A1B1B5A0400E1BAA4 /* ExampleFrameworkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1401EC361B15141B000D8737 /* ExampleFrameworkTests.swift */; };
14DE828A1B1B5A0400E1BAA4 /* CalculatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1401EC361B15141B000D8737 /* CalculatorTests.swift */; };
14DE828B1B1B5A1F00E1BAA4 /* Calculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1401EC401B151494000D8737 /* Calculator.swift */; };
14DE82B31B1B66D400E1BAA4 /* ExampleFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 1401EC291B15141B000D8737 /* ExampleFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -40,8 +44,10 @@
1401EC291B15141B000D8737 /* ExampleFramework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExampleFramework.h; sourceTree = "<group>"; };
1401EC2F1B15141B000D8737 /* ExampleFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = ExampleFrameworkTests.xctest; path = ExampleFrameworkiOSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
1401EC351B15141B000D8737 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1401EC361B15141B000D8737 /* ExampleFrameworkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleFrameworkTests.swift; sourceTree = "<group>"; };
1401EC361B15141B000D8737 /* CalculatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculatorTests.swift; sourceTree = "<group>"; };
1401EC401B151494000D8737 /* Calculator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Calculator.swift; sourceTree = "<group>"; };
1499139C1B20F7E90079325B /* Networking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Networking.swift; sourceTree = "<group>"; };
1499139F1B20F92B0079325B /* NetworkingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkingTests.swift; sourceTree = "<group>"; };
14DE82711B1B586D00E1BAA4 /* ExampleFramework.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ExampleFramework.framework; sourceTree = BUILT_PRODUCTS_DIR; };
14DE827B1B1B586E00E1BAA4 /* ExampleFramework-MacTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ExampleFramework-MacTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -105,6 +111,7 @@
children = (
1401EC291B15141B000D8737 /* ExampleFramework.h */,
1401EC401B151494000D8737 /* Calculator.swift */,
1499139C1B20F7E90079325B /* Networking.swift */,
1401EC271B15141B000D8737 /* Supporting Files */,
);
path = ExampleFramework;
Expand All @@ -121,7 +128,8 @@
1401EC331B15141B000D8737 /* ExampleFrameworkTests */ = {
isa = PBXGroup;
children = (
1401EC361B15141B000D8737 /* ExampleFrameworkTests.swift */,
1401EC361B15141B000D8737 /* CalculatorTests.swift */,
1499139F1B20F92B0079325B /* NetworkingTests.swift */,
1401EC341B15141B000D8737 /* Supporting Files */,
);
path = ExampleFrameworkTests;
Expand Down Expand Up @@ -309,14 +317,16 @@
buildActionMask = 2147483647;
files = (
1401EC411B151494000D8737 /* Calculator.swift in Sources */,
1499139D1B20F7E90079325B /* Networking.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1401EC2B1B15141B000D8737 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1401EC371B15141B000D8737 /* ExampleFrameworkTests.swift in Sources */,
1401EC371B15141B000D8737 /* CalculatorTests.swift in Sources */,
149913A01B20F92B0079325B /* NetworkingTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -325,14 +335,16 @@
buildActionMask = 2147483647;
files = (
14DE828B1B1B5A1F00E1BAA4 /* Calculator.swift in Sources */,
1499139E1B20F7E90079325B /* Networking.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
14DE82771B1B586E00E1BAA4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
14DE828A1B1B5A0400E1BAA4 /* ExampleFrameworkTests.swift in Sources */,
14DE828A1B1B5A0400E1BAA4 /* CalculatorTests.swift in Sources */,
149913A11B20F92B0079325B /* NetworkingTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
35 changes: 35 additions & 0 deletions Examples/ExampleFramework/ExampleFramework/Networking.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Networking.swift
// ExampleFramework
//
// Created by Kishikawa Katsumi on 2015/06/04.
// Copyright (c) 2015 Realm. All rights reserved.
//

import Foundation

public class Networking {
let requesetURL: NSURL

public init() {
if let URL = NSURL(string: "http://www.google.com") {
requesetURL = URL
} else {
fatalError("Unknown error occurred")
}
}

public init(URL: NSURL) {
requesetURL = URL
}

public func request(completion:(data: NSData?, response: NSURLResponse, error: NSError?) -> Void) -> Void {
var session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
var request = NSMutableURLRequest(URL: requesetURL)

session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
completion(data: data, response: response, error: error)
}).resume()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import XCTest
import ExampleFramework

class ExampleFrameworkTests: XCTestCase {
class CalculatorTests: XCTestCase {

override func setUp() {
super.setUp()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// NetworkingTests.swift
// ExampleFramework
//
// Created by kishikawakatsumi on 2015/06/04.
// Copyright (c) 2015年 kishikawakatsumi. All rights reserved.
//

import XCTest
import ExampleFramework

class NetworkingTests: XCTestCase {

override func setUp() {
super.setUp()
}

override func tearDown() {
super.tearDown()
}

func testAsyncNetworking() {
let expectation = expectationWithDescription("networking")

let networking = Networking(URL: NSURL(string: "http://www.google.com")!)
networking.request { (data, response, error) -> Void in
if let response = response as? NSHTTPURLResponse {
XCTAssertEqual(response.statusCode, 200)
} else {
XCTFail("Request failed")
}
expectation.fulfill()
}

waitForExpectationsWithTimeout(5.0, handler: { (error) -> Void in
if let error = error {
XCTFail("Connection timeout")
}
})
}

}
2 changes: 1 addition & 1 deletion Examples/ExampleFramework/results/Calculator.swift.gcov
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-: 0:Source:/Users/katsumi/Desktop/Realm/SwiftCov/Examples/ExampleFramework/ExampleFramework/Calculator.swift
-: 0:Source:/Users/katsumi/Dropbox/Xcode Projects/SwiftCov/Examples/ExampleFramework/ExampleFramework/Calculator.swift
-: 0:Runs:1
-: 0:Programs:1
-: 1://
Expand Down
38 changes: 38 additions & 0 deletions Examples/ExampleFramework/results/Networking.swift.gcov
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-: 0:Source:/Users/katsumi/Dropbox/Xcode Projects/SwiftCov/Examples/ExampleFramework/ExampleFramework/Networking.swift
-: 0:Runs:1
-: 0:Programs:1
-: 1://
-: 2:// Networking.swift
-: 3:// ExampleFramework
-: 4://
-: 5:// Created by Kishikawa Katsumi on 2015/06/04.
-: 6:// Copyright (c) 2015 Realm. All rights reserved.
-: 7://
-: 8:
-: 9:import Foundation
-: 10:
-: 11:public class Networking {
-: 12: let requesetURL: NSURL
-: 13:
-: 14: public init() {
#####: 15: if let URL = NSURL(string: "http://www.google.com") {
#####: 16: requesetURL = URL
#####: 17: } else {
#####: 18: fatalError("Unknown error occurred")
-: 19: }
-: 20: }
-: 21:
-: 22: public init(URL: NSURL) {
1: 23: requesetURL = URL
-: 24: }
-: 25:
-: 26: public func request(completion:(data: NSData?, response: NSURLResponse, error: NSError?) -> Void) -> Void {
1: 27: var session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
1: 28: var request = NSMutableURLRequest(URL: requesetURL)
-: 29:
2: 30: session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
1: 31: completion(data: data, response: response, error: error)
2: 32: }).resume()
-: 33: }
-: 34:
-: 35:}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
</tr>
<tr>
<td class="headerName">Date:</td>
<td class="headerValue">2015-06-01</td>
<td class="headerValue">2015-06-04</td>
<td></td>
<td class="headerName">Branches:</td>
<td class="headerTableEntry">0</td>
Expand Down
Loading

0 comments on commit 14c09f7

Please sign in to comment.