Flutter Engine
The Flutter Engine
third_party
skia
tests
LRUCacheTest.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
8
#include "
src/core/SkLRUCache.h
"
9
#include "
tests/Test.h
"
10
11
#include <memory>
12
13
struct
Value
{
14
Value
(
int
value
,
int
* counter)
15
:
fValue
(
value
)
16
,
fCounter
(counter) {
17
(*fCounter)++;
18
}
19
20
~Value
() {
21
(*fCounter)--;
22
}
23
24
int
fValue
;
25
int
*
fCounter
;
26
};
27
28
DEF_TEST
(LRUCacheSequential, r) {
29
int
instances = 0;
30
{
31
static
const
int
kSize
= 100;
32
SkLRUCache<int, std::unique_ptr<Value>
>
test
(
kSize
);
33
for
(
int
i
= 1;
i
<
kSize
* 2;
i
++) {
34
REPORTER_ASSERT
(r, !
test
.find(
i
));
35
test
.insert(
i
, std::make_unique<Value>(
i
*
i
, &instances));
36
REPORTER_ASSERT
(r,
test
.find(
i
));
37
REPORTER_ASSERT
(r,
i
*
i
== (*
test
.find(
i
))->fValue);
38
if
(
i
>
kSize
) {
39
REPORTER_ASSERT
(r,
kSize
== instances);
40
REPORTER_ASSERT
(r, !
test
.find(
i
-
kSize
));
41
}
else
{
42
REPORTER_ASSERT
(r,
i
== instances);
43
}
44
REPORTER_ASSERT
(r, (
int
)
test
.count() == instances);
45
}
46
}
47
REPORTER_ASSERT
(r, 0 == instances);
48
}
49
50
DEF_TEST
(LRUCacheRandom, r) {
51
int
instances = 0;
52
{
53
int
seq[] = { 0, 1, 2, 3, 4, 1, 6, 2, 7, 5, 3, 2, 2, 3, 1, 7 };
54
int
expected[] = { 7, 1, 3, 2, 5 };
55
static
const
int
kSize
= 5;
56
SkLRUCache<int, std::unique_ptr<Value>
>
test
(
kSize
);
57
for
(
int
i
= 0;
i
< (
int
) (
sizeof
(seq) /
sizeof
(
int
));
i
++) {
58
int
k = seq[
i
];
59
if
(!
test
.find(k)) {
60
test
.insert(k, std::make_unique<Value>(k, &instances));
61
}
62
}
63
REPORTER_ASSERT
(r,
kSize
== instances);
64
REPORTER_ASSERT
(r,
kSize
==
test
.count());
65
for
(
int
i
= 0;
i
<
kSize
;
i
++) {
66
int
k = expected[
i
];
67
REPORTER_ASSERT
(r,
test
.find(k));
68
REPORTER_ASSERT
(r, k == (*
test
.find(k))->fValue);
69
}
70
}
71
REPORTER_ASSERT
(r, 0 == instances);
72
}
test
#define test(name)
DEF_TEST
DEF_TEST(LRUCacheSequential, r)
Definition:
LRUCacheTest.cpp:28
SkLRUCache.h
Test.h
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition:
Test.h:286
SkLRUCache
Definition:
SkLRUCache.h:19
i
int i
Definition:
fl_socket_accessible.cc:18
value
uint8_t value
Definition:
fl_standard_message_codec.cc:36
kSize
constexpr int kSize
Definition:
largeclippedpath.cpp:12
test
tools.skpbench.skpbench.int
int
Definition:
skpbench.py:49
Value
Definition:
LRUCacheTest.cpp:13
Value::~Value
~Value()
Definition:
LRUCacheTest.cpp:20
Value::Value
Value(int value, int *counter)
Definition:
LRUCacheTest.cpp:14
Value::fValue
int fValue
Definition:
LRUCacheTest.cpp:24
Value::fCounter
int * fCounter
Definition:
LRUCacheTest.cpp:25
Generated on Sun Jun 23 2024 21:56:40 for Flutter Engine by
1.9.4