Download this file
| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import EquipoShareCore |
| 4 | |
| 5 | @Test func providerTextSupportsUTF8AndBOMUTF16WithinMessageBound() throws { |
| 6 | let value = "The sign-in button is cut off. đŸ“·" |
| 7 | for encoding in [String.Encoding.utf8, .utf16] { |
| 8 | #expect(try ShareText.decode(Data(value.data(using: encoding)!)) == value) |
| 9 | } |
| 10 | let archive = try NSKeyedArchiver.archivedData(withRootObject: value as NSString, requiringSecureCoding: true) |
| 11 | #expect(try ShareText.decode(archive) == value) |
| 12 | let longArchive = try NSKeyedArchiver.archivedData(withRootObject: String(repeating: "x", count: 16385) as NSString, requiringSecureCoding: true) |
| 13 | #expect(throws: AttachmentFailure.tooLarge) { try ShareText.decode(longArchive) } |
| 14 | #expect(throws: AttachmentFailure.tooLarge) { try ShareText.decode(Data(repeating: 65, count: 32771)) } |
| 15 | let nonString = try NSKeyedArchiver.archivedData(withRootObject: Data([1, 2, 3]) as NSData, requiringSecureCoding: true) |
| 16 | #expect(throws: AttachmentFailure.type) { try ShareText.decode(nonString) } |
| 17 | #expect(throws: AttachmentFailure.tooLarge) { try ShareText.decode(Data(String(repeating: "x", count: 16 * 1024 + 1).utf8)) } |
| 18 | #expect(throws: AttachmentFailure.type) { try ShareText.decode(Data([0xff, 0xff, 0xff])) } |
| 19 | } |
| 20 | |