From 768410b53081daf890c4412cdb7ff359c67cb263 Mon Sep 17 00:00:00 2001 From: Todd White Date: Sun, 12 Jul 2026 18:18:03 -0400 Subject: [PATCH] tests: add NSTextAttachment tests Cover the default attachment cell, the file wrapper round-trip and the attachment cell round-trip with its back reference to the attachment. --- ChangeLog | 8 ++++ Tests/gui/NSTextAttachment/TestInfo | 0 Tests/gui/NSTextAttachment/basic.m | 71 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 Tests/gui/NSTextAttachment/TestInfo create mode 100644 Tests/gui/NSTextAttachment/basic.m diff --git a/ChangeLog b/ChangeLog index 9944d98711..0194c49163 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-07-12 Todd White + + * Tests/gui/NSTextAttachment/basic.m: + * Tests/gui/NSTextAttachment/TestInfo: + Add tests for NSTextAttachment: the default attachment cell, the file + wrapper round-trip and the attachment cell round-trip with its back + reference. + 2026-07-12 Todd White * Tests/gui/NSTextFieldCell/attributes.m: diff --git a/Tests/gui/NSTextAttachment/TestInfo b/Tests/gui/NSTextAttachment/TestInfo new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/gui/NSTextAttachment/basic.m b/Tests/gui/NSTextAttachment/basic.m new file mode 100644 index 0000000000..93d82da3cc --- /dev/null +++ b/Tests/gui/NSTextAttachment/basic.m @@ -0,0 +1,71 @@ +/* Coverage for NSTextAttachment: the default attachment cell, the file + * wrapper round-trip, and the attachment cell round-trip with its back + * reference to the attachment. Setting a file wrapper reaches the file + * icon, so the set uses the backend and is skipped when it is unavailable. + */ +#include "Testing.h" +#include +#include +#include + +int +main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + NSData *data = [@"hello" dataUsingEncoding: NSUTF8StringEncoding]; + NSFileWrapper *fw = AUTORELEASE([[NSFileWrapper alloc] + initRegularFileWithContents: data]); + + START_SET("NSTextAttachment") + + NS_DURING + { + [NSApplication sharedApplication]; + } + NS_HANDLER + { + if ([[localException name] isEqualToString: NSInternalInconsistencyException]) + SKIP("It looks like GNUstep backend is not yet installed") + } + NS_ENDHANDLER + + { + NSTextAttachment *a = AUTORELEASE([[NSTextAttachment alloc] + initWithFileWrapper: nil]); + + pass([a fileWrapper] == nil, "an attachment with no wrapper has none"); + pass([(id)[a attachmentCell] isKindOfClass: [NSTextAttachmentCell class]], + "an attachment has a text attachment cell by default"); + } + + { + NSTextAttachment *a = AUTORELEASE([[NSTextAttachment alloc] + initWithFileWrapper: fw]); + + pass([a fileWrapper] == fw, "initWithFileWrapper: stores the wrapper"); + pass([(id)[a attachmentCell] isKindOfClass: [NSTextAttachmentCell class]], + "an attachment from a wrapper still has a cell"); + } + + { + NSTextAttachment *a = AUTORELEASE([[NSTextAttachment alloc] init]); + + [a setFileWrapper: fw]; + pass([a fileWrapper] == fw, "setFileWrapper: round trips"); + } + + { + NSTextAttachment *a = AUTORELEASE([[NSTextAttachment alloc] init]); + NSTextAttachmentCell *cell = AUTORELEASE([[NSTextAttachmentCell alloc] init]); + + [a setAttachmentCell: cell]; + pass([a attachmentCell] == cell, "setAttachmentCell: round trips"); + pass([cell attachment] == a, + "setAttachmentCell: points the cell back at the attachment"); + } + + END_SET("NSTextAttachment") + + DESTROY(arp); + return 0; +}