Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Sheet9// File : Packages/SheetTemplates/Tests/SheetTemplatesTests/ThumbnailTests.swift10// Module : SheetTemplatesTests11// Repository : https://git.spboucher.ai/orix-sheet12// Created : 2026-11-2113// Last Modified : 2026-11-2114//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 Foundation88import CoreGraphics89import Testing90import SheetCore91@testable import SheetTemplates9293@Suite struct Thumbnails {94 /// The chooser thumbnail is drawn from the real content: right size, mostly paper, with ink in the accent colour.95 @Test(arguments: Case.all) func thumbnailShowsTheTemplate(_ c: Case) throws {96 let wb = BuildCache.shared.get(c).workbook97 let image = try #require(TemplateThumbnail.image(of: wb, size: CGSize(width: 320, height: 200), scale: 2, locale: c.locale))98 #expect(image.width == 640 && image.height == 400)99 let data = try #require(image.dataProvider?.data as Data?)100 var ink = 0, accent = 0101 let a = c.template.accent, t = c.template.accent.onSheet, bpr = image.bytesPerRow // header fills, title text102 for y in stride(from: 0, to: image.height, by: 2) {103 for x in stride(from: 0, to: image.width, by: 2) {104 let i = y * bpr + x * 4105 let (r, g, b) = (Int(data[i]), Int(data[i + 1]), Int(data[i + 2]))106 if r < 235 || g < 235 || b < 235 { ink += 1 }107 for k in [a, t] where abs(r - Int(k.r)) < 24 && abs(g - Int(k.g)) < 24 && abs(b - Int(k.b)) < 24 { accent += 1; break }108 }109 }110 let total = (image.width / 2) * (image.height / 2)111 #expect(ink > total / 40 && ink < total * 9 / 10, "\(c.tag): \(ink) inked samples of \(total)")112 #expect(accent > 20, "\(c.tag): the accent colour appears in the thumbnail")113 if let dir = ProcessInfo.processInfo.environment["ORIX_TEMPLATES_THUMBS"], let png = TemplateThumbnail.pngData(of: c.template, locale: c.locale) {114 try FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)115 try png.write(to: URL(fileURLWithPath: dir).appendingPathComponent("\(c.tag).png"))116 }117 }118119 @Test func degenerateRequestsReturnNothing() {120 let wb = TemplateLibrary.blank(locale: english)121 #expect(TemplateThumbnail.image(of: wb, sheet: 3) == nil)122 #expect(TemplateThumbnail.image(of: wb, size: .zero) == nil)123 #expect(TemplateThumbnail.image(of: wb) != nil)124 }125}126