Skip to content

Commit 501e818

Browse files
authored
Merge pull request #474 from DTW-Thalion/tests/nsformcell-title
tests: add NSFormCell tests
2 parents 56dbe81 + ae6c85f commit 501e818

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
2026-07-12 Todd White <todd.white@thalion.global>
22

3+
* Tests/gui/NSFormCell/title.m:
4+
* Tests/gui/NSFormCell/TestInfo:
5+
Add tests for NSFormCell: the defaults, the title, title alignment,
6+
title font and title writing-direction accessors, the manual and
7+
automatic behaviour of titleWidth and titleWidth:, the mnemonic title,
8+
the attributed title and the string/attributed placeholder pair.
39
* Tests/gui/NSStepperCell/valueLogic.m:
410
* Tests/gui/NSStepperCell/TestInfo:
511
Add tests for NSStepperCell: the defaults, the increment, autorepeat

Tests/gui/NSFormCell/TestInfo

Whitespace-only changes.

Tests/gui/NSFormCell/title.m

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/* Coverage for the NSFormCell title API: the -init defaults, the title,
2+
title alignment, title font and title writing-direction accessors, the
3+
manual and automatic title-width behaviour of -titleWidth and
4+
-titleWidth:, the mnemonic title, the attributed title and the string /
5+
attributed placeholder pair. The title cell touches the font backend,
6+
so the set is skipped when the backend is unavailable.
7+
*/
8+
#include "Testing.h"
9+
10+
#include <Foundation/NSAttributedString.h>
11+
#include <Foundation/NSAutoreleasePool.h>
12+
#include <Foundation/NSGeometry.h>
13+
14+
#include <AppKit/NSApplication.h>
15+
#include <AppKit/NSFont.h>
16+
#include <AppKit/NSFormCell.h>
17+
18+
int main()
19+
{
20+
CREATE_AUTORELEASE_POOL(arp);
21+
NSFormCell *cell;
22+
23+
START_SET("NSFormCell title")
24+
25+
NS_DURING
26+
{
27+
[NSApplication sharedApplication];
28+
}
29+
NS_HANDLER
30+
{
31+
if ([[localException name] isEqualToString: NSInternalInconsistencyException])
32+
SKIP("It looks like GNUstep backend is not yet installed")
33+
}
34+
NS_ENDHANDLER
35+
36+
/* Defaults from -init. */
37+
cell = AUTORELEASE([[NSFormCell alloc] init]);
38+
pass([[cell title] isEqualToString: @"Field:"], "default title is Field:");
39+
pass([cell titleAlignment] == NSRightTextAlignment, "title is right aligned by default");
40+
pass([cell alignment] == NSLeftTextAlignment, "the entry itself is left aligned by default");
41+
pass([cell isEditable], "a form cell is editable by default");
42+
pass([cell isBezeled], "a form cell is bezeled by default");
43+
pass([cell titleBaseWritingDirection] == NSWritingDirectionNatural,
44+
"title writing direction is natural by default");
45+
46+
/* Title, alignment, font and writing-direction accessors. */
47+
[cell setTitle: @"Name:"];
48+
pass([[cell title] isEqualToString: @"Name:"], "setTitle: updates the title");
49+
pass([[[cell attributedTitle] string] isEqualToString: @"Name:"],
50+
"attributedTitle tracks the title string");
51+
[cell setTitleAlignment: NSLeftTextAlignment];
52+
pass([cell titleAlignment] == NSLeftTextAlignment, "setTitleAlignment: updates the alignment");
53+
[cell setTitleFont: [NSFont systemFontOfSize: 24.0]];
54+
pass([[cell titleFont] pointSize] == 24.0, "setTitleFont: updates the title font");
55+
[cell setTitleBaseWritingDirection: NSWritingDirectionRightToLeft];
56+
pass([cell titleBaseWritingDirection] == NSWritingDirectionRightToLeft,
57+
"setTitleBaseWritingDirection: updates the writing direction");
58+
59+
/* A manually set title width is reported verbatim and ignores the
60+
available size passed to -titleWidth:. */
61+
[cell setTitleWidth: 123.0];
62+
pass([cell titleWidth] == 123.0, "a manual title width is reported verbatim");
63+
pass([cell titleWidth: NSMakeSize(500.0, 20.0)] == 123.0,
64+
"a manual title width ignores the offered size");
65+
pass([cell titleWidth: NSMakeSize(10.0, 20.0)] == 123.0,
66+
"a manual title width ignores a small offered size too");
67+
68+
/* A negative width restores automatic sizing: -titleWidth is then the
69+
natural width, and -titleWidth: clamps to the offered size. */
70+
[cell setTitleWidth: -1.0];
71+
{
72+
CGFloat natural = [cell titleWidth];
73+
pass(natural > 0.0, "the automatic title width is positive");
74+
pass([cell titleWidth: NSMakeSize(1.0, 20.0)] == 1.0,
75+
"an offered width below the natural width is used as is");
76+
pass([cell titleWidth: NSMakeSize(natural + 1000.0, 20.0)] == natural,
77+
"an offered width above the natural width falls back to the natural width");
78+
}
79+
80+
/* The mnemonic title strips the ampersand. */
81+
cell = AUTORELEASE([[NSFormCell alloc] init]);
82+
[cell setTitleWithMnemonic: @"&File"];
83+
pass([[cell title] isEqualToString: @"File"], "setTitleWithMnemonic: drops the ampersand");
84+
85+
/* The placeholder is either a plain string or an attributed string; the
86+
accessor for the other kind returns nil. */
87+
cell = AUTORELEASE([[NSFormCell alloc] init]);
88+
[cell setPlaceholderString: @"type here"];
89+
pass([[cell placeholderString] isEqualToString: @"type here"],
90+
"placeholderString returns the plain placeholder");
91+
pass([cell placeholderAttributedString] == nil,
92+
"placeholderAttributedString is nil for a plain placeholder");
93+
{
94+
NSAttributedString *attr = AUTORELEASE([[NSAttributedString alloc] initWithString: @"attr ph"]);
95+
[cell setPlaceholderAttributedString: attr];
96+
pass([[[cell placeholderAttributedString] string] isEqualToString: @"attr ph"],
97+
"placeholderAttributedString returns the attributed placeholder");
98+
pass([cell placeholderString] == nil,
99+
"placeholderString is nil for an attributed placeholder");
100+
RELEASE(attr);
101+
}
102+
103+
END_SET("NSFormCell title")
104+
105+
DESTROY(arp);
106+
return 0;
107+
}

0 commit comments

Comments
 (0)