Repository Public BSD-3-Clause
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Maps9// File : Apps/ORIXMaps/Tests/ORIXMapsTests/LaunchOptionsTests.swift10// Module : ORIXMapsTests11// Repository : https://git.spboucher.ai/orix-maps12// Created : 2026-11-2513// Last Modified : 2026-11-2514//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 : Proprietary, all rights reserved (see license file)80// License File : LICENSE81// Maintainer : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import Foundation89import Testing90@testable import ORIXMaps9192/// A private UserDefaults domain per test, removed afterwards.93@MainActor94final class ScratchDefaults {95 let name = "ai.spboucher.orix.maps.tests." + UUID().uuidString96 let defaults: UserDefaults97 init() { defaults = UserDefaults(suiteName: name)! }98 deinit { UserDefaults().removePersistentDomain(forName: name) }99}100101@MainActor102struct LaunchOptionsTests {103 @Test func defaultsAreInert() {104 let scratch = ScratchDefaults()105 let o = LaunchOptions(defaults: scratch.defaults)106 #expect(!o.isUITest && !o.reset && !o.skipOnboarding && !o.simulateDrive)107 #expect(o.camera == nil && o.catalogURL == nil && o.themeID == nil && o.screen == nil)108 #expect(o.autoDownload == nil && o.routeFrom == nil && o.routeTo == nil && o.searchText == nil && o.travelMode == nil)109 }110111 @Test func flagsAndTexts() {112 let scratch = ScratchDefaults()113 let d = scratch.defaults114 d.set("YES", forKey: "ORIXUITest"); d.set("YES", forKey: "ORIXReset"); d.set("YES", forKey: "ORIXSkipOnboarding")115 d.set("orix.midnight", forKey: "ORIXTheme"); d.set("downloads", forKey: "ORIXScreen")116 d.set("http://127.0.0.1:8765/maps/v1/", forKey: "ORIXCatalogURL")117 d.set("ca-qc-montreal", forKey: "ORIXAutoDownload"); d.set("walk", forKey: "ORIXMode"); d.set("café", forKey: "ORIXSearch")118 d.set("YES", forKey: "ORIXSimulate")119 let o = LaunchOptions(defaults: d)120 #expect(o.isUITest && o.reset && o.skipOnboarding && o.simulateDrive)121 #expect(o.themeID == "orix.midnight")122 #expect(o.screen == "downloads")123 #expect(o.catalogURL == URL(string: "http://127.0.0.1:8765/maps/v1/"))124 #expect(o.autoDownload == "ca-qc-montreal")125 #expect(o.travelMode == "walk")126 #expect(o.searchText == "café")127 }128129 @Test func cameraWithThreeAndFiveComponents() {130 let scratch = ScratchDefaults()131 scratch.defaults.set("45.5017,-73.5673,14", forKey: "ORIXCamera")132 var camera = LaunchOptions(defaults: scratch.defaults).camera133 #expect(camera?.center.latitude == 45.5017 && camera?.center.longitude == -73.5673)134 #expect(camera?.zoom == 14 && camera?.bearing == 0 && camera?.pitch == 0)135 scratch.defaults.set("45.5,-73.6,12.5,90,45", forKey: "ORIXCamera")136 camera = LaunchOptions(defaults: scratch.defaults).camera137 #expect(camera?.zoom == 12.5 && camera?.bearing == 90 && camera?.pitch == 45)138 }139140 @Test(arguments: ["", "45.5", "45.5,-73.6", "north,west,3", "45,5;-73,6;12"])141 func malformedCameraIsIgnored(text: String) {142 let scratch = ScratchDefaults()143 scratch.defaults.set(text, forKey: "ORIXCamera")144 #expect(LaunchOptions(defaults: scratch.defaults).camera == nil)145 }146147 @Test func routeEndpoints() {148 let scratch = ScratchDefaults()149 scratch.defaults.set("45.5017,-73.5673", forKey: "ORIXRouteFrom")150 scratch.defaults.set("45.5579,-73.5515", forKey: "ORIXRouteTo")151 let o = LaunchOptions(defaults: scratch.defaults)152 #expect(o.routeFrom?.latitude == 45.5017 && o.routeFrom?.longitude == -73.5673)153 #expect(o.routeTo?.latitude == 45.5579 && o.routeTo?.longitude == -73.5515)154 }155156 @Test(arguments: ["45.5", "45.5,-73.6,12", "a,b", ""])157 func malformedRouteEndpointIsIgnored(text: String) {158 let scratch = ScratchDefaults()159 scratch.defaults.set(text, forKey: "ORIXRouteTo")160 #expect(LaunchOptions(defaults: scratch.defaults).routeTo == nil)161 }162163 @Test func simulatedPosition() {164 let scratch = ScratchDefaults()165 scratch.defaults.set("46.8139,-71.2080", forKey: "ORIXPosition")166 let p = LaunchOptions(defaults: scratch.defaults).simulatePosition167 #expect(p?.latitude == 46.8139 && p?.longitude == -71.2080)168 }169}170