/src/mozilla-central/gfx/2d/unittest/TestBugs.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "TestBugs.h" |
8 | | #include "2D.h" |
9 | | #include <string.h> |
10 | | |
11 | | using namespace mozilla; |
12 | | using namespace mozilla::gfx; |
13 | | |
14 | | TestBugs::TestBugs() |
15 | 0 | { |
16 | 0 | REGISTER_TEST(TestBugs, CairoClip918671); |
17 | 0 | REGISTER_TEST(TestBugs, PushPopClip950550); |
18 | 0 | } |
19 | | |
20 | | void |
21 | | TestBugs::CairoClip918671() |
22 | 0 | { |
23 | 0 | RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(BackendType::CAIRO, |
24 | 0 | IntSize(100, 100), |
25 | 0 | SurfaceFormat::B8G8R8A8); |
26 | 0 | RefPtr<DrawTarget> ref = Factory::CreateDrawTarget(BackendType::CAIRO, |
27 | 0 | IntSize(100, 100), |
28 | 0 | SurfaceFormat::B8G8R8A8); |
29 | 0 | // Create a path that extends around the center rect but doesn't intersect it. |
30 | 0 | RefPtr<PathBuilder> pb1 = dt->CreatePathBuilder(); |
31 | 0 | pb1->MoveTo(Point(10, 10)); |
32 | 0 | pb1->LineTo(Point(90, 10)); |
33 | 0 | pb1->LineTo(Point(90, 20)); |
34 | 0 | pb1->LineTo(Point(10, 20)); |
35 | 0 | pb1->Close(); |
36 | 0 | pb1->MoveTo(Point(90, 90)); |
37 | 0 | pb1->LineTo(Point(91, 90)); |
38 | 0 | pb1->LineTo(Point(91, 91)); |
39 | 0 | pb1->LineTo(Point(91, 90)); |
40 | 0 | pb1->Close(); |
41 | 0 |
|
42 | 0 | RefPtr<Path> path1 = pb1->Finish(); |
43 | 0 | dt->PushClip(path1); |
44 | 0 |
|
45 | 0 | // This center rect must NOT be rectilinear! |
46 | 0 | RefPtr<PathBuilder> pb2 = dt->CreatePathBuilder(); |
47 | 0 | pb2->MoveTo(Point(50, 50)); |
48 | 0 | pb2->LineTo(Point(55, 51)); |
49 | 0 | pb2->LineTo(Point(54, 55)); |
50 | 0 | pb2->LineTo(Point(50, 56)); |
51 | 0 | pb2->Close(); |
52 | 0 |
|
53 | 0 | RefPtr<Path> path2 = pb2->Finish(); |
54 | 0 | dt->PushClip(path2); |
55 | 0 |
|
56 | 0 | dt->FillRect(Rect(0, 0, 100, 100), ColorPattern(Color(1,0,0))); |
57 | 0 |
|
58 | 0 | RefPtr<SourceSurface> surf1 = dt->Snapshot(); |
59 | 0 | RefPtr<SourceSurface> surf2 = ref->Snapshot(); |
60 | 0 |
|
61 | 0 | RefPtr<DataSourceSurface> dataSurf1 = surf1->GetDataSurface(); |
62 | 0 | RefPtr<DataSourceSurface> dataSurf2 = surf2->GetDataSurface(); |
63 | 0 |
|
64 | 0 | DataSourceSurface::ScopedMap map1(dataSurf1, DataSourceSurface::READ); |
65 | 0 | DataSourceSurface::ScopedMap map2(dataSurf2, DataSourceSurface::READ); |
66 | 0 | for (int y = 0; y < dt->GetSize().height; y++) { |
67 | 0 | VERIFY(memcmp(map1.GetData() + y * map1.GetStride(), |
68 | 0 | map2.GetData() + y * map2.GetStride(), |
69 | 0 | dataSurf1->GetSize().width * 4) == 0); |
70 | 0 | } |
71 | 0 |
|
72 | 0 | } |
73 | | |
74 | | void |
75 | | TestBugs::PushPopClip950550() |
76 | 0 | { |
77 | 0 | RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(BackendType::CAIRO, |
78 | 0 | IntSize(500, 500), |
79 | 0 | SurfaceFormat::B8G8R8A8); |
80 | 0 | dt->PushClipRect(Rect(0, 0, 100, 100)); |
81 | 0 | Matrix m(1, 0, 0, 1, 45, -100); |
82 | 0 | dt->SetTransform(m); |
83 | 0 | dt->PopClip(); |
84 | 0 |
|
85 | 0 | // We fail the test if we assert in this call because our draw target's |
86 | 0 | // transforms are out of sync. |
87 | 0 | dt->FillRect(Rect(50, 50, 50, 50), ColorPattern(Color(0.5f, 0, 0, 1.0f))); |
88 | 0 | } |
89 | | |