@@ -79,6 +79,51 @@ TEST_F(EntityTest, TriangleInsideASquare) {
79
79
ASSERT_TRUE (OpenPlaygroundHere (callback));
80
80
}
81
81
82
+ TEST_F (EntityTest, StrokeCapAndJoinTest) {
83
+ auto callback = [&](ContentContext& context, RenderPass& pass) {
84
+ Entity entity;
85
+
86
+ auto create_contents = [](SolidStrokeContents::Cap cap) {
87
+ auto contents = std::make_unique<SolidStrokeContents>();
88
+ contents->SetColor (Color::Red ());
89
+ contents->SetStrokeSize (20.0 );
90
+ contents->SetStrokeCap (cap);
91
+ return contents;
92
+ };
93
+
94
+ const Point a_def (100 , 100 ), b_def (100 , 150 ), c_def (200 , 100 ),
95
+ d_def (200 , 50 );
96
+ const Scalar r = 10 ;
97
+
98
+ {
99
+ Point off (0 , 0 );
100
+ Point a, b, c, d;
101
+ std::tie (a, b) = IMPELLER_PLAYGROUND_LINE (off + a_def, off + b_def, r,
102
+ Color::Black (), Color::White ());
103
+ std::tie (c, d) = IMPELLER_PLAYGROUND_LINE (off + c_def, off + d_def, r,
104
+ Color::Black (), Color::White ());
105
+ entity.SetPath (PathBuilder{}.AddCubicCurve (a, b, d, c).TakePath ());
106
+ entity.SetContents (create_contents (SolidStrokeContents::Cap::kButt ));
107
+ entity.Render (context, pass);
108
+ }
109
+
110
+ {
111
+ Point off (0 , 100 );
112
+ Point a, b, c, d;
113
+ std::tie (a, b) = IMPELLER_PLAYGROUND_LINE (off + a_def, off + b_def, r,
114
+ Color::Black (), Color::White ());
115
+ std::tie (c, d) = IMPELLER_PLAYGROUND_LINE (off + c_def, off + d_def, r,
116
+ Color::Black (), Color::White ());
117
+ entity.SetPath (PathBuilder{}.AddCubicCurve (a, b, d, c).TakePath ());
118
+ entity.SetContents (create_contents (SolidStrokeContents::Cap::kSquare ));
119
+ entity.Render (context, pass);
120
+ }
121
+
122
+ return true ;
123
+ };
124
+ ASSERT_TRUE (OpenPlaygroundHere (callback));
125
+ }
126
+
82
127
TEST_F (EntityTest, CubicCurveTest) {
83
128
// Compare with https://fiddle.skia.org/c/b3625f26122c9de7afe7794fcf25ead3
84
129
Path path =
@@ -329,12 +374,25 @@ TEST_F(EntityTest, CubicCurveAndOverlapTest) {
329
374
ASSERT_TRUE (OpenPlaygroundHere (entity));
330
375
}
331
376
332
- TEST_F (EntityTest, SolidStrokeContentsSetStrokeDefaults) {
333
- SolidStrokeContents stroke;
334
- ASSERT_EQ (stroke.GetStrokeCap (), SolidStrokeContents::Cap::kButt );
335
- ASSERT_EQ (stroke.GetStrokeJoin (), SolidStrokeContents::Join::kBevel );
336
- // TODO(99089): Test that SetStroke[Cap|Join] works once there are multiple
337
- // caps and joins.
377
+ TEST_F (EntityTest, SolidStrokeContentsSetStrokeCapsAndJoins) {
378
+ {
379
+ SolidStrokeContents stroke;
380
+ // Defaults.
381
+ ASSERT_EQ (stroke.GetStrokeCap (), SolidStrokeContents::Cap::kButt );
382
+ ASSERT_EQ (stroke.GetStrokeJoin (), SolidStrokeContents::Join::kBevel );
383
+ }
384
+
385
+ {
386
+ SolidStrokeContents stroke;
387
+ stroke.SetStrokeCap (SolidStrokeContents::Cap::kSquare );
388
+ ASSERT_EQ (stroke.GetStrokeCap (), SolidStrokeContents::Cap::kSquare );
389
+ }
390
+
391
+ {
392
+ SolidStrokeContents stroke;
393
+ stroke.SetStrokeCap (SolidStrokeContents::Cap::kRound );
394
+ ASSERT_EQ (stroke.GetStrokeCap (), SolidStrokeContents::Cap::kRound );
395
+ }
338
396
}
339
397
340
398
} // namespace testing
0 commit comments