1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gtest/gtest.h>
18 #include <UnicodeUtils.h>
19 #include <minikin/Measurement.h>
20 
21 namespace minikin {
22 
getAdvance(const float * advances,const char * src)23 float getAdvance(const float* advances, const char* src) {
24     const size_t BUF_SIZE = 256;
25     uint16_t buf[BUF_SIZE];
26     size_t offset;
27     size_t size;
28     ParseUnicode(buf, BUF_SIZE, src, &size, &offset);
29     return getRunAdvance(advances, buf, 0, size, offset);
30 }
31 
32 // Latin fi
TEST(Measurement,getRunAdvance_fi)33 TEST(Measurement, getRunAdvance_fi) {
34     const float unligated[] = {30.0, 20.0};
35     EXPECT_EQ(0.0, getAdvance(unligated, "| 'f' 'i'"));
36     EXPECT_EQ(30.0, getAdvance(unligated, "'f' | 'i'"));
37     EXPECT_EQ(50.0, getAdvance(unligated, "'f' 'i' |"));
38 
39     const float ligated[] = {40.0, 0.0};
40     EXPECT_EQ(0.0, getAdvance(ligated, "| 'f' 'i'"));
41     EXPECT_EQ(20.0, getAdvance(ligated, "'f' | 'i'"));
42     EXPECT_EQ(40.0, getAdvance(ligated, "'f' 'i' |"));
43 }
44 
45 // Devanagari ka+virama+ka
TEST(Measurement,getRunAdvance_kka)46 TEST(Measurement, getRunAdvance_kka) {
47     const float unligated[] = {30.0, 0.0, 30.0};
48     EXPECT_EQ(0.0, getAdvance(unligated, "| U+0915 U+094D U+0915"));
49     EXPECT_EQ(30.0, getAdvance(unligated, "U+0915 | U+094D U+0915"));
50     EXPECT_EQ(30.0, getAdvance(unligated, "U+0915 U+094D | U+0915"));
51     EXPECT_EQ(60.0, getAdvance(unligated, "U+0915 U+094D U+0915 |"));
52 
53     const float ligated[] = {30.0, 0.0, 0.0};
54     EXPECT_EQ(0.0, getAdvance(ligated, "| U+0915 U+094D U+0915"));
55     EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 | U+094D U+0915"));
56     EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 U+094D | U+0915"));
57     EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 U+094D U+0915 |"));
58 }
59 
60 }  // namespace minikin
61