Flutter Engine
The Flutter Engine
third_party
skia
tests
TLazyTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2018 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 "
src/base/SkTLazy.h
"
9
#include "
tests/Test.h
"
10
11
DEF_TEST
(TLazy_copy, r) {
12
SkTLazy<int>
lazy;
13
14
REPORTER_ASSERT
(r, !lazy.
isValid
());
15
REPORTER_ASSERT
(r, lazy.
getMaybeNull
() ==
nullptr
);
16
17
{
18
SkTLazy<int>
lazy_copy(lazy);
// NOLINT(performance-unnecessary-copy-initialization)
19
REPORTER_ASSERT
(r, !lazy_copy.
isValid
());
20
REPORTER_ASSERT
(r, lazy_copy.
getMaybeNull
() ==
nullptr
);
21
}
22
23
lazy.
init
(42);
24
25
REPORTER_ASSERT
(r, lazy.
isValid
());
26
REPORTER_ASSERT
(r, 42 == *lazy.
get
());
27
28
{
29
SkTLazy<int>
lazy_copy(lazy);
// NOLINT(performance-unnecessary-copy-initialization)
30
REPORTER_ASSERT
(r, lazy_copy.
isValid
());
31
REPORTER_ASSERT
(r, 42 == *lazy_copy.
get
());
32
REPORTER_ASSERT
(r, lazy.
get
() != lazy_copy.
get
());
33
}
34
}
35
36
DEF_TEST
(TCopyOnFirstWrite_copy, r) {
37
const
int
v = 42;
38
39
SkTCopyOnFirstWrite<int>
cow(v);
40
41
REPORTER_ASSERT
(r, 42 == *cow);
42
REPORTER_ASSERT
(r, &v == cow.
get
());
43
44
{
45
SkTCopyOnFirstWrite<int>
cow_copy(cow);
46
REPORTER_ASSERT
(r, 42 == *cow_copy);
47
REPORTER_ASSERT
(r, &v == cow_copy.
get
());
48
REPORTER_ASSERT
(r, cow.
get
() == cow_copy.
get
());
49
50
*cow_copy.
writable
() = 43;
51
REPORTER_ASSERT
(r, 42 == *cow);
52
REPORTER_ASSERT
(r, &v == cow.
get
());
53
REPORTER_ASSERT
(r, 43 == *cow_copy);
54
REPORTER_ASSERT
(r, &v != cow_copy.
get
());
55
REPORTER_ASSERT
(r, cow.
get
() != cow_copy.
get
());
56
}
57
58
*cow.
writable
() = 43;
59
60
REPORTER_ASSERT
(r, 43 == *cow);
61
REPORTER_ASSERT
(r, &v != cow.
get
());
62
63
{
64
SkTCopyOnFirstWrite<int>
cow_copy(cow);
65
REPORTER_ASSERT
(r, 43 == *cow_copy);
66
REPORTER_ASSERT
(r, &v != cow_copy.
get
());
67
REPORTER_ASSERT
(r, cow.
get
() != cow_copy.
get
());
68
69
*cow_copy.
writable
() = 44;
70
71
REPORTER_ASSERT
(r, 43 == *cow);
72
REPORTER_ASSERT
(r, &v != cow.
get
());
73
REPORTER_ASSERT
(r, 44 == *cow_copy);
74
REPORTER_ASSERT
(r, &v != cow_copy.
get
());
75
REPORTER_ASSERT
(r, cow.
get
() != cow_copy.
get
());
76
}
77
}
SkTLazy.h
DEF_TEST
DEF_TEST(TLazy_copy, r)
Definition:
TLazyTest.cpp:11
Test.h
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition:
Test.h:286
SkTCopyOnFirstWrite
Definition:
SkTLazy.h:139
SkTCopyOnFirstWrite::get
const T * get() const
Definition:
SkTLazy.h:191
SkTCopyOnFirstWrite::writable
T * writable()
Definition:
SkTLazy.h:182
SkTLazy
Definition:
SkTLazy.h:20
SkTLazy::init
T * init(Args &&... args)
Definition:
SkTLazy.h:45
SkTLazy::get
T * get()
Definition:
SkTLazy.h:83
SkTLazy::isValid
bool isValid() const
Definition:
SkTLazy.h:77
SkTLazy::getMaybeNull
const T * getMaybeNull() const
Definition:
SkTLazy.h:108
Generated on Sun Jun 23 2024 21:56:48 for Flutter Engine by
1.9.4