Flutter Engine
The Flutter Engine
WindowRectanglesTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
10#include "src/base/SkRandom.h"
11#include "src/core/SkRectPriv.h"
13#include "tests/Test.h"
14
15#include <cstring>
16
18 return {r.nextS(), r.nextS(), r.nextS(), r.nextS()};
19}
20
21DEF_TEST(WindowRectangles, reporter) {
22 SkRandom r;
23
25 for (int i = 0; i < GrWindowRectangles::kMaxWindows; ++i) {
26 windowData[i] = next_irect(r);
27 }
28
30 for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; ++i) {
32 REPORTER_ASSERT(reporter, !memcmp(wr.data(), windowData, i * sizeof(SkIRect)));
33
34 GrWindowRectangles wr2(wr);
35 REPORTER_ASSERT(reporter, wr2 == wr);
36 REPORTER_ASSERT(reporter, wr2.count() == wr.count());
37 REPORTER_ASSERT(reporter, !memcmp(wr2.data(), wr.data(), i * sizeof(SkIRect)));
38
39 wr.addWindow(windowData[i]);
40 }
41
43 {
44 GrWindowRectangles A(wr), B(wr);
46 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
47
48 A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
49 REPORTER_ASSERT(reporter, B.data() != A.data());
51
52 B.addWindow(SkRectPriv::MakeILarge());
54
55 for (int i = 0; i < GrWindowRectangles::kMaxWindows - 1; i++) {
56 REPORTER_ASSERT(reporter, A.data()[i] == windowData[i]);
57 REPORTER_ASSERT(reporter, B.data()[i] == windowData[i]);
58 }
60 == windowData[GrWindowRectangles::kMaxWindows - 1]);
63 }
64 {
65 GrWindowRectangles A(wr), B(wr);
67 REPORTER_ASSERT(reporter, B.data() == A.data()); // Should use copy-on-write.
68
69 A.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
70 B.addWindow(windowData[GrWindowRectangles::kMaxWindows - 1]);
72 REPORTER_ASSERT(reporter, B.data() != A.data());
73
74 for (int i = 0; i < GrWindowRectangles::kMaxWindows; i++) {
75 REPORTER_ASSERT(reporter, B.data()[i] == A.data()[i]);
76 REPORTER_ASSERT(reporter, A.data()[i] == windowData[i]);
77 }
78 }
79}
reporter
Definition: FontMgrTest.cpp:39
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static SkIRect next_irect(SkRandom &r)
DEF_TEST(WindowRectangles, reporter)
const SkIRect * data() const
SkIRect & addWindow(const SkIRect &window)
static constexpr int kMaxWindows
int32_t nextS()
Definition: SkRandom.h:50
static SkIRect MakeILarge()
Definition: SkRectPriv.h:22
#define B
Definition: SkRect.h:32