Skip to content

Commit 632590f

Browse files
committed
Add ImageOrientationTests
1 parent 6b418d6 commit 632590f

File tree

4 files changed

+164
-1
lines changed

4 files changed

+164
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// ImageTestsStub.c
3+
// OpenSwiftUISymbolDualTestsSupport
4+
5+
#include "OpenSwiftUIBase.h"
6+
7+
#if OPENSWIFTUI_TARGET_OS_DARWIN
8+
9+
#import <SymbolLocator.h>
10+
11+
DEFINE_SL_STUB_SLF(OpenSwiftUITestStub_ImageOrientationInitWithExifValue, SwiftUI, $s7SwiftUI5ImageV11OrientationO9exifValueAESgSi_tcfC);
12+
13+
#endif
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// ImageTests.swift
3+
// OpenSwiftUICoreTests
4+
5+
#if canImport(ImageIO)
6+
import ImageIO
7+
#endif
8+
@_spi(Private) import OpenSwiftUICore
9+
import Testing
10+
11+
struct ImageOrientationTests {
12+
@Test(arguments: [
13+
(Image.Orientation.up, 0),
14+
(Image.Orientation.upMirrored, 2),
15+
(Image.Orientation.down, 6),
16+
(Image.Orientation.downMirrored, 4),
17+
(Image.Orientation.left, 1),
18+
(Image.Orientation.leftMirrored, 3),
19+
(Image.Orientation.right, 7),
20+
(Image.Orientation.rightMirrored, 5),
21+
])
22+
func rawValue(_ orientation: Image.Orientation, _ expectedRawValue: Int) {
23+
#expect(orientation.rawValue == expectedRawValue)
24+
}
25+
26+
@Test(arguments: [
27+
(0, Image.Orientation.up),
28+
(1, Image.Orientation.left),
29+
(2, Image.Orientation.upMirrored),
30+
(3, Image.Orientation.leftMirrored),
31+
(4, Image.Orientation.downMirrored),
32+
(5, Image.Orientation.rightMirrored),
33+
(6, Image.Orientation.down),
34+
(7, Image.Orientation.right),
35+
])
36+
func initFromRawValue(_ rawValue: Int, _ expectedOrientation: Image.Orientation) {
37+
#expect(Image.Orientation(rawValue: UInt8(rawValue)) == expectedOrientation)
38+
}
39+
40+
@Test(arguments: [
41+
(1, Image.Orientation.up),
42+
(2, Image.Orientation.upMirrored),
43+
(3, Image.Orientation.down),
44+
(4, Image.Orientation.downMirrored),
45+
(5, Image.Orientation.leftMirrored),
46+
(6, Image.Orientation.right),
47+
(7, Image.Orientation.rightMirrored),
48+
(8, Image.Orientation.left),
49+
])
50+
func initFromExifValue(_ exifValue: Int, _ expectedOrientation: Image.Orientation) {
51+
#expect(Image.Orientation(exifValue: exifValue) == expectedOrientation)
52+
}
53+
54+
#if canImport(ImageIO)
55+
@Test(arguments: [
56+
(CGImagePropertyOrientation.up, Image.Orientation.up),
57+
(CGImagePropertyOrientation.upMirrored, Image.Orientation.upMirrored),
58+
(CGImagePropertyOrientation.down, Image.Orientation.down),
59+
(CGImagePropertyOrientation.downMirrored, Image.Orientation.downMirrored),
60+
(CGImagePropertyOrientation.leftMirrored, Image.Orientation.leftMirrored),
61+
(CGImagePropertyOrientation.right, Image.Orientation.right),
62+
(CGImagePropertyOrientation.rightMirrored, Image.Orientation.rightMirrored),
63+
(CGImagePropertyOrientation.left, Image.Orientation.left),
64+
])
65+
func initFromCGImagePropertyOrientation(
66+
_ cgImagePropertyOrientation: CGImagePropertyOrientation,
67+
_ expectedOrientation: Image.Orientation
68+
) {
69+
let orientation = Image.Orientation(exifValue: Int(cgImagePropertyOrientation.rawValue))
70+
#expect(orientation == expectedOrientation)
71+
}
72+
#endif
73+
}

Tests/OpenSwiftUISymbolDualTests/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ DEFINE_SL_STUB_SLF(OpenSwiftUITestStub_CGSizeHasZero, SwiftUI, $sSo6CGSizeV7Swif
88
99
```swift
1010
import SwiftUI
11-
import OpenSwiftUI
1211
1312
extension CGSize {
1413
var swiftUI_hasZero: Bool {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// ImageTests.swift
3+
// OpenSwiftUISymbolDualTests
4+
5+
#if canImport(SwiftUI, _underlyingVersion: 6.0.87)
6+
import ImageIO
7+
import SwiftUI
8+
import Testing
9+
10+
extension Image.Orientation {
11+
@_silgen_name("OpenSwiftUITestStub_ImageOrientationInitWithExifValue")
12+
init?(exifValue: Int)
13+
}
14+
15+
struct ImageOrientationTests {
16+
@Test(arguments: [
17+
(Image.Orientation.up, 0),
18+
(Image.Orientation.upMirrored, 2),
19+
(Image.Orientation.down, 6),
20+
(Image.Orientation.downMirrored, 4),
21+
(Image.Orientation.left, 1),
22+
(Image.Orientation.leftMirrored, 3),
23+
(Image.Orientation.right, 7),
24+
(Image.Orientation.rightMirrored, 5),
25+
])
26+
func rawValue(_ orientation: Image.Orientation, _ expectedRawValue: Int) {
27+
#expect(orientation.rawValue == expectedRawValue)
28+
}
29+
30+
@Test(arguments: [
31+
(0, Image.Orientation.up),
32+
(1, Image.Orientation.left),
33+
(2, Image.Orientation.upMirrored),
34+
(3, Image.Orientation.leftMirrored),
35+
(4, Image.Orientation.downMirrored),
36+
(5, Image.Orientation.rightMirrored),
37+
(6, Image.Orientation.down),
38+
(7, Image.Orientation.right),
39+
])
40+
func initFromRawValue(_ rawValue: Int, _ expectedOrientation: Image.Orientation) {
41+
#expect(Image.Orientation(rawValue: UInt8(rawValue)) == expectedOrientation)
42+
}
43+
44+
@Test(arguments: [
45+
(1, Image.Orientation.up),
46+
(2, Image.Orientation.upMirrored),
47+
(3, Image.Orientation.down),
48+
(4, Image.Orientation.downMirrored),
49+
(5, Image.Orientation.leftMirrored),
50+
(6, Image.Orientation.right),
51+
(7, Image.Orientation.rightMirrored),
52+
(8, Image.Orientation.left),
53+
])
54+
func initFromExifValue(_ exifValue: Int, _ expectedOrientation: Image.Orientation) {
55+
#expect(Image.Orientation(exifValue: exifValue) == expectedOrientation)
56+
}
57+
58+
#if canImport(ImageIO)
59+
@Test(arguments: [
60+
(CGImagePropertyOrientation.up, Image.Orientation.up),
61+
(CGImagePropertyOrientation.upMirrored, Image.Orientation.upMirrored),
62+
(CGImagePropertyOrientation.down, Image.Orientation.down),
63+
(CGImagePropertyOrientation.downMirrored, Image.Orientation.downMirrored),
64+
(CGImagePropertyOrientation.leftMirrored, Image.Orientation.leftMirrored),
65+
(CGImagePropertyOrientation.right, Image.Orientation.right),
66+
(CGImagePropertyOrientation.rightMirrored, Image.Orientation.rightMirrored),
67+
(CGImagePropertyOrientation.left, Image.Orientation.left),
68+
])
69+
func initFromCGImagePropertyOrientation(
70+
_ cgImagePropertyOrientation: CGImagePropertyOrientation,
71+
_ expectedOrientation: Image.Orientation
72+
) {
73+
let orientation = Image.Orientation(exifValue: Int(cgImagePropertyOrientation.rawValue))
74+
#expect(orientation == expectedOrientation)
75+
}
76+
#endif
77+
}
78+
#endif

0 commit comments

Comments
 (0)