1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkTLazy.h"
#include "Test.h"
DEF_TEST(TLazy_copy, r) {
SkTLazy<int> lazy;
REPORTER_ASSERT(r, !lazy.isValid());
REPORTER_ASSERT(r, lazy.getMaybeNull() == nullptr);
{
SkTLazy<int> lazy_copy(lazy);
REPORTER_ASSERT(r, !lazy_copy.isValid());
REPORTER_ASSERT(r, lazy_copy.getMaybeNull() == nullptr);
}
lazy.init(42);
REPORTER_ASSERT(r, lazy.isValid());
REPORTER_ASSERT(r, 42 == *lazy.get());
{
SkTLazy<int> lazy_copy(lazy);
REPORTER_ASSERT(r, lazy_copy.isValid());
REPORTER_ASSERT(r, 42 == *lazy_copy.get());
REPORTER_ASSERT(r, lazy.get() != lazy_copy.get());
}
}
DEF_TEST(TCopyOnFirstWrite_copy, r) {
const int v = 42;
SkTCopyOnFirstWrite<int> cow(v);
REPORTER_ASSERT(r, 42 == *cow);
REPORTER_ASSERT(r, &v == cow.get());
{
SkTCopyOnFirstWrite<int> cow_copy(cow);
REPORTER_ASSERT(r, 42 == *cow_copy);
REPORTER_ASSERT(r, &v == cow_copy.get());
REPORTER_ASSERT(r, cow.get() == cow_copy.get());
*cow_copy.writable() = 43;
REPORTER_ASSERT(r, 42 == *cow);
REPORTER_ASSERT(r, &v == cow.get());
REPORTER_ASSERT(r, 43 == *cow_copy);
REPORTER_ASSERT(r, &v != cow_copy.get());
REPORTER_ASSERT(r, cow.get() != cow_copy.get());
}
*cow.writable() = 43;
REPORTER_ASSERT(r, 43 == *cow);
REPORTER_ASSERT(r, &v != cow.get());
{
SkTCopyOnFirstWrite<int> cow_copy(cow);
REPORTER_ASSERT(r, 43 == *cow_copy);
REPORTER_ASSERT(r, &v != cow_copy.get());
REPORTER_ASSERT(r, cow.get() != cow_copy.get());
*cow_copy.writable() = 44;
REPORTER_ASSERT(r, 43 == *cow);
REPORTER_ASSERT(r, &v != cow.get());
REPORTER_ASSERT(r, 44 == *cow_copy);
REPORTER_ASSERT(r, &v != cow_copy.get());
REPORTER_ASSERT(r, cow.get() != cow_copy.get());
}
}
|