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 "minikin/Measurement.h"
18
19 #include <gtest/gtest.h>
20
21 #include "UnicodeUtils.h"
22
23 namespace minikin {
24
getAdvance(const float * advances,const char * src)25 float getAdvance(const float* advances, const char* src) {
26 const size_t BUF_SIZE = 256;
27 uint16_t buf[BUF_SIZE];
28 size_t offset;
29 size_t size;
30 ParseUnicode(buf, BUF_SIZE, src, &size, &offset);
31 return getRunAdvance(advances, buf, 0, size, offset);
32 }
33
34 // Latin fi
TEST(Measurement,getRunAdvance_fi)35 TEST(Measurement, getRunAdvance_fi) {
36 const float unligated[] = {30.0, 20.0};
37 EXPECT_EQ(0.0, getAdvance(unligated, "| 'f' 'i'"));
38 EXPECT_EQ(30.0, getAdvance(unligated, "'f' | 'i'"));
39 EXPECT_EQ(50.0, getAdvance(unligated, "'f' 'i' |"));
40
41 const float ligated[] = {40.0, 0.0};
42 EXPECT_EQ(0.0, getAdvance(ligated, "| 'f' 'i'"));
43 EXPECT_EQ(20.0, getAdvance(ligated, "'f' | 'i'"));
44 EXPECT_EQ(40.0, getAdvance(ligated, "'f' 'i' |"));
45 }
46
47 // Devanagari ka+virama+ka
TEST(Measurement,getRunAdvance_kka)48 TEST(Measurement, getRunAdvance_kka) {
49 const float unligated[] = {30.0, 0.0, 30.0};
50 EXPECT_EQ(0.0, getAdvance(unligated, "| U+0915 U+094D U+0915"));
51 EXPECT_EQ(30.0, getAdvance(unligated, "U+0915 | U+094D U+0915"));
52 EXPECT_EQ(30.0, getAdvance(unligated, "U+0915 U+094D | U+0915"));
53 EXPECT_EQ(60.0, getAdvance(unligated, "U+0915 U+094D U+0915 |"));
54
55 const float ligated[] = {30.0, 0.0, 0.0};
56 EXPECT_EQ(0.0, getAdvance(ligated, "| U+0915 U+094D U+0915"));
57 EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 | U+094D U+0915"));
58 EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 U+094D | U+0915"));
59 EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 U+094D U+0915 |"));
60 }
61
62 } // namespace minikin
63