Bug 203817

Summary: Add Googletest assertion support for CGRect and NSRect
Product: WebKit Reporter: Daniel Bates <dbates>
Component: Tools / TestsAssignee: Daniel Bates <dbates>
Status: RESOLVED FIXED    
Severity: Normal CC: mmaxfield, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 203828    
Attachments:
Description Flags
Patch
none
Patch none

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>