Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / tests / StrokeTest.cpp
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #include "SkPaint.h"
9 #include "SkPath.h"
10 #include "SkRect.h"
11 #include "SkStroke.h"
12 #include "Test.h"
13
14 static bool equal(const SkRect& a, const SkRect& b) {
15     return  SkScalarNearlyEqual(a.left(), b.left()) &&
16             SkScalarNearlyEqual(a.top(), b.top()) &&
17             SkScalarNearlyEqual(a.right(), b.right()) &&
18             SkScalarNearlyEqual(a.bottom(), b.bottom());
19 }
20
21 static void test_strokerect(skiatest::Reporter* reporter) {
22     const SkScalar width = SkIntToScalar(10);
23     SkPaint paint;
24
25     paint.setStyle(SkPaint::kStroke_Style);
26     paint.setStrokeWidth(width);
27
28     SkRect r = { 0, 0, SkIntToScalar(200), SkIntToScalar(100) };
29
30     SkRect outer(r);
31     outer.outset(width/2, width/2);
32
33     static const SkPaint::Join joins[] = {
34         SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join
35     };
36
37     for (size_t i = 0; i < SK_ARRAY_COUNT(joins); ++i) {
38         paint.setStrokeJoin(joins[i]);
39
40         SkPath path, fillPath;
41         path.addRect(r);
42         paint.getFillPath(path, &fillPath);
43
44         REPORTER_ASSERT(reporter, equal(outer, fillPath.getBounds()));
45
46         bool isMiter = SkPaint::kMiter_Join == joins[i];
47         SkRect nested[2];
48         REPORTER_ASSERT(reporter, fillPath.isNestedRects(nested) == isMiter);
49         if (isMiter) {
50             SkRect inner(r);
51             inner.inset(width/2, width/2);
52             REPORTER_ASSERT(reporter, equal(nested[0], outer));
53             REPORTER_ASSERT(reporter, equal(nested[1], inner));
54         }
55     }
56 }
57
58 DEF_TEST(Stroke, reporter) {
59     test_strokerect(reporter);
60 }