Flutter Engine
The Flutter Engine
Functions
TLazyTest.cpp File Reference
#include "src/base/SkTLazy.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

 DEF_TEST (TLazy_copy, r)
 
 DEF_TEST (TCopyOnFirstWrite_copy, r)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( TCopyOnFirstWrite_copy  ,
 
)

Definition at line 36 of file TLazyTest.cpp.

36 {
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 REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286

◆ DEF_TEST() [2/2]

DEF_TEST ( TLazy_copy  ,
 
)

Definition at line 11 of file TLazyTest.cpp.

11 {
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}
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