1 // Copyright (c) 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "third_party/blink/renderer/platform/fonts/shaping/shape_result_inline_headers.h"
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 
9 namespace blink {
10 
11 class ShapeResultRunInfoTest : public testing::Test {};
12 
TEST_F(ShapeResultRunInfoTest,CopyConstructor)13 TEST_F(ShapeResultRunInfoTest, CopyConstructor) {
14   ShapeResult::RunInfo::GlyphOffsetArray offsets(2);
15 
16   ShapeResult::RunInfo::GlyphOffsetArray offsets2(offsets);
17   EXPECT_FALSE(offsets2.HasStorage());
18 
19   offsets.SetAt(0, ShapeResult::GlyphOffset(1, 1));
20   ShapeResult::RunInfo::GlyphOffsetArray offsets3(offsets);
21   ASSERT_TRUE(offsets3.HasStorage());
22   EXPECT_EQ(ShapeResult::GlyphOffset(1, 1), offsets3.GetStorage()[0]);
23 }
24 
TEST_F(ShapeResultRunInfoTest,CopyFromRange)25 TEST_F(ShapeResultRunInfoTest, CopyFromRange) {
26   ShapeResult::RunInfo::GlyphOffsetArray offsets(2);
27   HarfBuzzRunGlyphData glyhp_data[2];
28 
29   ShapeResult::RunInfo::GlyphOffsetArray offsets2(2);
30   offsets2.CopyFromRange({&glyhp_data[0], &glyhp_data[2], nullptr});
31   EXPECT_FALSE(offsets2.HasStorage());
32 
33   offsets.SetAt(0, ShapeResult::GlyphOffset(1, 1));
34   ASSERT_TRUE(offsets.HasStorage());
35 
36   ShapeResult::RunInfo::GlyphOffsetArray offsets3(2);
37   offsets3.CopyFromRange(
38       {&glyhp_data[0], &glyhp_data[2], offsets.GetStorage()});
39   ASSERT_TRUE(offsets3.HasStorage());
40   EXPECT_EQ(ShapeResult::GlyphOffset(1, 1), offsets3.GetStorage()[0]);
41 }
42 
TEST_F(ShapeResultRunInfoTest,GlyphOffsetArrayReverse)43 TEST_F(ShapeResultRunInfoTest, GlyphOffsetArrayReverse) {
44   ShapeResult::RunInfo::GlyphOffsetArray offsets(2);
45 
46   offsets.Reverse();
47   EXPECT_FALSE(offsets.HasStorage());
48 
49   offsets.SetAt(0, ShapeResult::GlyphOffset(1, 1));
50   ASSERT_TRUE(offsets.HasStorage());
51   offsets.Reverse();
52   EXPECT_EQ(ShapeResult::GlyphOffset(), offsets.GetStorage()[0]);
53   EXPECT_EQ(ShapeResult::GlyphOffset(1, 1), offsets.GetStorage()[1]);
54 }
55 
TEST_F(ShapeResultRunInfoTest,GlyphOffsetArraySetAddOffsetHeightAt)56 TEST_F(ShapeResultRunInfoTest, GlyphOffsetArraySetAddOffsetHeightAt) {
57   ShapeResult::RunInfo::GlyphOffsetArray offsets(2);
58 
59   offsets.AddHeightAt(1, 1.5f);
60   ASSERT_TRUE(offsets.HasStorage());
61   EXPECT_EQ(ShapeResult::GlyphOffset(0, 1.5f), offsets.GetStorage()[1]);
62 
63   offsets.AddHeightAt(1, 2.0f);
64   ASSERT_TRUE(offsets.HasStorage());
65   EXPECT_EQ(ShapeResult::GlyphOffset(0, 3.5f), offsets.GetStorage()[1]);
66 }
67 
TEST_F(ShapeResultRunInfoTest,GlyphOffsetArraySetAddOffsetWidthAt)68 TEST_F(ShapeResultRunInfoTest, GlyphOffsetArraySetAddOffsetWidthAt) {
69   ShapeResult::RunInfo::GlyphOffsetArray offsets(2);
70 
71   offsets.AddWidthAt(1, 1.5f);
72   ASSERT_TRUE(offsets.HasStorage());
73   EXPECT_EQ(ShapeResult::GlyphOffset(1.5f, 0), offsets.GetStorage()[1]);
74 
75   offsets.AddWidthAt(1, 2.0f);
76   ASSERT_TRUE(offsets.HasStorage());
77   EXPECT_EQ(ShapeResult::GlyphOffset(3.5f, 0), offsets.GetStorage()[1]);
78 }
79 
TEST_F(ShapeResultRunInfoTest,GlyphOffsetArraySetAt)80 TEST_F(ShapeResultRunInfoTest, GlyphOffsetArraySetAt) {
81   ShapeResult::RunInfo::GlyphOffsetArray offsets(2);
82 
83   offsets.SetAt(0, ShapeResult::GlyphOffset());
84   EXPECT_FALSE(offsets.HasStorage());
85 
86   offsets.SetAt(1, ShapeResult::GlyphOffset(1, 1));
87   EXPECT_TRUE(offsets.HasStorage());
88 }
89 
TEST_F(ShapeResultRunInfoTest,GlyphOffsetArrayShrink)90 TEST_F(ShapeResultRunInfoTest, GlyphOffsetArrayShrink) {
91   ShapeResult::RunInfo::GlyphOffsetArray offsets(3);
92 
93   offsets.Shrink(2);
94   EXPECT_FALSE(offsets.HasStorage());
95 
96   offsets.SetAt(0, ShapeResult::GlyphOffset(1, 1));
97   ASSERT_TRUE(offsets.HasStorage());
98 
99   offsets.Shrink(1);
100   ASSERT_TRUE(offsets.HasStorage());
101   EXPECT_EQ(ShapeResult::GlyphOffset(1, 1), offsets.GetStorage()[0]);
102 }
103 
104 }  // namespace blink
105