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 "textclassifier_jni.h"
18
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21
22 namespace libtextclassifier {
23 namespace {
24
TEST(TextClassifier,ConvertIndicesBMPUTF8)25 TEST(TextClassifier, ConvertIndicesBMPUTF8) {
26 // Test boundary cases.
27 EXPECT_EQ(ConvertIndicesBMPToUTF8("hello", {0, 5}), std::make_pair(0, 5));
28 EXPECT_EQ(ConvertIndicesUTF8ToBMP("hello", {0, 5}), std::make_pair(0, 5));
29
30 EXPECT_EQ(ConvertIndicesBMPToUTF8("hello world", {0, 5}),
31 std::make_pair(0, 5));
32 EXPECT_EQ(ConvertIndicesUTF8ToBMP("hello world", {0, 5}),
33 std::make_pair(0, 5));
34 EXPECT_EQ(ConvertIndicesBMPToUTF8("ello world", {0, 6}),
35 std::make_pair(0, 5));
36 EXPECT_EQ(ConvertIndicesUTF8ToBMP("ello world", {0, 5}),
37 std::make_pair(0, 6));
38
39 EXPECT_EQ(ConvertIndicesBMPToUTF8("hello world", {6, 11}),
40 std::make_pair(6, 11));
41 EXPECT_EQ(ConvertIndicesUTF8ToBMP("hello world", {6, 11}),
42 std::make_pair(6, 11));
43 EXPECT_EQ(ConvertIndicesBMPToUTF8("hello worl", {6, 12}),
44 std::make_pair(6, 11));
45 EXPECT_EQ(ConvertIndicesUTF8ToBMP("hello worl", {6, 11}),
46 std::make_pair(6, 12));
47
48 // Simple example where the longer character is before the selection.
49 // character is 0x1f601
50 EXPECT_EQ(ConvertIndicesBMPToUTF8(" Hello World.", {3, 8}),
51 std::make_pair(2, 7));
52
53 EXPECT_EQ(ConvertIndicesUTF8ToBMP(" Hello World.", {2, 7}),
54 std::make_pair(3, 8));
55
56 // Longer character is before and in selection.
57 EXPECT_EQ(ConvertIndicesBMPToUTF8(" Hell World.", {3, 9}),
58 std::make_pair(2, 7));
59
60 EXPECT_EQ(ConvertIndicesUTF8ToBMP(" Hell World.", {2, 7}),
61 std::make_pair(3, 9));
62
63 // Longer character is before and after selection.
64 EXPECT_EQ(ConvertIndicesBMPToUTF8(" HelloWorld.", {3, 8}),
65 std::make_pair(2, 7));
66
67 EXPECT_EQ(ConvertIndicesUTF8ToBMP(" HelloWorld.", {2, 7}),
68 std::make_pair(3, 8));
69
70 // Longer character is before in after selection.
71 EXPECT_EQ(ConvertIndicesBMPToUTF8(" HellWorld.", {3, 9}),
72 std::make_pair(2, 7));
73
74 EXPECT_EQ(ConvertIndicesUTF8ToBMP(" HellWorld.", {2, 7}),
75 std::make_pair(3, 9));
76 }
77
78 } // namespace
79 } // namespace libtextclassifier
80