Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
LRUCacheTest.cpp File Reference
#include "src/core/SkLRUCache.h"
#include "tests/Test.h"
#include <memory>

Go to the source code of this file.

Classes

struct  Value
 

Functions

 DEF_TEST (LRUCacheSequential, r)
 
 DEF_TEST (LRUCacheRandom, r)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( LRUCacheRandom  ,
 
)

Definition at line 50 of file LRUCacheTest.cpp.

50 {
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;
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}
#define test(name)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
Type::kYUV Type::kRGBA() int(0.7 *637)
static constexpr int kSize

◆ DEF_TEST() [2/2]

DEF_TEST ( LRUCacheSequential  ,
 
)

Definition at line 28 of file LRUCacheTest.cpp.

28 {
29 int instances = 0;
30 {
31 static const int kSize = 100;
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}