blob: 7cc613eb7c8525e388d43c3b74f2890ff044fbdc [file] [log] [blame]
Herb Derby3b946c12020-03-15 12:55:16 -04001/*
2 * Copyright 2020 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/SkStrikeCache.h"
9#include "src/core/SkStrikeSpec.h"
10#include "tests/Test.h"
11#include "tools/ToolUtils.h"
12
13DEF_TEST(SkStrikeCache_CachePurge, Reporter) {
14 SkStrikeCache cache;
15
16 sk_sp<SkTypeface> typeface =
17 ToolUtils::create_portable_typeface("serif", SkFontStyle::Italic());
18
19 SkFont font;
20 font.setEdging(SkFont::Edging::kAntiAlias);
21 font.setSubpixel(true);
22 font.setTypeface(typeface);
23
24 SkPaint defaultPaint;
25 SkStrikeSpec strikeSpec = SkStrikeSpec::MakeMask(
26 font, defaultPaint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
27 SkScalerContextFlags::kNone, SkMatrix::I());
28
29 // Initially empty cache
30 REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
31
32 {
33 sk_sp<SkStrike> strike = strikeSpec.findOrCreateStrike(&cache);
34 }
35
36 // Stuff in cache.
37 REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() > 0);
38
39 cache.purgeAll();
40
41 // Purged cache.
42 REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
43
44 // Smallest cache.
45 cache.setCacheSizeLimit(0);
46 {
47 sk_sp<SkStrike> strike = strikeSpec.findOrCreateStrike(&cache);
48 REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
49 }
50 REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
51
52
53}