Skip to content

Commit ecd3676

Browse files
author
Simon Gladman
committed
Tests to check error throwing for buffer copy.
1 parent 3d9baaf commit ecd3676

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

stdlib/public/Darwin/Accelerate/vImage_Buffer.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,13 @@ extension vImage_Buffer {
208208
///
209209
/// - Parameter destinationBuffer: The destination vImage buffer.
210210
/// - Parameter options: The options to use when performing this operation.
211-
///
212-
/// - Returns: `kvImageNoError`; otherwise, one of the error codes described
213-
/// in Data Types and Constants.
214211
public func copy(destinationBuffer: inout vImage_Buffer,
215212
flags options: vImage.Options = .noFlags) throws {
216213

217214
if Int(width) == 0 {
218215
throw vImage.Error(vImageError: kvImageInvalidParameter)
219216
}
220-
217+
221218
var error = kvImageNoError
222219

223220
_ = withUnsafePointer(to: self) {

test/stdlib/Accelerate_vImage.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,22 @@ if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
261261
buffer.free()
262262
}
263263

264+
Accelerate_vImageTests.test("vImage/CopyBadWidth") {
265+
var source = try! vImage_Buffer(width: 10, height: 100, bitsPerPixel: 32)
266+
var destination = try! vImage_Buffer(width: 20, height: 20, bitsPerPixel: 32)
267+
268+
expectCrashLater()
269+
try! source.copy(destinationBuffer: &destination)
270+
}
271+
272+
Accelerate_vImageTests.test("vImage/CopyBadHeight") {
273+
var source = try! vImage_Buffer(width: 100, height: 10, bitsPerPixel: 32)
274+
var destination = try! vImage_Buffer(width: 20, height: 20, bitsPerPixel: 32)
275+
276+
expectCrashLater()
277+
try! source.copy(destinationBuffer: &destination)
278+
}
279+
264280
Accelerate_vImageTests.test("vImage/Copy") {
265281
let pixels: [UInt8] = (0 ..< width * height * 4).map { _ in
266282
return UInt8.random(in: 0 ..< 255)
@@ -275,7 +291,7 @@ if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
275291
var destination = try! vImage_Buffer(width: widthi, height: heighti,
276292
bitsPerPixel: 32)
277293

278-
_ = try! source.copy(destinationBuffer: &destination)
294+
try! source.copy(destinationBuffer: &destination)
279295

280296
let sourcePixels: [UInt8] = arrayFromBuffer(buffer: source,
281297
count: pixels.count)

0 commit comments

Comments
 (0)