Bug 203817 - Add Googletest assertion support for CGRect and NSRect
Summary: Add Googletest assertion support for CGRect and NSRect
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Daniel Bates
URL:
Keywords: InRadar
Depends on:
Blocks: 203828
  Show dependency treegraph
 
Reported: 2019-11-04 10:41 PST by Daniel Bates
Modified: 2019-11-04 15:56 PST (History)
2 users (show)

See Also:


Attachments
Patch (17.56 KB, patch)
2019-11-04 10:52 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch (17.61 KB, patch)
2019-11-04 11:05 PST, Daniel Bates
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2019-11-04 10:41:09 PST
Make EXPECT_EQ() and other Googletest assertions work with CGRect and NSRect types. This makes it easy to write tests using these types and gives pretty output like this:

/Volumes/.../Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:231
Expected equality of these values:
  CGRectMake(138, 0, 23, 24)
    Which is: (origin = (x = 138, y = 0), size = (width = 23, height = 24))
  rects.firstObject.CGRectValue
    Which is: (origin = (x = 96, y = 0), size = (width = 16, height = 17))
Comment 1 Daniel Bates 2019-11-04 10:52:58 PST
Created attachment 382749 [details]
Patch
Comment 2 Daniel Bates 2019-11-04 10:54:56 PST
Comment on attachment 382749 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=382749&action=review

> Tools/TestWebKitAPI/cocoa/TestCocoa.mm:48
> +std::ostream& operator<<(std::ostream& os, const NSRect& rect)
> +{
> +    return os << "(origin = (x = " << rect.origin.x << ", y = " << rect.origin.y << "), size = (width = " << rect.size.width << ", height = " << rect.size.height << "))";
> +}

Probably could use a template to avoid duplicating this code.... I'm not really bothered by duplicating this code.
Comment 3 Daniel Bates 2019-11-04 11:05:15 PST
Created attachment 382752 [details]
Patch
Comment 4 Daniel Bates 2019-11-04 11:05:45 PST
Updated patch to use template to avoid duplication.
Comment 5 Myles C. Maxfield 2019-11-04 15:45:18 PST
Comment on attachment 382752 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=382752&action=review

> Tools/TestWebKitAPI/cocoa/TestCocoa.mm:32
> +    return os << "(origin = (x = " << rect.origin.x << ", y = " << rect.origin.y << "), size = (width = " << rect.size.width << ", height = " << rect.size.height << "))";

makeString() would make this more elegant
Comment 6 Daniel Bates 2019-11-04 15:52:07 PST
(In reply to Myles C. Maxfield from comment #5)
> Comment on attachment 382752 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=382752&action=review
> 
> > Tools/TestWebKitAPI/cocoa/TestCocoa.mm:32
> > +    return os << "(origin = (x = " << rect.origin.x << ", y = " << rect.origin.y << "), size = (width = " << rect.size.width << ", height = " << rect.size.height << "))";
> 
> makeString() would make this more elegant

Maybe, but it would be a tiny bit less efficient because the resulting WTF::String needs to be converted (implicitly or explicitly) to a C-string at the end to insert into the stream.
Comment 7 Daniel Bates 2019-11-04 15:55:21 PST
Comment on attachment 382752 [details]
Patch

Clearing flags on attachment: 382752

Committed r252023: <https://trac.webkit.org/changeset/252023>
Comment 8 Daniel Bates 2019-11-04 15:55:23 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Radar WebKit Bug Importer 2019-11-04 15:56:15 PST
<rdar://problem/56884305>