SPB Git

Repository Public

KAMultiTouchTests.swift 9.7 KB 205 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : KA Maps Engine9// File             : sdk/ios/Example/UITests/KAMultiTouchTests.swift10// Module           : sdk11// Repository       : https://git.spboucher.ai/ka-maps-engine12// Created          : 2026-12-0113// Last Modified    : 2026-12-0114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : None specified (no license file in this repository)80// Maintainer       : Simon-Pierre Boucher81// Technical Contact: dev@spboucher.ai82//83// =============================================================================84// END OF SP BOUCHER SOURCE HEADER85// =============================================================================8687import XCTest8889/// Gestes que l'API publique d'XCUITest ne sait pas produire : inclinaison à deux doigts, zoom à un doigt90/// (double toucher puis glisser), pincement et rotation simultanés. Les séquences tactiles (une trajectoire91/// horodatée par doigt) sont injectées comme de vrais touchers et traversent les reconnaisseurs du SDK.92@MainActor93final class KAMultiTouchTests: XCTestCase {94    override func setUp() {95        continueAfterFailure = false96        XCUIDevice.shared.orientation = .portrait97    }9899    private func hud(_ app: XCUIApplication) -> (zoom: Double, pitch: Double, bearing: Double) {100        let label = app.descendants(matching: .any)["hud"].label101        let nums = label.replacingOccurrences(of: ",", with: ".").components(separatedBy: CharacterSet(charactersIn: "0123456789.-").inverted).compactMap(Double.init)102        return (nums.count > 0 ? nums[0] : -1, nums.count > 1 ? nums[1] : -1, nums.count > 2 ? nums[2] : -1)103    }104105    private func waitFor(_ what: String, timeout: TimeInterval = 10, _ cond: () -> Bool) {106        let end = Date().addingTimeInterval(timeout)107        while Date() < end {108            if cond() { return }109            usleep(150_000)110        }111        XCTFail("délai dépassé : \(what) — bandeau « \(XCUIApplication().descendants(matching: .any)["hud"].label) »")112    }113114    private func launch() -> (XCUIApplication, CGRect) {115        let app = XCUIApplication()116        app.launch()117        let map = app.descendants(matching: .any)["KAMapSummary"]118        XCTAssertTrue(map.waitForExistence(timeout: 30))119        waitFor("premier chargement", timeout: 30) { self.hud(app).zoom > 0 }120        sleep(3)121        return (app, map.frame)122    }123124    /// Trajectoire d'un doigt : interpolation linéaire entre des points clés `(x, y, t)`.125    private func path(_ keys: [(CGFloat, CGFloat, Double)], step: Double = 1.0 / 60) -> [[NSNumber]] {126        var out: [[NSNumber]] = []127        for (a, b) in zip(keys, keys.dropFirst()) {128            let n = max(Int((b.2 - a.2) / step), 1)129            for i in 0..<n {130                let f = Double(i) / Double(n)131                out.append([NSNumber(value: a.0 + (b.0 - a.0) * f), NSNumber(value: a.1 + (b.1 - a.1) * f), NSNumber(value: a.2 + (b.2 - a.2) * f)])132            }133        }134        if let l = keys.last { out.append([NSNumber(value: l.0), NSNumber(value: l.1), NSNumber(value: l.2)]) }135        return out136    }137138    private func perform(_ fingers: [[[NSNumber]]]) throws {139        try KAMultiTouch.performFingers(fingers)140    }141142    /// Deux doigts côte à côte qui montent ensemble : la carte s'incline ; qui redescendent : elle se couche.143    func testTwoFingerPitch() throws {144        let (app, f) = launch()145        let y0 = f.minY + f.height * 0.62, x1 = f.midX - 55, x2 = f.midX + 55146        XCTAssertLessThan(hud(app).pitch, 1)147        try perform([path([(x1, y0, 0), (x1, y0, 0.08), (x1, y0 - 150, 0.7), (x1, y0 - 150, 0.8)]), path([(x2, y0, 0), (x2, y0, 0.08), (x2, y0 - 150, 0.7), (x2, y0 - 150, 0.8)])])148        waitFor("inclinaison par glissement vertical à deux doigts") { self.hud(app).pitch > 25 }149        let p = hud(app)150        // 150 points × 0,42° par point = 63° en théorie, moins le seuil de départ du reconnaisseur.151        XCTAssertGreaterThan(p.pitch, 40)152        XCTAssertLessThanOrEqual(p.pitch, 72)153        XCTAssertEqual(p.bearing, 0, accuracy: 1, "l'inclinaison ne doit pas faire tourner la carte")154        let z = p.zoom155        try perform([path([(x1, y0 - 150, 0), (x1, y0 - 150, 0.08), (x1, y0 + 60, 0.7), (x1, y0 + 60, 0.8)]), path([(x2, y0 - 150, 0), (x2, y0 - 150, 0.08), (x2, y0 + 60, 0.7), (x2, y0 + 60, 0.8)])])156        waitFor("retour à plat") { self.hud(app).pitch < 1 }157        XCTAssertEqual(hud(app).zoom, z, accuracy: 0.15, "l'inclinaison ne doit pas zoomer")158    }159160    /// Double toucher puis glisser sans lever le doigt : zoom à un doigt (vers le bas : avant).161    func testOneFingerZoom() throws {162        let (app, f) = launch()163        let x = f.midX, y = f.minY + f.height * 0.4164        let z0 = hud(app).zoom165        // Premier toucher bref, second toucher maintenu puis glissé de 220 points vers le bas.166        try perform([path([(x, y, 0), (x, y, 0.06)])])167        try perform([path([(x, y, 0), (x, y, 0.12), (x, y + 220, 0.75), (x, y + 220, 0.85)])])168        waitFor("zoom avant à un doigt") { self.hud(app).zoom > z0 + 1.2 }169        let z1 = hud(app).zoom170        // 220 points à 110 points par niveau : deux niveaux, moins le seuil de 8 points.171        XCTAssertEqual(z1, z0 + 2, accuracy: 0.35)172        try perform([path([(x, y + 200, 0), (x, y + 200, 0.06)])])173        try perform([path([(x, y + 200, 0), (x, y + 200, 0.12), (x, y + 90, 0.6), (x, y + 90, 0.7)])])174        waitFor("zoom arrière à un doigt") { self.hud(app).zoom < z1 - 0.6 }175        XCTAssertEqual(hud(app).pitch, 0, accuracy: 0.5)176    }177178    /// Deux doigts qui s'écartent en tournant : zoom et rotation dans le même geste.179    func testSimultaneousPinchAndRotate() throws {180        let (app, f) = launch()181        let c = CGPoint(x: f.midX, y: f.minY + f.height * 0.45)182        let before = hud(app)183        func finger(_ sign: CGFloat) -> [[NSNumber]] {184            // Rayon 55 → 150 points, angle 0 → 55°.185            var keys: [(CGFloat, CGFloat, Double)] = [(c.x + sign * 55, c.y, 0), (c.x + sign * 55, c.y, 0.08)]186            for i in 1...24 {187                let t = Double(i) / 24188                let r = 55 + 95 * t, a = 55 * Double.pi / 180 * t189                keys.append((c.x + sign * r * cos(a), c.y + sign * r * sin(a), 0.08 + 0.75 * t))190            }191            keys.append((keys.last!.0, keys.last!.1, 0.95))192            return path(keys)193        }194        try perform([finger(1), finger(-1)])195        waitFor("pincement et rotation simultanés") { self.hud(app).zoom > before.zoom + 0.8 && abs(self.hud(app).bearing - before.bearing) > 20 }196        let after = hud(app)197        // Écartement × 2,7 : log2 ≈ 1,45 niveau ; rotation de 55° moins le seuil de 8°.198        XCTAssertEqual(after.zoom, before.zoom + 1.45, accuracy: 0.6)199        let turned = abs(after.bearing > 180 ? after.bearing - 360 : after.bearing)200        XCTAssertGreaterThan(turned, 30)201        XCTAssertLessThan(turned, 70)202        XCTAssertEqual(after.pitch, 0, accuracy: 0.5, "pincer et tourner ne doit pas incliner")203    }204}205
Files main
Menu

Theme