Skip to content

Commit

Permalink
Updated docstrings and added a stream image test for DataRequest exte…
Browse files Browse the repository at this point in the history
…nsion.
  • Loading branch information
cnoon committed Oct 2, 2016
1 parent ad7240f commit f9da26d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
10 changes: 6 additions & 4 deletions Source/Request+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extension DataRequest {
}
}

/// Adds a handler to be called once the request has finished.
/// Adds a response handler to be called once the request has finished.
///
/// - parameter imageScale: The scale factor used when interpreting the image data to construct
/// `responseImage`. Specifying a scale factor of 1.0 results in an image whose
Expand Down Expand Up @@ -134,7 +134,8 @@ extension DataRequest {
)
}

/// Adds a response handler to be called when the request has a new image.
/// Sets a closure to be called periodically during the lifecycle of the request as data is read from the server
/// and converted into images.
///
/// - parameter imageScale: The scale factor used when interpreting the image data to construct
/// `responseImage`. Specifying a scale factor of 1.0 results in an image whose
Expand Down Expand Up @@ -237,7 +238,7 @@ extension DataRequest {
}
}

/// Adds a handler to be called once the request has finished.
/// Adds a response handler to be called once the request has finished.
///
/// - parameter completionHandler: A closure to be executed once the request has finished. The closure takes 4
/// arguments: the URL request, the URL response, if one was received, the image, if
Expand All @@ -253,7 +254,8 @@ extension DataRequest {
)
}

/// Adds a response handler to be called when the request has new image.
/// Sets a closure to be called periodically during the lifecycle of the request as data is read from the server
/// and converted into images.
///
/// - parameter completionHandler: A closure to be executed when the request has new image. The closure takes 1
/// argument: the image, if one could be created from the data.
Expand Down
38 changes: 34 additions & 4 deletions Tests/RequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DataRequestTestCase: BaseTestCase {
DataRequest.acceptableImageContentTypes = acceptableImageContentTypes
}

// MARK: - Image Content Type Tests
// MARK: - Tests - Image Content Type

func testThatAddingAcceptableImageContentTypesInsertsThemIntoTheGlobalList() {
// Given
Expand All @@ -58,7 +58,7 @@ class DataRequestTestCase: BaseTestCase {
XCTAssertEqual(afterCount, 13, "after count should be 13")
}

// MARK: - Image Serialization Tests
// MARK: - Tests - Image Serialization

func testThatImageResponseSerializerCanDownloadPNGImage() {
// Given
Expand Down Expand Up @@ -170,7 +170,7 @@ class DataRequestTestCase: BaseTestCase {

#if os(iOS) || os(tvOS)

// MARK: - Image Inflation Tests
// MARK: - Tests - Image Inflation

func testThatImageResponseSerializerCanDownloadAndInflatePNGImage() {
// Given
Expand Down Expand Up @@ -238,7 +238,7 @@ class DataRequestTestCase: BaseTestCase {

#endif

// MARK: - Image Serialization Error Tests
// MARK: - Tests - Image Serialization Errors

func testThatAttemptingToDownloadImageFromBadURLReturnsFailureResult() {
// Given
Expand Down Expand Up @@ -379,4 +379,34 @@ class DataRequestTestCase: BaseTestCase {
XCTFail("error should not be nil")
}
}

// MARK: - Tests - Stream Images

func testThatImagesCanBeStreamedDynamicallyFromMJPEGStream() {
// Given
let urlString = "http://173.14.66.201/anony/mjpg.cgi" // Northgate Launder Land
let expectation = self.expectation(description: "Request should return images")

let expectedImageCount = 8
var imageCount = 0

// When
let request = sessionManager.request(urlString)

request.streamImage { image in
guard imageCount < expectedImageCount else { return }

imageCount += 1

if imageCount == expectedImageCount {
request.cancel()
expectation.fulfill()
}
}

waitForExpectations(timeout: timeout, handler: nil)

// Then
XCTAssertEqual(imageCount, expectedImageCount)
}
}

0 comments on commit f9da26d

Please sign in to comment.