| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // ReachabilityTests.swift
- // ReachabilityTests
- //
- // Created by Ashley Mills on 23/11/2015.
- // Copyright © 2015 Ashley Mills. All rights reserved.
- //
- import XCTest
- import Reachability
- class ReachabilityTests: XCTestCase {
-
- override func setUp() {
- super.setUp()
- }
-
- override func tearDown() {
- super.tearDown()
- }
-
- func testInvalidHost() {
-
- let reachability: Reachability
- let invalidHostName = "google.com"
- do {
- try reachability = Reachability(hostname: invalidHostName)
- } catch {
- XCTAssert(false, "Unable to create reachability")
- return
- }
-
- let expectation = expectationWithDescription("Check invalid host")
- reachability.whenReachable = { reachability in
- dispatch_async(dispatch_get_main_queue()) {
- XCTAssert(false, "\(invalidHostName) should be unreachable - \(reachability)")
- expectation.fulfill()
- }
- }
- reachability.whenUnreachable = { reachability in
- dispatch_async(dispatch_get_main_queue()) {
- print("Pass: \(invalidHostName) is unreachable - \(reachability))")
- expectation.fulfill()
- }
- }
-
- do {
- try reachability.startNotifier()
- } catch {
- XCTAssert(false, "Unable to start notifier")
- return
- }
-
- waitForExpectationsWithTimeout(5, handler: nil)
-
- reachability.stopNotifier()
- }
-
- func testaValidHost() {
-
- let reachability: Reachability
- let validHostName = "google.com"
-
- do {
- try reachability = Reachability(hostname: validHostName)
- } catch {
- XCTAssert(false, "Unable to create reachability")
- return
- }
-
- let expectation = expectationWithDescription("Check invalid host")
- reachability.whenReachable = { reachability in
- dispatch_async(dispatch_get_main_queue()) {
- print("Pass: \(validHostName) is reachable - \(reachability)")
- expectation.fulfill()
- }
- }
- reachability.whenUnreachable = { reachability in
- dispatch_async(dispatch_get_main_queue()) {
- XCTAssert(false, "\(validHostName) should be reachable - \(reachability)")
- expectation.fulfill()
- }
- }
-
- do {
- try reachability.startNotifier()
- } catch {
- XCTAssert(false, "Unable to start notifier")
- return
- }
-
- waitForExpectationsWithTimeout(5, handler: nil)
-
- reachability.stopNotifier()
- }
-
- }
|