xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Tests / XToolTests / WiFiAwareEntitlementTests.swift
WiFiAwareEntitlementTests.swift39 lines · 1.3 KiBRaw
| 1 | import Foundation |
| 2 | import Testing |
| 3 | @testable import XKit |
| 4 | |
| 5 | @Test func wifiAwareEntitlementMapsToDeveloperCapability() throws { |
| 6 | let plist = """ |
| 7 | <?xml version="1.0" encoding="UTF-8"?> |
| 8 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 9 | <plist version="1.0"> |
| 10 | <dict> |
| 11 | <key>com.apple.developer.wifi-aware</key> |
| 12 | <array> |
| 13 | <string>Publish</string> |
| 14 | <string>Subscribe</string> |
| 15 | </array> |
| 16 | </dict> |
| 17 | </plist> |
| 18 | """ |
| 19 | |
| 20 | let entitlements = try PropertyListDecoder().decode( |
| 21 | Entitlements.self, |
| 22 | from: Data(plist.utf8) |
| 23 | ) |
| 24 | let wifiAware = try #require( |
| 25 | entitlements.entitlements().compactMap { $0 as? WiFiAwareEntitlement }.first |
| 26 | ) |
| 27 | |
| 28 | #expect(wifiAware.rawValue == ["Publish", "Subscribe"]) |
| 29 | #expect(wifiAware.capability.capabilityType.value1 == nil) |
| 30 | #expect(wifiAware.capability.capabilityType.value2 == "WIFI_AWARE") |
| 31 | #expect(wifiAware.capability.settings == nil) |
| 32 | #expect(!wifiAware.capability.isFree) |
| 33 | |
| 34 | let encoded = try PropertyListEncoder().encode(entitlements) |
| 35 | let dictionary = try #require( |
| 36 | PropertyListSerialization.propertyList(from: encoded, format: nil) as? [String: Any] |
| 37 | ) |
| 38 | #expect(dictionary[WiFiAwareEntitlement.identifier] as? [String] == ["Publish", "Subscribe"]) |
| 39 | } |