import XCTest @testable import EPODWindowBar // GeometryTests checks the coordinate conversion between the Cocoa system and // the AX system. The tests use a primary screen height of 1000. The tests // cover the primary screen and a second screen above, below, and left of the // primary screen (spec section 7.10). final class GeometryTests: XCTestCase { private let primaryHeight: CGFloat = 1000 func testPrimaryScreenRect() { // A window sits at the bottom-left of the primary screen. let cocoa = CGRect(x: 0, y: 0, width: 100, height: 100) let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight) XCTAssertEqual(ax.origin.x, 0) XCTAssertEqual(ax.origin.y, 900) // 1000 - 100 XCTAssertEqual(ax.width, 100) XCTAssertEqual(ax.height, 100) } func testRoundTripPrimary() { let cocoa = CGRect(x: 10, y: 20, width: 300, height: 200) let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight) let back = Geometry.axToCocoa(ax, primaryHeight: primaryHeight) XCTAssertEqual(back, cocoa) } func testScreenAbovePrimary() { // A window above the primary top has a negative AX Y value. let cocoa = CGRect(x: 0, y: 1000, width: 100, height: 100) let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight) XCTAssertEqual(ax.origin.y, -100) // 1000 - 1100 } func testScreenBelowPrimary() { // A window below the primary bottom has an AX Y value past the height. let cocoa = CGRect(x: 0, y: -200, width: 100, height: 100) let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight) XCTAssertEqual(ax.origin.y, 1100) // 1000 - (-100) } func testScreenLeftKeepsX() { // A screen left of the primary has a negative X. The X value does not // change in the conversion. let cocoa = CGRect(x: -1440, y: 0, width: 100, height: 100) let ax = Geometry.cocoaToAX(cocoa, primaryHeight: primaryHeight) XCTAssertEqual(ax.origin.x, -1440) } func testCocoaYToAXTop() { let top = Geometry.cocoaYToAXTop(100, primaryHeight: primaryHeight) XCTAssertEqual(top, 900) } }