|
6 | 6 | // RUN: %target-run %t/a.out_Debug
|
7 | 7 | // RUN: %target-run %t/a.out_Release
|
8 | 8 | // REQUIRES: executable_test
|
9 |
| -// |
10 |
| -// FIXME: rdar://problem/19648117 Needs splitting objc parts out |
11 |
| -// XFAIL: linux |
12 | 9 |
|
13 | 10 | import StdlibUnittest
|
14 |
| -import Foundation |
15 |
| - |
16 |
| -struct NotBridgedKeyTy : Equatable, Hashable { |
17 |
| - init(_ value: Int) { |
18 |
| - self.value = value |
19 |
| - } |
20 |
| - var hashValue: Int { |
21 |
| - return value |
22 |
| - } |
23 |
| - var value: Int |
24 |
| -} |
25 |
| - |
26 |
| -func == (lhs: NotBridgedKeyTy, rhs: NotBridgedKeyTy) -> Bool { |
27 |
| - return lhs.value == rhs.value |
28 |
| -} |
29 |
| - |
30 |
| -assert(!_isBridgedToObjectiveC(NotBridgedKeyTy.self)) |
31 |
| - |
32 |
| -struct NotBridgedValueTy {} |
33 |
| - |
34 |
| -assert(!_isBridgedToObjectiveC(NotBridgedValueTy.self)) |
35 |
| - |
36 |
| -class BridgedVerbatimRefTy : Equatable, Hashable { |
37 |
| - init(_ value: Int) { |
38 |
| - self.value = value |
39 |
| - } |
40 |
| - var hashValue: Int { |
41 |
| - return value |
42 |
| - } |
43 |
| - var value: Int |
44 |
| -} |
45 |
| - |
46 |
| -func == (lhs: BridgedVerbatimRefTy, rhs: BridgedVerbatimRefTy) -> Bool { |
47 |
| - return lhs.value == rhs.value |
48 |
| -} |
49 |
| - |
50 |
| -assert(_isBridgedToObjectiveC(BridgedVerbatimRefTy.self)) |
51 |
| -assert(_isBridgedVerbatimToObjectiveC(BridgedVerbatimRefTy.self)) |
52 | 11 |
|
53 | 12 | var DictionaryTraps = TestSuite("DictionaryTraps")
|
54 | 13 |
|
55 |
| -DictionaryTraps.test("sanity") { |
56 |
| - // Sanity checks. This code should not trap. |
57 |
| - var d = Dictionary<BridgedVerbatimRefTy, BridgedVerbatimRefTy>() |
58 |
| - var nsd = d as NSDictionary |
59 |
| -} |
60 |
| - |
61 | 14 | DictionaryTraps.test("DuplicateKeys1")
|
62 | 15 | .skip(.custom(
|
63 | 16 | { _isFastAssertConfiguration() },
|
@@ -136,118 +89,4 @@ DictionaryTraps.test("RemoveInvalidIndex4")
|
136 | 89 | d.remove(at: index)
|
137 | 90 | }
|
138 | 91 |
|
139 |
| -class TestObjCKeyTy : NSObject { |
140 |
| - init(_ value: Int) { |
141 |
| - self.value = value |
142 |
| - } |
143 |
| - |
144 |
| - override func isEqual(_ object: AnyObject!) -> Bool { |
145 |
| - if let other = object { |
146 |
| - if let otherObjcKey = other as? TestObjCKeyTy { |
147 |
| - return self.value == otherObjcKey.value |
148 |
| - } |
149 |
| - } |
150 |
| - return false |
151 |
| - } |
152 |
| - |
153 |
| - override var hash : Int { |
154 |
| - return value |
155 |
| - } |
156 |
| - |
157 |
| - var value: Int |
158 |
| -} |
159 |
| - |
160 |
| -struct TestBridgedKeyTy : Hashable, _ObjectiveCBridgeable { |
161 |
| - static func _isBridgedToObjectiveC() -> Bool { |
162 |
| - return true |
163 |
| - } |
164 |
| - |
165 |
| - init(_ value: Int) { self.value = value } |
166 |
| - |
167 |
| - var hashValue: Int { return value } |
168 |
| - |
169 |
| - func _bridgeToObjectiveC() -> TestObjCKeyTy { |
170 |
| - return TestObjCKeyTy(value) |
171 |
| - } |
172 |
| - |
173 |
| - static func _forceBridgeFromObjectiveC( |
174 |
| - _ x: TestObjCKeyTy, |
175 |
| - result: inout TestBridgedKeyTy? |
176 |
| - ) { |
177 |
| - result = TestBridgedKeyTy(x.value) |
178 |
| - } |
179 |
| - |
180 |
| - static func _conditionallyBridgeFromObjectiveC( |
181 |
| - _ x: TestObjCKeyTy, |
182 |
| - result: inout TestBridgedKeyTy? |
183 |
| - ) -> Bool { |
184 |
| - result = TestBridgedKeyTy(x.value) |
185 |
| - return true |
186 |
| - } |
187 |
| - |
188 |
| - static func _unconditionallyBridgeFromObjectiveC(_ source: TestObjCKeyTy?) |
189 |
| - -> TestBridgedKeyTy { |
190 |
| - var result: TestBridgedKeyTy? = nil |
191 |
| - _forceBridgeFromObjectiveC(source!, result: &result) |
192 |
| - return result! |
193 |
| - } |
194 |
| - |
195 |
| - var value: Int |
196 |
| -} |
197 |
| - |
198 |
| -func ==(x: TestBridgedKeyTy, y: TestBridgedKeyTy) -> Bool { |
199 |
| - return x.value == y.value |
200 |
| -} |
201 |
| - |
202 |
| -DictionaryTraps.test("BridgedKeyIsNotNSCopyable1") |
203 |
| - .skip(.custom( |
204 |
| - { _isFastAssertConfiguration() }, |
205 |
| - reason: "this trap is not guaranteed to happen in -Ounchecked")) |
206 |
| - .crashOutputMatches("unrecognized selector sent to instance").code { |
207 |
| - // This Dictionary is bridged in O(1). |
208 |
| - var d = [ TestObjCKeyTy(10): NSObject() ] |
209 |
| - var nsd = d as NSDictionary |
210 |
| - expectCrashLater() |
211 |
| - nsd.mutableCopy() |
212 |
| -} |
213 |
| - |
214 |
| -DictionaryTraps.test("BridgedKeyIsNotNSCopyable2") |
215 |
| - .skip(.custom( |
216 |
| - { _isFastAssertConfiguration() }, |
217 |
| - reason: "this trap is not guaranteed to happen in -Ounchecked")) |
218 |
| - .code { |
219 |
| - // This Dictionary is bridged in O(1). |
220 |
| - var d = [ TestObjCKeyTy(10): 10 ] |
221 |
| - var nsd = d as NSDictionary |
222 |
| - expectCrashLater() |
223 |
| - nsd.mutableCopy() |
224 |
| -} |
225 |
| - |
226 |
| -DictionaryTraps.test("Downcast1") { |
227 |
| - let d: Dictionary<NSObject, NSObject> = [ TestObjCKeyTy(10): NSObject(), |
228 |
| - NSObject() : NSObject() ] |
229 |
| - let d2: Dictionary<TestObjCKeyTy, NSObject> = _dictionaryDownCast(d) |
230 |
| - expectCrashLater() |
231 |
| - let v1 = d2[TestObjCKeyTy(10)] |
232 |
| - let v2 = d2[TestObjCKeyTy(20)] |
233 |
| - |
234 |
| - // This triggers failure. |
235 |
| - for (k, v) in d2 { } |
236 |
| -} |
237 |
| - |
238 |
| -DictionaryTraps.test("Downcast2") |
239 |
| - .skip(.custom( |
240 |
| - { _isFastAssertConfiguration() }, |
241 |
| - reason: "this trap is not guaranteed to happen in -Ounchecked")) |
242 |
| - .code { |
243 |
| - let d: Dictionary<NSObject, NSObject> = [ TestObjCKeyTy(10): NSObject(), |
244 |
| - NSObject() : NSObject() ] |
245 |
| - |
246 |
| - expectCrashLater() |
247 |
| - let d2: Dictionary<TestBridgedKeyTy, NSObject> |
248 |
| - = _dictionaryBridgeFromObjectiveC(d) |
249 |
| - let v1 = d2[TestBridgedKeyTy(10)] |
250 |
| -} |
251 |
| - |
252 | 92 | runAllTests()
|
253 |
| - |
0 commit comments