// Presentation-only changes must never rewrite a host's grading parameters. { DYDiagnosticManager *host=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(host,nil); DYInspector *view=[[[DYInspector alloc]initWithAPIManager:host]autorelease];[view refresh];[view setFrameSize:NSMakeSize(400,780)];[view layoutSubtreeIfNeeded]; NSButton *settings=[view valueForKey:@"colorSettings"];NSView *panel=[view valueForKey:@"managedPanel"];NSArray *cards=[view valueForKey:@"cards"];NSView *first=cards.firstObject[@"view"]; run.record(@"compact-color-settings-hidden-without-gap",panel.hidden&&first.frame.origin.y==8&&[settings.accessibilityLabel isEqual:@"颜色设置"]); NSDictionary *values=[[host->_values copy]autorelease],*custom=[[host->_custom copy]autorelease];int starts=host->_undoStarts,ends=host->_undoEnds; [settings performClick:nil];[view layoutSubtreeIfNeeded];run.record(@"compact-color-settings-button-expands-panel",!panel.hidden&&first.frame.origin.y>=NSMaxY(panel.frame)+12&&settings.state==NSControlStateValueOn); for(int i=0;i<9;i++){[settings performClick:nil];[view layoutSubtreeIfNeeded];} run.record(@"compact-color-settings-repeated-toggle-does-not-edit-grade",panel.hidden&&first.frame.origin.y==8&&[values isEqual:host->_values]&&[custom isEqual:host->_custom]&&starts==host->_undoStarts&&ends==host->_undoEnds); for(NSDictionary *state in @[@{},DYManagedColorDefaults(),DYPrimaryColorDefaults()]){ DYAssetState *assets=[[[DYAssetState alloc]init]autorelease];assets.colorManagement=state.count?state:nil;DYWriteAssets(host,assets,kCMTimeZero);[view refresh];NSDictionary *snapshot=[view presetSnapshot];[settings performClick:nil];[settings performClick:nil]; run.record([NSString stringWithFormat:@"compact-settings-preserve-CMS-version-%@",state[@"version"]?:@1],[[view presetSnapshot]isEqual:snapshot]); } for(NSNumber *width in @[@280,@320,@400]){ [view setFrameSize:NSMakeSize(width.doubleValue,780)];[view layoutSubtreeIfNeeded];NSArray *buttons=@[[view valueForKey:@"save"],[view valueForKey:@"load"],[view valueForKey:@"export"],settings];BOOL fit=YES; for(NSView *button in buttons){fit&=NSMinX(button.frame)>=0&&NSMaxX(button.frame)<=width.doubleValue&&button.frame.size.width>=66;for(NSView *other in buttons)if(button!=other)fit&=!NSIntersectsRect(button.frame,other.frame);} NSArray *themes=[view valueForKey:@"themeButtons"];NSView *brand=[view valueForKey:@"brand"];fit&=themes.count==8&&NSMaxX(brand.frame)<=NSMinX([themes.firstObject frame]); run.record([NSString stringWithFormat:@"compact-header-controls-fit-%@",width],fit); } DYDiagnosticManager *fresh=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(fresh,nil);run.record(@"compact-new-host-stays-original-flow",!DYReadAssets(fresh,kCMTimeZero).colorManagement); NSInteger previous=DYThemeIndex();@try{ BOOL colors=DYThemeNames().count==8&&[DYThemeNames()[5]isEqual:@"黑金渐变"]; for(NSInteger i=0;i<8;i++){DYSetThemeIndex(i);colors&=DYThemeIndex()==i&&DYThemePalette()[@"background"]&&DYThemePalette()[@"text"];} run.record(@"compact-eight-stable-theme-choices",colors); DYSetThemeIndex(5);auto luminance=[](NSColor *color){NSColor *c=[color colorUsingColorSpace:NSColorSpace.sRGBColorSpace];auto linear=[](double x){return x<=.04045?x/12.92:pow((x+.055)/1.055,2.4);};return .2126*linear(c.redComponent)+.7152*linear(c.greenComponent)+.0722*linear(c.blueComponent);}; double minimum=100;for(NSString *text in @[@"text",@"secondary"])for(NSString *surface in @[@"background",@"backgroundEnd",@"card",@"cardEnd",@"field",@"headerTop"])minimum=std::min(minimum,(luminance(DYThemePalette()[text])+.05)/(luminance(DYThemePalette()[surface])+.05)); run.record(@"compact-gold-labels-have-readable-contrast",minimum>=4.5,@{@"minimumContrast":@(minimum)}); NSDictionary *themeSnapshot=[view presetSnapshot];int themeUndo=host->_undoStarts; DYSetThemeIndex(7);double lightMinimum=100; for(NSString *text in @[@"text",@"secondary",@"slot15"])for(NSString *surface in @[@"background",@"backgroundEnd",@"card",@"cardEnd",@"field",@"headerTop",@"headerBottom"]) lightMinimum=std::min(lightMinimum,(luminance(DYThemePalette()[surface])+.05)/(luminance(DYThemePalette()[text])+.05)); run.record(@"soft-light-text-contrast-at-least-4.5",lightMinimum>=4.5,@{@"minimumContrast":@(lightMinimum)}); [view performSelector:@selector(themeChanged:) withObject:nil]; run.record(@"soft-native-controls-use-light-appearance",[view.appearance.name isEqual:NSAppearanceNameAqua]&&DYThemeTextShadow()==nil); run.record(@"soft-theme-preserves-grade-and-undo",[themeSnapshot isEqual:[view presetSnapshot]]&&themeUndo==host->_undoStarts); DYSetThemeIndex(5); DYThemePopUpButton *pullDown=[[[DYThemePopUpButton alloc]initWithFrame:NSMakeRect(0,0,240,28) pullsDown:YES]autorelease];[pullDown addItemWithTitle:@"+ 添加模块"];pullDown.font=[NSFont systemFontOfSize:11]; NSBitmapImageRep *bitmap=[[[NSBitmapImageRep alloc]initWithBitmapDataPlanes:NULL pixelsWide:240 pixelsHigh:28 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]autorelease]; [NSGraphicsContext saveGraphicsState];[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];[pullDown drawRect:pullDown.bounds];[NSGraphicsContext restoreGraphicsState];NSUInteger glyphPixels=0; for(int y=6;y<23;y++)for(int x=9;x<90;x++){NSColor *c=[bitmap colorAtX:x y:y];if(c.redComponent>.55&&c.greenComponent>.35)glyphPixels++;} run.record(@"compact-gold-pull-down-draws-readable-caption",glyphPixels>30,@{@"brightCaptionPixels":@(glyphPixels)}); BOOL reduced=NSWorkspace.sharedWorkspace.accessibilityDisplayShouldIncreaseContrast||NSWorkspace.sharedWorkspace.accessibilityDisplayShouldReduceTransparency; run.record(@"compact-gold-glow-respects-system-display-options",reduced?DYThemeTextShadow()==nil:DYThemeTextShadow().shadowBlurRadius<=2); }@finally{DYSetThemeIndex(previous);} } // Histogram math is independent of UI palettes and never edits a host document. { float pixels[][4]={{0,0,0,1},{1,1,1,1},{1,0,0,1},{0,1,0,1},{0,0,1,1},{-.5,2,.5,1},{1,1,1,0},{NAN,0,0,1},{0,0,0,INFINITY}}; NSData *input=[NSData dataWithBytes:pixels length:sizeof(pixels)];NSData *data=DYHistogramFromRGBA(input);const DYHistogram *h=(const DYHistogram*)data.bytes; run.record(@"histogram-rejects-transparent-and-nonfinite",h->samples==6); run.record(@"histogram-rgb-endpoints-and-clamped-headroom",h->bins[1][0]==4&&h->bins[1][255]==2&&h->bins[2][255]==3&&h->bins[3][128]==1); run.record(@"histogram-luma-primary-coefficients",h->bins[0][54]==1&&h->bins[0][182]==1&&h->bins[0][18]==1); BOOL totals=YES;for(int c=0;c<4;c++){uint32_t total=0;for(int b=0;b<256;b++)total+=h->bins[c][b];totals&=total==6;} run.record(@"histogram-each-channel-conserves-valid-samples",totals); run.record(@"histogram-malformed-and-empty-safe",!DYHistogramFromRGBA([NSData dataWithBytes:pixels length:3])&&((const DYHistogram*)DYHistogramFromRGBA([NSData data]).bytes)->samples==0); DYDiagnosticManager *host=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(host,nil);DYRenderer *renderer=[[[DYRenderer alloc]init]autorelease];[renderer setValue:data forKey:@"histogram"]; DYInspector *view=[[[DYInspector alloc]initWithAPIManager:host renderer:renderer]autorelease];[view refresh];NSDictionary *before=[view presetSnapshot]; NSView *graph=nil;for(NSView *v in [view valueForKey:@"graphics"])if([v.identifier isEqual:@"curveGraph"])graph=v; NSButton *toggle=[graph valueForKey:@"histogramToggle"];NSSegmentedControl *channels=[graph valueForKey:@"channels"]; run.record(@"histogram-new-inspector-uses-renderer-cached-snapshot",[[graph valueForKey:@"histogram"]isEqual:data]&&toggle.state==NSControlStateValueOn); NSMutableSet *images=[NSMutableSet set]; for(NSInteger c=0;c<4;c++){ channels.selectedSegment=c;[graph performSelector:@selector(channelChanged:) withObject:channels];[graph setFrameSize:NSMakeSize(320,240)];[graph layoutSubtreeIfNeeded]; NSBitmapImageRep *bitmap=[[[NSBitmapImageRep alloc]initWithBitmapDataPlanes:NULL pixelsWide:320 pixelsHigh:240 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0]autorelease]; [NSGraphicsContext saveGraphicsState];[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap]];[graph drawRect:graph.bounds];[NSGraphicsContext restoreGraphicsState];[images addObject:[NSData dataWithBytes:bitmap.bitmapData length:bitmap.bytesPerRow*bitmap.pixelsHigh]]; } [toggle performClick:nil];[toggle performClick:nil]; run.record(@"histogram-four-channel-drawings-distinct",images.count==4); run.record(@"histogram-channel-and-overlay-presentation-does-not-edit-grade",[before isEqual:[view presetSnapshot]]&&host->_undoStarts==0&&host->_undoEnds==0); [renderer invalidatePreview];[view performSelector:@selector(previewChanged:) withObject:nil]; run.record(@"histogram-invalidation-clears-view-and-renderer",![renderer histogram]&&![graph valueForKey:@"histogram"]); NSInteger previous=DYThemeIndex();DYSetThemeIndex(6); run.record(@"neon-stable-theme-id-and-no-text-glow",[DYThemeNames()[6]isEqual:@"霓虹炫彩"]&&DYThemeTextShadow()==nil&&![DYThemePalette()[@"background"]isEqual:DYThemePalette()[@"backgroundEnd"]]); DYSetThemeIndex(previous); }