Skip to content

Commit 3adfa01

Browse files
committed
Add COpenSwiftUICoreTests Shims Tests
1 parent a93fef3 commit 3adfa01

File tree

8 files changed

+231
-6
lines changed

8 files changed

+231
-6
lines changed

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ let openSwiftUIExtensionTarget = Target.target(
112112
swiftSettings: sharedSwiftSettings
113113
)
114114
let cOpenSwiftUICoreTestTarget = Target.testTarget(
115-
name: "cOpenSwiftUICoreTests",
115+
name: "COpenSwiftUICoreTests",
116116
dependencies: [
117117
"COpenSwiftUICore",
118+
// For ProtocolDescriptor symbol linking
119+
"OpenSwiftUI",
118120
],
119121
exclude: ["README.md"],
120122
swiftSettings: sharedSwiftSettings

Sources/COpenSwiftUICore/Shims/CoreFoundation_Private.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// CoreFoundation_Private.c
3-
// COpenSwiftUI
3+
// COpenSwiftUICore
44

55
#include "CoreFoundation_Private.h"
66
#include "dyld_Private.h"

Sources/COpenSwiftUICore/Shims/CoreFoundation_Private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// CoreFoundation_Private.h
3-
// COpenSwiftUI
3+
// COpenSwiftUICore
44

55
#ifndef CoreFoundation_Private_h
66
#define CoreFoundation_Private_h

Sources/COpenSwiftUICore/Shims/dyld_Private.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// dyld_Private.c
3-
// COpenSwiftUI
3+
// COpenSwiftUICore
44

55
#include "dyld_Private.h"
66

Sources/COpenSwiftUICore/Shims/dyld_Private.h

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//
22
// dyld_Private.h
3-
// OpenSwiftUI
3+
// COpenSwiftUICore
44
//
5-
// Audited for RELEASE_2021
5+
// Audited for RELEASE_2024
66
// Status: Complete
77

88
#ifndef dyld_Private_h
@@ -12,6 +12,66 @@
1212

1313
typedef uint32_t dyld_platform_t;
1414

15+
typedef OPENSWIFTUI_ENUM(dyld_platform_t, DyldPlatform) {
16+
unknown = 0,
17+
macOS = 1,
18+
iOS = 2,
19+
tvOS = 3,
20+
watchOS = 4,
21+
bridgeOS = 5,
22+
macCatalyst = 6,
23+
iOSSimulator = 7,
24+
tvOSSimulator = 8,
25+
watchOSSimulator = 9,
26+
driverKit = 10,
27+
xROS = 11,
28+
xROSSimulator = 12,
29+
};
30+
31+
typedef OPENSWIFTUI_ENUM(uint32_t, DyldMacOSXVersion) {
32+
V10_4 = 0x000A0400,
33+
V10_5 = 0x000A0500,
34+
V10_6 = 0x000A0600,
35+
V10_7 = 0x000A0700,
36+
V10_8 = 0x000A0800,
37+
V10_9 = 0x000A0900,
38+
V10_10 = 0x000A0A00,
39+
V10_11 = 0x000A0B00,
40+
V10_12 = 0x000A0C00,
41+
V10_13 = 0x000A0D00,
42+
V10_14 = 0x000A0E00,
43+
V10_15 = 0x000A0F00,
44+
V15_0 = 0x000F0000,
45+
/// For Test Only
46+
V16_0 = 0x00100000,
47+
};
48+
49+
typedef OPENSWIFTUI_ENUM(uint32_t, DyldIOSVersion) {
50+
V2_0 = 0x00020000,
51+
V2_1 = 0x00020100,
52+
V2_2 = 0x00020200,
53+
V3_0 = 0x00030000,
54+
V3_1 = 0x00030100,
55+
V3_2 = 0x00030200,
56+
V4_0 = 0x00040000,
57+
V4_1 = 0x00040100,
58+
V4_2 = 0x00040200,
59+
V4_3 = 0x00040300,
60+
V5_0 = 0x00050000,
61+
V5_1 = 0x00050100,
62+
V6_0 = 0x00060000,
63+
V6_1 = 0x00060100,
64+
V7_0 = 0x00070000,
65+
V7_1 = 0x00070100,
66+
V8_0 = 0x00080000,
67+
V8_1 = 0x00080100,
68+
V8_2 = 0x00080200,
69+
V9_0 = 0x00090000,
70+
V18_0 = 0x00120000,
71+
/// For Test Only
72+
V19_0 = 0x00130000,
73+
};
74+
1575
typedef struct {
1676
dyld_platform_t platform;
1777
uint32_t version;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// CoreFoundationPrivateTests.swift
3+
// COpenSwiftUICoreTests
4+
5+
import COpenSwiftUICore
6+
import Testing
7+
8+
struct CoreFoundationPrivateTests {
9+
@Test
10+
func CFMZEnabled() {
11+
let result = _CFMZEnabled()
12+
#if canImport(Darwin)
13+
#if targetEnvironment(macCatalyst)
14+
#expect(result == true)
15+
#elseif targetEnvironment(simulator)
16+
#expect(result == false)
17+
#else
18+
#if os(iOS)
19+
#expect(result == true)
20+
#else
21+
#expect(result == false)
22+
#endif
23+
#endif
24+
#else
25+
#expect(result == false)
26+
#endif
27+
}
28+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// DyldPrivateTests.swift
3+
// COpenSwiftUICoreTests
4+
5+
import COpenSwiftUICore
6+
import Testing
7+
8+
struct DyldPrivateTests {
9+
@Test
10+
func sdkAtLeastVersion() {
11+
#if canImport(Darwin)
12+
#expect(dyld_program_sdk_at_least(.init(
13+
platform: dyld_get_active_platform(),
14+
version: .max
15+
)) == false)
16+
#expect(dyld_program_sdk_at_least(.init(
17+
platform: dyld_get_active_platform(),
18+
version: .min
19+
)) == true)
20+
21+
#if os(iOS)
22+
if #unavailable(iOS 19) {
23+
#expect(dyld_program_sdk_at_least(.init(
24+
platform: dyld_get_active_platform(),
25+
version: DyldIOSVersion.V19_0.rawValue
26+
)) == false)
27+
if #unavailable(iOS 18) {
28+
#expect(dyld_program_sdk_at_least(.init(
29+
platform: dyld_get_active_platform(),
30+
version: DyldIOSVersion.V18_0.rawValue
31+
)) == false)
32+
} else {
33+
#expect(dyld_program_sdk_at_least(.init(
34+
platform: dyld_get_active_platform(),
35+
version: DyldIOSVersion.V18_0.rawValue
36+
)) == true)
37+
}
38+
} else {
39+
#expect(dyld_program_sdk_at_least(.init(
40+
platform: dyld_get_active_platform(),
41+
version: DyldIOSVersion.V19_0.rawValue
42+
)) == true)
43+
}
44+
#elseif os(macOS)
45+
if #unavailable(macOS 16) {
46+
#expect(dyld_program_sdk_at_least(.init(
47+
platform: dyld_get_active_platform(),
48+
version: DyldMacOSXVersion.V16_0.rawValue
49+
)) == false)
50+
if #unavailable(macOS 15) {
51+
#expect(dyld_program_sdk_at_least(.init(
52+
platform: dyld_get_active_platform(),
53+
version: DyldMacOSXVersion.V15_0.rawValue
54+
)) == false)
55+
} else {
56+
#expect(dyld_program_sdk_at_least(.init(
57+
platform: dyld_get_active_platform(),
58+
version: DyldMacOSXVersion.V15_0.rawValue
59+
)) == true)
60+
}
61+
} else {
62+
#expect(dyld_program_sdk_at_least(.init(
63+
platform: dyld_get_active_platform(),
64+
version: DyldMacOSXVersion.V16_0.rawValue
65+
)) == true)
66+
}
67+
#else
68+
fatalError("Unsupported Darwin platform")
69+
#endif
70+
71+
#else
72+
#expect(dyld_program_sdk_at_least(.init(
73+
platform: dyld_get_active_platform(),
74+
version: .max
75+
)) == true)
76+
#expect(dyld_program_sdk_at_least(.init(
77+
platform: dyld_get_active_platform(),
78+
version: .min
79+
)) == true)
80+
#endif
81+
}
82+
83+
@Test
84+
func activePlatform() throws {
85+
let platform = try #require(DyldPlatform(rawValue: dyld_get_active_platform()))
86+
#if canImport(Darwin)
87+
#if targetEnvironment(macCatalyst)
88+
#expect(platform == .macCatalyst)
89+
#elseif targetEnvironment(simulator)
90+
#if os(iOS)
91+
#expect(platform == .iOSSimulator)
92+
#elseif os(tvOS)
93+
#expect(platform == .tvOSSimulator)
94+
#elseif os(watchOS)
95+
#expect(platform == .watchOSSimulator)
96+
#elseif os(visionOS)
97+
#expect(platform == .xROSSimulator)
98+
#else
99+
fatalError("Unsupported Darwin simulator platform")
100+
#endif
101+
#else
102+
#if os(iOS)
103+
#expect(platform == .iOS)
104+
#elseif os(macOS)
105+
#expect(platform == .macOS)
106+
#elseif os(tvOS)
107+
#expect(platform == .tvOS)
108+
#elseif os(watchOS)
109+
#expect(platform == .watchOS)
110+
#elseif os(visionOS)
111+
#expect(platform == .xROS)
112+
#else
113+
fatalError("Unsupported Darwin platform")
114+
#endif
115+
#endif
116+
#else
117+
#expect(platform == .unknown)
118+
#endif
119+
}
120+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// KDebugPrivateTests.swift
3+
// COpenSwiftUICoreTests
4+
5+
import COpenSwiftUICore
6+
import Testing
7+
8+
#if canImport(Darwin)
9+
struct KDebugPrivateTests {
10+
@Test
11+
func enable() {
12+
#expect(kdebug_is_enabled(0) == false)
13+
}
14+
}
15+
#endif

0 commit comments

Comments
 (0)