aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--native/jni/NativeFileList.mk1
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp3
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h2
-rw-r--r--native/jni/tests/suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp78
4 files changed, 82 insertions, 2 deletions
diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk
index 4f77388fd..68d2bbd83 100644
--- a/native/jni/NativeFileList.mk
+++ b/native/jni/NativeFileList.mk
@@ -125,6 +125,7 @@ LATIN_IME_CORE_TEST_FILES := \
suggest/core/dictionary/bloom_filter_test.cpp \
suggest/core/layout/geometry_utils_test.cpp \
suggest/core/layout/normal_distribution_2d_test.cpp \
+ suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp \
suggest/policyimpl/dictionary/structure/v4/content/language_model_dict_content_test.cpp \
suggest/policyimpl/dictionary/structure/v4/content/probability_entry_test.cpp \
suggest/policyimpl/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp \
diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp
index a8f8f284b..d2c3d2fe0 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.cpp
@@ -142,7 +142,8 @@ typedef DictionaryHeaderStructurePolicy::AttributeMap AttributeMap;
}
/* static */ void HeaderReadWriteUtils::setCodePointVectorAttribute(
- AttributeMap *const headerAttributes, const char *const key, const std::vector<int> value) {
+ AttributeMap *const headerAttributes, const char *const key,
+ const std::vector<int> &value) {
AttributeMap::key_type keyVector;
insertCharactersIntoVector(key, &keyVector);
(*headerAttributes)[keyVector] = value;
diff --git a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h
index 9b90488fc..1ab2eec69 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h
+++ b/native/jni/src/suggest/policyimpl/dictionary/header/header_read_write_utils.h
@@ -64,7 +64,7 @@ class HeaderReadWriteUtils {
*/
static void setCodePointVectorAttribute(
DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
- const char *const key, const std::vector<int> value);
+ const char *const key, const std::vector<int> &value);
static void setBoolAttribute(
DictionaryHeaderStructurePolicy::AttributeMap *const headerAttributes,
diff --git a/native/jni/tests/suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp b/native/jni/tests/suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp
new file mode 100644
index 000000000..da6a2af27
--- /dev/null
+++ b/native/jni/tests/suggest/policyimpl/dictionary/header/header_read_write_utils_test.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "suggest/policyimpl/dictionary/header/header_read_write_utils.h"
+
+#include <gtest/gtest.h>
+
+#include <cstring>
+#include <vector>
+
+#include "suggest/core/policy/dictionary_header_structure_policy.h"
+
+namespace latinime {
+namespace {
+
+TEST(HeaderReadWriteUtilsTest, TestInsertCharactersIntoVector) {
+ DictionaryHeaderStructurePolicy::AttributeMap::key_type vector;
+
+ HeaderReadWriteUtils::insertCharactersIntoVector("", &vector);
+ EXPECT_TRUE(vector.empty());
+
+ static const char *str = "abc-xyz!?";
+ HeaderReadWriteUtils::insertCharactersIntoVector(str, &vector);
+ EXPECT_EQ(strlen(str) , vector.size());
+ for (size_t i = 0; i < vector.size(); ++i) {
+ EXPECT_EQ(str[i], vector[i]);
+ }
+}
+
+TEST(HeaderReadWriteUtilsTest, TestAttributeMapForInt) {
+ DictionaryHeaderStructurePolicy::AttributeMap attributeMap;
+
+ // Returns default value if not exists.
+ EXPECT_EQ(-1, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "", -1));
+ EXPECT_EQ(100, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100));
+
+ HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abc", 10);
+ EXPECT_EQ(10, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100));
+ HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abc", 20);
+ EXPECT_EQ(20, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100));
+ HeaderReadWriteUtils::setIntAttribute(&attributeMap, "abcd", 30);
+ EXPECT_EQ(30, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abcd", 100));
+ EXPECT_EQ(20, HeaderReadWriteUtils::readIntAttributeValue(&attributeMap, "abc", 100));
+}
+
+TEST(HeaderReadWriteUtilsTest, TestAttributeMapCodeForPoints) {
+ DictionaryHeaderStructurePolicy::AttributeMap attributeMap;
+
+ // Returns empty vector if not exists.
+ EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue(&attributeMap, "").empty());
+ EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue(
+ &attributeMap, "abc").empty());
+
+ HeaderReadWriteUtils::setCodePointVectorAttribute(&attributeMap, "abc", {});
+ EXPECT_TRUE(HeaderReadWriteUtils::readCodePointVectorAttributeValue(
+ &attributeMap, "abc").empty());
+
+ const std::vector<int> codePoints = { 0x0, 0x20, 0x1F, 0x100000 };
+ HeaderReadWriteUtils::setCodePointVectorAttribute(&attributeMap, "abc", codePoints);
+ EXPECT_EQ(codePoints, HeaderReadWriteUtils::readCodePointVectorAttributeValue(
+ &attributeMap, "abc"));
+}
+
+} // namespace
+} // namespace latinime