diff --git a/ChangeLog b/ChangeLog index c5ee30cfa..a6ecf8b60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -37,6 +37,14 @@ size, postscript name and matrix extractors, and the descriptor derivation methods. +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/NSTextContainer/basic.m: diff --git a/Tests/gui/NSTextAttachment/TestInfo b/Tests/gui/NSTextAttachment/TestInfo new file mode 100644 index 000000000..e69de29bb diff --git a/Tests/gui/NSTextAttachment/basic.m b/Tests/gui/NSTextAttachment/basic.m new file mode 100644 index 000000000..93d82da3c --- /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; +}