• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "include/core/SkData.h"
9 #include "include/core/SkFont.h"
10 #include "include/core/SkRefCnt.h"
11 #include "src/core/SkReadBuffer.h"
12 #include "src/core/SkStrike.h"
13 #include "src/core/SkStrikeCache.h"
14 #include "src/core/SkStrikeSpec.h"
15 #include "src/core/SkWriteBuffer.h"
16 #include "src/text/StrikeForGPU.h"
17 #include "tests/Test.h"
18 
19 #include <cstdint>
20 #include <memory>
21 #include <optional>
22 #include <utility>
23 
24 using namespace sktext;
25 
DEF_TEST(SkStrikePromise_Basic,reporter)26 DEF_TEST(SkStrikePromise_Basic, reporter) {
27     auto strikeCache = std::make_unique<SkStrikeCache>();
28     auto [strikeSpec, _] = SkStrikeSpec::MakeCanonicalized(SkFont());
29 
30     class Pinner : public ::SkStrikePinner {
31     public:
32         // Changing canDelete to return true causes this test to expectedly fail.
33         bool canDelete() override { return false; }
34     };
35 
36     intptr_t toCompareWith;
37     sk_sp<SkData> data;
38 
39     // Ensure that the ref in srcPromise is dropped.
40     {
41         // Make a strike with a Pinner.
42         auto strike = strikeCache->createStrike(strikeSpec, nullptr, std::make_unique<Pinner>());
43         toCompareWith = reinterpret_cast<intptr_t>(strike.get());
44         SkStrikePromise srcPromise(std::move(strike));
45         SkBinaryWriteBuffer writeBuffer;
46         srcPromise.flatten(writeBuffer);
47         data = writeBuffer.snapshotAsData();
48     }
49 
50     // Remove all unpinned strikes.
51     strikeCache->purgeAll();
52 
53     SkReadBuffer readBuffer{data->data(), data->size()};
54     std::optional<SkStrikePromise> dstPromise = SkStrikePromise::MakeFromBuffer(
55             readBuffer, nullptr, strikeCache.get());
56 
57     REPORTER_ASSERT(reporter, dstPromise.has_value());
58     REPORTER_ASSERT(reporter,
59         reinterpret_cast<intptr_t>(dstPromise->strike()) == toCompareWith);
60 }
61