Flutter Engine
The Flutter Engine
StrikeForGPUTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
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
12#include "src/core/SkStrike.h"
17#include "tests/Test.h"
19
20#include <cstdint>
21#include <memory>
22#include <optional>
23#include <utility>
24
25using namespace sktext;
26
27DEF_TEST(SkStrikePromise_Basic, reporter) {
28 auto strikeCache = std::make_unique<SkStrikeCache>();
30
31 class Pinner : public ::SkStrikePinner {
32 public:
33 // Changing canDelete to return true causes this test to expectedly fail.
34 bool canDelete() override { return false; }
35 };
36
37 intptr_t toCompareWith;
39
40 // Ensure that the ref in srcPromise is dropped.
41 {
42 // Make a strike with a Pinner.
43 auto strike = strikeCache->createStrike(strikeSpec, nullptr, std::make_unique<Pinner>());
44 toCompareWith = reinterpret_cast<intptr_t>(strike.get());
45 SkStrikePromise srcPromise(std::move(strike));
46 SkBinaryWriteBuffer writeBuffer({});
47 srcPromise.flatten(writeBuffer);
48 data = writeBuffer.snapshotAsData();
49 }
50
51 // Remove all unpinned strikes.
52 strikeCache->purgeAll();
53
54 SkReadBuffer readBuffer{data->data(), data->size()};
55 std::optional<SkStrikePromise> dstPromise = SkStrikePromise::MakeFromBuffer(
56 readBuffer, nullptr, strikeCache.get());
57
58 REPORTER_ASSERT(reporter, dstPromise.has_value());
60 reinterpret_cast<intptr_t>(dstPromise->strike()) == toCompareWith);
61}
reporter
Definition: FontMgrTest.cpp:39
DEF_TEST(SkStrikePromise_Basic, reporter)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
virtual bool canDelete()=0
static std::tuple< SkStrikeSpec, SkScalar > MakeCanonicalized(const SkFont &font, const SkPaint *paint=nullptr)
void flatten(SkWriteBuffer &buffer) const
SkFont DefaultFont()
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63