Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
11DEF_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
36DEF_TEST(TCopyOnFirstWrite_copy, r) {
37 const int v = 42;
38
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}
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
const T * get() const
Definition SkTLazy.h:191
T * init(Args &&... args)
Definition SkTLazy.h:45
T * get()
Definition SkTLazy.h:83
bool isValid() const
Definition SkTLazy.h:77
const T * getMaybeNull() const
Definition SkTLazy.h:108