Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DiscardableMemoryTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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
11#include "tests/Test.h"
12
13#include <cstring>
14#include <memory>
15
16namespace {
17constexpr char kTestString[] = "HELLO, WORLD!";
18constexpr size_t kTestStringLength = sizeof(kTestString);
19} // namespace
20
23 bool assertRelock) {
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}
50
51DEF_TEST(DiscardableMemory_global, reporter) {
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}
57
58DEF_TEST(DiscardableMemory_nonglobal, reporter) {
61 std::unique_ptr<SkDiscardableMemory> dm(pool->create(kTestStringLength));
62 test_dm(reporter, dm.get(), true);
63}
64
AutoreleasePool pool
static void test_dm(skiatest::Reporter *reporter, SkDiscardableMemory *dm, bool assertRelock)
reporter
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static sk_sp< SkDiscardableMemoryPool > Make(size_t size)
virtual bool lock()=0
virtual void unlock()=0
static SkDiscardableMemory * Create(size_t bytes)
virtual void * data()=0