objc2-xc-test 0.3.2

Bindings to the XCTest framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
// This file has been automatically generated by `objc2`'s `header-translator`.
// DO NOT EDIT

#![allow(unused_imports)]
#![allow(deprecated)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(missing_docs)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::type_complexity)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::identity_op)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::doc_lazy_continuation)]
#![allow(rustdoc::broken_intra_doc_links)]
#![allow(rustdoc::bare_urls)]
#![allow(rustdoc::invalid_html_tags)]

#[link(name = "XCTest", kind = "framework")]
extern "C" {}

use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-app-kit")]
#[cfg(target_os = "macos")]
use objc2_app_kit::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-xc-ui-automation")]
use objc2_xc_ui_automation::*;

use crate::*;

extern "C" {
    /// Domain for errors provided by the XCTest framework.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctesterrordomain?language=objc)
    pub static XCTestErrorDomain: &'static NSErrorDomain;
}

/// Error codes used with errors in the XCTestErrorDomain.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctesterrorcode?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTestErrorCode(pub NSInteger);
impl XCTestErrorCode {
    #[doc(alias = "XCTestErrorCodeTimeoutWhileWaiting")]
    pub const TimeoutWhileWaiting: Self = Self(0);
    #[doc(alias = "XCTestErrorCodeFailureWhileWaiting")]
    pub const FailureWhileWaiting: Self = Self(1);
}

unsafe impl Encode for XCTestErrorCode {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for XCTestErrorCode {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// An abstract base class for testing. XCTestCase and XCTestSuite extend XCTest to provide
    /// for creating, managing, and executing tests. Most developers will not need to subclass
    /// XCTest directly.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctest?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTest;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTest {}
);

impl XCTest {
    extern_methods!(
        /// Number of test cases. Must be overridden by subclasses.
        #[unsafe(method(testCaseCount))]
        #[unsafe(method_family = none)]
        pub fn testCaseCount(&self) -> NSUInteger;

        /// Test's name. Must be overridden by subclasses.
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub fn name(&self) -> Retained<NSString>;

        /// The XCTestRun subclass that will be instantiated when the test is run to hold
        /// the test's results. Must be overridden by subclasses.
        #[unsafe(method(testRunClass))]
        #[unsafe(method_family = none)]
        pub fn testRunClass(&self) -> Option<&'static AnyClass>;

        /// The test run object that executed the test, an instance of testRunClass. If the test has not yet been run, this will be nil.
        #[unsafe(method(testRun))]
        #[unsafe(method_family = none)]
        pub fn testRun(&self) -> Option<Retained<XCTestRun>>;

        /// The method through which tests are executed. Must be overridden by subclasses.
        #[unsafe(method(performTest:))]
        #[unsafe(method_family = none)]
        pub fn performTest(&self, run: &XCTestRun);

        /// Creates an instance of the testRunClass and passes it as a parameter to -performTest:.
        #[unsafe(method(runTest))]
        #[unsafe(method_family = none)]
        pub fn runTest(&self);

        #[cfg(feature = "block2")]
        /// Asynchronous set up method called before the invocation of each test method in the class.
        /// This method is called before invoking `setUpWithError`, `setUp`, and the test method.
        ///
        ///
        /// Parameter `completion`: A block which must be called to signal completion of set up.
        /// May be called asynchronously. If the block's `error` argument is non-nil, the specified error
        /// is recorded as a thrown error issue.
        #[unsafe(method(setUpWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub fn setUpWithCompletionHandler(
            &self,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );

        /// This method is called before invoking `setUp` and the test method.
        #[unsafe(method(setUpWithError:_))]
        #[unsafe(method_family = none)]
        pub fn setUpWithError(&self) -> Result<(), Retained<NSError>>;

        /// Setup method called before the invocation of each test method in the class.
        #[unsafe(method(setUp))]
        #[unsafe(method_family = none)]
        pub fn setUp(&self);

        /// Teardown method called after the invocation of each test method in the class.
        #[unsafe(method(tearDown))]
        #[unsafe(method_family = none)]
        pub fn tearDown(&self);

        /// This method is called after invoking the test method (if applicable) and
        /// `tearDown`.
        #[unsafe(method(tearDownWithError:_))]
        #[unsafe(method_family = none)]
        pub fn tearDownWithError(&self) -> Result<(), Retained<NSError>>;

        #[cfg(feature = "block2")]
        /// Asynchronous tear down method called after invoking the test method.
        /// This method is called after invoking the test method (if applicable), `tearDown`, and
        /// `tearDownWithError`.
        ///
        ///
        /// Parameter `completion`: A block which must be called to signal completion of tear down.
        /// May be called asynchronously. If the block's `error` argument is non-nil, the specified error
        /// is recorded as a thrown error issue.
        #[unsafe(method(tearDownWithCompletionHandler:))]
        #[unsafe(method_family = none)]
        pub fn tearDownWithCompletionHandler(
            &self,
            completion: &block2::DynBlock<dyn Fn(*mut NSError)>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTest {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTest {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/_xctestcaseinterruptionexception?language=objc)
    #[unsafe(super(NSException, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct _XCTestCaseInterruptionException;
);

extern_conformance!(
    unsafe impl NSCoding for _XCTestCaseInterruptionException {}
);

extern_conformance!(
    unsafe impl NSCopying for _XCTestCaseInterruptionException {}
);

unsafe impl CopyingHelper for _XCTestCaseInterruptionException {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for _XCTestCaseInterruptionException {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for _XCTestCaseInterruptionException {}
);

impl _XCTestCaseInterruptionException {
    extern_methods!();
}

/// Methods declared on superclass `NSException`.
impl _XCTestCaseInterruptionException {
    extern_methods!(
        /// # Safety
        ///
        /// `a_user_info` generic should be of the correct type.
        #[unsafe(method(initWithName:reason:userInfo:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_reason_userInfo(
            this: Allocated<Self>,
            a_name: &NSExceptionName,
            a_reason: Option<&NSString>,
            a_user_info: Option<&NSDictionary>,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl _XCTestCaseInterruptionException {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for _XCTestCaseInterruptionException {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

#[inline]
pub(crate) extern "C-unwind" fn _XCTPreformattedFailureHandler(
    test: Option<&XCTestCase>,
    expected: bool,
    file_path: &NSString,
    line_number: NSUInteger,
    condition: &NSString,
    message: &NSString,
) {
    extern "C-unwind" {
        fn _XCTPreformattedFailureHandler(
            test: Option<&XCTestCase>,
            expected: Bool,
            file_path: &NSString,
            line_number: NSUInteger,
            condition: &NSString,
            message: &NSString,
        );
    }
    unsafe {
        _XCTPreformattedFailureHandler(
            test,
            Bool::new(expected),
            file_path,
            line_number,
            condition,
            message,
        )
    }
}

/// [Apple's documentation](https://developer.apple.com/documentation/xctest/_xctassertiontype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct _XCTAssertionType(pub NSUInteger);
impl _XCTAssertionType {
    #[doc(alias = "_XCTAssertion_Fail")]
    pub const Fail: Self = Self(0);
    #[doc(alias = "_XCTAssertion_Nil")]
    pub const Nil: Self = Self(1);
    #[doc(alias = "_XCTAssertion_NotNil")]
    pub const NotNil: Self = Self(2);
    #[doc(alias = "_XCTAssertion_EqualObjects")]
    pub const EqualObjects: Self = Self(3);
    #[doc(alias = "_XCTAssertion_NotEqualObjects")]
    pub const NotEqualObjects: Self = Self(4);
    #[doc(alias = "_XCTAssertion_Equal")]
    pub const Equal: Self = Self(5);
    #[doc(alias = "_XCTAssertion_NotEqual")]
    pub const NotEqual: Self = Self(6);
    #[doc(alias = "_XCTAssertion_EqualWithAccuracy")]
    pub const EqualWithAccuracy: Self = Self(7);
    #[doc(alias = "_XCTAssertion_NotEqualWithAccuracy")]
    pub const NotEqualWithAccuracy: Self = Self(8);
    #[doc(alias = "_XCTAssertion_GreaterThan")]
    pub const GreaterThan: Self = Self(9);
    #[doc(alias = "_XCTAssertion_GreaterThanOrEqual")]
    pub const GreaterThanOrEqual: Self = Self(10);
    #[doc(alias = "_XCTAssertion_LessThan")]
    pub const LessThan: Self = Self(11);
    #[doc(alias = "_XCTAssertion_LessThanOrEqual")]
    pub const LessThanOrEqual: Self = Self(12);
    #[doc(alias = "_XCTAssertion_True")]
    pub const True: Self = Self(13);
    #[doc(alias = "_XCTAssertion_False")]
    pub const False: Self = Self(14);
    #[doc(alias = "_XCTAssertion_Throws")]
    pub const Throws: Self = Self(15);
    #[doc(alias = "_XCTAssertion_ThrowsSpecific")]
    pub const ThrowsSpecific: Self = Self(16);
    #[doc(alias = "_XCTAssertion_ThrowsSpecificNamed")]
    pub const ThrowsSpecificNamed: Self = Self(17);
    #[doc(alias = "_XCTAssertion_NoThrow")]
    pub const NoThrow: Self = Self(18);
    #[doc(alias = "_XCTAssertion_NoThrowSpecific")]
    pub const NoThrowSpecific: Self = Self(19);
    #[doc(alias = "_XCTAssertion_NoThrowSpecificNamed")]
    pub const NoThrowSpecificNamed: Self = Self(20);
    #[doc(alias = "_XCTAssertion_Unwrap")]
    pub const Unwrap: Self = Self(21);
    #[doc(alias = "_XCTAssertion_Identical")]
    pub const Identical: Self = Self(22);
    #[doc(alias = "_XCTAssertion_NotIdentical")]
    pub const NotIdentical: Self = Self(23);
}

unsafe impl Encode for _XCTAssertionType {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for _XCTAssertionType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

#[inline]
pub(crate) extern "C-unwind" fn _XCTFailureFormat(
    assertion_type: _XCTAssertionType,
    format_index: NSUInteger,
) -> Retained<NSString> {
    extern "C-unwind" {
        fn _XCTFailureFormat(
            assertion_type: _XCTAssertionType,
            format_index: NSUInteger,
        ) -> *mut NSString;
    }
    let ret = unsafe { _XCTFailureFormat(assertion_type, format_index) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

#[inline]
pub(crate) extern "C-unwind" fn _XCTDescriptionForValue(value: &NSValue) -> Retained<NSString> {
    extern "C-unwind" {
        fn _XCTDescriptionForValue(value: &NSValue) -> *mut NSString;
    }
    let ret = unsafe { _XCTDescriptionForValue(value) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

#[inline]
pub(crate) extern "C-unwind" fn _XCTGetCurrentExceptionReasonWithFallback(
    fallback: Option<&NSString>,
) -> Retained<NSString> {
    extern "C-unwind" {
        fn _XCTGetCurrentExceptionReasonWithFallback(fallback: Option<&NSString>) -> *mut NSString;
    }
    let ret = unsafe { _XCTGetCurrentExceptionReasonWithFallback(fallback) };
    unsafe { Retained::retain_autoreleased(ret) }
        .expect("function was marked as returning non-null, but actually returned NULL")
}

extern_protocol!(
    /// Represents a test activity.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctactivity?language=objc)
    pub unsafe trait XCTActivity: NSObjectProtocol {
        /// Human-readable name of the activity, given at creation time.
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        fn name(&self) -> Retained<NSString>;

        /// Adds an attachment which is always kept by Xcode, regardless of the test result.
        /// Thread-safe, attachments can be added from any thread, are reported in the order they are added.
        #[unsafe(method(addAttachment:))]
        #[unsafe(method_family = none)]
        fn addAttachment(&self, attachment: &XCTAttachment);
    }
);

extern_class!(
    /// XCTestCase is a concrete subclass of XCTest that should be the override point for
    /// most developers creating tests for their projects. A test case subclass can have
    /// multiple test methods and supports setup and tear down that executes for every test
    /// method as well as class level setup and tear down.
    ///
    /// To define a test case:
    ///
    /// • Create a subclass of XCTestCase.
    /// • Implement -test methods.
    /// • Optionally define instance variables or properties that store the state of the test.
    /// • Optionally initialize state by overriding -setUp
    /// • Optionally clean-up after a test by overriding -tearDown.
    ///
    /// Test methods are instance methods meeting these requirements:
    /// • accepting no parameters
    /// • returning no value
    /// • prefixed with 'test'
    ///
    /// For example:
    ///
    /// - (void)testSomething;
    ///
    /// Test methods are automatically recognized as test cases by the XCTest framework.
    /// Each XCTestCase subclass's defaultTestSuite is a XCTestSuite which includes these
    /// tests. Test method implementations usually contain assertions that must be verified
    /// for the test to pass, for example:
    ///
    /// ```text
    ///
    ///     @interface MathTest : XCTestCase
    ///
    ///     @property float f1;
    ///     @property float f2;
    ///
    ///     @end
    ///
    ///     @implementation MathTest
    ///
    ///     - (void)setUp
    ///     {
    ///         self.f1 = 2.0;
    ///         self.f2 = 3.0;
    ///     }
    ///
    ///     - (void)testAddition
    ///     {
    ///         XCTAssertTrue(f1 + f2 == 5.0);
    ///     }
    ///
    ///     @end
    ///
    /// ```
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestcase?language=objc)
    #[unsafe(super(XCTest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTestCase;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestCase {}
);

impl XCTestCase {
    extern_methods!(
        #[unsafe(method(testCaseWithInvocation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testCaseWithInvocation(invocation: Option<&NSInvocation>) -> Retained<Self>;

        #[unsafe(method(initWithInvocation:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithInvocation(
            this: Allocated<Self>,
            invocation: Option<&NSInvocation>,
        ) -> Retained<Self>;

        /// # Safety
        ///
        /// `selector` must be a valid selector.
        #[unsafe(method(testCaseWithSelector:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testCaseWithSelector(selector: Sel) -> Option<Retained<Self>>;

        /// # Safety
        ///
        /// `selector` must be a valid selector.
        #[unsafe(method(initWithSelector:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithSelector(this: Allocated<Self>, selector: Sel) -> Retained<Self>;

        /// The invocation used when this test is run.
        #[unsafe(method(invocation))]
        #[unsafe(method_family = none)]
        pub unsafe fn invocation(&self) -> Option<Retained<NSInvocation>>;

        /// Setter for [`invocation`][Self::invocation].
        #[unsafe(method(setInvocation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setInvocation(&self, invocation: Option<&NSInvocation>);

        /// Invoking a test performs its setUp, invocation, and tearDown. In general this
        /// should not be called directly.
        #[unsafe(method(invokeTest))]
        #[unsafe(method_family = none)]
        pub fn invokeTest(&self);

        /// Determines whether the test method continues execution after an XCTAssert fails.
        ///
        /// By default, this property is YES, meaning the test method will complete regardless of how many
        /// XCTAssert failures occur. Setting this to NO causes the test method to end execution immediately
        /// after the first failure occurs, but does not affect remaining test methods in the suite.
        ///
        /// If XCTAssert failures in the test method indicate problems with state or determinism, additional
        /// failures may be not be helpful information. Setting `continueAfterFailure` to NO can reduce the
        /// noise in the test report for these kinds of tests.
        #[unsafe(method(continueAfterFailure))]
        #[unsafe(method_family = none)]
        pub fn continueAfterFailure(&self) -> bool;

        /// Setter for [`continueAfterFailure`][Self::continueAfterFailure].
        #[unsafe(method(setContinueAfterFailure:))]
        #[unsafe(method_family = none)]
        pub fn setContinueAfterFailure(&self, continue_after_failure: bool);

        /// Records a failure or other issue in the execution of the test and is used by all test assertions.
        /// Overrides of this method should call super unless they wish to suppress the issue.
        /// Super can be invoked with a different issue object.
        ///
        ///
        /// Parameter `issue`: Object with all details related to the issue.
        #[unsafe(method(recordIssue:))]
        #[unsafe(method_family = none)]
        pub fn recordIssue(&self, issue: &XCTIssue);

        /// Invocations for each test method in the test case.
        #[unsafe(method(testInvocations))]
        #[unsafe(method_family = none)]
        pub fn testInvocations() -> Retained<NSArray<NSInvocation>>;

        #[cfg(feature = "block2")]
        /// Registers a block to be run at the end of a test.
        ///
        /// Teardown blocks are executed after the current test method has returned but before
        /// -tearDown is invoked.
        ///
        /// Registered blocks are run on the main thread but can be registered from any thread.
        /// They are guaranteed to run only once, in LIFO order, and are executed serially. You
        /// may register blocks during -setUp, but you may *not* register blocks during -tearDown
        /// or from other teardown blocks.
        ///
        ///
        /// Parameter `block`: A block to enqueue for future execution.
        #[unsafe(method(addTeardownBlock:))]
        #[unsafe(method_family = none)]
        pub fn addTeardownBlock(&self, block: &block2::DynBlock<dyn Fn()>);

        #[cfg(feature = "block2")]
        /// Registers an async block to be run at the end of a test.
        ///
        /// Teardown blocks are executed after the current test method has returned but before
        /// -tearDown is invoked.
        ///
        /// Registered blocks are run on the main thread but can be registered from any thread.
        /// They are guaranteed to run only once, in LIFO order, and are executed serially. You
        /// may register blocks during -setUp, but you may *not* register blocks during -tearDown
        /// or from other teardown blocks.
        ///
        ///
        /// Parameter `block`: An async block to enqueue for future execution. The completion handler
        /// passed to this block must be invoked for test execution to continue. Invoking the completion
        /// handler with a non-nil NSError will cause an XCTIssue to be recorded representing the error.
        ///
        /// # Safety
        ///
        /// `block` block's argument block's argument must be a valid pointer or null.
        #[unsafe(method(addAsyncTeardownBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addAsyncTeardownBlock(
            &self,
            block: &block2::DynBlock<dyn Fn(NonNull<block2::DynBlock<dyn Fn(*mut NSError)>>)>,
        );

        /// If test timeouts are enabled, this property represents the amount of time the test would like to be given to run.
        /// If the test exceeds its allowance, Xcode will capture a spindump of the process and then restart it
        /// so that test execution can continue on with the next test. The test that timed out will be marked
        /// as a failure, and the spindump will be attached to the test in Xcode's test report.
        ///
        /// Note that the value you supply will be rounded up to the nearest minute value. Also note that a test
        /// may be given less time than the value you specify if the -maximum-test-execution-time-allowance
        /// option is passed to xcodebuild.
        ///
        /// The default value is 10 minutes.
        #[unsafe(method(executionTimeAllowance))]
        #[unsafe(method_family = none)]
        pub fn executionTimeAllowance(&self) -> NSTimeInterval;

        /// Setter for [`executionTimeAllowance`][Self::executionTimeAllowance].
        #[unsafe(method(setExecutionTimeAllowance:))]
        #[unsafe(method_family = none)]
        pub fn setExecutionTimeAllowance(&self, execution_time_allowance: NSTimeInterval);
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTestCase {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTestCase {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// XCTestSuiteExtensions.
impl XCTestCase {
    extern_methods!(
        /// Returns a test suite containing test cases for all of the tests in the class.
        #[unsafe(method(defaultTestSuite))]
        #[unsafe(method_family = none)]
        pub fn defaultTestSuite() -> Retained<XCTestSuite>;

        /// Suite-level setup method called before the class begins to run any of its test methods or their associated
        /// per-instance setUp methods.
        #[unsafe(method(setUp))]
        #[unsafe(method_family = none)]
        pub fn setUp();

        /// Suite-level teardown method called after the class has finished running all of its test methods and their
        /// associated per-instance tearDown methods and teardown blocks.
        #[unsafe(method(tearDown))]
        #[unsafe(method_family = none)]
        pub fn tearDown();
    );
}

/// XCTActivity.
///
/// XCTestCase conforms to XCTActivity, allowing test attachments to be added directly from test methods.
///
/// See XCTAttachment.h for details on how to create attachments. Once created, they can be added directly to XCTestCase:
///
///
/// ```text
///  
///      - (void)testFoo
///      {
///          XCTAttachment *attachment = ...
///          [self addAttachment:attachment];
///      }
///  
/// ```
impl XCTestCase {
    extern_methods!();
}

extern_conformance!(
    unsafe impl XCTActivity for XCTestCase {}
);

/// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctperformancemetric?language=objc)
// NS_TYPED_EXTENSIBLE_ENUM
pub type XCTPerformanceMetric = NSString;

extern "C" {
    /// Records wall clock time in seconds between startMeasuring/stopMeasuring.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctperformancemetric_wallclocktime?language=objc)
    pub static XCTPerformanceMetric_WallClockTime: &'static XCTPerformanceMetric;
}

/// XCTPerformanceAnalysis.
///
/// Interface extension for measure related API.
impl XCTestCase {
    extern_methods!(
        /// The names of the performance metrics to measure when invoking -measureBlock:. Returns XCTPerformanceMetric_WallClockTime by default. Subclasses can override this to change the behavior of -measureBlock:
        #[unsafe(method(defaultPerformanceMetrics))]
        #[unsafe(method_family = none)]
        pub fn defaultPerformanceMetrics() -> Retained<NSArray<XCTPerformanceMetric>>;

        #[cfg(feature = "block2")]
        /// Call from a test method to measure resources (+defaultPerformanceMetrics) used by the
        /// block in the current process.
        ///
        /// - (void)testPerformanceOfMyFunction {
        ///
        /// [self measureBlock:^{
        /// // Do that thing you want to measure.
        /// MyFunction();
        /// }];
        /// }
        ///
        ///
        /// Parameter `block`: A block whose performance to measure.
        #[unsafe(method(measureBlock:))]
        #[unsafe(method_family = none)]
        pub fn measureBlock(&self, block: &block2::DynBlock<dyn Fn() + '_>);

        #[cfg(feature = "block2")]
        /// Call from a test method to measure resources (XCTPerformanceMetrics) used by the
        /// block in the current process. Each metric will be measured across calls to the block.
        /// The number of times the block will be called is undefined and may change in the
        /// future. For one example of why, as long as the requested performance metrics do
        /// not interfere with each other the API will measure all metrics across the same
        /// calls to the block. If the performance metrics may interfere the API will measure
        /// them separately.
        ///
        /// - (void)testMyFunction2_WallClockTime {
        /// [self measureMetrics:[self class].defaultPerformanceMetrics automaticallyStartMeasuring:NO forBlock:^{
        ///
        /// // Do setup work that needs to be done for every iteration but you don't want to measure before the call to -startMeasuring
        /// SetupSomething();
        /// [self startMeasuring];
        ///
        /// // Do that thing you want to measure.
        /// MyFunction();
        /// [self stopMeasuring];
        ///
        /// // Do teardown work that needs to be done for every iteration but you don't want to measure after the call to -stopMeasuring
        /// TeardownSomething();
        /// }];
        /// }
        ///
        /// Caveats:
        /// • If YES was passed for automaticallyStartMeasuring and -startMeasuring is called
        /// anyway, the test will fail.
        /// • If NO was passed for automaticallyStartMeasuring then -startMeasuring must be
        /// called once and only once before the end of the block or the test will fail.
        /// • If -stopMeasuring is called multiple times during the block the test will fail.
        ///
        ///
        /// Parameter `metrics`: An array of NSStrings (XCTPerformanceMetrics) to measure. Providing an unrecognized string is a test failure.
        ///
        ///
        /// Parameter `automaticallyStartMeasuring`: If NO, XCTestCase will not take any measurements until -startMeasuring is called.
        ///
        ///
        /// Parameter `block`: A block whose performance to measure.
        #[unsafe(method(measureMetrics:automaticallyStartMeasuring:forBlock:))]
        #[unsafe(method_family = none)]
        pub fn measureMetrics_automaticallyStartMeasuring_forBlock(
            &self,
            metrics: &NSArray<XCTPerformanceMetric>,
            automatically_start_measuring: bool,
            block: &block2::DynBlock<dyn Fn() + '_>,
        );

        /// Call this from within a measure block to set the beginning of the critical section.
        /// Measurement of metrics will start at this point.
        #[unsafe(method(startMeasuring))]
        #[unsafe(method_family = none)]
        pub fn startMeasuring(&self);

        /// Call this from within a measure block to set the ending of the critical section.
        /// Measurement of metrics will stop at this point.
        #[unsafe(method(stopMeasuring))]
        #[unsafe(method_family = none)]
        pub fn stopMeasuring(&self);

        /// A collection of metrics to be taken by default when -measureBlock or -measureWithOptions:block: is called.
        #[unsafe(method(defaultMetrics))]
        #[unsafe(method_family = none)]
        pub fn defaultMetrics() -> Retained<NSArray<ProtocolObject<dyn XCTMetric>>>;

        /// Collection of configurable settings to change how measurements are taken.
        #[unsafe(method(defaultMeasureOptions))]
        #[unsafe(method_family = none)]
        pub fn defaultMeasureOptions() -> Retained<XCTMeasureOptions>;

        #[cfg(feature = "block2")]
        /// Measures the block using the provided metrics and the default options from your XCTestCase class.
        ///
        ///
        /// Parameter `metrics`: A non-empty array of objects which adopt the XCTMetric protocol, describing the set of metrics to measure.
        ///
        /// Parameter `block`: The block to be measured.
        #[unsafe(method(measureWithMetrics:block:))]
        #[unsafe(method_family = none)]
        pub fn measureWithMetrics_block(
            &self,
            metrics: &NSArray<ProtocolObject<dyn XCTMetric>>,
            block: &block2::DynBlock<dyn Fn() + '_>,
        );

        #[cfg(feature = "block2")]
        /// Measures the block using the default metrics from your XCTestCase class and the provided options.
        ///
        ///
        /// Parameter `options`: An object describing the options to use when measuring the block, such as the number of times the block should be executed.
        ///
        /// Parameter `block`: The block to be measured.
        ///
        ///
        /// See also: XCTMeasureOptions
        #[unsafe(method(measureWithOptions:block:))]
        #[unsafe(method_family = none)]
        pub fn measureWithOptions_block(
            &self,
            options: &XCTMeasureOptions,
            block: &block2::DynBlock<dyn Fn() + '_>,
        );

        #[cfg(feature = "block2")]
        /// Measures the block using the provided metrics and options.
        ///
        ///
        /// Parameter `metrics`: A non-empty array of objects which adopt the XCTMetric protocol, describing the set of metrics to measure.
        ///
        /// Parameter `options`: An object describing the options to use when measuring the block, such as the number of times the block should be executed.
        ///
        /// Parameter `block`: The block to be measured.
        #[unsafe(method(measureWithMetrics:options:block:))]
        #[unsafe(method_family = none)]
        pub fn measureWithMetrics_options_block(
            &self,
            metrics: &NSArray<ProtocolObject<dyn XCTMetric>>,
            options: &XCTMeasureOptions,
            block: &block2::DynBlock<dyn Fn() + '_>,
        );
    );
}

/// XCTDeprecated.
impl XCTestCase {
    extern_methods!(
        /// Records a failure in the execution of the test.
        ///
        /// This method is deprecated and has been replaced by the `-recordIssue:` method and XCTIssue class, which
        /// provide greater flexibility for recording issues that arise during testing. Overriding this method in an XCTestCase subclass and
        /// modifying its arguments before calling `super` may cause information about the failure to be lost and is not recommended.
        /// Instead, override `-recordIssue:` and pass `super` a modified XCTIssue.
        ///
        ///
        /// Parameter `description`: The description of the failure being recorded. When replacing usage of this deprecated API,
        /// this can be represented using the `compactDescription` property on XCTIssue.
        ///
        ///
        /// Parameter `filePath`: The file path to the source file where the failure being recorded was encountered.
        /// When replacing usage of this deprecated API, this can be specified using an XCTSourceCodeLocation instance
        /// associated with an XCTIssue via its `sourceCodeContext` property.
        ///
        ///
        /// Parameter `lineNumber`: The line number in the source file at filePath where the failure being recorded
        /// was encountered. When replacing usage of this deprecated API, this can be specified using an XCTSourceCodeLocation
        /// instance associated with an XCTIssue via its `sourceCodeContext` property.
        ///
        ///
        /// Parameter `expected`: NO if the failure being recorded was the result of an uncaught exception, YES if it was the result
        /// of a failed assertion or any other reason. When replacing usage of this deprecated API, the representation using XCTIssue may vary.
        /// A NO value may be specified using the issue type `XCTIssueTypeUncaughtException`, and a YES value may be represented
        /// using a different issue type such as `XCTIssueTypeAssertionFailure` combined with other properties on XCTIssue.
        #[deprecated]
        #[unsafe(method(recordFailureWithDescription:inFile:atLine:expected:))]
        #[unsafe(method_family = none)]
        pub fn recordFailureWithDescription_inFile_atLine_expected(
            &self,
            description: &NSString,
            file_path: &NSString,
            line_number: NSUInteger,
            expected: bool,
        );
    );
}

extern_class!(
    /// A test run collects information about the execution of a test. Failures in explicit
    /// test assertions are classified as "expected", while failures from unrelated or
    /// uncaught exceptions are classified as "unexpected".
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestrun?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTestRun;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestRun {}
);

impl XCTestRun {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Class factory method for the XCTestRun class.
        ///
        ///
        /// Parameter `test`: An XCTest instance.
        ///
        ///
        /// Returns: A test run for the provided test.
        #[unsafe(method(testRunWithTest:))]
        #[unsafe(method_family = none)]
        pub fn testRunWithTest(test: &XCTest) -> Retained<Self>;

        /// Designated initializer for the XCTestRun class.
        ///
        ///
        /// Parameter `test`: An XCTest instance.
        ///
        ///
        /// Returns: A test run for the provided test.
        #[unsafe(method(initWithTest:))]
        #[unsafe(method_family = init)]
        pub fn initWithTest(this: Allocated<Self>, test: &XCTest) -> Retained<Self>;

        /// The test instance provided when the test run was initialized.
        #[unsafe(method(test))]
        #[unsafe(method_family = none)]
        pub fn test(&self) -> Retained<XCTest>;

        /// Start a test run. Must not be called more than once.
        #[unsafe(method(start))]
        #[unsafe(method_family = none)]
        pub fn start(&self);

        /// Stop a test run. Must not be called unless the run has been started. Must not be called more than once.
        #[unsafe(method(stop))]
        #[unsafe(method_family = none)]
        pub fn stop(&self);

        /// The time at which the test run was started, or nil.
        #[unsafe(method(startDate))]
        #[unsafe(method_family = none)]
        pub fn startDate(&self) -> Option<Retained<NSDate>>;

        /// The time at which the test run was stopped, or nil.
        #[unsafe(method(stopDate))]
        #[unsafe(method_family = none)]
        pub fn stopDate(&self) -> Option<Retained<NSDate>>;

        /// The number of seconds that elapsed between when the run was started and when it was stopped.
        #[unsafe(method(totalDuration))]
        #[unsafe(method_family = none)]
        pub fn totalDuration(&self) -> NSTimeInterval;

        /// The number of seconds that elapsed between when the run was started and when it was stopped.
        #[unsafe(method(testDuration))]
        #[unsafe(method_family = none)]
        pub fn testDuration(&self) -> NSTimeInterval;

        /// The number of tests in the run.
        #[unsafe(method(testCaseCount))]
        #[unsafe(method_family = none)]
        pub fn testCaseCount(&self) -> NSUInteger;

        /// The number of test executions recorded during the run.
        #[unsafe(method(executionCount))]
        #[unsafe(method_family = none)]
        pub fn executionCount(&self) -> NSUInteger;

        /// The number of test skips recorded during the run.
        #[unsafe(method(skipCount))]
        #[unsafe(method_family = none)]
        pub fn skipCount(&self) -> NSUInteger;

        /// The number of test failures recorded during the run.
        #[unsafe(method(failureCount))]
        #[unsafe(method_family = none)]
        pub fn failureCount(&self) -> NSUInteger;

        /// The number of uncaught exceptions recorded during the run.
        #[unsafe(method(unexpectedExceptionCount))]
        #[unsafe(method_family = none)]
        pub fn unexpectedExceptionCount(&self) -> NSUInteger;

        /// The total number of test failures and uncaught exceptions recorded during the run.
        #[unsafe(method(totalFailureCount))]
        #[unsafe(method_family = none)]
        pub fn totalFailureCount(&self) -> NSUInteger;

        /// YES if all tests in the run completed their execution without recording any failures, otherwise NO.
        #[unsafe(method(hasSucceeded))]
        #[unsafe(method_family = none)]
        pub fn hasSucceeded(&self) -> bool;

        /// YES if the test was skipped, otherwise NO.
        #[unsafe(method(hasBeenSkipped))]
        #[unsafe(method_family = none)]
        pub fn hasBeenSkipped(&self) -> bool;

        /// Records a failure or other  issue in the execution of the test and is used by all test assertions.
        /// Overrides of this method should call super unless they wish to suppress the issue.
        /// Super can be invoked with a different issue object.
        ///
        ///
        /// Parameter `issue`: Object with all details related to the issue.
        #[unsafe(method(recordIssue:))]
        #[unsafe(method_family = none)]
        pub fn recordIssue(&self, issue: &XCTIssue);
    );
}

/// XCTDeprecated.
impl XCTestRun {
    extern_methods!(
        /// Records a failure in the execution of the test for this test run. Must not be called
        /// unless the run has been started. Must not be called if the test run has been stopped.
        ///
        /// This method is deprecated and has been replaced by the `-recordIssue:` method and XCTIssue class, which
        /// provide greater flexibility for recording issues that arise during testing. Overriding this method in an XCTestRun subclass and
        /// modifying its arguments before calling `super` may cause information about the failure to be lost and is not recommended.
        /// Instead, override `-recordIssue:` and pass `super` a modified XCTIssue.
        ///
        ///
        /// Parameter `description`: The description of the failure being recorded. When replacing usage of this deprecated API,
        /// this can be represented using the `compactDescription` property on XCTIssue.
        ///
        ///
        /// Parameter `filePath`: The file path to the source file where the failure being recorded was encountered
        /// or nil if unknown. When replacing usage of this deprecated API, this can be specified using an XCTSourceCodeLocation instance
        /// associated with an XCTIssue via its `sourceCodeContext` property.
        ///
        ///
        /// Parameter `lineNumber`: The line number in the source file at filePath where the failure being recorded
        /// was encountered or 0 if unknown. When replacing usage of this deprecated API, this can be specified using an
        /// XCTSourceCodeLocation instance associated with an XCTIssue via its `sourceCodeContext` property.
        ///
        ///
        /// Parameter `expected`: NO if the failure being recorded was the result of an uncaught exception, YES if it was the result
        /// of a failed assertion or any other reason. When replacing usage of this deprecated API, the representation using XCTIssue may vary.
        /// A NO value may be specified using the issue type `XCTIssueTypeUncaughtException`, and a YES value may be represented
        /// using a different issue type such as `XCTIssueTypeAssertionFailure` combined with other properties on XCTIssue.
        #[deprecated]
        #[unsafe(method(recordFailureWithDescription:inFile:atLine:expected:))]
        #[unsafe(method_family = none)]
        pub fn recordFailureWithDescription_inFile_atLine_expected(
            &self,
            description: &NSString,
            file_path: Option<&NSString>,
            line_number: NSUInteger,
            expected: bool,
        );
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestcaserun?language=objc)
    #[unsafe(super(XCTestRun, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTestCaseRun;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestCaseRun {}
);

impl XCTestCaseRun {
    extern_methods!(
        #[deprecated]
        #[unsafe(method(recordFailureInTest:withDescription:inFile:atLine:expected:))]
        #[unsafe(method_family = none)]
        pub fn recordFailureInTest_withDescription_inFile_atLine_expected(
            &self,
            test_case: &XCTestCase,
            description: &NSString,
            file_path: &NSString,
            line_number: NSUInteger,
            expected: bool,
        );
    );
}

/// Methods declared on superclass `XCTestRun`.
impl XCTestCaseRun {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Class factory method for the XCTestRun class.
        ///
        ///
        /// Parameter `test`: An XCTest instance.
        ///
        ///
        /// Returns: A test run for the provided test.
        #[unsafe(method(testRunWithTest:))]
        #[unsafe(method_family = none)]
        pub fn testRunWithTest(test: &XCTest) -> Retained<Self>;

        /// Designated initializer for the XCTestRun class.
        ///
        ///
        /// Parameter `test`: An XCTest instance.
        ///
        ///
        /// Returns: A test run for the provided test.
        #[unsafe(method(initWithTest:))]
        #[unsafe(method_family = init)]
        pub fn initWithTest(this: Allocated<Self>, test: &XCTest) -> Retained<Self>;
    );
}

extern_class!(
    /// XCTestObserver is deprecated.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestobserver?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[deprecated]
    pub struct XCTestObserver;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestObserver {}
);

impl XCTestObserver {
    extern_methods!(
        #[unsafe(method(startObserving))]
        #[unsafe(method_family = none)]
        pub fn startObserving(&self);

        #[unsafe(method(stopObserving))]
        #[unsafe(method_family = none)]
        pub fn stopObserving(&self);

        /// # Safety
        ///
        /// `test_run` might not allow `None`.
        #[unsafe(method(testSuiteDidStart:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testSuiteDidStart(&self, test_run: Option<&XCTestRun>);

        /// # Safety
        ///
        /// `test_run` might not allow `None`.
        #[unsafe(method(testSuiteDidStop:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testSuiteDidStop(&self, test_run: Option<&XCTestRun>);

        /// # Safety
        ///
        /// `test_run` might not allow `None`.
        #[unsafe(method(testCaseDidStart:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testCaseDidStart(&self, test_run: Option<&XCTestRun>);

        /// # Safety
        ///
        /// `test_run` might not allow `None`.
        #[unsafe(method(testCaseDidStop:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testCaseDidStop(&self, test_run: Option<&XCTestRun>);

        /// # Safety
        ///
        /// - `test_run` might not allow `None`.
        /// - `description` might not allow `None`.
        /// - `file_path` might not allow `None`.
        #[unsafe(method(testCaseDidFail:withDescription:inFile:atLine:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testCaseDidFail_withDescription_inFile_atLine(
            &self,
            test_run: Option<&XCTestRun>,
            description: Option<&NSString>,
            file_path: Option<&NSString>,
            line_number: NSUInteger,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTestObserver {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTestObserver {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern "C" {
    /// XCTestObserverClassKey is deprecated and ignored.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestobserverclasskey?language=objc)
    #[deprecated]
    pub static XCTestObserverClassKey: Option<&'static NSString>;
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestlog?language=objc)
    #[unsafe(super(XCTestObserver, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[deprecated]
    pub struct XCTestLog;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestLog {}
);

impl XCTestLog {
    extern_methods!(
        #[unsafe(method(logFileHandle))]
        #[unsafe(method_family = none)]
        pub fn logFileHandle(&self) -> Option<Retained<NSFileHandle>>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTestLog {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTestLog {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_protocol!(
    /// Objects conforming to XCTestObservation can register to be notified of the progress of test runs. See XCTestObservationCenter
    /// for details on registration.
    ///
    /// Progress events are delivered in the following sequence:
    ///
    /// -testBundleWillStart:                            // exactly once per test bundle
    /// -testSuiteWillStart:                        // exactly once per test suite
    /// -testCaseWillStart:                     // exactly once per test case
    /// -testCase:didRecordIssue:               // zero or more times per test case, any time between test case start and finish
    /// -testCaseDidFinish:                     // exactly once per test case
    /// -testSuite:didRecordIssue:                  // zero or more times per test suite, any time between test suite start and finish
    /// -testSuiteDidFinish:                        // exactly once per test suite
    /// -testBundleDidFinish:                            // exactly once per test bundle
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestobservation?language=objc)
    pub unsafe trait XCTestObservation: NSObjectProtocol {
        /// Sent immediately before tests begin as a hook for any pre-testing setup.
        ///
        ///
        /// Parameter `testBundle`: The bundle containing the tests that were executed.
        #[optional]
        #[unsafe(method(testBundleWillStart:))]
        #[unsafe(method_family = none)]
        fn testBundleWillStart(&self, test_bundle: &NSBundle);

        /// Sent immediately after all tests have finished as a hook for any post-testing activity. The test process will generally
        /// exit after this method returns, so if there is long running and/or asynchronous work to be done after testing, be sure
        /// to implement this method in a way that it blocks until all such activity is complete.
        ///
        ///
        /// Parameter `testBundle`: The bundle containing the tests that were executed.
        #[optional]
        #[unsafe(method(testBundleDidFinish:))]
        #[unsafe(method_family = none)]
        fn testBundleDidFinish(&self, test_bundle: &NSBundle);

        /// Sent when a test suite starts executing.
        ///
        ///
        /// Parameter `testSuite`: The test suite that started. Additional information can be retrieved from the associated XCTestRun.
        #[optional]
        #[unsafe(method(testSuiteWillStart:))]
        #[unsafe(method_family = none)]
        fn testSuiteWillStart(&self, test_suite: &XCTestSuite);

        /// Sent when a test suite reports an issue. Suite issues are most commonly reported during suite-level setup and teardown
        /// whereas issues during tests are reported for the test case alone and are not reported as suite issues.
        ///
        ///
        /// Parameter `testSuite`: The test suite that recorded the issue.
        ///
        /// Parameter `issue`: Object with all details related to the issue.
        #[optional]
        #[unsafe(method(testSuite:didRecordIssue:))]
        #[unsafe(method_family = none)]
        fn testSuite_didRecordIssue(&self, test_suite: &XCTestSuite, issue: &XCTIssue);

        /// Sent when a test suite records an expected failure.
        ///
        ///
        /// Parameter `testSuite`: The test suite that recorded the expected failure.
        ///
        /// Parameter `expectedFailure`: Object with all details related to the expected failure, including the suppressed issue.
        #[optional]
        #[unsafe(method(testSuite:didRecordExpectedFailure:))]
        #[unsafe(method_family = none)]
        fn testSuite_didRecordExpectedFailure(
            &self,
            test_suite: &XCTestSuite,
            expected_failure: &XCTExpectedFailure,
        );

        /// Sent when a test suite finishes executing.
        ///
        ///
        /// Parameter `testSuite`: The test suite that finished. Additional information can be retrieved from the associated XCTestRun.
        #[optional]
        #[unsafe(method(testSuiteDidFinish:))]
        #[unsafe(method_family = none)]
        fn testSuiteDidFinish(&self, test_suite: &XCTestSuite);

        /// Sent when a test case starts executing.
        ///
        ///
        /// Parameter `testCase`: The test case that started. Additional information can be retrieved from the associated XCTestRun.
        #[optional]
        #[unsafe(method(testCaseWillStart:))]
        #[unsafe(method_family = none)]
        fn testCaseWillStart(&self, test_case: &XCTestCase);

        /// Sent when a test case reports an issue.
        ///
        ///
        /// Parameter `testCase`: The test case that recorded the issue.
        ///
        /// Parameter `issue`: Object with all details related to the issue.
        #[optional]
        #[unsafe(method(testCase:didRecordIssue:))]
        #[unsafe(method_family = none)]
        fn testCase_didRecordIssue(&self, test_case: &XCTestCase, issue: &XCTIssue);

        /// Sent when a test case records an expected failure.
        ///
        ///
        /// Parameter `testCase`: The test case that recorded the expected failure.
        ///
        /// Parameter `expectedFailure`: Object with all details related to the expected failure, including the suppressed issue.
        #[optional]
        #[unsafe(method(testCase:didRecordExpectedFailure:))]
        #[unsafe(method_family = none)]
        fn testCase_didRecordExpectedFailure(
            &self,
            test_case: &XCTestCase,
            expected_failure: &XCTExpectedFailure,
        );

        /// Sent when a test case finishes executing.
        ///
        ///
        /// Parameter `testCase`: The test case that finished. Additional information can be retrieved from the associated XCTestRun.
        #[optional]
        #[unsafe(method(testCaseDidFinish:))]
        #[unsafe(method_family = none)]
        fn testCaseDidFinish(&self, test_case: &XCTestCase);

        /// Sent when a test suite reports a failure. Suite failures are most commonly reported during suite-level setup and teardown
        /// whereas failures during tests are reported for the test case alone and are not reported as suite failures.
        ///
        /// This method is deprecated and replaced by the `-testSuite:didRecordIssue:` method whose XCTIssue parameter provides greater flexibility
        /// for describing issues that arise during testing. If the receiver of this method also responds to `-testSuite:didRecordIssue:`, that method
        /// is called instead and this will not be called.
        ///
        ///
        /// Parameter `testSuite`: The test suite that failed. Additional information can be retrieved from the associated XCTestRun.
        ///
        ///
        /// Parameter `description`: A textual description of the failure. When replacing usage of this deprecated API, this can
        /// be obtained using the `compactDescription` property on XCTIssue.
        ///
        ///
        /// Parameter `filePath`: The path of file where the failure occurred or nil if unknown. When replacing usage of this deprecated API, this
        /// can be obtained using the XCTSourceCodeLocation instance associated with an XCTIssue via its `sourceCodeContext` property
        ///
        ///
        /// Parameter `lineNumber`: The line where the failure was reported or 0 if unknown. When replacing usage of this deprecated API, this
        /// can be obtained using the XCTSourceCodeLocation instance associated with an XCTIssue via its `sourceCodeContext` property
        #[deprecated]
        #[optional]
        #[unsafe(method(testSuite:didFailWithDescription:inFile:atLine:))]
        #[unsafe(method_family = none)]
        fn testSuite_didFailWithDescription_inFile_atLine(
            &self,
            test_suite: &XCTestSuite,
            description: &NSString,
            file_path: Option<&NSString>,
            line_number: NSUInteger,
        );

        /// Sent when a test case reports a failure.
        ///
        /// This method is deprecated and replaced by the `-testCase:didRecordIssue:` method whose XCTIssue parameter provides greater flexibility
        /// for describing issues that arise during testing. If the receiver of this method also responds to `-testCase:didRecordIssue:`, that method
        /// is called instead and this will not be called.
        ///
        ///
        /// Parameter `testCase`: The test case that failed. Additional information can be retrieved from the associated XCTestRun.
        ///
        ///
        /// Parameter `description`: A textual description of the failure. When replacing usage of this deprecated API, this can
        /// be obtained using the `compactDescription` property on XCTIssue.
        ///
        ///
        /// Parameter `filePath`: The path of file where the failure occurred or nil if unknown. When replacing usage of this deprecated API, this
        /// can be obtained using the XCTSourceCodeLocation instance associated with an XCTIssue via its `sourceCodeContext` property
        ///
        ///
        /// Parameter `lineNumber`: The line where the failure was reported or 0 if unknown. When replacing usage of this deprecated API, this
        /// can be obtained using the XCTSourceCodeLocation instance associated with an XCTIssue via its `sourceCodeContext` property
        #[deprecated]
        #[optional]
        #[unsafe(method(testCase:didFailWithDescription:inFile:atLine:))]
        #[unsafe(method_family = none)]
        fn testCase_didFailWithDescription_inFile_atLine(
            &self,
            test_case: &XCTestCase,
            description: &NSString,
            file_path: Option<&NSString>,
            line_number: NSUInteger,
        );
    }
);

extern_class!(
    /// The XCTestObservationCenter distributes information about the progress of test runs to registered
    /// observers. Observers can be any object conforming to the XCTestObservation protocol.
    ///
    /// If an NSPrincipalClass is declared in the test bundle's Info.plist, XCTest automatically creates a
    /// single instance of that class when the test bundle is loaded. This instance provides a means to register
    /// observers or do other pretesting global set up.
    ///
    /// Observers must be registered manually. The NSPrincipalClass instance is not automatically
    /// registered as an observer even if the class conforms to
    /// <XCTestObservation
    /// >.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestobservationcenter?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTestObservationCenter;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestObservationCenter {}
);

impl XCTestObservationCenter {
    extern_methods!(
        /// Returns: The shared XCTestObservationCenter singleton instance.
        #[unsafe(method(sharedTestObservationCenter))]
        #[unsafe(method_family = none)]
        pub fn sharedTestObservationCenter() -> Retained<XCTestObservationCenter>;

        /// Register an object conforming to XCTestObservation as an observer for the current test session. Observers may be added
        /// at any time, but will not receive events that occurred before they were registered. The observation center maintains a strong
        /// reference to observers.
        ///
        /// Events may be delivered to observers in any order - given observers A and B, A may be notified of a test failure before
        /// or after B. Any ordering dependencies or serialization requirements must be managed by clients.
        #[unsafe(method(addTestObserver:))]
        #[unsafe(method_family = none)]
        pub fn addTestObserver(&self, test_observer: &ProtocolObject<dyn XCTestObservation>);

        /// Unregister an object conforming to XCTestObservation as an observer for the current test session.
        #[unsafe(method(removeTestObserver:))]
        #[unsafe(method_family = none)]
        pub fn removeTestObserver(&self, test_observer: &ProtocolObject<dyn XCTestObservation>);
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTestObservationCenter {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTestObservationCenter {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

#[deprecated]
#[inline]
pub extern "C-unwind" fn XCTSelfTestMain() -> c_int {
    extern "C-unwind" {
        fn XCTSelfTestMain() -> c_int;
    }
    unsafe { XCTSelfTestMain() }
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestprobe?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    #[deprecated]
    pub struct XCTestProbe;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestProbe {}
);

impl XCTestProbe {
    extern_methods!(
        #[unsafe(method(isTesting))]
        #[unsafe(method_family = none)]
        pub fn isTesting() -> bool;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTestProbe {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTestProbe {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestedunitpath?language=objc)
    #[deprecated]
    pub static XCTestedUnitPath: Option<&'static NSString>;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestscopekey?language=objc)
    #[deprecated]
    pub static XCTestScopeKey: Option<&'static NSString>;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestscopeall?language=objc)
    #[deprecated]
    pub static XCTestScopeAll: Option<&'static NSString>;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestscopenone?language=objc)
    #[deprecated]
    pub static XCTestScopeNone: Option<&'static NSString>;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestscopeself?language=objc)
    #[deprecated]
    pub static XCTestScopeSelf: Option<&'static NSString>;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctesttoolkey?language=objc)
    #[deprecated]
    pub static XCTestToolKey: Option<&'static NSString>;
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/_xctskipfailureexception?language=objc)
    #[unsafe(super(NSException, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct _XCTSkipFailureException;
);

extern_conformance!(
    unsafe impl NSCoding for _XCTSkipFailureException {}
);

extern_conformance!(
    unsafe impl NSCopying for _XCTSkipFailureException {}
);

unsafe impl CopyingHelper for _XCTSkipFailureException {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for _XCTSkipFailureException {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for _XCTSkipFailureException {}
);

impl _XCTSkipFailureException {
    extern_methods!();
}

/// Methods declared on superclass `NSException`.
impl _XCTSkipFailureException {
    extern_methods!(
        /// # Safety
        ///
        /// `a_user_info` generic should be of the correct type.
        #[unsafe(method(initWithName:reason:userInfo:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_reason_userInfo(
            this: Allocated<Self>,
            a_name: &NSExceptionName,
            a_reason: Option<&NSString>,
            a_user_info: Option<&NSDictionary>,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl _XCTSkipFailureException {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for _XCTSkipFailureException {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// A concrete subclass of XCTest, XCTestSuite is a collection of test cases. Suites
    /// are usually managed by the IDE, but XCTestSuite also provides API for dynamic test
    /// and suite management:
    ///
    /// ```text
    ///
    ///     XCTestSuite *suite = [XCTestSuite testSuiteWithName:@"My tests"];
    ///     [suite addTest:[MathTest testCaseWithSelector:@selector(testAdd)]];
    ///     [suite addTest:[MathTest testCaseWithSelector:@selector(testDivideByZero)]];
    ///
    /// ```
    ///
    /// Alternatively, a test suite can extract the tests to be run automatically. To do so,
    /// pass the class of your test case class to the suite's constructor:
    ///
    /// ```text
    ///
    ///     XCTestSuite *suite = [XCTestSuite testSuiteForTestCaseClass:[MathTest class]];
    ///
    /// ```
    ///
    /// This creates a suite with all the methods starting with "test" that take no arguments.
    /// Also, a test suite of all the test cases found in the runtime can be created automatically:
    ///
    /// ```text
    ///
    ///     XCTestSuite *suite = XCTestSuite.defaultTestSuite;
    ///
    /// ```
    ///
    /// This creates a suite of suites with all the XCTestCase subclasses methods that start
    /// with "test" and take no arguments.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestsuite?language=objc)
    #[unsafe(super(XCTest, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTestSuite;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestSuite {}
);

impl XCTestSuite {
    extern_methods!(
        #[unsafe(method(defaultTestSuite))]
        #[unsafe(method_family = none)]
        pub fn defaultTestSuite() -> Retained<XCTestSuite>;

        #[unsafe(method(testSuiteForBundlePath:))]
        #[unsafe(method_family = none)]
        pub fn testSuiteForBundlePath(bundle_path: &NSString) -> Retained<Self>;

        #[unsafe(method(testSuiteForTestCaseWithName:))]
        #[unsafe(method_family = none)]
        pub fn testSuiteForTestCaseWithName(name: &NSString) -> Retained<Self>;

        /// # Safety
        ///
        /// `test_case_class` probably has further requirements.
        #[unsafe(method(testSuiteForTestCaseClass:))]
        #[unsafe(method_family = none)]
        pub unsafe fn testSuiteForTestCaseClass(test_case_class: &AnyClass) -> Retained<Self>;

        #[unsafe(method(testSuiteWithName:))]
        #[unsafe(method_family = none)]
        pub fn testSuiteWithName(name: &NSString) -> Retained<Self>;

        #[unsafe(method(initWithName:))]
        #[unsafe(method_family = init)]
        pub fn initWithName(this: Allocated<Self>, name: &NSString) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(addTest:))]
        #[unsafe(method_family = none)]
        pub fn addTest(&self, test: &XCTest);

        #[unsafe(method(tests))]
        #[unsafe(method_family = none)]
        pub fn tests(&self) -> Retained<NSArray<XCTest>>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestsuiterun?language=objc)
    #[unsafe(super(XCTestRun, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTestSuiteRun;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestSuiteRun {}
);

impl XCTestSuiteRun {
    extern_methods!(
        #[unsafe(method(testRuns))]
        #[unsafe(method_family = none)]
        pub fn testRuns(&self) -> Retained<NSArray<XCTestRun>>;

        #[unsafe(method(addTestRun:))]
        #[unsafe(method_family = none)]
        pub fn addTestRun(&self, test_run: &XCTestRun);
    );
}

/// Methods declared on superclass `XCTestRun`.
impl XCTestSuiteRun {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Class factory method for the XCTestRun class.
        ///
        ///
        /// Parameter `test`: An XCTest instance.
        ///
        ///
        /// Returns: A test run for the provided test.
        #[unsafe(method(testRunWithTest:))]
        #[unsafe(method_family = none)]
        pub fn testRunWithTest(test: &XCTest) -> Retained<Self>;

        /// Designated initializer for the XCTestRun class.
        ///
        ///
        /// Parameter `test`: An XCTest instance.
        ///
        ///
        /// Returns: A test run for the provided test.
        #[unsafe(method(initWithTest:))]
        #[unsafe(method_family = init)]
        pub fn initWithTest(this: Allocated<Self>, test: &XCTest) -> Retained<Self>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctattachmentlifetime?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTAttachmentLifetime(pub NSInteger);
impl XCTAttachmentLifetime {
    #[doc(alias = "XCTAttachmentLifetimeKeepAlways")]
    pub const KeepAlways: Self = Self(0);
    #[doc(alias = "XCTAttachmentLifetimeDeleteOnSuccess")]
    pub const DeleteOnSuccess: Self = Self(1);
}

unsafe impl Encode for XCTAttachmentLifetime {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for XCTAttachmentLifetime {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Represents the concept of data attached to an XCTActivity. Allows reporting more context about the test run
    /// for debugging, such as screenshots, log files, and configuration dictionaries.
    ///
    /// Each attachment must be added to an activity to be handed off to XCTest. There are two ways to get an activity:
    /// 1. XCTestCase conforms to the XCTActivity protocol, attachments can be added to it directly.
    /// 2. Create a nested activity with +[XCTContext runActivityNamed:block:], the parameter inside the block is a new activity to which attachments can be added.
    ///
    /// Once you have an XCTActivity-conforming object:
    /// • Create a new XCTAttachment with one of the initializers provided.
    /// • Optionally customize the attachment's `lifetime`, `name` and `userInfo` properties.
    /// • Add the attachment to the activity with -[XCTActivity addAttachment:].
    ///
    ///
    /// ```text
    ///  
    ///     - (void)testFoo
    ///     {
    ///         // ...
    ///         NSString *logs = ...
    ///         XCTAttachment *attachment = [XCTAttachment attachmentWithString:logs];
    ///         attachment.name = @"Build logs";
    ///         [self addAttachment:attachment];
    ///     }
    ///
    ///     - (void)testNestedFoo
    ///     {
    ///         // ...
    ///         [XCTContext runActivityNamed:@"Collect logs" block:^(id<XCTActivity> activity){
    ///             NSString *logs = ...
    ///             XCTAttachment *attachment = [XCTAttachment attachmentWithString:logs];
    ///             attachment.name = @"Build logs";
    ///             [activity addAttachment:attachment];
    ///         }];
    ///     }
    ///  
    /// ```
    ///
    /// Attachments have the default lifetime of .deleteOnSuccess, which means they are deleted when
    /// their test passes. This ensures attachments are only kept when test fails. To override this
    /// behavior, change the value of the `lifetime` property to .keepAlways before adding it to an activity.
    ///
    ///
    /// ```text
    ///  
    ///      - (void)testImportantAttachment
    ///      {
    ///          XCTAttachment *attachment = ...
    ///          attachment.lifetime = XCTAttachmentLifetimeKeepAlways;
    ///          [self addAttachment:attachment];
    ///      }
    ///  
    /// ```
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctattachment?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTAttachment;
);

extern_conformance!(
    unsafe impl NSCoding for XCTAttachment {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTAttachment {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTAttachment {}
);

impl XCTAttachment {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        /// # Safety
        ///
        /// `user_info` generic should be of the correct type.
        #[unsafe(method(initWithUniformTypeIdentifier:name:payload:userInfo:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithUniformTypeIdentifier_name_payload_userInfo(
            this: Allocated<Self>,
            identifier: Option<&NSString>,
            name: Option<&NSString>,
            payload: Option<&NSData>,
            user_info: Option<&NSDictionary>,
        ) -> Retained<Self>;

        /// # Safety
        ///
        /// `user_info` generic should be of the correct type.
        #[unsafe(method(attachmentWithUniformTypeIdentifier:name:payload:userInfo:))]
        #[unsafe(method_family = none)]
        pub unsafe fn attachmentWithUniformTypeIdentifier_name_payload_userInfo(
            identifier: Option<&NSString>,
            name: Option<&NSString>,
            payload: Option<&NSData>,
            user_info: Option<&NSDictionary>,
        ) -> Retained<Self>;

        /// Uniform Type Identifier of the payload data.
        /// Examples: "public.png", "public.jpeg", "public.plain-text", "public.data", "com.apple.xml-property-list".
        #[unsafe(method(uniformTypeIdentifier))]
        #[unsafe(method_family = none)]
        pub fn uniformTypeIdentifier(&self) -> Retained<NSString>;

        /// Attachment name.
        #[unsafe(method(name))]
        #[unsafe(method_family = none)]
        pub fn name(&self) -> Option<Retained<NSString>>;

        /// Setter for [`name`][Self::name].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setName:))]
        #[unsafe(method_family = none)]
        pub fn setName(&self, name: Option<&NSString>);

        /// Container for additional metadata, such as pixel density with images.
        #[unsafe(method(userInfo))]
        #[unsafe(method_family = none)]
        pub fn userInfo(&self) -> Option<Retained<NSDictionary>>;

        /// Setter for [`userInfo`][Self::userInfo].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `user_info` generic should be of the correct type.
        #[unsafe(method(setUserInfo:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setUserInfo(&self, user_info: Option<&NSDictionary>);

        #[unsafe(method(lifetime))]
        #[unsafe(method_family = none)]
        pub fn lifetime(&self) -> XCTAttachmentLifetime;

        /// Setter for [`lifetime`][Self::lifetime].
        #[unsafe(method(setLifetime:))]
        #[unsafe(method_family = none)]
        pub fn setLifetime(&self, lifetime: XCTAttachmentLifetime);
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctimagequality?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTImageQuality(pub NSInteger);
impl XCTImageQuality {
    #[doc(alias = "XCTImageQualityOriginal")]
    pub const Original: Self = Self(0);
    #[doc(alias = "XCTImageQualityMedium")]
    pub const Medium: Self = Self(1);
    #[doc(alias = "XCTImageQualityLow")]
    pub const Low: Self = Self(2);
}

unsafe impl Encode for XCTImageQuality {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for XCTImageQuality {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// ConvenienceInitializers.
impl XCTAttachment {
    extern_methods!(
        /// Creates a new data attachment (type "public.data") with the specified payload.
        #[unsafe(method(attachmentWithData:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithData(payload: &NSData) -> Retained<Self>;

        /// Creates a new attachment with the specified payload and type.
        #[unsafe(method(attachmentWithData:uniformTypeIdentifier:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithData_uniformTypeIdentifier(
            payload: &NSData,
            identifier: &NSString,
        ) -> Retained<Self>;

        /// Creates a new plain UTF-8 encoded text attachment (type "public.plain-text") with the specified string.
        #[unsafe(method(attachmentWithString:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithString(string: &NSString) -> Retained<Self>;

        /// Creates an attachment with an object that can be encoded with NSSecureCoding.
        /// Defaults to type "public.data".
        ///
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(attachmentWithArchivableObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn attachmentWithArchivableObject(
            object: &ProtocolObject<dyn NSSecureCoding>,
        ) -> Retained<Self>;

        /// Creates an attachment with an object that can be encoded with NSSecureCoding and type.
        ///
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(attachmentWithArchivableObject:uniformTypeIdentifier:))]
        #[unsafe(method_family = none)]
        pub unsafe fn attachmentWithArchivableObject_uniformTypeIdentifier(
            object: &ProtocolObject<dyn NSSecureCoding>,
            identifier: &NSString,
        ) -> Retained<Self>;

        /// Creates an attachment with an object that can be encoded into an XML property list.
        ///
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(attachmentWithPlistObject:))]
        #[unsafe(method_family = none)]
        pub unsafe fn attachmentWithPlistObject(object: &AnyObject) -> Retained<Self>;

        /// Creates an attachment with an existing file on disk. Attachment's uniform type identifier is inferred from the file extension.
        /// If no type can be inferred from the extension, fallback is "public.data".
        ///
        /// Note: Only works for files, not directories.
        #[unsafe(method(attachmentWithContentsOfFileAtURL:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithContentsOfFileAtURL(url: &NSURL) -> Retained<Self>;

        /// Creates an attachment with an existing file on disk and type.
        ///
        /// Note: Only works for files, not directories.
        #[unsafe(method(attachmentWithContentsOfFileAtURL:uniformTypeIdentifier:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithContentsOfFileAtURL_uniformTypeIdentifier(
            url: &NSURL,
            identifier: &NSString,
        ) -> Retained<Self>;

        /// Creates an attachment with an existing directory on disk. Automatically zips the directory, the content type is "public.zip-archive".
        #[unsafe(method(attachmentWithCompressedContentsOfDirectoryAtURL:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithCompressedContentsOfDirectoryAtURL(url: &NSURL) -> Retained<Self>;

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        #[unsafe(method(attachmentWithImage:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithImage(image: &NSImage) -> Retained<Self>;

        #[cfg(feature = "objc2-app-kit")]
        #[cfg(target_os = "macos")]
        #[unsafe(method(attachmentWithImage:quality:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithImage_quality(
            image: &NSImage,
            quality: XCTImageQuality,
        ) -> Retained<Self>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctcontext?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTContext;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTContext {}
);

impl XCTContext {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;

        #[cfg(feature = "block2")]
        /// Call to create a named activity around the block.
        /// Can be used to group low level actions, such as typing and tapping, into high level
        /// tasks, such as filling of a form in a UI test.
        ///
        /// ```text
        ///  
        ///  - (void)testSignUpFlow {
        ///      XCUIElement *form = ...
        ///      [XCTContext runActivityNamed:@"Fill in account information" block:^{
        ///          [form.textFields[@"Email"] typeText:@"john.appleseed@icloud.com"];
        ///          [form.secureTextFields[@"New Password"] typeText:@"myPassword"];
        ///      }];
        ///      [XCTContext runActivityNamed:@"Create account" block:^{
        ///          XCUIElement *submit = form.buttons[@"Create"];
        ///          XCTAssert(submit.isEnabled);
        ///          [submit tap];
        ///      }];
        ///  }
        ///  
        /// ```
        ///
        /// Such test would result in an activity hierarchy of:
        ///
        /// ```text
        ///  
        ///  - Fill in account information
        ///      - Type "john.appleseed@icloud.com" into "Email"
        ///      - Type "myPassword" into "New Password"
        ///  - Create account
        ///      - Tap "Create"
        ///  
        /// ```
        ///
        /// Must be called from the main thread.
        ///
        ///
        /// Parameter `name`: A string that will help identify the activity.
        ///
        ///
        /// Parameter `block`: A block whose contents are wrapped in the new activity.
        #[unsafe(method(runActivityNamed:block:))]
        #[unsafe(method_family = none)]
        pub fn runActivityNamed_block(
            name: &NSString,
            block: &block2::DynBlock<dyn Fn(NonNull<ProtocolObject<dyn XCTActivity>>) + '_>,
        );
    );
}

impl DefaultRetained for XCTContext {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// Declares that the test is expected to fail at some point beyond the call. This can be used to both document and
/// suppress a known issue when immediate resolution is not possible. Issues caught by XCTExpectFailure do not
/// impact the aggregate results of the test suites which own them.
///
/// This function may be invoked repeatedly and has stack semantics. Failures are associated with the closest
/// matching expected failure and the stack is cleaned up by the test after it runs. If a failure is expected
/// but none is recorded, a distinct failure for the unmatched expected failure will be recorded instead.
///
/// Threading considerations: when XCTExpectFailure is called on the test's primary thread it will match against
/// any issue recorded on any thread. When XCTExpectFailure is called on any other thread, it will only match
/// against issues recorded on the same thread.
///
///
/// Parameter `failureReason`: Explanation of the issue being suppressed. If it contains
/// a URL, that URL can be extracted and presented as a link in reporting UI (Xcode and CI).
#[inline]
pub extern "C-unwind" fn XCTExpectFailure(failure_reason: Option<&NSString>) {
    extern "C-unwind" {
        fn XCTExpectFailure(failure_reason: Option<&NSString>);
    }
    unsafe { XCTExpectFailure(failure_reason) }
}

/// Like XCTExpectFailure, but takes an options object that can be used to customize the behavior.
///
///
/// Parameter `options`: The options can include a custom issue matching block as well as the ability to
/// disable "strict" behavior, which relaxes the requirement that a call to XCTExpectFailure must be matched
/// against at least one recorded issue.
#[inline]
pub extern "C-unwind" fn XCTExpectFailureWithOptions(
    failure_reason: Option<&NSString>,
    options: &XCTExpectedFailureOptions,
) {
    extern "C-unwind" {
        fn XCTExpectFailureWithOptions(
            failure_reason: Option<&NSString>,
            options: &XCTExpectedFailureOptions,
        );
    }
    unsafe { XCTExpectFailureWithOptions(failure_reason, options) }
}

/// Like XCTExpectFailure, but limits the scope in which issues are matched.
///
///
/// Parameter `failingBlock`: The scope of code in which the failure is expected. Note that this will only
/// match against failures in that scope on the same thread; failures in dispatch callouts or other code
/// running on a different thread will not be matched.
#[cfg(feature = "block2")]
#[inline]
pub extern "C-unwind" fn XCTExpectFailureInBlock(
    failure_reason: Option<&NSString>,
    failing_block: &block2::DynBlock<dyn Fn()>,
) {
    extern "C-unwind" {
        fn XCTExpectFailureInBlock(
            failure_reason: Option<&NSString>,
            failing_block: &block2::DynBlock<dyn Fn()>,
        );
    }
    unsafe { XCTExpectFailureInBlock(failure_reason, failing_block) }
}

/// Like XCTExpectFailure, but takes an options object that can be used to customize the behavior and
/// limits the scope in which issues are matched.
#[cfg(feature = "block2")]
#[inline]
pub extern "C-unwind" fn XCTExpectFailureWithOptionsInBlock(
    failure_reason: Option<&NSString>,
    options: &XCTExpectedFailureOptions,
    failing_block: &block2::DynBlock<dyn Fn()>,
) {
    extern "C-unwind" {
        fn XCTExpectFailureWithOptionsInBlock(
            failure_reason: Option<&NSString>,
            options: &XCTExpectedFailureOptions,
            failing_block: &block2::DynBlock<dyn Fn()>,
        );
    }
    unsafe { XCTExpectFailureWithOptionsInBlock(failure_reason, options, failing_block) }
}

extern_class!(
    /// Describes the rules for matching issues to expected failures and other behaviors related to
    /// expected failure handling.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctexpectedfailureoptions?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTExpectedFailureOptions;
);

extern_conformance!(
    unsafe impl NSCoding for XCTExpectedFailureOptions {}
);

extern_conformance!(
    unsafe impl NSCopying for XCTExpectedFailureOptions {}
);

unsafe impl CopyingHelper for XCTExpectedFailureOptions {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTExpectedFailureOptions {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTExpectedFailureOptions {}
);

impl XCTExpectedFailureOptions {
    extern_methods!(
        #[cfg(feature = "block2")]
        /// An optional filter can be used to determine whether or not an issue recorded inside an expected
        /// failure block should be matched to the expected failure. Issues that are not matched to an expected
        /// failure will be recorded as normal issues (real test failures). By default the filter is nil and
        /// all issues are matched.
        ///
        /// # Safety
        ///
        /// The returned block's argument must be a valid pointer.
        #[unsafe(method(issueMatcher))]
        #[unsafe(method_family = none)]
        pub unsafe fn issueMatcher(
            &self,
        ) -> NonNull<block2::DynBlock<dyn Fn(NonNull<XCTIssue>) -> Bool>>;

        #[cfg(feature = "block2")]
        /// Setter for [`issueMatcher`][Self::issueMatcher].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setIssueMatcher:))]
        #[unsafe(method_family = none)]
        pub fn setIssueMatcher(
            &self,
            issue_matcher: &block2::DynBlock<dyn Fn(NonNull<XCTIssue>) -> Bool>,
        );

        /// For expected failures that only occur under certain circumstances, this flag can be used to
        /// disable the expected failure. In the closure-based variants of XCTExpectFailure, the failing block
        /// will be executed normally. Defaults to YES/true.
        #[unsafe(method(isEnabled))]
        #[unsafe(method_family = none)]
        pub fn isEnabled(&self) -> bool;

        /// Setter for [`isEnabled`][Self::isEnabled].
        #[unsafe(method(setEnabled:))]
        #[unsafe(method_family = none)]
        pub fn setEnabled(&self, enabled: bool);

        /// If true (the default) and no issue is matched to the expected failure, then an issue will be
        /// recorded for the unmatched expected failure itself.
        #[unsafe(method(isStrict))]
        #[unsafe(method_family = none)]
        pub fn isStrict(&self) -> bool;

        /// Setter for [`isStrict`][Self::isStrict].
        #[unsafe(method(setStrict:))]
        #[unsafe(method_family = none)]
        pub fn setStrict(&self, strict: bool);

        /// Convenience factory method which returns a new instance of XCTExpectedFailureOptions that has `isStrict` set to NO, with every other value set to its default.
        #[unsafe(method(nonStrictOptions))]
        #[unsafe(method_family = none)]
        pub fn nonStrictOptions() -> Retained<XCTExpectedFailureOptions>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTExpectedFailureOptions {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTExpectedFailureOptions {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// Contains the details about a single instance of an expected failure, including the failure
    /// reason and the underlying issue that was recorded.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctexpectedfailure?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTExpectedFailure;
);

extern_conformance!(
    unsafe impl NSCoding for XCTExpectedFailure {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTExpectedFailure {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTExpectedFailure {}
);

impl XCTExpectedFailure {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;

        /// Explanation of the problem requiring the issue to be suppressed.
        #[unsafe(method(failureReason))]
        #[unsafe(method_family = none)]
        pub fn failureReason(&self) -> Option<Retained<NSString>>;

        /// The issue being suppressed.
        #[unsafe(method(issue))]
        #[unsafe(method_family = none)]
        pub fn issue(&self) -> Retained<XCTIssue>;
    );
}

impl DefaultRetained for XCTExpectedFailure {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// Types of failures and other issues that can be reported for tests.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctissuetype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTIssueType(pub NSInteger);
impl XCTIssueType {
    /// Issue raised by a failed XCTAssert or related API.
    #[doc(alias = "XCTIssueTypeAssertionFailure")]
    pub const AssertionFailure: Self = Self(0);
    /// Issue raised by the test throwing an error in Swift. This could also occur if an Objective C test is implemented in the form `- (BOOL)testFoo:(NSError **)outError` and returns NO with a non-nil out error.
    #[doc(alias = "XCTIssueTypeThrownError")]
    pub const ThrownError: Self = Self(1);
    /// Code in the test throws and does not catch an exception, Objective C, C++, or other.
    #[doc(alias = "XCTIssueTypeUncaughtException")]
    pub const UncaughtException: Self = Self(2);
    /// One of the XCTestCase(measure:) family of APIs detected a performance regression.
    #[doc(alias = "XCTIssueTypePerformanceRegression")]
    pub const PerformanceRegression: Self = Self(3);
    /// One of the framework APIs failed internally. For example, XCUIApplication was unable to launch or terminate an app or XCUIElementQuery was unable to complete a query.
    #[doc(alias = "XCTIssueTypeSystem")]
    pub const System: Self = Self(4);
    /// Issue raised when XCTExpectFailure is used but no matching issue is recorded.
    #[doc(alias = "XCTIssueTypeUnmatchedExpectedFailure")]
    pub const UnmatchedExpectedFailure: Self = Self(5);
}

unsafe impl Encode for XCTIssueType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for XCTIssueType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// An enum representing the severity of a test issue.
///
/// The numeric values of this enum's cases are comparable. A case which represents
/// higher severity has a larger numeric value than one which represents lower
/// severity. Specifying a numeric severity value other than one corresponding to
/// a case defined below when initializing an ``XCTIssue`` is unsupported.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctissueseverity?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTIssueSeverity(pub NSInteger);
impl XCTIssueSeverity {
    /// The severity level for an issue which should be noted but is not
    /// necessarily an error.
    ///
    /// An issue with warning severity does not cause the test it's associated
    /// with to be marked as a failure, but is noted in the results.
    #[doc(alias = "XCTIssueSeverityWarning")]
    pub const Warning: Self = Self(4);
    /// The severity level for an issue which represents an error in a test.
    ///
    /// An issue with error severity causes the test it's associated with to be
    /// marked as a failure.
    #[doc(alias = "XCTIssueSeverityError")]
    pub const Error: Self = Self(8);
}

unsafe impl Encode for XCTIssueSeverity {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for XCTIssueSeverity {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Encapsulates all data concerning a test failure or other issue.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctissue?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTIssue;
);

extern_conformance!(
    unsafe impl NSCoding for XCTIssue {}
);

extern_conformance!(
    unsafe impl NSCopying for XCTIssue {}
);

unsafe impl CopyingHelper for XCTIssue {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSMutableCopying for XCTIssue {}
);

unsafe impl MutableCopyingHelper for XCTIssue {
    type Result = XCTMutableIssue;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTIssue {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTIssue {}
);

impl XCTIssue {
    extern_methods!(
        #[unsafe(method(initWithType:compactDescription:detailedDescription:sourceCodeContext:associatedError:attachments:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription_detailedDescription_sourceCodeContext_associatedError_attachments(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
            detailed_description: Option<&NSString>,
            source_code_context: &XCTSourceCodeContext,
            associated_error: Option<&NSError>,
            attachments: &NSArray<XCTAttachment>,
        ) -> Retained<Self>;

        #[unsafe(method(initWithType:compactDescription:detailedDescription:sourceCodeContext:associatedError:attachments:severity:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription_detailedDescription_sourceCodeContext_associatedError_attachments_severity(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
            detailed_description: Option<&NSString>,
            source_code_context: &XCTSourceCodeContext,
            associated_error: Option<&NSError>,
            attachments: &NSArray<XCTAttachment>,
            severity: XCTIssueSeverity,
        ) -> Retained<Self>;

        #[unsafe(method(initWithType:compactDescription:severity:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription_severity(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
            severity: XCTIssueSeverity,
        ) -> Retained<Self>;

        #[unsafe(method(initWithType:compactDescription:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        /// The type of the issue.
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub fn r#type(&self) -> XCTIssueType;

        /// A concise description of the issue, expected to be free of transient data and suitable for use in test run
        /// summaries and for aggregation of results across multiple test runs.
        #[unsafe(method(compactDescription))]
        #[unsafe(method_family = none)]
        pub fn compactDescription(&self) -> Retained<NSString>;

        /// A detailed description of the issue designed to help diagnose the issue. May include transient data such as
        /// numbers, object identifiers, timestamps, etc.
        #[unsafe(method(detailedDescription))]
        #[unsafe(method_family = none)]
        pub fn detailedDescription(&self) -> Option<Retained<NSString>>;

        /// The source code location (file and line number) and the call stack associated with the issue.
        #[unsafe(method(sourceCodeContext))]
        #[unsafe(method_family = none)]
        pub fn sourceCodeContext(&self) -> Retained<XCTSourceCodeContext>;

        /// Error associated with the issue.
        #[unsafe(method(associatedError))]
        #[unsafe(method_family = none)]
        pub fn associatedError(&self) -> Option<Retained<NSError>>;

        /// All attachments associated with the issue.
        #[unsafe(method(attachments))]
        #[unsafe(method_family = none)]
        pub fn attachments(&self) -> Retained<NSArray<XCTAttachment>>;

        /// The severity of the issue.
        #[unsafe(method(severity))]
        #[unsafe(method_family = none)]
        pub fn severity(&self) -> XCTIssueSeverity;

        /// Whether or not this issue should cause the test it's associated with to be
        /// considered a failure.
        ///
        /// The value of this property is `YES` for issues which have a severity level of
        /// ``XCTIssueSeverityError`` or higher.
        /// Otherwise, the value of this property is `NO`.
        ///
        /// Use this property to determine if an issue should be considered a failure, instead of
        /// directly comparing the value of the ``severity`` property.
        #[unsafe(method(isFailure))]
        #[unsafe(method_family = none)]
        pub fn isFailure(&self) -> bool;
    );
}

extern_class!(
    /// Mutable variant of XCTIssue, suitable for modifying by overrides in the reporting chain.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctmutableissue?language=objc)
    #[unsafe(super(XCTIssue, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTMutableIssue;
);

extern_conformance!(
    unsafe impl NSCoding for XCTMutableIssue {}
);

extern_conformance!(
    unsafe impl NSCopying for XCTMutableIssue {}
);

unsafe impl CopyingHelper for XCTMutableIssue {
    type Result = XCTIssue;
}

extern_conformance!(
    unsafe impl NSMutableCopying for XCTMutableIssue {}
);

unsafe impl MutableCopyingHelper for XCTMutableIssue {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTMutableIssue {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTMutableIssue {}
);

impl XCTMutableIssue {
    extern_methods!(
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub fn r#type(&self) -> XCTIssueType;

        /// Setter for [`type`][Self::type].
        #[unsafe(method(setType:))]
        #[unsafe(method_family = none)]
        pub fn setType(&self, r#type: XCTIssueType);

        #[unsafe(method(compactDescription))]
        #[unsafe(method_family = none)]
        pub fn compactDescription(&self) -> Retained<NSString>;

        /// Setter for [`compactDescription`][Self::compactDescription].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setCompactDescription:))]
        #[unsafe(method_family = none)]
        pub fn setCompactDescription(&self, compact_description: &NSString);

        #[unsafe(method(detailedDescription))]
        #[unsafe(method_family = none)]
        pub fn detailedDescription(&self) -> Option<Retained<NSString>>;

        /// Setter for [`detailedDescription`][Self::detailedDescription].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setDetailedDescription:))]
        #[unsafe(method_family = none)]
        pub fn setDetailedDescription(&self, detailed_description: Option<&NSString>);

        #[unsafe(method(sourceCodeContext))]
        #[unsafe(method_family = none)]
        pub fn sourceCodeContext(&self) -> Retained<XCTSourceCodeContext>;

        /// Setter for [`sourceCodeContext`][Self::sourceCodeContext].
        #[unsafe(method(setSourceCodeContext:))]
        #[unsafe(method_family = none)]
        pub fn setSourceCodeContext(&self, source_code_context: &XCTSourceCodeContext);

        #[unsafe(method(associatedError))]
        #[unsafe(method_family = none)]
        pub fn associatedError(&self) -> Option<Retained<NSError>>;

        /// Setter for [`associatedError`][Self::associatedError].
        #[unsafe(method(setAssociatedError:))]
        #[unsafe(method_family = none)]
        pub fn setAssociatedError(&self, associated_error: Option<&NSError>);

        #[unsafe(method(attachments))]
        #[unsafe(method_family = none)]
        pub fn attachments(&self) -> Retained<NSArray<XCTAttachment>>;

        /// Setter for [`attachments`][Self::attachments].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setAttachments:))]
        #[unsafe(method_family = none)]
        pub fn setAttachments(&self, attachments: &NSArray<XCTAttachment>);

        #[unsafe(method(severity))]
        #[unsafe(method_family = none)]
        pub fn severity(&self) -> XCTIssueSeverity;

        /// Setter for [`severity`][Self::severity].
        #[unsafe(method(setSeverity:))]
        #[unsafe(method_family = none)]
        pub fn setSeverity(&self, severity: XCTIssueSeverity);

        /// Add an attachment to this issue.
        #[unsafe(method(addAttachment:))]
        #[unsafe(method_family = none)]
        pub fn addAttachment(&self, attachment: &XCTAttachment);
    );
}

/// Methods declared on superclass `XCTIssue`.
impl XCTMutableIssue {
    extern_methods!(
        #[unsafe(method(initWithType:compactDescription:detailedDescription:sourceCodeContext:associatedError:attachments:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription_detailedDescription_sourceCodeContext_associatedError_attachments(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
            detailed_description: Option<&NSString>,
            source_code_context: &XCTSourceCodeContext,
            associated_error: Option<&NSError>,
            attachments: &NSArray<XCTAttachment>,
        ) -> Retained<Self>;

        #[unsafe(method(initWithType:compactDescription:detailedDescription:sourceCodeContext:associatedError:attachments:severity:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription_detailedDescription_sourceCodeContext_associatedError_attachments_severity(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
            detailed_description: Option<&NSString>,
            source_code_context: &XCTSourceCodeContext,
            associated_error: Option<&NSError>,
            attachments: &NSArray<XCTAttachment>,
            severity: XCTIssueSeverity,
        ) -> Retained<Self>;

        #[unsafe(method(initWithType:compactDescription:severity:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription_severity(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
            severity: XCTIssueSeverity,
        ) -> Retained<Self>;

        #[unsafe(method(initWithType:compactDescription:))]
        #[unsafe(method_family = init)]
        pub fn initWithType_compactDescription(
            this: Allocated<Self>,
            r#type: XCTIssueType,
            compact_description: &NSString,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctmeasurementinvocationoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTMeasurementInvocationOptions(pub NSUInteger);
bitflags::bitflags! {
    impl XCTMeasurementInvocationOptions: NSUInteger {
        #[doc(alias = "XCTMeasurementInvocationNone")]
        const None = 0;
        #[doc(alias = "XCTMeasurementInvocationManuallyStart")]
        const ManuallyStart = 1<<0;
        #[doc(alias = "XCTMeasurementInvocationManuallyStop")]
        const ManuallyStop = 1<<1;
    }
}

unsafe impl Encode for XCTMeasurementInvocationOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for XCTMeasurementInvocationOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Collection of options which configures behavior when passed into the -[XCTMeasure measure*] APIs.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctmeasureoptions?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTMeasureOptions;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTMeasureOptions {}
);

impl XCTMeasureOptions {
    extern_methods!(
        /// Builds a set of recommended default options for measuring.
        ///
        ///
        /// Returns: An object which represents a set of default configuration options for measuring.
        #[unsafe(method(defaultOptions))]
        #[unsafe(method_family = none)]
        pub fn defaultOptions() -> Retained<XCTMeasureOptions>;

        /// Set of options which configure how measurements are taken. The default option is XCTMeasurementInvocationNone.
        #[unsafe(method(invocationOptions))]
        #[unsafe(method_family = none)]
        pub fn invocationOptions(&self) -> XCTMeasurementInvocationOptions;

        /// Setter for [`invocationOptions`][Self::invocationOptions].
        #[unsafe(method(setInvocationOptions:))]
        #[unsafe(method_family = none)]
        pub fn setInvocationOptions(&self, invocation_options: XCTMeasurementInvocationOptions);

        /// The number of times the block being measured should be invoked. The default value is 5.
        /// Note that the block is actually invoked `iterationCount` + 1 times, and the first iteration
        /// is discarded. This is done to reduce the chance that the first iteration will be an outlier.
        #[unsafe(method(iterationCount))]
        #[unsafe(method_family = none)]
        pub fn iterationCount(&self) -> NSUInteger;

        /// Setter for [`iterationCount`][Self::iterationCount].
        #[unsafe(method(setIterationCount:))]
        #[unsafe(method_family = none)]
        pub fn setIterationCount(&self, iteration_count: NSUInteger);
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTMeasureOptions {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTMeasureOptions {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// [Apple's documentation](https://developer.apple.com/documentation/xctest/xctperformancemeasurementpolarity?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTPerformanceMeasurementPolarity(pub NSInteger);
impl XCTPerformanceMeasurementPolarity {
    /// Represents measurements where smaller values are considered "better".
    #[doc(alias = "XCTPerformanceMeasurementPolarityPrefersSmaller")]
    pub const PrefersSmaller: Self = Self(-1);
    /// Represents measurements which do not have a meaningful polarity. Suitable for situations where neither smaller nor larger values are considered "better".
    #[doc(alias = "XCTPerformanceMeasurementPolarityUnspecified")]
    pub const Unspecified: Self = Self(0);
    /// Represents measurements where larger values are considered "better".
    #[doc(alias = "XCTPerformanceMeasurementPolarityPrefersLarger")]
    pub const PrefersLarger: Self = Self(1);
}

unsafe impl Encode for XCTPerformanceMeasurementPolarity {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for XCTPerformanceMeasurementPolarity {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Encapsulates timestamps at various levels
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctperformancemeasurementtimestamp?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTPerformanceMeasurementTimestamp;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTPerformanceMeasurementTimestamp {}
);

impl XCTPerformanceMeasurementTimestamp {
    extern_methods!(
        /// The timestamp recorded using mach_absolute_time().
        #[unsafe(method(absoluteTime))]
        #[unsafe(method_family = none)]
        pub fn absoluteTime(&self) -> u64;

        /// Nanoseconds since an arbitrary point, does not increment while the system is asleep.
        #[unsafe(method(absoluteTimeNanoSeconds))]
        #[unsafe(method_family = none)]
        pub fn absoluteTimeNanoSeconds(&self) -> u64;

        /// The timestamp recorded using an NSDate.
        #[unsafe(method(date))]
        #[unsafe(method_family = none)]
        pub fn date(&self) -> Retained<NSDate>;

        /// Initializes an object with the given mach absolute time and NSDate instance.
        #[unsafe(method(initWithAbsoluteTime:date:))]
        #[unsafe(method_family = init)]
        pub fn initWithAbsoluteTime_date(
            this: Allocated<Self>,
            absolute_time: u64,
            date: &NSDate,
        ) -> Retained<Self>;

        /// Initializes an object which represents a timestamp at the current time.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTPerformanceMeasurementTimestamp {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTPerformanceMeasurementTimestamp {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// Contains the data acquired from a single metric being measured for an individual iteration.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctperformancemeasurement?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTPerformanceMeasurement;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTPerformanceMeasurement {}
);

impl XCTPerformanceMeasurement {
    extern_methods!(
        /// A unique identifier for this measurement such as "com.apple.XCTPerformanceMetric_WallClockTime".
        #[unsafe(method(identifier))]
        #[unsafe(method_family = none)]
        pub fn identifier(&self) -> Retained<NSString>;

        /// The human-readable name for this measurement, such as "Wall Clock Time".
        #[unsafe(method(displayName))]
        #[unsafe(method_family = none)]
        pub fn displayName(&self) -> Retained<NSString>;

        /// The value of the measurement.
        #[unsafe(method(value))]
        #[unsafe(method_family = none)]
        pub fn value(&self) -> Retained<NSMeasurement>;

        /// The double value of the measurement.
        #[unsafe(method(doubleValue))]
        #[unsafe(method_family = none)]
        pub fn doubleValue(&self) -> c_double;

        /// A string describing the unit the value is in.
        #[unsafe(method(unitSymbol))]
        #[unsafe(method_family = none)]
        pub fn unitSymbol(&self) -> Retained<NSString>;

        /// An enum value representing in which direction measurements should be compared against their baselines.
        #[unsafe(method(polarity))]
        #[unsafe(method_family = none)]
        pub fn polarity(&self) -> XCTPerformanceMeasurementPolarity;

        /// Initializes an object which encapsulates the measurement for a metric during a single iteration.
        ///
        ///
        /// Parameter `identifier`: A unique identifier for this measurement such as "com.apple.XCTPerformanceMetric_WallClockTime".
        ///
        /// Parameter `displayName`: A human-readable name for this measurement, such as "Wall Clock Time".
        ///
        /// Parameter `value`: The value of the measurement.
        ///
        /// # Safety
        ///
        /// `value` generic should be bound by `AsRef<NSUnit>`.
        #[unsafe(method(initWithIdentifier:displayName:value:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithIdentifier_displayName_value(
            this: Allocated<Self>,
            identifier: &NSString,
            display_name: &NSString,
            value: &NSMeasurement,
        ) -> Retained<Self>;

        /// Initializes an object which encapsulates the measurement for a metric during a single iteration.
        ///
        ///
        /// Parameter `identifier`: A unique identifier for this measurement such as "com.apple.XCTPerformanceMetric_WallClockTime".
        ///
        /// Parameter `displayName`: A human-readable name for this measurement, such as "Wall Clock Time".
        ///
        /// Parameter `doubleValue`: The double value of the measurement.
        ///
        /// Parameter `unitSymbol`: A string describing the unit the value is in.
        #[unsafe(method(initWithIdentifier:displayName:doubleValue:unitSymbol:))]
        #[unsafe(method_family = init)]
        pub fn initWithIdentifier_displayName_doubleValue_unitSymbol(
            this: Allocated<Self>,
            identifier: &NSString,
            display_name: &NSString,
            double_value: c_double,
            unit_symbol: &NSString,
        ) -> Retained<Self>;

        /// Initializes an object which encapsulates the measurement for a metric during a single iteration.
        ///
        ///
        /// Parameter `identifier`: A unique identifier for this measurement such as "com.apple.XCTPerformanceMetric_WallClockTime".
        ///
        /// Parameter `displayName`: A human-readable name for this measurement, such as "Wall Clock Time".
        ///
        /// Parameter `value`: The value of the measurement.
        ///
        /// Parameter `polarity`: An enum value representing in which direction measurements should be compared against their baselines.
        ///
        /// # Safety
        ///
        /// `value` generic should be bound by `AsRef<NSUnit>`.
        #[unsafe(method(initWithIdentifier:displayName:value:polarity:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithIdentifier_displayName_value_polarity(
            this: Allocated<Self>,
            identifier: &NSString,
            display_name: &NSString,
            value: &NSMeasurement,
            polarity: XCTPerformanceMeasurementPolarity,
        ) -> Retained<Self>;

        /// Initializes an object which encapsulates the measurement for a metric during a single iteration.
        ///
        ///
        /// Parameter `identifier`: A unique identifier for this measurement such as "com.apple.XCTPerformanceMetric_WallClockTime".
        ///
        /// Parameter `displayName`: A human-readable name for this measurement, such as "Wall Clock Time".
        ///
        /// Parameter `doubleValue`: The double value of the measurement.
        ///
        /// Parameter `unitSymbol`: A string describing the unit the value is in.
        ///
        /// Parameter `polarity`: An enum value representing in which direction measurements should be compared against their baselines.
        #[unsafe(method(initWithIdentifier:displayName:doubleValue:unitSymbol:polarity:))]
        #[unsafe(method_family = init)]
        pub fn initWithIdentifier_displayName_doubleValue_unitSymbol_polarity(
            this: Allocated<Self>,
            identifier: &NSString,
            display_name: &NSString,
            double_value: c_double,
            unit_symbol: &NSString,
            polarity: XCTPerformanceMeasurementPolarity,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTPerformanceMeasurement {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_protocol!(
    /// Defines a protocol which may be used with the -measureWithMetrics* methods on XCTestCase.
    ///
    ///
    /// Classes conforming to XCTMetric must also adopt NSCopying, as a unique metric instance is copied for each iteration.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctmetric?language=objc)
    pub unsafe trait XCTMetric: NSCopying + NSObjectProtocol {
        /// Report measurements for the iteration that started and ended at the specified times.
        ///
        ///
        /// Called after -didStopMeasuring has been invoked and when XCTest is ready to gather
        /// the measurements that were collected. You can truncate the data accumulated to be as
        /// accurate as possible with the start and end times.
        #[unsafe(method(reportMeasurementsFromStartTime:toEndTime:error:_))]
        #[unsafe(method_family = none)]
        fn reportMeasurementsFromStartTime_toEndTime_error(
            &self,
            start_time: &XCTPerformanceMeasurementTimestamp,
            end_time: &XCTPerformanceMeasurementTimestamp,
        ) -> Result<Retained<NSArray<XCTPerformanceMeasurement>>, Retained<NSError>>;

        /// Called every iteration just before the measure block is about to be invoked.
        /// You should begin measuring when this is called.
        #[optional]
        #[unsafe(method(willBeginMeasuring))]
        #[unsafe(method_family = none)]
        fn willBeginMeasuring(&self);

        /// Called after the measure block's invocation. You should stop measuring when
        /// this is called.
        #[optional]
        #[unsafe(method(didStopMeasuring))]
        #[unsafe(method_family = none)]
        fn didStopMeasuring(&self);
    }
);

extern_class!(
    /// A metric which gathers monotonic time data.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctclockmetric?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTClockMetric;
);

extern_conformance!(
    unsafe impl NSCopying for XCTClockMetric {}
);

unsafe impl CopyingHelper for XCTClockMetric {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTClockMetric {}
);

extern_conformance!(
    unsafe impl XCTMetric for XCTClockMetric {}
);

impl XCTClockMetric {
    extern_methods!(
        /// Initializes a metric which is recommended for measuring time.
        ///
        ///
        /// Returns: A new instance of a metric which will measure time.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTClockMetric {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTClockMetric {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// A metric which measures timestamp data gathered from os_signposts.
    /// If the interval being measured is an animation os_signpost interval then the following
    /// data will also be gathered:
    /// - frame rate (fps)
    /// - frame count
    /// - number of hitches
    /// - hitch total time duration (ms)
    /// - hitch time ratio (ms per s)
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctossignpostmetric?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTOSSignpostMetric;
);

extern_conformance!(
    unsafe impl NSCopying for XCTOSSignpostMetric {}
);

unsafe impl CopyingHelper for XCTOSSignpostMetric {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTOSSignpostMetric {}
);

extern_conformance!(
    unsafe impl XCTMetric for XCTOSSignpostMetric {}
);

impl XCTOSSignpostMetric {
    extern_methods!(
        /// Initializes a metric which describes a custom signpost.
        ///
        ///
        /// Parameter `subsystem`: The subsystem of the target signpost.
        ///
        /// Parameter `category`: The category of the target signpost.
        ///
        /// Parameter `name`: The name of the target signpost.
        ///
        /// Returns: A signpost metric describing the target signpost.
        #[unsafe(method(initWithSubsystem:category:name:))]
        #[unsafe(method_family = init)]
        pub fn initWithSubsystem_category_name(
            this: Allocated<Self>,
            subsystem: &NSString,
            category: &NSString,
            name: &NSString,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTOSSignpostMetric {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// XCTBuiltinOSSignposts.
///
/// Interface extension describing OS Signposts that are instrumented by the OS.
impl XCTOSSignpostMetric {
    extern_methods!(
        /// The XCTOSSignpostMetric object covering application launch
        #[deprecated = "Use XCTApplicationLaunchMetric instead"]
        #[unsafe(method(applicationLaunchMetric))]
        #[unsafe(method_family = none)]
        pub fn applicationLaunchMetric() -> Retained<XCTOSSignpostMetric>;

        /// The XCTMetric object covering navigation transitions between views
        #[unsafe(method(navigationTransitionMetric))]
        #[unsafe(method_family = none)]
        pub fn navigationTransitionMetric() -> Retained<ProtocolObject<dyn XCTMetric>>;

        /// The XCTMetric object covering custom navigation transitions between views
        #[unsafe(method(customNavigationTransitionMetric))]
        #[unsafe(method_family = none)]
        pub fn customNavigationTransitionMetric() -> Retained<ProtocolObject<dyn XCTMetric>>;

        /// The XCTMetric object covering both the scroll and deceleration animations
        #[unsafe(method(scrollingAndDecelerationMetric))]
        #[unsafe(method_family = none)]
        pub fn scrollingAndDecelerationMetric() -> Retained<ProtocolObject<dyn XCTMetric>>;

        /// The XCTMetric object covering scroll deceleration animations
        #[deprecated]
        #[unsafe(method(scrollDecelerationMetric))]
        #[unsafe(method_family = none)]
        pub fn scrollDecelerationMetric() -> Retained<ProtocolObject<dyn XCTMetric>>;

        /// The XCTMetric object covering scroll dragging animations
        #[deprecated]
        #[unsafe(method(scrollDraggingMetric))]
        #[unsafe(method_family = none)]
        pub fn scrollDraggingMetric() -> Retained<ProtocolObject<dyn XCTMetric>>;
    );
}

extern_class!(
    /// A metric which measures application launch durations.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctapplicationlaunchmetric?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTApplicationLaunchMetric;
);

extern_conformance!(
    unsafe impl NSCopying for XCTApplicationLaunchMetric {}
);

unsafe impl CopyingHelper for XCTApplicationLaunchMetric {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTApplicationLaunchMetric {}
);

extern_conformance!(
    unsafe impl XCTMetric for XCTApplicationLaunchMetric {}
);

impl XCTApplicationLaunchMetric {
    extern_methods!(
        /// Initializes an application launch metric that measures the amount of time an
        /// application takes to display its first frame to screen.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        /// Initializes an application launch metric that measures the amount of time it takes
        /// for an application to display its first frame to screen and for its main thread to be
        /// ready to accept user input.
        ///
        ///
        /// Parameter `waitUntilResponsive`: Specifies the end of the application launch
        /// interval to be when the application's main thread is responsive to user input.
        #[unsafe(method(initWithWaitUntilResponsive:))]
        #[unsafe(method_family = init)]
        pub fn initWithWaitUntilResponsive(
            this: Allocated<Self>,
            wait_until_responsive: bool,
        ) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTApplicationLaunchMetric {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTApplicationLaunchMetric {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// A metric which measures instructions retired and time utilization of the CPU.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctcpumetric?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTCPUMetric;
);

extern_conformance!(
    unsafe impl NSCopying for XCTCPUMetric {}
);

unsafe impl CopyingHelper for XCTCPUMetric {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTCPUMetric {}
);

extern_conformance!(
    unsafe impl XCTMetric for XCTCPUMetric {}
);

impl XCTCPUMetric {
    extern_methods!(
        /// Creates a metric which will observe CPU activity for the thread that executes
        /// the block being measured. For single-threaded workloads, this provides greater
        /// precision and lower variance than -init.
        ///
        ///
        /// Note: The Thread under test is defined as the thread which will perform the execution of the work provided to the -[XCTestCase measure*] API.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(initLimitingToCurrentThread:))]
        #[unsafe(method_family = init)]
        pub fn initLimitingToCurrentThread(
            this: Allocated<Self>,
            limit_to_current_thread: bool,
        ) -> Retained<Self>;

        /// Creates a metric that will target the current process.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTCPUMetric {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTCPUMetric {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// A metric which measures utilization of physical memory.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctmemorymetric?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTMemoryMetric;
);

extern_conformance!(
    unsafe impl NSCopying for XCTMemoryMetric {}
);

unsafe impl CopyingHelper for XCTMemoryMetric {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTMemoryMetric {}
);

extern_conformance!(
    unsafe impl XCTMetric for XCTMemoryMetric {}
);

impl XCTMemoryMetric {
    extern_methods!(
        /// Creates a metric that will target the current process.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTMemoryMetric {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTMemoryMetric {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// A metric which measures utilization of the file storage media.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctstoragemetric?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTStorageMetric;
);

extern_conformance!(
    unsafe impl NSCopying for XCTStorageMetric {}
);

unsafe impl CopyingHelper for XCTStorageMetric {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTStorageMetric {}
);

extern_conformance!(
    unsafe impl XCTMetric for XCTStorageMetric {}
);

impl XCTStorageMetric {
    extern_methods!(
        /// Creates a metric that will target the current process.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTStorageMetric {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTStorageMetric {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_class!(
    /// A metric which measures the hitches encountered.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xcthitchmetric?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTHitchMetric;
);

extern_conformance!(
    unsafe impl NSCopying for XCTHitchMetric {}
);

unsafe impl CopyingHelper for XCTHitchMetric {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTHitchMetric {}
);

extern_conformance!(
    unsafe impl XCTMetric for XCTHitchMetric {}
);

impl XCTHitchMetric {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// Contains a file URL and line number representing a distinct location in source code related to a run of a test.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctsourcecodelocation?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTSourceCodeLocation;
);

extern_conformance!(
    unsafe impl NSCoding for XCTSourceCodeLocation {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTSourceCodeLocation {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTSourceCodeLocation {}
);

impl XCTSourceCodeLocation {
    extern_methods!(
        #[unsafe(method(initWithFileURL:lineNumber:))]
        #[unsafe(method_family = init)]
        pub fn initWithFileURL_lineNumber(
            this: Allocated<Self>,
            file_url: &NSURL,
            line_number: NSInteger,
        ) -> Retained<Self>;

        #[unsafe(method(initWithFilePath:lineNumber:))]
        #[unsafe(method_family = init)]
        pub fn initWithFilePath_lineNumber(
            this: Allocated<Self>,
            file_path: &NSString,
            line_number: NSInteger,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(fileURL))]
        #[unsafe(method_family = none)]
        pub fn fileURL(&self) -> Retained<NSURL>;

        #[unsafe(method(lineNumber))]
        #[unsafe(method_family = none)]
        pub fn lineNumber(&self) -> NSInteger;
    );
}

extern_class!(
    /// Contains symbolication information for a given frame in a call stack.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctsourcecodesymbolinfo?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTSourceCodeSymbolInfo;
);

extern_conformance!(
    unsafe impl NSCoding for XCTSourceCodeSymbolInfo {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTSourceCodeSymbolInfo {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTSourceCodeSymbolInfo {}
);

impl XCTSourceCodeSymbolInfo {
    extern_methods!(
        #[unsafe(method(initWithImageName:symbolName:location:))]
        #[unsafe(method_family = init)]
        pub fn initWithImageName_symbolName_location(
            this: Allocated<Self>,
            image_name: &NSString,
            symbol_name: &NSString,
            location: Option<&XCTSourceCodeLocation>,
        ) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(imageName))]
        #[unsafe(method_family = none)]
        pub fn imageName(&self) -> Retained<NSString>;

        #[unsafe(method(symbolName))]
        #[unsafe(method_family = none)]
        pub fn symbolName(&self) -> Retained<NSString>;

        #[unsafe(method(location))]
        #[unsafe(method_family = none)]
        pub fn location(&self) -> Option<Retained<XCTSourceCodeLocation>>;
    );
}

extern_class!(
    /// Represents a single frame in a call stack and supports retrieval of symbol information for the address.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctsourcecodeframe?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTSourceCodeFrame;
);

extern_conformance!(
    unsafe impl NSCoding for XCTSourceCodeFrame {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTSourceCodeFrame {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTSourceCodeFrame {}
);

impl XCTSourceCodeFrame {
    extern_methods!(
        #[unsafe(method(initWithAddress:symbolInfo:))]
        #[unsafe(method_family = init)]
        pub fn initWithAddress_symbolInfo(
            this: Allocated<Self>,
            address: u64,
            symbol_info: Option<&XCTSourceCodeSymbolInfo>,
        ) -> Retained<Self>;

        #[unsafe(method(initWithAddress:))]
        #[unsafe(method_family = init)]
        pub fn initWithAddress(this: Allocated<Self>, address: u64) -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(address))]
        #[unsafe(method_family = none)]
        pub fn address(&self) -> u64;

        #[unsafe(method(symbolInfo))]
        #[unsafe(method_family = none)]
        pub fn symbolInfo(&self) -> Option<Retained<XCTSourceCodeSymbolInfo>>;

        /// Error previously returned for symbolication attempt. This is not serialized when the frame is encoded.
        #[unsafe(method(symbolicationError))]
        #[unsafe(method_family = none)]
        pub fn symbolicationError(&self) -> Option<Retained<NSError>>;

        /// method -symbolInfoWithError:
        /// Attempts to get symbol information for the address. This can fail if required symbol data is not available. Only
        /// one attempt will be made and the error will be stored and returned for future requests.
        #[unsafe(method(symbolInfoWithError:_))]
        #[unsafe(method_family = none)]
        pub fn symbolInfoWithError(
            &self,
        ) -> Result<Retained<XCTSourceCodeSymbolInfo>, Retained<NSError>>;
    );
}

extern_class!(
    /// Call stack and optional specific location - which may or may not be also included in the call stack
    /// providing context around a point of execution in a test.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctsourcecodecontext?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTSourceCodeContext;
);

extern_conformance!(
    unsafe impl NSCoding for XCTSourceCodeContext {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTSourceCodeContext {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for XCTSourceCodeContext {}
);

impl XCTSourceCodeContext {
    extern_methods!(
        #[unsafe(method(initWithCallStack:location:))]
        #[unsafe(method_family = init)]
        pub fn initWithCallStack_location(
            this: Allocated<Self>,
            call_stack: &NSArray<XCTSourceCodeFrame>,
            location: Option<&XCTSourceCodeLocation>,
        ) -> Retained<Self>;

        /// The call stack addresses could be those from NSThread.callStackReturnAddresses,
        /// NSException.callStackReturnAddresses, or another source.
        #[unsafe(method(initWithCallStackAddresses:location:))]
        #[unsafe(method_family = init)]
        pub fn initWithCallStackAddresses_location(
            this: Allocated<Self>,
            call_stack_addresses: &NSArray<NSNumber>,
            location: Option<&XCTSourceCodeLocation>,
        ) -> Retained<Self>;

        /// Initializes a new instance with call stack derived from NSThread.callStackReturnAddresses and the specified location.
        #[unsafe(method(initWithLocation:))]
        #[unsafe(method_family = init)]
        pub fn initWithLocation(
            this: Allocated<Self>,
            location: Option<&XCTSourceCodeLocation>,
        ) -> Retained<Self>;

        /// Initializes a new instance with call stack derived from NSThread.callStackReturnAddresses and a nil location.
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(callStack))]
        #[unsafe(method_family = none)]
        pub fn callStack(&self) -> Retained<NSArray<XCTSourceCodeFrame>>;

        #[unsafe(method(location))]
        #[unsafe(method_family = none)]
        pub fn location(&self) -> Option<Retained<XCTSourceCodeLocation>>;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTSourceCodeContext {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTSourceCodeContext {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// Values returned by a waiter when it completes, times out, or is interrupted due to another waiter
/// higher in the call stack timing out.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctwaiterresult?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct XCTWaiterResult(pub NSInteger);
impl XCTWaiterResult {
    #[doc(alias = "XCTWaiterResultCompleted")]
    pub const Completed: Self = Self(1);
    #[doc(alias = "XCTWaiterResultTimedOut")]
    pub const TimedOut: Self = Self(2);
    #[doc(alias = "XCTWaiterResultIncorrectOrder")]
    pub const IncorrectOrder: Self = Self(3);
    #[doc(alias = "XCTWaiterResultInvertedFulfillment")]
    pub const InvertedFulfillment: Self = Self(4);
    #[doc(alias = "XCTWaiterResultInterrupted")]
    pub const Interrupted: Self = Self(5);
}

unsafe impl Encode for XCTWaiterResult {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for XCTWaiterResult {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Manages waiting - pausing the current execution context - for an array of XCTestExpectations. Waiters
    /// can be used with or without a delegate to respond to events such as completion, timeout, or invalid
    /// expectation fulfillment. XCTestCase conforms to the delegate protocol and will automatically report
    /// timeouts and other unexpected events as test failures.
    ///
    /// Waiters can be used without a delegate or any association with a test case instance. This allows test
    /// support libraries to provide convenience methods for waiting without having to pass test cases through
    /// those APIs.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctwaiter?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTWaiter;
);

unsafe impl Send for XCTWaiter {}

unsafe impl Sync for XCTWaiter {}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTWaiter {}
);

impl XCTWaiter {
    extern_methods!(
        /// Creates a new waiter with the specified delegate.
        #[unsafe(method(initWithDelegate:))]
        #[unsafe(method_family = init)]
        pub fn initWithDelegate(
            this: Allocated<Self>,
            delegate: Option<&ProtocolObject<dyn XCTWaiterDelegate>>,
        ) -> Retained<Self>;

        /// The waiter delegate will be called with various events described in
        /// <XCTWaiterDelegate
        /// >.
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub fn delegate(&self) -> Option<Retained<ProtocolObject<dyn XCTWaiterDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn XCTWaiterDelegate>>);

        /// Returns an array containing the expectations that were fulfilled, in that order, up until the waiter
        /// stopped waiting. Expectations fulfilled after the waiter stopped waiting will not be in the array.
        /// The array will be empty until the waiter has started waiting, even if expectations have already been
        /// fulfilled. If a waiter is used to wait multiple times, this array will contain all of the
        /// fulfilled expectations from each wait operation.
        #[unsafe(method(fulfilledExpectations))]
        #[unsafe(method_family = none)]
        pub fn fulfilledExpectations(&self) -> Retained<NSArray<XCTestExpectation>>;

        /// Waits on a group of expectations indefinitely.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// The test will continue to run until
        /// _expectations_are fulfilled or the
        /// test reaches its execution time allowance.
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// Enabling test timeouts is recommended when using this method to prevent a
        /// runaway expectation from hanging the test.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[unsafe(method(waitForExpectations:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations(
            &self,
            expectations: &NSArray<XCTestExpectation>,
        ) -> XCTWaiterResult;

        /// Waits on a group of expectations for up to the specified timeout.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `seconds`: The number of seconds within which all expectations must be fulfilled.
        ///
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[unsafe(method(waitForExpectations:timeout:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_timeout(
            &self,
            expectations: &NSArray<XCTestExpectation>,
            seconds: NSTimeInterval,
        ) -> XCTWaiterResult;

        /// Waits on a group of expectations indefinitely, optionally enforcing their
        /// order of fulfillment.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `enforceOrderOfFulfillment`: If
        /// `YES,`the expectations specified by the
        /// _expectations_parameter must
        /// be satisfied in the order they appear in the array.
        ///
        ///
        /// The test will continue to run until
        /// _expectations_are fulfilled or the
        /// test reaches its execution time allowance.
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// Enabling test timeouts is recommended when using this method to prevent a
        /// runaway expectation from hanging the test.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[unsafe(method(waitForExpectations:enforceOrder:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_enforceOrder(
            &self,
            expectations: &NSArray<XCTestExpectation>,
            enforce_order_of_fulfillment: bool,
        ) -> XCTWaiterResult;

        /// Waits on a group of expectations for up to the specified timeout, optionally
        /// enforcing their order of fulfillment.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `seconds`: The number of seconds within which all expectations must be fulfilled.
        ///
        ///
        /// Parameter `enforceOrderOfFulfillment`: If
        /// `YES,`the expectations specified by the
        /// _expectations_parameter must
        /// be satisfied in the order they appear in the array.
        ///
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[unsafe(method(waitForExpectations:timeout:enforceOrder:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_timeout_enforceOrder(
            &self,
            expectations: &NSArray<XCTestExpectation>,
            seconds: NSTimeInterval,
            enforce_order_of_fulfillment: bool,
        ) -> XCTWaiterResult;

        /// Creates a waiter that waits on a group of expectations indefinitely.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// The test will continue to run until
        /// _expectations_are fulfilled or the
        /// test reaches its execution time allowance.
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// Enabling test timeouts is recommended when using this method to prevent a
        /// runaway expectation from hanging the test.
        ///
        /// The waiter is discarded when the wait completes.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[must_use]
        #[unsafe(method(waitForExpectations:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_class(
            expectations: &NSArray<XCTestExpectation>,
        ) -> XCTWaiterResult;

        /// Creates a waiter that waits on a group of expectations for up to the
        /// specified timeout.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `seconds`: The number of seconds within which all expectations must be fulfilled.
        ///
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// The waiter is discarded when the wait completes.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[must_use]
        #[unsafe(method(waitForExpectations:timeout:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_timeout_class(
            expectations: &NSArray<XCTestExpectation>,
            seconds: NSTimeInterval,
        ) -> XCTWaiterResult;

        /// Creates a waiter that waits on a group of expectations indefinitely,
        /// optionally enforcing their order of fulfillment.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `enforceOrderOfFulfillment`: If
        /// `YES,`the expectations specified by the
        /// _expectations_parameter must
        /// be satisfied in the order they appear in the array.
        ///
        ///
        /// The test will continue to run until
        /// _expectations_are fulfilled or the
        /// test reaches its execution time allowance.
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// Enabling test timeouts is recommended when using this method to prevent a
        /// runaway expectation from hanging the test.
        ///
        /// The waiter is discarded when the wait completes.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[must_use]
        #[unsafe(method(waitForExpectations:enforceOrder:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_enforceOrder_class(
            expectations: &NSArray<XCTestExpectation>,
            enforce_order_of_fulfillment: bool,
        ) -> XCTWaiterResult;

        /// Creates a waiter that waits on a group of expectations for up to the
        /// specified timeout, optionally enforcing their order of fulfillment.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `seconds`: The number of seconds within which all expectations must be fulfilled.
        ///
        ///
        /// Parameter `enforceOrderOfFulfillment`: If
        /// `YES,`the expectations specified by the
        /// _expectations_parameter must
        /// be satisfied in the order they appear in the array.
        ///
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// The waiter is discarded when the wait completes.
        ///
        ///
        /// Returns: A value describing the outcome of waiting for
        /// _expectations._
        #[must_use]
        #[unsafe(method(waitForExpectations:timeout:enforceOrder:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_timeout_enforceOrder_class(
            expectations: &NSArray<XCTestExpectation>,
            seconds: NSTimeInterval,
            enforce_order_of_fulfillment: bool,
        ) -> XCTWaiterResult;
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTWaiter {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTWaiter {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_protocol!(
    /// Events are reported to the waiter's delegate via these methods. XCTestCase conforms to the delegate
    /// protocol and will automatically report timeouts and other unexpected events as test failures.
    ///
    ///
    /// Note: These methods are invoked on an arbitrary queue.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctwaiterdelegate?language=objc)
    pub unsafe trait XCTWaiterDelegate: NSObjectProtocol {
        /// Invoked when not all waited on expectations are fulfilled during the timeout period. If the delegate
        /// is an XCTestCase instance, this will be reported as a test failure.
        #[optional]
        #[unsafe(method(waiter:didTimeoutWithUnfulfilledExpectations:))]
        #[unsafe(method_family = none)]
        fn waiter_didTimeoutWithUnfulfilledExpectations(
            &self,
            waiter: &XCTWaiter,
            unfulfilled_expectations: &NSArray<XCTestExpectation>,
        );

        /// Invoked when the -wait call has specified that fulfillment order should be enforced and an expectation
        /// has been fulfilled in the wrong order. If the delegate is an XCTestCase instance, this will be reported
        /// as a test failure.
        #[optional]
        #[unsafe(method(waiter:fulfillmentDidViolateOrderingConstraintsForExpectation:requiredExpectation:))]
        #[unsafe(method_family = none)]
        fn waiter_fulfillmentDidViolateOrderingConstraintsForExpectation_requiredExpectation(
            &self,
            waiter: &XCTWaiter,
            expectation: &XCTestExpectation,
            required_expectation: &XCTestExpectation,
        );

        /// Invoked when an expectation marked as inverted (/see inverted) is fulfilled. If the delegate is an
        /// XCTestCase instance, this will be reported as a test failure.
        #[optional]
        #[unsafe(method(waiter:didFulfillInvertedExpectation:))]
        #[unsafe(method_family = none)]
        fn waiter_didFulfillInvertedExpectation(
            &self,
            waiter: &XCTWaiter,
            expectation: &XCTestExpectation,
        );

        /// Invoked when the waiter is interrupted prior to its expectations being fulfilled or timing out.
        /// This occurs when an "outer" waiter times out, resulting in any waiters nested inside it being
        /// interrupted to allow the call stack to quickly unwind.
        #[optional]
        #[unsafe(method(nestedWaiter:wasInterruptedByTimedOutWaiter:))]
        #[unsafe(method_family = none)]
        fn nestedWaiter_wasInterruptedByTimedOutWaiter(
            &self,
            waiter: &XCTWaiter,
            outer_waiter: &XCTWaiter,
        );
    }
);

extern_class!(
    /// Expectations represent specific conditions in asynchronous testing.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctestexpectation?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTestExpectation;
);

unsafe impl Send for XCTestExpectation {}

unsafe impl Sync for XCTestExpectation {}

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTestExpectation {}
);

impl XCTestExpectation {
    extern_methods!(
        /// Designated initializer, requires a nonnull description of the condition the expectation is checking.
        #[unsafe(method(initWithDescription:))]
        #[unsafe(method_family = init)]
        pub fn initWithDescription(
            this: Allocated<Self>,
            expectation_description: &NSString,
        ) -> Retained<Self>;

        /// The human readable string used to describe the expectation in log output and test reports.
        #[unsafe(method(expectationDescription))]
        #[unsafe(method_family = none)]
        pub fn expectationDescription(&self) -> Retained<NSString>;

        /// Setter for [`expectationDescription`][Self::expectationDescription].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setExpectationDescription:))]
        #[unsafe(method_family = none)]
        pub fn setExpectationDescription(&self, expectation_description: &NSString);

        /// If an expectation is set to have inverted behavior, then fulfilling it will have a similar effect that
        /// failing to fulfill a conventional expectation has, as handled by the waiter and its delegate. Furthermore,
        /// waiters that wait on an inverted expectation will allow the full timeout to elapse and not report
        /// timeout to the delegate if it is not fulfilled.
        #[unsafe(method(isInverted))]
        #[unsafe(method_family = none)]
        pub fn isInverted(&self) -> bool;

        /// Setter for [`isInverted`][Self::isInverted].
        #[unsafe(method(setInverted:))]
        #[unsafe(method_family = none)]
        pub fn setInverted(&self, inverted: bool);

        /// The expectedFulfillmentCount is the number of times -fulfill must be called on the expectation in order for it
        /// to report complete fulfillment to its waiter. By default, expectations have an expectedFufillmentCount of 1.
        /// This value must be greater than 0 and is not meaningful if combined with
        /// @
        /// inverted.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(expectedFulfillmentCount))]
        #[unsafe(method_family = none)]
        pub unsafe fn expectedFulfillmentCount(&self) -> NSUInteger;

        /// Setter for [`expectedFulfillmentCount`][Self::expectedFulfillmentCount].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setExpectedFulfillmentCount:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setExpectedFulfillmentCount(&self, expected_fulfillment_count: NSUInteger);

        /// If set, calls to fulfill() after the expectation has already been fulfilled - exceeding the fulfillment
        /// count - will raise. This is the legacy behavior of expectations created through APIs on XCTestCase
        /// but is not enabled for expectations created using XCTestExpectation initializers.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(assertForOverFulfill))]
        #[unsafe(method_family = none)]
        pub unsafe fn assertForOverFulfill(&self) -> bool;

        /// Setter for [`assertForOverFulfill`][Self::assertForOverFulfill].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setAssertForOverFulfill:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setAssertForOverFulfill(&self, assert_for_over_fulfill: bool);

        /// Call -fulfill to mark an expectation as having been met. It's an error to call -fulfill on an
        /// expectation more times than its `expectedFulfillmentCount` value specifies, or when the test case
        /// that vended the expectation has already completed. If `assertForOverFulfill` is set when either
        /// of these occur, -fulfill will raise an exception.
        #[unsafe(method(fulfill))]
        #[unsafe(method_family = none)]
        pub fn fulfill(&self);
    );
}

/// Methods declared on superclass `NSObject`.
impl XCTestExpectation {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for XCTestExpectation {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

/// A block to be invoked when a change is observed for the keyPath of the observed object.
///
///
/// Parameter `observedObject`: The observed object, provided to avoid block capture issues.
///
///
/// Parameter `change`: The KVO change dictionary.
///
///
/// Returns: Return YES if the expectation is fulfilled, NO if it is not.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xckeyvalueobservingexpectationhandler?language=objc)
#[cfg(feature = "block2")]
pub type XCKeyValueObservingExpectationHandler =
    *mut block2::DynBlock<dyn Fn(NonNull<AnyObject>, NonNull<NSDictionary>) -> Bool>;

extern_class!(
    /// Expectation subclass for waiting on a condition defined Key Value Observation of a key path for an object.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctkvoexpectation?language=objc)
    #[unsafe(super(XCTestExpectation, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTKVOExpectation;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTKVOExpectation {}
);

impl XCTKVOExpectation {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(initWithDescription:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDescription(
            this: Allocated<Self>,
            expectation_description: &NSString,
        ) -> Retained<Self>;

        /// Initializes an expectation that is fulfilled when a key value coding compliant change is made such
        /// that the specified key path of the observed object has the expected value.
        ///
        /// # Safety
        ///
        /// - `object` should be of the correct type.
        /// - `expected_value` should be of the correct type.
        #[unsafe(method(initWithKeyPath:object:expectedValue:options:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithKeyPath_object_expectedValue_options(
            this: Allocated<Self>,
            key_path: &NSString,
            object: &AnyObject,
            expected_value: Option<&AnyObject>,
            options: NSKeyValueObservingOptions,
        ) -> Retained<Self>;

        /// Initializes an expectation that is fulfilled when a key value coding compliant change is made such
        /// that the specified key path of the observed object has the expected value. The NSKeyValueObservingOptions
        /// passed for this initializer include NSKeyValueObservingOptionInitial, so the object/key path will be
        /// checked immediately. The options also include NSKeyValueObservingOptionNew and NSKeyValueObservingOptionOld,
        /// so if a handler is used the change dictionary passed to it will contain NSKeyValueChangeNewKey and
        /// NSKeyValueChangeOldKey entries.
        ///
        /// # Safety
        ///
        /// - `object` should be of the correct type.
        /// - `expected_value` should be of the correct type.
        #[unsafe(method(initWithKeyPath:object:expectedValue:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithKeyPath_object_expectedValue(
            this: Allocated<Self>,
            key_path: &NSString,
            object: &AnyObject,
            expected_value: Option<&AnyObject>,
        ) -> Retained<Self>;

        /// Convenience initializer that is fulfilled by any change to the specified key path of the observed object.
        /// The NSKeyValueObservingOptions passed for this initializer do not include NSKeyValueObservingOptionInitial
        /// since there is no value to check. If that behavior is desired in conjunction with a handler, use the
        /// designated initializer. The options do include NSKeyValueObservingOptionNew and NSKeyValueObservingOptionOld,
        /// so if a handler is used the change dictionary passed to it will contain NSKeyValueChangeNewKey and
        /// NSKeyValueChangeOldKey entries.
        ///
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(initWithKeyPath:object:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithKeyPath_object(
            this: Allocated<Self>,
            key_path: &NSString,
            object: &AnyObject,
        ) -> Retained<Self>;

        /// Returns the key path that is being monitored for the KVO change.
        #[unsafe(method(keyPath))]
        #[unsafe(method_family = none)]
        pub fn keyPath(&self) -> Retained<NSString>;

        /// Returns the object that is being monitored for the KVO change.
        #[unsafe(method(observedObject))]
        #[unsafe(method_family = none)]
        pub fn observedObject(&self) -> Retained<AnyObject>;

        /// Returns the value that the expectation is waiting for the observed object/key path to have.
        #[unsafe(method(expectedValue))]
        #[unsafe(method_family = none)]
        pub fn expectedValue(&self) -> Option<Retained<AnyObject>>;

        /// The KVO options used when the expectation registered for observation.
        #[unsafe(method(options))]
        #[unsafe(method_family = none)]
        pub fn options(&self) -> NSKeyValueObservingOptions;

        #[cfg(feature = "block2")]
        /// Allows the caller to install a special handler to do custom evaluation of the change to the value
        /// of the object/key path. If a handler is set, expectedValue will be ignored.
        ///
        /// # Safety
        ///
        /// The returned block must be sendable.
        #[unsafe(method(handler))]
        #[unsafe(method_family = none)]
        pub unsafe fn handler(&self) -> XCKeyValueObservingExpectationHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`handler`][Self::handler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[unsafe(method(setHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHandler(&self, handler: XCKeyValueObservingExpectationHandler);
    );
}

/// A block to be invoked when a notification matching the specified name is observed
/// from the object.
///
///
/// Parameter `notification`: The notification object.
///
///
/// Returns: Return YES if the expectation is fulfilled, NO if it is not.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xcnotificationexpectationhandler?language=objc)
#[cfg(feature = "block2")]
pub type XCNotificationExpectationHandler =
    *mut block2::DynBlock<dyn Fn(NonNull<NSNotification>) -> Bool>;

extern_class!(
    /// Expectation subclass for waiting on a condition defined by an NSNotification.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctnsnotificationexpectation?language=objc)
    #[unsafe(super(XCTestExpectation, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTNSNotificationExpectation;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTNSNotificationExpectation {}
);

impl XCTNSNotificationExpectation {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(initWithDescription:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDescription(
            this: Allocated<Self>,
            expectation_description: &NSString,
        ) -> Retained<Self>;

        /// Initializes an expectation that waits for an NSNotification to be posted by an optional object from
        /// a given notification center.
        ///
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(initWithName:object:notificationCenter:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_object_notificationCenter(
            this: Allocated<Self>,
            notification_name: &NSNotificationName,
            object: Option<&AnyObject>,
            notification_center: &NSNotificationCenter,
        ) -> Retained<Self>;

        /// Initializes an expectation that waits for an NSNotification to be posted by an optional object from
        /// the default notification center.
        ///
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(initWithName:object:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithName_object(
            this: Allocated<Self>,
            notification_name: &NSNotificationName,
            object: Option<&AnyObject>,
        ) -> Retained<Self>;

        /// Initializes an expectation that waits for an NSNotification to be posted by any object from
        /// the default notification center.
        #[unsafe(method(initWithName:))]
        #[unsafe(method_family = init)]
        pub fn initWithName(
            this: Allocated<Self>,
            notification_name: &NSNotificationName,
        ) -> Retained<Self>;

        /// Returns the name of the notification being waited on.
        #[unsafe(method(notificationName))]
        #[unsafe(method_family = none)]
        pub fn notificationName(&self) -> Retained<NSNotificationName>;

        /// Returns the object that will post the notification.
        #[unsafe(method(observedObject))]
        #[unsafe(method_family = none)]
        pub fn observedObject(&self) -> Option<Retained<AnyObject>>;

        /// Returns the notification center that is being used.
        #[unsafe(method(notificationCenter))]
        #[unsafe(method_family = none)]
        pub fn notificationCenter(&self) -> Retained<NSNotificationCenter>;

        #[cfg(feature = "block2")]
        /// Allows the caller to install a special handler to do custom evaluation of received notifications
        /// matching the specified object and notification center.
        ///
        /// # Safety
        ///
        /// The returned block must be sendable.
        #[unsafe(method(handler))]
        #[unsafe(method_family = none)]
        pub unsafe fn handler(&self) -> XCNotificationExpectationHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`handler`][Self::handler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[unsafe(method(setHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHandler(&self, handler: XCNotificationExpectationHandler);
    );
}

/// Handler called when evaluating the predicate against the object returns true. If the handler is not
/// provided the first successful evaluation will fulfill the expectation. If provided, the handler will
/// be queried each time the notification is received to determine whether the expectation should be fulfilled
/// or not.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xcpredicateexpectationhandler?language=objc)
#[cfg(feature = "block2")]
pub type XCPredicateExpectationHandler = *mut block2::DynBlock<dyn Fn() -> Bool>;

extern_class!(
    /// Expectation subclass for waiting on a condition defined by an NSPredicate and an object.
    ///
    /// When an instance of this class is used from Swift and is awaited using
    /// `fulfillment(of:)`rather than
    /// `wait(for:),`XCTest evaluates the associated predicate on the main actor.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctnspredicateexpectation?language=objc)
    #[unsafe(super(XCTestExpectation, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTNSPredicateExpectation;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTNSPredicateExpectation {}
);

impl XCTNSPredicateExpectation {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(initWithDescription:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDescription(
            this: Allocated<Self>,
            expectation_description: &NSString,
        ) -> Retained<Self>;

        /// Initializes an expectation that waits for a predicate to evaluate as true with the provided object.
        ///
        /// When an instance of this class is used from Swift and is awaited using
        /// `fulfillment(of:)`rather than
        /// `wait(for:),`XCTest evaluates
        /// _predicate_on the main actor.
        ///
        /// # Safety
        ///
        /// `object` should be of the correct type.
        #[unsafe(method(initWithPredicate:object:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithPredicate_object(
            this: Allocated<Self>,
            predicate: &NSPredicate,
            object: Option<&AnyObject>,
        ) -> Retained<Self>;

        /// Returns the predicate used by the expectation.
        #[unsafe(method(predicate))]
        #[unsafe(method_family = none)]
        pub fn predicate(&self) -> Retained<NSPredicate>;

        /// Returns the object against which the predicate is evaluated.
        #[unsafe(method(object))]
        #[unsafe(method_family = none)]
        pub fn object(&self) -> Option<Retained<AnyObject>>;

        #[cfg(feature = "block2")]
        /// Allows the caller to install a special handler to do custom evaluation of predicate and its object.
        ///
        /// # Safety
        ///
        /// The returned block must be sendable.
        #[unsafe(method(handler))]
        #[unsafe(method_family = none)]
        pub unsafe fn handler(&self) -> XCPredicateExpectationHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`handler`][Self::handler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[unsafe(method(setHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHandler(&self, handler: XCPredicateExpectationHandler);

        /// Unavailable on this class; XCTNSPredicateExpectation repeatedly evaluates its predicate until it becomes
        /// true. Once the predicate has become true, it is expected to remain true and will not be evaluated again.
        /// Setting expectedFulfillmentCount has no impact on fulfillment of the expectation.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(expectedFulfillmentCount))]
        #[unsafe(method_family = none)]
        pub unsafe fn expectedFulfillmentCount(&self) -> NSUInteger;

        /// Setter for [`expectedFulfillmentCount`][Self::expectedFulfillmentCount].
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(setExpectedFulfillmentCount:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setExpectedFulfillmentCount(&self, expected_fulfillment_count: NSUInteger);
    );
}

/// A block to be invoked when a call to -waitForExpectationsWithTimeout:handler: times out or has
/// had all associated expectations fulfilled.
///
///
/// Parameter `error`: If the wait timed out or a failure was raised while waiting, the error's code
/// will specify the type of failure. Otherwise error will be nil.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xcwaitcompletionhandler?language=objc)
#[cfg(feature = "block2")]
pub type XCWaitCompletionHandler = *mut block2::DynBlock<dyn Fn(*mut NSError)>;

/// AsynchronousTesting.
///
/// This category introduces support for asynchronous testing in XCTestCase. The mechanism
/// allows you to specify one or more "expectations" that will occur asynchronously
/// as a result of actions in the test. Once all expectations have been set, a "wait"
/// API is called that will block execution of subsequent test code until all expected
/// conditions have been fulfilled or a timeout occurs.
impl XCTestCase {
    extern_methods!(
        /// Parameter `description`: This string will be displayed in the test log to help diagnose failures.
        ///
        ///
        /// Creates and returns an expectation associated with the test case.
        #[must_use]
        #[unsafe(method(expectationWithDescription:))]
        #[unsafe(method_family = none)]
        pub fn expectationWithDescription(
            &self,
            description: &NSString,
        ) -> Retained<XCTestExpectation>;

        #[cfg(feature = "block2")]
        /// Parameter `timeout`: The amount of time within which all expectations must be fulfilled.
        ///
        ///
        /// Parameter `handler`: If provided, the handler will be invoked both on timeout or fulfillment of all
        /// expectations. Timeout is always treated as a test failure.
        ///
        ///
        /// -waitForExpectationsWithTimeout:handler: creates a point of synchronization in the flow of a
        /// test. Only one -waitForExpectationsWithTimeout:handler: can be active at any given time, but
        /// multiple discrete sequences of { expectations -> wait } can be chained together.
        ///
        /// -waitForExpectationsWithTimeout:handler: runs the run loop while handling events until all expectations
        /// are fulfilled or the timeout is reached. Clients should not manipulate the run
        /// loop while using this API.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[unsafe(method(waitForExpectationsWithTimeout:handler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn waitForExpectationsWithTimeout_handler(
            &self,
            timeout: NSTimeInterval,
            handler: XCWaitCompletionHandler,
            mtm: MainThreadMarker,
        );

        /// Waits on a group of expectations indefinitely.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// The test will continue to run until
        /// _expectations_are fulfilled or the
        /// test reaches its execution time allowance.
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// Enabling test timeouts is recommended when using this method to prevent a
        /// runaway expectation from hanging the test.
        #[unsafe(method(waitForExpectations:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations(&self, expectations: &NSArray<XCTestExpectation>);

        /// Waits on a group of expectations for up to the specified timeout.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `seconds`: The number of seconds within which all expectations must be fulfilled.
        ///
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        #[unsafe(method(waitForExpectations:timeout:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_timeout(
            &self,
            expectations: &NSArray<XCTestExpectation>,
            seconds: NSTimeInterval,
        );

        /// Waits on a group of expectations indefinitely, optionally enforcing their
        /// order of fulfillment.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `enforceOrderOfFulfillment`: If
        /// `YES,`the expectations specified by the
        /// _expectations_parameter must
        /// be satisfied in the order they appear in the array.
        ///
        ///
        /// The test will continue to run until
        /// _expectations_are fulfilled or the
        /// test reaches its execution time allowance.
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        ///
        /// Enabling test timeouts is recommended when using this method to prevent a
        /// runaway expectation from hanging the test.
        #[unsafe(method(waitForExpectations:enforceOrder:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_enforceOrder(
            &self,
            expectations: &NSArray<XCTestExpectation>,
            enforce_order_of_fulfillment: bool,
        );

        /// Waits on a group of expectations for up to the specified timeout, optionally
        /// enforcing their order of fulfillment.
        ///
        ///
        /// Parameter `expectations`: An array of expectations that must be fulfilled.
        ///
        ///
        /// Parameter `seconds`: The number of seconds within which all expectations must be fulfilled.
        ///
        ///
        /// Parameter `enforceOrderOfFulfillment`: If
        /// `YES,`the expectations specified by the
        /// _expectations_parameter must
        /// be satisfied in the order they appear in the array.
        ///
        ///
        /// Expectations can only appear in the list once. This method may return
        /// early based on fulfillment of the provided expectations.
        #[unsafe(method(waitForExpectations:timeout:enforceOrder:))]
        #[unsafe(method_family = none)]
        pub fn waitForExpectations_timeout_enforceOrder(
            &self,
            expectations: &NSArray<XCTestExpectation>,
            seconds: NSTimeInterval,
            enforce_order_of_fulfillment: bool,
        );

        /// A convenience method for asynchronous tests that use Key Value Observing to detect changes
        /// to values on an object. This variant takes an expected value and observes changes on the object
        /// until the keyPath's value matches the expected value using -[NSObject isEqual:]. If
        /// other comparisons are needed, use the variant below that takes a handler block.
        ///
        ///
        /// Parameter `objectToObserve`: The object to observe.
        ///
        ///
        /// Parameter `keyPath`: The key path to observe.
        ///
        ///
        /// Parameter `expectedValue`: Expected value of the keyPath for the object. The expectation will fulfill itself when the
        /// keyPath is equal, as tested using -[NSObject isEqual:]. If nil, the expectation will be
        /// fulfilled by the first change to the key path of the observed object.
        ///
        ///
        /// Returns: Creates and returns an expectation associated with the test case.
        ///
        /// # Safety
        ///
        /// - `object_to_observe` should be of the correct type.
        /// - `expected_value` should be of the correct type.
        #[unsafe(method(keyValueObservingExpectationForObject:keyPath:expectedValue:))]
        #[unsafe(method_family = none)]
        pub unsafe fn keyValueObservingExpectationForObject_keyPath_expectedValue(
            &self,
            object_to_observe: &AnyObject,
            key_path: &NSString,
            expected_value: Option<&AnyObject>,
        ) -> Retained<XCTestExpectation>;

        #[cfg(feature = "block2")]
        /// Variant of the convenience for tests that use Key Value Observing. Takes a handler
        /// block instead of an expected value. Every KVO change will run the handler block until
        /// it returns YES (or the wait times out). Returning YES from the block will fulfill the
        /// expectation. XCTAssert and related APIs can be used in the block to report a failure.
        ///
        ///
        /// Parameter `objectToObserve`: The object to observe.
        ///
        ///
        /// Parameter `keyPath`: The key path to observe.
        ///
        ///
        /// Parameter `handler`: Optional handler, /see XCKeyValueObservingExpectationHandler. If not provided, the expectation will
        /// be fulfilled by the first change to the key path of the observed object.
        ///
        ///
        /// Returns: Creates and returns an expectation associated with the test case.
        ///
        /// # Safety
        ///
        /// - `object_to_observe` should be of the correct type.
        /// - `handler` must be a valid pointer or null.
        #[unsafe(method(keyValueObservingExpectationForObject:keyPath:handler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn keyValueObservingExpectationForObject_keyPath_handler(
            &self,
            object_to_observe: &AnyObject,
            key_path: &NSString,
            handler: XCKeyValueObservingExpectationHandler,
        ) -> Retained<XCTestExpectation>;

        #[cfg(feature = "block2")]
        /// A convenience method for asynchronous tests that observe NSNotifications from the default
        /// NSNotificationCenter.
        ///
        ///
        /// Parameter `notificationName`: The notification to register for.
        ///
        ///
        /// Parameter `objectToObserve`: The object to observe.
        ///
        ///
        /// Parameter `handler`: Optional handler, /see XCNotificationExpectationHandler. If not provided, the expectation
        /// will be fulfilled by the first notification matching the specified name from the
        /// observed object.
        ///
        ///
        /// Returns: Creates and returns an expectation associated with the test case.
        ///
        /// # Safety
        ///
        /// - `object_to_observe` should be of the correct type.
        /// - `handler` must be a valid pointer or null.
        #[unsafe(method(expectationForNotification:object:handler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn expectationForNotification_object_handler(
            &self,
            notification_name: &NSNotificationName,
            object_to_observe: Option<&AnyObject>,
            handler: XCNotificationExpectationHandler,
        ) -> Retained<XCTestExpectation>;

        #[cfg(feature = "block2")]
        /// A convenience method for asynchronous tests that observe NSNotifications from a specific
        /// NSNotificationCenter.
        ///
        ///
        /// Parameter `notificationName`: The notification to register for.
        ///
        ///
        /// Parameter `objectToObserve`: The object to observe.
        ///
        ///
        /// Parameter `notificationCenter`: The notification center from which to observe the notification.
        ///
        ///
        /// Parameter `handler`: Optional handler, /see XCNotificationExpectationHandler. If not provided, the expectation
        /// will be fulfilled by the first notification matching the specified name from the
        /// observed object.
        ///
        ///
        /// Returns: Creates and returns an expectation associated with the test case.
        ///
        /// # Safety
        ///
        /// - `object_to_observe` should be of the correct type.
        /// - `handler` must be a valid pointer or null.
        #[unsafe(method(expectationForNotification:object:notificationCenter:handler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn expectationForNotification_object_notificationCenter_handler(
            &self,
            notification_name: &NSNotificationName,
            object_to_observe: Option<&AnyObject>,
            notification_center: &NSNotificationCenter,
            handler: XCNotificationExpectationHandler,
        ) -> Retained<XCTestExpectation>;

        #[cfg(feature = "block2")]
        /// Creates an expectation that is fulfilled if the predicate returns true when evaluated with the given
        /// object. The expectation periodically evaluates the predicate and also may use notifications or other
        /// events to optimistically re-evaluate.
        ///
        /// When the resulting expectation is used from Swift and is awaited using
        /// `fulfillment(of:)`rather
        /// than
        /// `wait(for:),`XCTest evaluates
        /// _predicate_on the main actor.
        ///
        /// # Safety
        ///
        /// - `object` should be of the correct type.
        /// - `handler` must be a valid pointer or null.
        #[unsafe(method(expectationForPredicate:evaluatedWithObject:handler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn expectationForPredicate_evaluatedWithObject_handler(
            &self,
            predicate: &NSPredicate,
            object: Option<&AnyObject>,
            handler: XCPredicateExpectationHandler,
        ) -> Retained<XCTestExpectation>;
    );
}

extern_conformance!(
    unsafe impl XCTWaiterDelegate for XCTestCase {}
);

/// Handler called when the expectation has received the Darwin notification. If the handler is not
/// provided the first posting of the notification will fulfill the expectation. If provided, the handler
/// will be queried each time the notification is received to determine whether the expectation should
/// be fulfilled or not. This allows the caller to check Darwin state variables or perform other logic
/// beyond simply verifying that the notification has been posted.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctdarwinnotificationexpectationhandler?language=objc)
#[cfg(feature = "block2")]
pub type XCTDarwinNotificationExpectationHandler = *mut block2::DynBlock<dyn Fn() -> Bool>;

extern_class!(
    /// Expectation subclass for waiting on a condition defined by a Darwin notification. The notification
    /// which may be posted in the same process or by other processes. Be aware that Darwin notifications
    /// may be coalesced when posted in quick succession, so be careful especially when using the
    /// `expectedFulfillmentCount` property with this class.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/xctest/xctdarwinnotificationexpectation?language=objc)
    #[unsafe(super(XCTestExpectation, NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct XCTDarwinNotificationExpectation;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for XCTDarwinNotificationExpectation {}
);

impl XCTDarwinNotificationExpectation {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(initWithDescription:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDescription(
            this: Allocated<Self>,
            expectation_description: &NSString,
        ) -> Retained<Self>;

        /// Initializes an expectation that waits for a Darwin notification to be posted.
        #[unsafe(method(initWithNotificationName:))]
        #[unsafe(method_family = init)]
        pub fn initWithNotificationName(
            this: Allocated<Self>,
            notification_name: &NSString,
        ) -> Retained<Self>;

        /// Returns the value of the notification name that was provided to the initializer.
        #[unsafe(method(notificationName))]
        #[unsafe(method_family = none)]
        pub fn notificationName(&self) -> Retained<NSString>;

        #[cfg(feature = "block2")]
        /// Allows the caller to install a special handler to do custom evaluation when the notification is posted.
        ///
        /// # Safety
        ///
        /// The returned block must be sendable.
        #[unsafe(method(handler))]
        #[unsafe(method_family = none)]
        pub unsafe fn handler(&self) -> XCTDarwinNotificationExpectationHandler;

        #[cfg(feature = "block2")]
        /// Setter for [`handler`][Self::handler].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        ///
        /// # Safety
        ///
        /// `handler` must be a valid pointer or null.
        #[unsafe(method(setHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHandler(&self, handler: XCTDarwinNotificationExpectationHandler);
    );
}

/// XCUIScreenshot_ConvenienceInitializers.
impl XCTAttachment {
    extern_methods!(
        #[cfg(feature = "objc2-xc-ui-automation")]
        /// Creates an attachment with a screenshot and the specified quality.
        #[unsafe(method(attachmentWithScreenshot:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithScreenshot(screenshot: &XCUIScreenshot) -> Retained<Self>;

        #[cfg(feature = "objc2-xc-ui-automation")]
        /// Creates an attachment with a screenshot and the specified quality.
        #[unsafe(method(attachmentWithScreenshot:quality:))]
        #[unsafe(method_family = none)]
        pub fn attachmentWithScreenshot_quality(
            screenshot: &XCUIScreenshot,
            quality: XCTImageQuality,
        ) -> Retained<Self>;
    );
}

/// XCUIApplication_LaunchTesting.
impl XCTestCase {
    extern_methods!(
        /// Determines whether the tests in this class should run multiple times, once for each of the target application's UI configurations.
        ///
        /// Returns false by default. If overridden in a UI test subclass to return true, each test in that
        /// class will run multiple times, once for each supported UI configuration of the default target application.
        ///
        /// Supported UI configurations are detected by Xcode according to the settings of the default target app
        /// for the UI test target and may include:
        ///
        /// - Appearances (e.g. light mode, dark mode)
        /// - Orientations (e.g. portrait, landscape)
        /// - Localizations (e.g. en_US, zh_CN)
        ///
        /// Given the above example, one UI configuration would be {dark mode, landscape, en_US}, another would be
        /// {light mode, portrait, zh_CN}, and so forth. The number of combinations determines the number of times each
        /// test will run. The UI configuration is used automatically when calling `XCUIApplication.launch()` in each test.
        #[unsafe(method(runsForEachTargetApplicationUIConfiguration))]
        #[unsafe(method_family = none)]
        pub fn runsForEachTargetApplicationUIConfiguration() -> bool;
    );
}

/// XCUIInterruptionMonitoring.
impl XCTestCase {
    extern_methods!(
        #[cfg(all(feature = "block2", feature = "objc2-xc-ui-automation"))]
        /// Adds a monitor to the test. Monitors are automatically removed at the end of the test or can be manually removed using -removeUIInterruptionMonitor:.
        /// Monitors are invoked in the reverse order in which they are added until one of the monitors returns true, indicating that it has handled the interruption.
        ///
        ///
        /// Parameter `handlerDescription`: Explanation of the behavior and purpose of this monitor, mainly used for debugging and analysis.
        ///
        ///
        /// Parameter `handler`: Handler block for asynchronous, non-deterministic interrupting UI such as alerts and other dialogs. Handlers should return true if they handled the UI, false if they did not.
        /// The handler is passed an XCUIElement representing the top level UI element for the alert.
        ///
        ///
        /// Returns: Returns an opaque token that can be used to remove the monitor.
        ///
        ///
        /// A "UI interruption" is any element which unexpectedly blocks access to an element with which a UI test is trying to interact. Interrupting elements are most commonly alerts,
        /// dialogs, or other windows, but can be of other types as well. Interruptions are unexpected or at least not deterministic: the appearance of an alert in direct response to
        /// a test action such as clicking a button is not an interruption and should not be handled using a UI interruption monitor. Instead, it's simply part of the UI and should be
        /// found using standard queries and interacted with using standard event methods. Note that some interruptions are part of the app's own UI, others are presented on
        /// behalf of system apps and services, so queries for these elements must be constructed with the right process at their root.
        ///
        /// Use a UI interruption monitor for alerts that appear unexpectedly or with non-deterministic timing. Monitors are not invoked simply by the appearance of an alert or similar
        /// UI, they are called when the presence of such UI interferes with actions the test is attempting to take. For example, consider the following sequence:
        ///
        /// - test taps button
        /// - app displays confirmation dialog
        ///
        /// In this case, the dialog that is presented can be anticipated by the test, so a UI interruption monitor should not be used. Instead, the sequence should look like:
        ///
        /// - test taps button
        /// - test constructs an XCUIElement for the dialog and uses XCUIElement.waitForExistence(timeout:) to wait for it to appear
        /// - app displays confirmation dialog
        /// - test synthesizes a tap for the appropriate button in the dialog
        /// - test continues execution
        ///
        /// There was no UI interruption in this example because every step was deterministic and known in advance. Note the use of XCUIElement.waitForExistence(timeout:) to deal with
        /// asynchronous delays in the display of the dialog.
        ///
        /// By contrast, consider the next sequence, where use of a UI interruption monitor is the correct solution:
        ///
        /// - test launches app
        /// - app initiates asynchronous network request
        /// - test interacts with app
        /// - network request completes, app decides to display a dialog to the user
        /// - dialog appears just as the test is about to tap on a button
        /// - the appearance of the dialog is not deterministic
        /// - the test can anticipate that the dialog might be displayed at some point, but not when
        /// - accordingly, the test has installed a UI interruption monitor that knows how to handle the network response dialog
        /// - when XCTest computes a hit point for the button, it discovers the dialog and treats it as "interrupting UI"
        /// - the previously installed UI interruption monitor is invoked
        /// - it handles the dialog
        /// - XCTest computes the hit point for the button and synthesizes the requested tap event
        /// - test execution continues...
        ///
        /// Monitors can be designed to be general or specific in how they handle interruptions. The simplest general approach might simply attempt to cancel/dismiss/close
        /// any interrupting dialog/alert/window without consideration for its contents or purpose. A more specific monitor might make decisions based on the UI and contents
        /// of the interruption. Tests may install multiple monitors, which will be invoked in reverse order of installation. If a more specific monitor wishes to be skipped for a
        /// given interruption, its handler can simply return false - the next monitor will be invoked, and so on, until one of them returns true, signifying that it has handled
        /// the interruption. In some cases, a default monitor may handle interruptions.
        #[unsafe(method(addUIInterruptionMonitorWithDescription:handler:))]
        #[unsafe(method_family = none)]
        pub fn addUIInterruptionMonitorWithDescription_handler(
            &self,
            handler_description: &NSString,
            handler: &block2::DynBlock<dyn Fn(NonNull<XCUIElement>) -> Bool>,
        ) -> Retained<ProtocolObject<dyn NSObjectProtocol>>;

        /// Removes a monitor using the token provided when it was added.
        ///
        ///
        /// Parameter `monitor`: The token representing the monitor returned from the call to addUIInterruptionMonitorWithDescription:handler: where it was registered.
        ///
        /// # Safety
        ///
        /// `monitor` should be of the correct type.
        #[unsafe(method(removeUIInterruptionMonitor:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeUIInterruptionMonitor(
            &self,
            monitor: &ProtocolObject<dyn NSObjectProtocol>,
        );
    );
}

/// UIAutomation.
impl XCTCPUMetric {
    extern_methods!(
        #[cfg(feature = "objc2-xc-ui-automation")]
        /// Creates a metric which will target the process described by the XCUIApplication instance.
        ///
        ///
        /// Parameter `application`: An instance of XCUIApplication which will be targeted to gather measurements.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(initWithApplication:))]
        #[unsafe(method_family = init)]
        pub fn initWithApplication(
            this: Allocated<Self>,
            application: &XCUIApplication,
        ) -> Retained<Self>;
    );
}

/// UIAutomation.
impl XCTMemoryMetric {
    extern_methods!(
        #[cfg(feature = "objc2-xc-ui-automation")]
        /// Creates a metric which will target the process described by the XCUIApplication instance.
        ///
        ///
        /// Parameter `application`: An instance of XCUIApplication which will be targeted to gather measurements.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(initWithApplication:))]
        #[unsafe(method_family = init)]
        pub fn initWithApplication(
            this: Allocated<Self>,
            application: &XCUIApplication,
        ) -> Retained<Self>;
    );
}

/// UIAutomation.
impl XCTStorageMetric {
    extern_methods!(
        #[cfg(feature = "objc2-xc-ui-automation")]
        /// Creates a metric which will target the process described by the XCUIApplication instance.
        ///
        ///
        /// Parameter `application`: An instance of XCUIApplication which will be targeted to gather measurements.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(initWithApplication:))]
        #[unsafe(method_family = init)]
        pub fn initWithApplication(
            this: Allocated<Self>,
            application: &XCUIApplication,
        ) -> Retained<Self>;
    );
}

/// UIAutomation.
impl XCTHitchMetric {
    extern_methods!(
        #[cfg(feature = "objc2-xc-ui-automation")]
        /// Creates a metric which will target the process described by the XCUIApplication instance.
        ///
        ///
        /// Parameter `application`: An instance of XCUIApplication which will be targeted to gather measurements.
        ///
        ///
        /// Returns: An initialized metric.
        #[unsafe(method(initWithApplication:))]
        #[unsafe(method_family = init)]
        pub fn initWithApplication(
            this: Allocated<Self>,
            application: &XCUIApplication,
        ) -> Retained<Self>;
    );
}