Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
DiscardableMemoryTest.cpp File Reference
#include "include/core/SkRefCnt.h"
#include "include/private/chromium/SkDiscardableMemory.h"
#include "src/lazy/SkDiscardableMemoryPool.h"
#include "tests/Test.h"
#include <cstring>
#include <memory>

Go to the source code of this file.

Functions

static void test_dm (skiatest::Reporter *reporter, SkDiscardableMemory *dm, bool assertRelock)
 
 DEF_TEST (DiscardableMemory_global, reporter)
 
 DEF_TEST (DiscardableMemory_nonglobal, reporter)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( DiscardableMemory_global  ,
reporter   
)

Definition at line 51 of file DiscardableMemoryTest.cpp.

51 {
52 std::unique_ptr<SkDiscardableMemory> dm(SkDiscardableMemory::Create(kTestStringLength));
53 // lock() test is allowed to fail, since other threads could be
54 // using global pool.
55 test_dm(reporter, dm.get(), false);
56}
static void test_dm(skiatest::Reporter *reporter, SkDiscardableMemory *dm, bool assertRelock)
reporter
static SkDiscardableMemory * Create(size_t bytes)

◆ DEF_TEST() [2/2]

DEF_TEST ( DiscardableMemory_nonglobal  ,
reporter   
)

Definition at line 58 of file DiscardableMemoryTest.cpp.

58 {
61 std::unique_ptr<SkDiscardableMemory> dm(pool->create(kTestStringLength));
62 test_dm(reporter, dm.get(), true);
63}
AutoreleasePool pool
static sk_sp< SkDiscardableMemoryPool > Make(size_t size)

◆ test_dm()

static void test_dm ( skiatest::Reporter reporter,
SkDiscardableMemory dm,
bool  assertRelock 
)
static

Definition at line 21 of file DiscardableMemoryTest.cpp.

23 {
25 if (!dm) {
26 return;
27 }
28 void* ptr = dm->data();
30 if (!ptr) {
31 return;
32 }
33 memcpy(ptr, kTestString, sizeof(kTestString));
34 dm->unlock();
35 bool relockSuccess = dm->lock();
36 if (assertRelock) {
37 REPORTER_ASSERT(reporter, relockSuccess);
38 }
39 if (!relockSuccess) {
40 return;
41 }
42 ptr = dm->data();
44 if (!ptr) {
45 return;
46 }
47 REPORTER_ASSERT(reporter, 0 == memcmp(ptr, kTestString, kTestStringLength));
48 dm->unlock();
49}
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
virtual bool lock()=0
virtual void unlock()=0
virtual void * data()=0