File: glyph_usage_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (106 lines) | stat: -rw-r--r-- 3,294 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/paint_preview/common/glyph_usage.h"

#include <memory>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace paint_preview {

TEST(PaintPreviewGlyphUsageTest, TestEmpty) {
  DenseGlyphUsage dense;
  EXPECT_EQ(dense.First(), 0U);
  EXPECT_EQ(dense.Last(), 0U);
  EXPECT_FALSE(dense.ShouldSubset());
  dense.Set(0);
  EXPECT_FALSE(dense.IsSet(0));
  dense.Set(5);
  EXPECT_FALSE(dense.IsSet(5));
  dense.Set(60);
  EXPECT_FALSE(dense.IsSet(60));
  size_t counter = 0;
  auto cb = base::BindRepeating(
      [](size_t* counter, uint16_t glyph_id) { ++(*counter); },
      base::Unretained(&counter));
  dense.ForEach(cb);
  EXPECT_EQ(counter, 0U);

  SparseGlyphUsage sparse;
  EXPECT_EQ(sparse.First(), 0U);
  EXPECT_EQ(sparse.Last(), 0U);
  EXPECT_FALSE(sparse.ShouldSubset());
  sparse.Set(0);
  EXPECT_FALSE(sparse.IsSet(0));
  sparse.Set(5);
  EXPECT_FALSE(sparse.IsSet(5));
  sparse.Set(60);
  EXPECT_FALSE(sparse.IsSet(60));
  counter = 0;
  sparse.ForEach(cb);
  EXPECT_EQ(counter, 0U);
}

TEST(PaintPreviewGlyphUsageTest, TestDense) {
  const uint16_t kFirst = 1;
  const uint16_t kNumGlyphs = 70;
  DenseGlyphUsage dense(kNumGlyphs);
  EXPECT_EQ(dense.First(), kFirst);
  EXPECT_EQ(dense.Last(), kNumGlyphs);
  EXPECT_TRUE(dense.ShouldSubset());
  // 0 should be valid even though it is before "first".
  std::vector<uint16_t> test_glyph_ids = {0, 1, 24, 70, 68, 1, 9, 8};
  for (const auto& gid : test_glyph_ids) {
    dense.Set(gid);
    EXPECT_TRUE(dense.IsSet(gid));
  }
  dense.Set(kNumGlyphs + 1);
  EXPECT_FALSE(dense.IsSet(kNumGlyphs + 1));
  dense.Set(kNumGlyphs * 2);
  EXPECT_FALSE(dense.IsSet(kNumGlyphs * 2));
  std::vector<uint16_t> set_gids;
  auto cb = base::BindRepeating(
      [](std::vector<uint16_t>* set_gids, uint16_t glyph_id) {
        set_gids->push_back(glyph_id);
      },
      base::Unretained(&set_gids));
  dense.ForEach(cb);
  EXPECT_THAT(set_gids,
              testing::UnorderedElementsAre(0U, 1U, 24U, 70U, 68U, 9U, 8U));
}

TEST(PaintPreviewGlyphUsageTest, TestSparse) {
  const uint16_t kFirst = 1;
  const uint16_t kNumGlyphs = 70;
  SparseGlyphUsage sparse(kNumGlyphs);
  EXPECT_EQ(sparse.First(), kFirst);
  EXPECT_EQ(sparse.Last(), kNumGlyphs);
  EXPECT_TRUE(sparse.ShouldSubset());
  // 0 should be valid even though it is before "first".
  std::vector<uint16_t> test_glyph_ids = {0, 1, 24, 70, 68, 1, 9, 8};
  for (const auto& gid : test_glyph_ids) {
    sparse.Set(gid);
    EXPECT_TRUE(sparse.IsSet(gid));
  }
  sparse.Set(kNumGlyphs + 1);
  EXPECT_FALSE(sparse.IsSet(kNumGlyphs + 1));
  sparse.Set(kNumGlyphs * 2);
  EXPECT_FALSE(sparse.IsSet(kNumGlyphs * 2));
  std::vector<uint16_t> set_gids;
  auto cb = base::BindRepeating(
      [](std::vector<uint16_t>* set_gids, uint16_t glyph_id) {
        set_gids->push_back(glyph_id);
      },
      base::Unretained(&set_gids));
  sparse.ForEach(cb);
  EXPECT_THAT(set_gids,
              testing::UnorderedElementsAre(0U, 1U, 24U, 70U, 68U, 9U, 8U));
}

}  // namespace paint_preview