mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Consolidated four CoreGraphics execution tests
I don't see any reason to split the tests like this. I merged the tests into the biggest and best-organized test file. I also removed the `REQUIRES: OS=macosx` line and made some small adjustments to the test to make it cross-platform.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// RUN: %target-run-simple-swift
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: objc_interop
|
||||
// REQUIRES: OS=macosx
|
||||
|
||||
import CoreGraphics
|
||||
import Foundation
|
||||
import StdlibUnittest
|
||||
|
||||
let CoreGraphicsTests = TestSuite("CoreGraphics")
|
||||
@@ -26,37 +26,199 @@ CoreGraphicsTests.test("CGAffineTransform/Equatable") {
|
||||
// CGColor
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
func makeCGColor(
|
||||
red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat
|
||||
) -> CGColor {
|
||||
return CGColor(
|
||||
colorSpace: CGColorSpaceCreateDeviceRGB(),
|
||||
components: [red, green, blue, alpha])!
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGColor/Equatable") {
|
||||
checkEquatable([
|
||||
CGColor(red: 1, green: 0, blue: 0, alpha: 1),
|
||||
CGColor(red: 1, green: 0, blue: 0, alpha: 0),
|
||||
CGColor(red: 0, green: 1, blue: 0, alpha: 1),
|
||||
CGColor(red: 0, green: 1, blue: 0, alpha: 0),
|
||||
CGColor(red: 0, green: 0, blue: 1, alpha: 1),
|
||||
CGColor(red: 0, green: 0, blue: 1, alpha: 0),
|
||||
makeCGColor(red: 1, green: 0, blue: 0, alpha: 1),
|
||||
makeCGColor(red: 1, green: 0, blue: 0, alpha: 0),
|
||||
makeCGColor(red: 0, green: 1, blue: 0, alpha: 1),
|
||||
makeCGColor(red: 0, green: 1, blue: 0, alpha: 0),
|
||||
makeCGColor(red: 0, green: 0, blue: 1, alpha: 1),
|
||||
makeCGColor(red: 0, green: 0, blue: 1, alpha: 0),
|
||||
] as [CGColor],
|
||||
oracle: { $0 == $1 })
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGColor.components") {
|
||||
let red = CGColor(red: 1, green: 0, blue: 0, alpha: 1)
|
||||
let components = red.components!
|
||||
expectEqual(components.count, 4)
|
||||
expectEqual(components[0], 1)
|
||||
expectEqual(components[1], 0)
|
||||
expectEqual(components[2], 0)
|
||||
expectEqual(components[3], 1)
|
||||
let red = makeCGColor(red: 1, green: 0, blue: 0, alpha: 1)
|
||||
expectEqual([1, 0, 0, 1], red.components)
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGColor/ExpressibleByColorLiteral") {
|
||||
let colorLit: CGColor = #colorLiteral(red: 0.25, green: 0.5, blue: 0.75,
|
||||
alpha: 1.0)
|
||||
let components = colorLit.components!
|
||||
expectEqual(components.count, 4)
|
||||
expectEqual(components[0], 0.25)
|
||||
expectEqual(components[1], 0.50)
|
||||
expectEqual(components[2], 0.75)
|
||||
expectEqual(components[3], 1.0)
|
||||
CoreGraphicsTests.test("CGColor/_ExpressibleByColorLiteral") {
|
||||
let color: CGColor = #colorLiteral(
|
||||
red: 0.5, green: 0.5, blue: 0.5, alpha: 1.0)
|
||||
expectEqual([0.5, 0.5, 0.5, 1.0], color.components)
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGColor/description") {
|
||||
expectTrue(String(describing: makeCGColor(red: 1, green: 0, blue: 0, alpha: 1)).contains("1 0 0 1"))
|
||||
#if os(macOS)
|
||||
expectTrue(String(describing: CGColor.black).contains("Generic Gray Profile"))
|
||||
expectTrue(String(describing: CGColor.white).contains("Generic Gray Profile"))
|
||||
expectTrue(String(describing: CGColor.clear).contains("Generic Gray Profile"))
|
||||
#endif
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// CGEventMouseSubtype
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if os(macOS)
|
||||
CoreGraphicsTests.test("CGEventMouseSubtype.rawValue") {
|
||||
expectEqual(CGEventMouseSubtype.defaultType.rawValue, 0)
|
||||
expectEqual(CGEventMouseSubtype.tabletPoint.rawValue, 1)
|
||||
}
|
||||
#endif
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// CGEventSourceStateID
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if os(macOS)
|
||||
CoreGraphicsTests.test("CGEventSourceStateID.rawValue") {
|
||||
expectEqual(CGEventSourceStateID.privateState.rawValue, -1)
|
||||
expectEqual(CGEventSourceStateID.combinedSessionState.rawValue, 0)
|
||||
}
|
||||
#endif
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// CGEventTapOptions
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if os(macOS)
|
||||
CoreGraphicsTests.test("CGEventTapOptions.rawValue") {
|
||||
expectEqual(CGEventTapOptions.defaultTap.rawValue, 0)
|
||||
expectEqual(CGEventTapOptions.listenOnly.rawValue, 1)
|
||||
}
|
||||
#endif
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// CGFloat
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/literals") {
|
||||
var flt: CGFloat = 4.125
|
||||
expectEqual(4.125, flt)
|
||||
|
||||
flt = 42
|
||||
expectEqual(42, flt)
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/init") {
|
||||
expectEqual(0.0, CGFloat())
|
||||
expectEqual(4.125, CGFloat(Float(4.125)))
|
||||
expectEqual(4.125, CGFloat(Double(4.125)))
|
||||
expectEqual(4.125, CGFloat(CGFloat(Double(4.125))))
|
||||
|
||||
expectEqual(42, CGFloat(Int(42)))
|
||||
expectEqual(42, CGFloat(Int8(42)))
|
||||
expectEqual(42, CGFloat(Int16(42)))
|
||||
expectEqual(42, CGFloat(Int32(42)))
|
||||
expectEqual(42, CGFloat(Int64(42)))
|
||||
expectEqual(42, CGFloat(UInt(42)))
|
||||
expectEqual(42, CGFloat(UInt8(42)))
|
||||
expectEqual(42, CGFloat(UInt16(42)))
|
||||
expectEqual(42, CGFloat(UInt32(42)))
|
||||
expectEqual(42, CGFloat(UInt64(42)))
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/initOtherTypesFromCGFloat") {
|
||||
let flt: CGFloat = 4.125
|
||||
|
||||
expectEqual(4.125, Float(flt))
|
||||
expectEqual(4.125, Double(flt))
|
||||
|
||||
expectEqual(4, Int(flt))
|
||||
expectEqual(4, Int8(flt))
|
||||
expectEqual(4, Int16(flt))
|
||||
expectEqual(4, Int32(flt))
|
||||
expectEqual(4, Int64(flt))
|
||||
expectEqual(4, UInt(flt))
|
||||
expectEqual(4, UInt8(flt))
|
||||
expectEqual(4, UInt16(flt))
|
||||
expectEqual(4, UInt32(flt))
|
||||
expectEqual(4, UInt64(flt))
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/comparisons") {
|
||||
let instances: [CGFloat] = [ 2.71, 3.14 ]
|
||||
|
||||
checkHashable(instances, equalityOracle: { $0 == $1 })
|
||||
|
||||
checkComparable(instances, oracle: { $0 <=> $1 })
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/arithmetic") {
|
||||
let x: CGFloat = 0.25
|
||||
let y: CGFloat = 4
|
||||
|
||||
expectEqual(4.25, x + y)
|
||||
expectEqual(-3.75, x - y)
|
||||
expectEqual(1.0, x * y)
|
||||
expectEqual(0.0625, x / y)
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/striding") {
|
||||
do {
|
||||
var result = [CGFloat]()
|
||||
for f in stride(from: (1.0 as CGFloat), to: 2.0, by: 0.5) {
|
||||
result.append(f)
|
||||
}
|
||||
expectEqual([ 1.0, 1.5 ], result)
|
||||
}
|
||||
|
||||
do {
|
||||
var result = [CGFloat]()
|
||||
for f in stride(from: (1.0 as CGFloat), through: 2.0, by: 0.5) {
|
||||
result.append(f)
|
||||
}
|
||||
expectEqual([ 1.0, 1.5, 2.0 ], result)
|
||||
}
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/bridging") {
|
||||
// Bridging to NSNumber.
|
||||
do {
|
||||
let flt: CGFloat = 4.125
|
||||
|
||||
// CGFloat -> NSNumber conversion.
|
||||
let nsnum: NSNumber = flt as NSNumber
|
||||
expectEqual("4.125", "\(nsnum)")
|
||||
|
||||
// NSNumber -> CGFloat
|
||||
let bridgedBack: CGFloat = nsnum as! CGFloat
|
||||
expectEqual(flt, bridgedBack)
|
||||
}
|
||||
|
||||
// Array bridging.
|
||||
do {
|
||||
let originalArray: [CGFloat] = [ 4.125, 10.625 ]
|
||||
|
||||
// Array -> NSArray
|
||||
let nsarr: NSArray = originalArray as NSArray
|
||||
expectEqual(2, nsarr.count)
|
||||
expectEqual("4.125", "\(nsarr[0])")
|
||||
expectEqual("10.625", "\(nsarr[1])")
|
||||
|
||||
// NSArray -> Array
|
||||
expectEqualSequence(originalArray, nsarr as! [CGFloat])
|
||||
}
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGFloat/varargs") {
|
||||
expectEqual(
|
||||
"0.023230", NSString(format: "%.6f", CGFloat(0.02323) as CVarArg))
|
||||
expectEqual(
|
||||
"0.123450", NSString(format: "%.6f", CGFloat(0.12345) as CVarArg))
|
||||
expectEqual(
|
||||
"1.234560", NSString(format: "%.6f", CGFloat(1.23456) as CVarArg))
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -75,9 +237,9 @@ CoreGraphicsTests.test("CGPoint/Equatable") {
|
||||
CGPoint(x: 1, y: 0),
|
||||
CGPoint(x: 0, y: 1),
|
||||
|
||||
CGPoint(x: 1.nextUp, y: 1.nextUp),
|
||||
CGPoint(x: 1.nextUp, y: 0),
|
||||
CGPoint(x: 0, y: 1.nextUp),
|
||||
CGPoint(x: CGFloat(1).nextUp, y: CGFloat(1).nextUp),
|
||||
CGPoint(x: CGFloat(1).nextUp, y: 0),
|
||||
CGPoint(x: 0, y: CGFloat(1).nextUp),
|
||||
|
||||
CGPoint(x: CGFloat.greatestFiniteMagnitude, y: 0),
|
||||
] as [CGPoint],
|
||||
@@ -142,9 +304,9 @@ CoreGraphicsTests.test("CGSize/Equatable") {
|
||||
CGSize(width: 1, height: 0),
|
||||
CGSize(width: 0, height: 1),
|
||||
|
||||
CGSize(width: 1.nextUp, height: 1.nextUp),
|
||||
CGSize(width: 1.nextUp, height: 0),
|
||||
CGSize(width: 0, height: 1.nextUp),
|
||||
CGSize(width: CGFloat(1).nextUp, height: CGFloat(1).nextUp),
|
||||
CGSize(width: CGFloat(1).nextUp, height: 0),
|
||||
CGSize(width: 0, height: CGFloat(1).nextUp),
|
||||
|
||||
CGSize(width: CGFloat.greatestFiniteMagnitude, height: 0),
|
||||
] as [CGSize],
|
||||
@@ -315,8 +477,8 @@ CoreGraphicsTests.test("CGRect.divided()") {
|
||||
}
|
||||
|
||||
CoreGraphicsTests.test("CGRect.standardized") {
|
||||
var unstandard = CGRect(x: 10, y: 20, width: -30, height: -50)
|
||||
var standard = unstandard.standardized
|
||||
let unstandard = CGRect(x: 10, y: 20, width: -30, height: -50)
|
||||
let standard = unstandard.standardized
|
||||
|
||||
expectEqual(CGPoint(x: 10, y: 20), unstandard.origin)
|
||||
expectEqual(CGPoint(x: -20, y: -30), standard.origin)
|
||||
@@ -398,7 +560,7 @@ CoreGraphicsTests.test("CGRect.intersection(_:)") {
|
||||
let bigRect = CGRect(x: 1, y: 2, width: 101, height: 102)
|
||||
let distantRect = CGRect(x: 1000, y: 2000, width: 1, height: 1)
|
||||
|
||||
var rect = CGRect(x: 11.25, y: 22.25, width: 33.25, height: 44.25)
|
||||
let rect = CGRect(x: 11.25, y: 22.25, width: 33.25, height: 44.25)
|
||||
|
||||
expectTrue(rect.intersects(smallRect))
|
||||
expectEqual(
|
||||
@@ -443,9 +605,9 @@ CoreGraphicsTests.test("CGVector/Equatable") {
|
||||
CGVector(dx: 1, dy: 0),
|
||||
CGVector(dx: 0, dy: 1),
|
||||
|
||||
CGVector(dx: 1.nextUp, dy: 1.nextUp),
|
||||
CGVector(dx: 1.nextUp, dy: 0),
|
||||
CGVector(dx: 0, dy: 1.nextUp),
|
||||
CGVector(dx: CGFloat(1).nextUp, dy: CGFloat(1).nextUp),
|
||||
CGVector(dx: CGFloat(1).nextUp, dy: 0),
|
||||
CGVector(dx: 0, dy: CGFloat(1).nextUp),
|
||||
|
||||
CGVector(dx: CGFloat.greatestFiniteMagnitude, dy: 0),
|
||||
] as [CGVector],
|
||||
|
||||
Reference in New Issue
Block a user