import AppKit @main struct ProcessIconCacheChecks { @MainActor static func main() { var reads = 0, now: TimeInterval = 1 let cache = ProcessIconCache(resolve: { _ in reads += 1 return NSImage(size: NSSize(width: 1024, height: 1024), flipped: false) { bounds in NSColor.systemBlue.setFill(); bounds.fill(); return true } }, clock: { now }) let first = cache.image(for: "/Applications/Example.app/Contents/MacOS/main")! let second = cache.image(for: "/Applications/Example.app/Contents/Helpers/worker")! precondition(first === second && reads == 1, "Executables in the same app must share a thumbnail") let bitmap = first.representations.first as! NSBitmapImageRep precondition(first.size == NSSize(width: 15, height: 15) && bitmap.pixelsWide == 30 && bitmap.pixelsHigh == 30) precondition(first.representations.count == 1 && cache.pixelBytes <= 4096) precondition(bitmap.colorAt(x: 15, y: 15)!.alphaComponent > 0.9, "Thumbnail must retain rendered pixels") now = 32 let renewed = cache.image(for: "/Applications/Example.app/Contents/MacOS/main")! precondition(renewed !== first && reads == 2 && cache.count == 1) for index in 0..<200 { _ = cache.image(for: "/test/\(index)/worker") } precondition(cache.count == 128 && cache.pixelBytes <= ProcessIconCache.pixelLimit) let before = reads _ = cache.image(for: "/test/199/worker") precondition(reads == before, "Recent entry must survive eviction") _ = cache.image(for: "/test/0/worker") precondition(reads == before + 1, "Evicted entry must be resolved again") cache.removeAll() precondition(cache.count == 0 && cache.pixelBytes == 0) print("PASS: app-shared raster thumbnails, pixel content/dimensions, expiry, strict bounds, LRU and explicit clearing") } }