15 #include "absl/strings/str_format.h"
25 #ifndef DISABLED_LEGACY_ENGINE
37 static void Setup352(
int font_id, Shape* shape) {
38 shape->AddToShape(3, font_id);
39 shape->AddToShape(5, font_id);
40 shape->AddToShape(2, font_id);
44 static void Expect352(
int font_id,
const Shape& shape) {
45 EXPECT_EQ(3, shape.size());
46 EXPECT_TRUE(shape.ContainsUnichar(2));
47 EXPECT_TRUE(shape.ContainsUnichar(3));
48 EXPECT_TRUE(shape.ContainsUnichar(5));
49 EXPECT_FALSE(shape.ContainsUnichar(1));
50 EXPECT_TRUE(shape.ContainsUnicharAndFont(2, font_id));
51 EXPECT_FALSE(shape.ContainsUnicharAndFont(2, font_id - 1));
52 EXPECT_FALSE(shape.ContainsUnicharAndFont(font_id, 2));
54 EXPECT_TRUE(shape.IsSubsetOf(shape));
60 class ShapeTest :
public testing::Test {
63 std::locale::global(std::locale(
""));
68 TEST_F(ShapeTest, BasicTest) {
69 #ifdef DISABLED_LEGACY_ENGINE
74 EXPECT_EQ(0, shape1.size());
75 Setup352(101, &shape1);
76 Expect352(101, shape1);
79 FILE* fp = fopen(filename.c_str(),
"wb");
80 EXPECT_TRUE(fp !=
nullptr);
81 EXPECT_TRUE(shape1.Serialize(fp));
84 EXPECT_TRUE(tfp.Open(filename.c_str(),
nullptr));
86 EXPECT_TRUE(shape2.DeSerialize(&tfp));
87 Expect352(101, shape2);
89 EXPECT_TRUE(shape1.IsSubsetOf(shape2));
90 EXPECT_TRUE(shape2.IsSubsetOf(shape1));
92 EXPECT_TRUE(shape1.IsEqualUnichars(&shape2));
94 Expect352(101, shape1);
95 Expect352(101, shape2);
100 TEST_F(ShapeTest, AddShapeTest) {
101 #ifdef DISABLED_LEGACY_ENGINE
106 Setup352(101, &shape1);
107 Expect352(101, shape1);
110 shape2.AddToShape(3, 101);
111 shape2.AddToShape(5, 110);
112 shape2.AddToShape(7, 101);
114 EXPECT_FALSE(shape1.IsSubsetOf(shape2));
115 EXPECT_FALSE(shape2.IsSubsetOf(shape1));
117 shape1.AddShape(shape2);
119 EXPECT_FALSE(shape1.IsSubsetOf(shape2));
120 EXPECT_TRUE(shape2.IsSubsetOf(shape1));
121 EXPECT_EQ(4, shape1.size());
122 EXPECT_FALSE(shape1.ContainsUnichar(1));
123 EXPECT_TRUE(shape1.ContainsUnicharAndFont(5, 101));
124 EXPECT_TRUE(shape1.ContainsUnicharAndFont(5, 110));
125 EXPECT_FALSE(shape1.ContainsUnicharAndFont(3, 110));
126 EXPECT_FALSE(shape1.ContainsUnicharAndFont(7, 110));
127 EXPECT_FALSE(shape1.IsEqualUnichars(&shape2));
132 class ShapeTableTest :
public testing::Test {};
135 TEST_F(ShapeTableTest, FullTest) {
136 #ifdef DISABLED_LEGACY_ENGINE
141 Setup352(101, &shape1);
145 for (
int i = 1; i <= 10; ++i) {
146 std::string class_str = absl::StrFormat(
"class%d", i);
149 ShapeTable st(unicharset);
150 EXPECT_EQ(0, st.AddShape(3, 101));
151 EXPECT_EQ(1, st.AddShape(5, 101));
152 EXPECT_EQ(2, st.AddShape(2, 101));
153 EXPECT_EQ(3, st.NumShapes());
154 Expect352(101, shape1);
155 EXPECT_EQ(3, st.AddShape(shape1));
156 for (
int i = 0; i < 3; ++i) {
157 EXPECT_FALSE(st.MutableShape(i)->IsEqualUnichars(&shape1));
159 EXPECT_TRUE(st.MutableShape(3)->IsEqualUnichars(&shape1));
160 EXPECT_TRUE(st.AnyMultipleUnichars());
162 EXPECT_FALSE(st.AnyMultipleUnichars());
165 EXPECT_EQ(1, st.MasterUnicharCount(0));
166 st.MergeShapes(0, 1);
167 EXPECT_EQ(3, st.MergedUnicharCount(1, 2));
168 st.MergeShapes(1, 2);
169 for (
int i = 0; i < 3; ++i) {
170 EXPECT_EQ(3, st.MasterUnicharCount(i));
173 EXPECT_EQ(3, st.MasterFontCount(i));
175 EXPECT_EQ(0, st.MasterDestinationIndex(1));
176 EXPECT_EQ(0, st.MasterDestinationIndex(2));
178 st2.AppendMasterShapes(st,
nullptr);
179 EXPECT_EQ(1, st.NumMasterShapes());
180 EXPECT_EQ(1, st2.NumShapes());
181 EXPECT_TRUE(st2.MutableShape(0)->IsEqualUnichars(&shape1));
182 EXPECT_TRUE(st2.AnyMultipleUnichars());