Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for maximum capacity #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions QRCodeTests/QRCodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,37 @@ class QRCodeTests: XCTestCase {
XCTAssert(image != nil, "image is nil")
XCTAssertEqual(image!.size, size)
}

func testCapacity() {
let limitBytes = 2953

let maximumBytes = randomBytes(count: limitBytes)!
let tooManyBytes = randomBytes(count: limitBytes + 1)!

let codeWithMaximumBytes = QRCode(maximumBytes)
let codeWithTooManyBytes = QRCode(tooManyBytes)

XCTAssertEqual(maximumBytes, codeWithMaximumBytes.data, "data is not equal")
XCTAssertEqual(tooManyBytes, codeWithTooManyBytes.data, "data is not equal")

XCTAssertNotNil(codeWithMaximumBytes.image)
XCTAssertNil(codeWithTooManyBytes.image)
}
}

// MARK: - Helpers

func randomBytes(count: Int) -> Data? {
var bytes = Data(count: count)
let status = bytes.withUnsafeMutableBytes {
bytesPtr in

SecRandomCopyBytes(kSecRandomDefault, bytes.count, bytesPtr)
}

guard status == errSecSuccess else {
return nil
}

return bytes
}