Loading native/jni/NativeFileList.mk +1 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,7 @@ LATIN_IME_CORE_TEST_FILES := \ 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/utils/buffer_with_extendable_buffer_test.cpp \ suggest/policyimpl/dictionary/utils/byte_array_utils_test.cpp \ suggest/policyimpl/dictionary/utils/trie_map_test.cpp \ utils/autocorrection_threshold_utils_test.cpp \ utils/int_array_view_test.cpp native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ uint32_t BufferWithExtendableBuffer::readUint(const int size, const int pos) con uint32_t BufferWithExtendableBuffer::readUintAndAdvancePosition(const int size, int *const pos) const { const int value = readUint(size, *pos); const uint32_t value = readUint(size, *pos); *pos += size; return value; } Loading native/jni/src/suggest/policyimpl/dictionary/utils/byte_array_utils.h +1 −1 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ class ByteArrayUtils { return buffer[(*pos)++]; } static AK_FORCE_INLINE int readUint(const uint8_t *const buffer, static AK_FORCE_INLINE uint32_t readUint(const uint8_t *const buffer, const int size, const int pos) { // size must be in 1 to 4. ASSERT(size >= 1 && size <= 4); Loading native/jni/tests/suggest/policyimpl/dictionary/utils/byte_array_utils_test.cpp 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * 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/utils/byte_array_utils.h" #include <gtest/gtest.h> #include <cstdint> namespace latinime { namespace { TEST(ByteArrayUtilsTest, TestReadInt) { const uint8_t buffer[] = { 0x1u, 0x8Au, 0x0u, 0xAAu }; EXPECT_EQ(0x01u, ByteArrayUtils::readUint8(buffer, 0)); EXPECT_EQ(0x8Au, ByteArrayUtils::readUint8(buffer, 1)); EXPECT_EQ(0x0u, ByteArrayUtils::readUint8(buffer, 2)); EXPECT_EQ(0xAAu, ByteArrayUtils::readUint8(buffer, 3)); EXPECT_EQ(0x018Au, ByteArrayUtils::readUint16(buffer, 0)); EXPECT_EQ(0x8A00u, ByteArrayUtils::readUint16(buffer, 1)); EXPECT_EQ(0xAAu, ByteArrayUtils::readUint16(buffer, 2)); EXPECT_EQ(0x18A00AAu, ByteArrayUtils::readUint32(buffer, 0)); int pos = 0; EXPECT_EQ(0x18A00, ByteArrayUtils::readSint24AndAdvancePosition(buffer, &pos)); pos = 1; EXPECT_EQ(-0xA00AA, ByteArrayUtils::readSint24AndAdvancePosition(buffer, &pos)); } TEST(ByteArrayUtilsTest, TestWriteAndReadInt) { uint8_t buffer[4]; int pos = 0; const uint8_t data_1B = 0xC8; ByteArrayUtils::writeUintAndAdvancePosition(buffer, data_1B, 1, &pos); EXPECT_EQ(data_1B, ByteArrayUtils::readUint(buffer, 1, 0)); pos = 0; const uint32_t data_4B = 0xABCD1234; ByteArrayUtils::writeUintAndAdvancePosition(buffer, data_4B, 4, &pos); EXPECT_EQ(data_4B, ByteArrayUtils::readUint(buffer, 4, 0)); } TEST(ByteArrayUtilsTest, TestReadCodePoint) { const uint8_t buffer[] = { 0x10, 0xFF, 0x00u, 0x20u, 0x41u, 0x1Fu, 0x60 }; EXPECT_EQ(0x10FF00, ByteArrayUtils::readCodePoint(buffer, 0)); EXPECT_EQ(0x20, ByteArrayUtils::readCodePoint(buffer, 3)); EXPECT_EQ(0x41, ByteArrayUtils::readCodePoint(buffer, 4)); EXPECT_EQ(NOT_A_CODE_POINT, ByteArrayUtils::readCodePoint(buffer, 5)); int pos = 0; int codePointArray[3]; EXPECT_EQ(3, ByteArrayUtils::readStringAndAdvancePosition(buffer, MAX_WORD_LENGTH, codePointArray, &pos)); EXPECT_EQ(0x10FF00, codePointArray[0]); EXPECT_EQ(0x20, codePointArray[1]); EXPECT_EQ(0x41, codePointArray[2]); EXPECT_EQ(0x60, ByteArrayUtils::readCodePoint(buffer, pos)); } TEST(ByteArrayUtilsTest, TestWriteAndReadCodePoint) { uint8_t buffer[10]; const int codePointArray[] = { 0x10FF00, 0x20, 0x41 }; int pos = 0; ByteArrayUtils::writeCodePointsAndAdvancePosition(buffer, codePointArray, 3, true /* writesTerminator */, &pos); EXPECT_EQ(0x10FF00, ByteArrayUtils::readCodePoint(buffer, 0)); EXPECT_EQ(0x20, ByteArrayUtils::readCodePoint(buffer, 3)); EXPECT_EQ(0x41, ByteArrayUtils::readCodePoint(buffer, 4)); EXPECT_EQ(NOT_A_CODE_POINT, ByteArrayUtils::readCodePoint(buffer, 5)); } } // namespace } // namespace latinime Loading
native/jni/NativeFileList.mk +1 −0 Original line number Diff line number Diff line Loading @@ -128,6 +128,7 @@ LATIN_IME_CORE_TEST_FILES := \ 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/utils/buffer_with_extendable_buffer_test.cpp \ suggest/policyimpl/dictionary/utils/byte_array_utils_test.cpp \ suggest/policyimpl/dictionary/utils/trie_map_test.cpp \ utils/autocorrection_threshold_utils_test.cpp \ utils/int_array_view_test.cpp
native/jni/src/suggest/policyimpl/dictionary/utils/buffer_with_extendable_buffer.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ uint32_t BufferWithExtendableBuffer::readUint(const int size, const int pos) con uint32_t BufferWithExtendableBuffer::readUintAndAdvancePosition(const int size, int *const pos) const { const int value = readUint(size, *pos); const uint32_t value = readUint(size, *pos); *pos += size; return value; } Loading
native/jni/src/suggest/policyimpl/dictionary/utils/byte_array_utils.h +1 −1 Original line number Diff line number Diff line Loading @@ -114,7 +114,7 @@ class ByteArrayUtils { return buffer[(*pos)++]; } static AK_FORCE_INLINE int readUint(const uint8_t *const buffer, static AK_FORCE_INLINE uint32_t readUint(const uint8_t *const buffer, const int size, const int pos) { // size must be in 1 to 4. ASSERT(size >= 1 && size <= 4); Loading
native/jni/tests/suggest/policyimpl/dictionary/utils/byte_array_utils_test.cpp 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * 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/utils/byte_array_utils.h" #include <gtest/gtest.h> #include <cstdint> namespace latinime { namespace { TEST(ByteArrayUtilsTest, TestReadInt) { const uint8_t buffer[] = { 0x1u, 0x8Au, 0x0u, 0xAAu }; EXPECT_EQ(0x01u, ByteArrayUtils::readUint8(buffer, 0)); EXPECT_EQ(0x8Au, ByteArrayUtils::readUint8(buffer, 1)); EXPECT_EQ(0x0u, ByteArrayUtils::readUint8(buffer, 2)); EXPECT_EQ(0xAAu, ByteArrayUtils::readUint8(buffer, 3)); EXPECT_EQ(0x018Au, ByteArrayUtils::readUint16(buffer, 0)); EXPECT_EQ(0x8A00u, ByteArrayUtils::readUint16(buffer, 1)); EXPECT_EQ(0xAAu, ByteArrayUtils::readUint16(buffer, 2)); EXPECT_EQ(0x18A00AAu, ByteArrayUtils::readUint32(buffer, 0)); int pos = 0; EXPECT_EQ(0x18A00, ByteArrayUtils::readSint24AndAdvancePosition(buffer, &pos)); pos = 1; EXPECT_EQ(-0xA00AA, ByteArrayUtils::readSint24AndAdvancePosition(buffer, &pos)); } TEST(ByteArrayUtilsTest, TestWriteAndReadInt) { uint8_t buffer[4]; int pos = 0; const uint8_t data_1B = 0xC8; ByteArrayUtils::writeUintAndAdvancePosition(buffer, data_1B, 1, &pos); EXPECT_EQ(data_1B, ByteArrayUtils::readUint(buffer, 1, 0)); pos = 0; const uint32_t data_4B = 0xABCD1234; ByteArrayUtils::writeUintAndAdvancePosition(buffer, data_4B, 4, &pos); EXPECT_EQ(data_4B, ByteArrayUtils::readUint(buffer, 4, 0)); } TEST(ByteArrayUtilsTest, TestReadCodePoint) { const uint8_t buffer[] = { 0x10, 0xFF, 0x00u, 0x20u, 0x41u, 0x1Fu, 0x60 }; EXPECT_EQ(0x10FF00, ByteArrayUtils::readCodePoint(buffer, 0)); EXPECT_EQ(0x20, ByteArrayUtils::readCodePoint(buffer, 3)); EXPECT_EQ(0x41, ByteArrayUtils::readCodePoint(buffer, 4)); EXPECT_EQ(NOT_A_CODE_POINT, ByteArrayUtils::readCodePoint(buffer, 5)); int pos = 0; int codePointArray[3]; EXPECT_EQ(3, ByteArrayUtils::readStringAndAdvancePosition(buffer, MAX_WORD_LENGTH, codePointArray, &pos)); EXPECT_EQ(0x10FF00, codePointArray[0]); EXPECT_EQ(0x20, codePointArray[1]); EXPECT_EQ(0x41, codePointArray[2]); EXPECT_EQ(0x60, ByteArrayUtils::readCodePoint(buffer, pos)); } TEST(ByteArrayUtilsTest, TestWriteAndReadCodePoint) { uint8_t buffer[10]; const int codePointArray[] = { 0x10FF00, 0x20, 0x41 }; int pos = 0; ByteArrayUtils::writeCodePointsAndAdvancePosition(buffer, codePointArray, 3, true /* writesTerminator */, &pos); EXPECT_EQ(0x10FF00, ByteArrayUtils::readCodePoint(buffer, 0)); EXPECT_EQ(0x20, ByteArrayUtils::readCodePoint(buffer, 3)); EXPECT_EQ(0x41, ByteArrayUtils::readCodePoint(buffer, 4)); EXPECT_EQ(NOT_A_CODE_POINT, ByteArrayUtils::readCodePoint(buffer, 5)); } } // namespace } // namespace latinime