diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index b696a96a..9952d934 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -23,6 +23,7 @@ If you have questions or would like to communicate with the team, please [join u
- [Bug reports](#bug-reports)
- [Feature requests](#feature-requests)
- [Pull requests](#pull-requests)
+- [Adding keyboards](#adding-keyboards)
- [Data edits](#data-edits)
- [Localization](#localization)
- [Documentation](#documentation)
@@ -356,6 +357,16 @@ Thank you in advance for your contributions!
Back to top.
+## Adding keyboards
+
+Scribe has interest in adding keyboards for any language! Please let the community know if you'd like a Scribe keyboard in your second or native language.
+
+As of now the Scribe-Android keyboard application is leveraging AOSP based autosuggestions and autocompletions. This means that adding a new keyboard that has AOSP based dictionaries available is dramatically easier than adding other languages. Please see the following for a list of available dictionaries:
+
+- [Codeberg:Helium314/aosp-dictionaries](https://codeberg.org/Helium314/aosp-dictionaries)
+
+Back to top.
+
## Data edits
> [!NOTE]\
diff --git a/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt b/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt
index b8475281..23686594 100644
--- a/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt
+++ b/app/src/keyboards/java/be/scri/helpers/AutocompletionHandler.kt
@@ -19,40 +19,50 @@ class AutocompletionHandler(
private var autocompleteRunnable: Runnable? = null
companion object {
- private const val AUTOCOMPLETE_DELAY_MS = 50L
+ private const val AUTOCOMPLETE_DELAY_MS = 150L
+ private const val MAX_COMPLETIONS = 2
+
+ /**
+ * Filters dictionary/engine [completions] down to the ones worth showing
+ * alongside the word the user already typed: no duplicate of [typedWord],
+ * capped at [MAX_COMPLETIONS] (the word itself takes the remaining slot).
+ */
+ internal fun buildCompletions(
+ typedWord: String,
+ completions: List,
+ ): List =
+ completions
+ .filterNot { it.equals(typedWord, ignoreCase = true) }
+ .take(MAX_COMPLETIONS)
}
/**
* Processes the current word for autocompletion.
*
- * This function is called whenever the user types.
- * It cancels any pending autocomplete request and schedules a new one
- * after a short delay to prevent excessive lookups.
+ * This function is called whenever the user types. The word being typed is
+ * shown immediately (it's already known, no lookup needed), while the
+ * dictionary/engine completions are debounced to avoid excessive lookups.
*
* @param currentWord The word currently being typed by the user.
*/
fun processAutocomplete(currentWord: String?) {
autocompleteRunnable?.let { handler.removeCallbacks(it) }
+ if (ime.currentState != ScribeState.IDLE || currentWord.isNullOrEmpty()) {
+ ime.clearAutocomplete()
+ return
+ }
+
+ ime.updateTypedWordSuggestion(currentWord)
+
autocompleteRunnable =
Runnable {
- if (ime.currentState != ScribeState.IDLE) {
- ime.clearAutocomplete()
- return@Runnable
- }
-
- if (currentWord.isNullOrEmpty()) {
- ime.clearAutocomplete()
- return@Runnable
- }
+ if (ime.currentState != ScribeState.IDLE) return@Runnable
- val completions = ime.getAutocompletions(currentWord, limit = 5)
+ val previousWord = ime.getPreviousWordBeforeCursor()
+ val completions = ime.getAutocompletions(currentWord, previousWord, limit = MAX_COMPLETIONS + 1)
- if (completions.isNotEmpty()) {
- ime.updateAutocompleteSuggestions(completions)
- } else {
- ime.clearAutocomplete()
- }
+ ime.updateAutocompleteCompletions(buildCompletions(currentWord, completions))
}
handler.postDelayed(autocompleteRunnable!!, AUTOCOMPLETE_DELAY_MS)
diff --git a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt
index 7b34094e..0b2eff6d 100644
--- a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt
+++ b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt
@@ -1208,16 +1208,17 @@ abstract class GeneralKeyboardIME(
*/
fun getAutocompletions(
prefix: String,
+ previousWord: String? = null,
limit: Int = 3,
): List {
if (this::nativeSuggestionEngine.isInitialized) {
- val nativeCompletions = nativeSuggestionEngine.getAutocompletions(language, prefix, limit)
+ val nativeCompletions = nativeSuggestionEngine.getAutocompletions(language, prefix, previousWord, limit)
if (nativeCompletions.isNotEmpty()) {
- return nativeCompletions
+ return nativeCompletions.map { it.substringBefore("-") }
}
}
return try {
- dbManagers.autocompletionManager.getAutocompletions(prefix, limit)
+ dbManagers.autocompletionManager.getAutocompletions(prefix, limit).map { it.substringBefore("-") }
} catch (e: SQLiteException) {
Log.e("GeneralKeyboardIME", "Database error in autocompletion", e)
emptyList()
@@ -1252,6 +1253,18 @@ abstract class GeneralKeyboardIME(
*/
fun getLastWordBeforeCursor(): String? = getText()?.trim()?.split("\\s+".toRegex())?.lastOrNull()
+ /**
+ * Extracts the word immediately before the one currently being composed, i.e. the last
+ * completed word preceding the in-progress word at the cursor. Used to give the autocomplete
+ * engine sentence context so it can bias completions instead of scoring the prefix in isolation.
+ *
+ * @return The previous completed word as a [String], or null if there isn't one.
+ */
+ fun getPreviousWordBeforeCursor(): String? {
+ val words = getText()?.trim()?.split("\\s+".toRegex()) ?: return null
+ return words.getOrNull(words.size - 2)
+ }
+
/**
* Retrieves the text immediately preceding the cursor.
*
@@ -1499,10 +1512,10 @@ abstract class GeneralKeyboardIME(
if (this::nativeSuggestionEngine.isInitialized) {
val nativeSuggestions = nativeSuggestionEngine.getNextWordSuggestions(language, lastWord)
if (nativeSuggestions.isNotEmpty()) {
- return nativeSuggestions
+ return nativeSuggestions.map { it.substringBefore("-") }
}
}
- return wordSuggestions[lastWord.lowercase()]
+ return wordSuggestions[lastWord.lowercase()]?.map { it.substringBefore("-") }
}
/**
@@ -1928,29 +1941,56 @@ abstract class GeneralKeyboardIME(
// MARK: Autocomplete
/**
- * Updates autocomplete UI with a new list of suggestions.
- * Clears it if not idle or no completions.
+ * Pins the word currently being typed into the first (leftmost) suggestion
+ * slot, quoted like most mobile keyboards do to mark it as "what you typed"
+ * rather than a dictionary suggestion. Called immediately on every keystroke
+ * — unlike the completions, it needs no lookup, so it should never lag.
*/
- fun updateAutocompleteSuggestions(completions: List?) {
- if (currentState != ScribeState.IDLE) {
- uiManager.disableAutoSuggest(language)
- return
- }
- if (completions.isNullOrEmpty()) {
+ fun updateTypedWordSuggestion(word: String?) {
+ if (currentState != ScribeState.IDLE || word.isNullOrEmpty()) {
uiManager.disableAutoSuggest(language)
return
}
+ setTypedWordButton(uiManager.binding.translateBtn, word)
+ setAutocompleteButton(uiManager.binding.conjugateBtn, "")
+ uiManager.pluralBtn?.let { setAutocompleteButton(it, "") }
+
+ uiManager.binding.separator1.visibility = View.VISIBLE
+ uiManager.binding.separator2.visibility = View.VISIBLE
+ }
+
+ /**
+ * Fills the remaining suggestion slots with dictionary/engine completions.
+ * Clears them (leaving the typed word alone) if not idle.
+ */
+ fun updateAutocompleteCompletions(completions: List) {
+ if (currentState != ScribeState.IDLE) return
+
val completion1 = completions.getOrNull(0) ?: ""
val completion2 = completions.getOrNull(1) ?: ""
- val completion3 = completions.getOrNull(2) ?: ""
setAutocompleteButton(uiManager.binding.conjugateBtn, completion1)
- setAutocompleteButton(uiManager.binding.translateBtn, completion2)
- setAutocompleteButton(uiManager.pluralBtn!!, completion3)
+ uiManager.pluralBtn?.let { setAutocompleteButton(it, completion2) }
+ }
- uiManager.binding.separator1.visibility = View.VISIBLE
- uiManager.binding.separator2.visibility = View.VISIBLE
+ /**
+ * Sets up the "what you typed" button: displayed quoted, but tapping it
+ * doesn't re-insert the word (it's already in the text field) — it just
+ * confirms the word with a space, the same as pressing the space bar
+ * would, and moves on to next-word suggestions based on it.
+ */
+ private fun setTypedWordButton(
+ button: Button,
+ word: String,
+ ) {
+ setSuggestionButton(button, "\"$word\"")
+ button.setOnClickListener {
+ currentInputConnection?.commitText(" ", 1)
+ suggestionHandler.processLinguisticSuggestions(word)
+ suggestionHandler.processWordSuggestions(word)
+ moveToIdleState()
+ }
}
/**
diff --git a/app/src/main/assets/dicts/main_bg.dict b/app/src/main/assets/dicts/main_bg.dict
deleted file mode 100644
index b39d7e3f..00000000
Binary files a/app/src/main/assets/dicts/main_bg.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_bn.dict b/app/src/main/assets/dicts/main_bn.dict
deleted file mode 100644
index c0329fff..00000000
Binary files a/app/src/main/assets/dicts/main_bn.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_de.dict b/app/src/main/assets/dicts/main_de.dict
index 58aecf9e..b3c8c8fb 100644
Binary files a/app/src/main/assets/dicts/main_de.dict and b/app/src/main/assets/dicts/main_de.dict differ
diff --git a/app/src/main/assets/dicts/main_el.dict b/app/src/main/assets/dicts/main_el.dict
deleted file mode 100644
index fb8bbcee..00000000
Binary files a/app/src/main/assets/dicts/main_el.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_en-GB.dict b/app/src/main/assets/dicts/main_en-GB.dict
deleted file mode 100644
index 77145c7d..00000000
Binary files a/app/src/main/assets/dicts/main_en-GB.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_en-US.dict b/app/src/main/assets/dicts/main_en-US.dict
index 081a8c8c..ba56d826 100644
Binary files a/app/src/main/assets/dicts/main_en-US.dict and b/app/src/main/assets/dicts/main_en-US.dict differ
diff --git a/app/src/main/assets/dicts/main_es.dict b/app/src/main/assets/dicts/main_es.dict
index 076d5aa8..3e4a10ee 100644
Binary files a/app/src/main/assets/dicts/main_es.dict and b/app/src/main/assets/dicts/main_es.dict differ
diff --git a/app/src/main/assets/dicts/main_fr.dict b/app/src/main/assets/dicts/main_fr.dict
index 0e868609..25744c28 100644
Binary files a/app/src/main/assets/dicts/main_fr.dict and b/app/src/main/assets/dicts/main_fr.dict differ
diff --git a/app/src/main/assets/dicts/main_hu.dict b/app/src/main/assets/dicts/main_hu.dict
deleted file mode 100644
index 0b05b265..00000000
Binary files a/app/src/main/assets/dicts/main_hu.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_it.dict b/app/src/main/assets/dicts/main_it.dict
index 609ef13b..65edbed5 100644
Binary files a/app/src/main/assets/dicts/main_it.dict and b/app/src/main/assets/dicts/main_it.dict differ
diff --git a/app/src/main/assets/dicts/main_nl.dict b/app/src/main/assets/dicts/main_nl.dict
deleted file mode 100644
index 4d031d0c..00000000
Binary files a/app/src/main/assets/dicts/main_nl.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_pl.dict b/app/src/main/assets/dicts/main_pl.dict
deleted file mode 100644
index f55af662..00000000
Binary files a/app/src/main/assets/dicts/main_pl.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_pt-BR.dict b/app/src/main/assets/dicts/main_pt-BR.dict
index c3386518..091a1195 100644
Binary files a/app/src/main/assets/dicts/main_pt-BR.dict and b/app/src/main/assets/dicts/main_pt-BR.dict differ
diff --git a/app/src/main/assets/dicts/main_pt-PT.dict b/app/src/main/assets/dicts/main_pt-PT.dict
deleted file mode 100644
index a685e35d..00000000
Binary files a/app/src/main/assets/dicts/main_pt-PT.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_ro.dict b/app/src/main/assets/dicts/main_ro.dict
deleted file mode 100644
index 1f69a653..00000000
Binary files a/app/src/main/assets/dicts/main_ro.dict and /dev/null differ
diff --git a/app/src/main/assets/dicts/main_ru.dict b/app/src/main/assets/dicts/main_ru.dict
index f24552dd..f022ca16 100644
Binary files a/app/src/main/assets/dicts/main_ru.dict and b/app/src/main/assets/dicts/main_ru.dict differ
diff --git a/app/src/main/assets/dicts/main_sv.dict b/app/src/main/assets/dicts/main_sv.dict
index 0e7fdda6..dc74757d 100644
Binary files a/app/src/main/assets/dicts/main_sv.dict and b/app/src/main/assets/dicts/main_sv.dict differ
diff --git a/app/src/main/assets/dicts/main_tr.dict b/app/src/main/assets/dicts/main_tr.dict
deleted file mode 100644
index 3951fa23..00000000
Binary files a/app/src/main/assets/dicts/main_tr.dict and /dev/null differ
diff --git a/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt b/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt
index cfb3778c..0059f8e2 100644
--- a/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt
+++ b/app/src/main/java/be/scri/helpers/NativeSuggestionEngine.kt
@@ -116,6 +116,7 @@ class NativeSuggestionEngine(private val context: Context) {
fun getAutocompletions(
language: String,
prefix: String,
+ previousWord: String? = null,
limit: Int = 3
): List {
val dict = getDictionary(language) ?: return emptyList()
@@ -123,18 +124,30 @@ class NativeSuggestionEngine(private val context: Context) {
return try {
val composedData = ComposedData.createForWord(prefix)
+ val ngramContext =
+ if (previousWord.isNullOrBlank()) {
+ NgramContext.EMPTY_PREV_WORDS_INFO
+ } else {
+ NgramContext(NgramContext.WordInfo(previousWord))
+ }
val suggestions = dict.getSuggestions(
composedData,
- NgramContext.EMPTY_PREV_WORDS_INFO,
+ ngramContext,
dummyProximityInfo.nativeProximityInfo, // proximityInfoHandle
- SettingsValuesForSuggestion(false, false),
+ SettingsValuesForSuggestion(true, false), // blockPotentiallyOffensive, spaceAwareGesture
1, // sessionId
1.0f, // weightForLocale
null // inOutWeightOfLangModelVsSpatialModel
)
+ val isCapitalized = StringUtils.isWordCapitalized(prefix)
suggestions?.map { it.mWord }
- ?.filter { it.isNotBlank() && it.lowercase(Locale.ROOT) != prefix.lowercase(Locale.ROOT) }
+ ?.filter {
+ it.isNotBlank() &&
+ it.startsWith(prefix, ignoreCase = true) &&
+ it.lowercase(Locale.ROOT) != prefix.lowercase(Locale.ROOT)
+ }
+ ?.map { if (isCapitalized) it.replaceFirstChar { c -> c.uppercaseChar() } else it }
?.take(limit)
?: emptyList()
} catch (e: Exception) {
@@ -162,14 +175,14 @@ class NativeSuggestionEngine(private val context: Context) {
composedData,
ngramContext,
dummyProximityInfo.nativeProximityInfo, // proximityInfoHandle
- SettingsValuesForSuggestion(false, false),
+ SettingsValuesForSuggestion(true, false), // blockPotentiallyOffensive, spaceAwareGesture
1, // sessionId
1.0f, // weightForLocale
null // inOutWeightOfLangModelVsSpatialModel
)
suggestions?.map { it.mWord }
- ?.filter { it.isNotBlank() }
+ ?.filter { it.isNotBlank() && it.lowercase(Locale.ROOT) != lastWord.lowercase(Locale.ROOT) }
?.take(limit)
?: emptyList()
} catch (e: Exception) {
diff --git a/app/src/main/java/be/scri/latin/common/ComposedData.kt b/app/src/main/java/be/scri/latin/common/ComposedData.kt
index d0d1e416..3a8f9d77 100644
--- a/app/src/main/java/be/scri/latin/common/ComposedData.kt
+++ b/app/src/main/java/be/scri/latin/common/ComposedData.kt
@@ -8,8 +8,6 @@
*/
package be.scri.latin.common
-import kotlin.random.Random
-
/** An immutable class that encapsulates a snapshot of word composition data. */
class ComposedData(
@JvmField val mInputPointers: InputPointers,
@@ -48,10 +46,12 @@ class ComposedData(
companion object {
fun createForWord(word: String): ComposedData {
val codePoints = StringUtils.toCodePointArray(word)
- val coordinates = CoordinateUtils.newCoordinateArray(codePoints.size)
- for (i in codePoints.indices) {
- CoordinateUtils.setXYInArray(coordinates, i, Random.nextBits(2), Random.nextBits(2))
- }
+ val coordinates =
+ CoordinateUtils.newCoordinateArray(
+ codePoints.size,
+ Constants.NOT_A_COORDINATE,
+ Constants.NOT_A_COORDINATE,
+ )
val pointers = InputPointers(codePoints.size).apply {
for (i in codePoints.indices) {
addPointer(CoordinateUtils.xFromArray(coordinates, i), CoordinateUtils.yFromArray(coordinates, i), 0, 0)
diff --git a/app/src/main/jni/Android.bp b/app/src/main/jni/Android.bp
deleted file mode 100644
index 5649fc1e..00000000
--- a/app/src/main/jni/Android.bp
+++ /dev/null
@@ -1,215 +0,0 @@
-// Copyright (C) 2013 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.
-
-filegroup {
- name: "LATIN_IME_CORE_SRC_FILES",
- srcs: [
- "src/dictionary/header/header_policy.cpp",
- "src/dictionary/header/header_read_write_utils.cpp",
- "src/dictionary/property/ngram_context.cpp",
- "src/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp",
- "src/dictionary/structure/pt_common/bigram/bigram_list_read_write_utils.cpp",
- "src/dictionary/structure/pt_common/dynamic_pt_gc_event_listeners.cpp",
- "src/dictionary/structure/pt_common/dynamic_pt_reading_helper.cpp",
- "src/dictionary/structure/pt_common/dynamic_pt_reading_utils.cpp",
- "src/dictionary/structure/pt_common/dynamic_pt_updating_helper.cpp",
- "src/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp",
- "src/dictionary/structure/pt_common/patricia_trie_reading_utils.cpp",
- "src/dictionary/structure/pt_common/shortcut/shortcut_list_reading_utils.cpp",
- "src/dictionary/structure/v2/patricia_trie_policy.cpp",
- "src/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp",
- "src/dictionary/structure/v2/ver2_pt_node_array_reader.cpp",
- "src/dictionary/structure/v4/ver4_dict_buffers.cpp",
- "src/dictionary/structure/v4/ver4_dict_constants.cpp",
- "src/dictionary/structure/v4/ver4_patricia_trie_node_reader.cpp",
- "src/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp",
- "src/dictionary/structure/v4/ver4_patricia_trie_policy.cpp",
- "src/dictionary/structure/v4/ver4_patricia_trie_reading_utils.cpp",
- "src/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp",
- "src/dictionary/structure/v4/ver4_pt_node_array_reader.cpp",
- "src/dictionary/structure/v4/content/dynamic_language_model_probability_utils.cpp",
- "src/dictionary/structure/v4/content/language_model_dict_content.cpp",
- "src/dictionary/structure/v4/content/language_model_dict_content_global_counters.cpp",
- "src/dictionary/structure/v4/content/shortcut_dict_content.cpp",
- "src/dictionary/structure/v4/content/sparse_table_dict_content.cpp",
- "src/dictionary/structure/v4/content/terminal_position_lookup_table.cpp",
- "src/dictionary/utils/buffer_with_extendable_buffer.cpp",
- "src/dictionary/utils/byte_array_utils.cpp",
- "src/dictionary/utils/dict_file_writing_utils.cpp",
- "src/dictionary/utils/file_utils.cpp",
- "src/dictionary/utils/forgetting_curve_utils.cpp",
- "src/dictionary/utils/format_utils.cpp",
- "src/dictionary/utils/mmapped_buffer.cpp",
- "src/dictionary/utils/multi_bigram_map.cpp",
- "src/dictionary/utils/probability_utils.cpp",
- "src/dictionary/utils/sparse_table.cpp",
- "src/dictionary/utils/trie_map.cpp",
- "src/suggest/core/suggest.cpp",
- "src/suggest/core/dicnode/dic_node.cpp",
- "src/suggest/core/dicnode/dic_node_utils.cpp",
- "src/suggest/core/dicnode/dic_nodes_cache.cpp",
- "src/suggest/core/dictionary/dictionary.cpp",
- "src/suggest/core/dictionary/dictionary_utils.cpp",
- "src/suggest/core/dictionary/digraph_utils.cpp",
- "src/suggest/core/dictionary/error_type_utils.cpp",
- "src/suggest/core/layout/additional_proximity_chars.cpp",
- "src/suggest/core/layout/proximity_info.cpp",
- "src/suggest/core/layout/proximity_info_params.cpp",
- "src/suggest/core/layout/proximity_info_state.cpp",
- "src/suggest/core/layout/proximity_info_state_utils.cpp",
- "src/suggest/core/policy/weighting.cpp",
- "src/suggest/core/session/dic_traverse_session.cpp",
- "src/suggest/core/result/suggestion_results.cpp",
- "src/suggest/core/result/suggestions_output_utils.cpp",
- "src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp",
- "src/suggest/policyimpl/typing/scoring_params.cpp",
- "src/suggest/policyimpl/typing/typing_scoring.cpp",
- "src/suggest/policyimpl/typing/typing_suggest_policy.cpp",
- "src/suggest/policyimpl/typing/typing_traversal.cpp",
- "src/suggest/policyimpl/typing/typing_weighting.cpp",
- "src/utils/autocorrection_threshold_utils.cpp",
- "src/utils/char_utils.cpp",
- "src/utils/jni_data_utils.cpp",
- "src/utils/log_utils.cpp",
- "src/utils/time_keeper.cpp",
-
- // BACKWARD_V402
- "src/dictionary/structure/backward/v402/ver4_dict_buffers.cpp",
- "src/dictionary/structure/backward/v402/ver4_dict_constants.cpp",
- "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_reader.cpp",
- "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp",
- "src/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp",
- "src/dictionary/structure/backward/v402/ver4_patricia_trie_reading_utils.cpp",
- "src/dictionary/structure/backward/v402/ver4_patricia_trie_writing_helper.cpp",
- "src/dictionary/structure/backward/v402/ver4_pt_node_array_reader.cpp",
- "src/dictionary/structure/backward/v402/content/bigram_dict_content.cpp",
- "src/dictionary/structure/backward/v402/content/probability_dict_content.cpp",
- "src/dictionary/structure/backward/v402/content/shortcut_dict_content.cpp",
- "src/dictionary/structure/backward/v402/content/sparse_table_dict_content.cpp",
- "src/dictionary/structure/backward/v402/content/terminal_position_lookup_table.cpp",
- "src/dictionary/structure/backward/v402/bigram/ver4_bigram_list_policy.cpp",
- ],
-}
-
-cc_library {
- name: "libjni_latinime",
- host_supported: true,
- product_specific: true,
-
- sdk_version: "14",
- cflags: [
- "-Werror",
- "-Wall",
- "-Wextra",
- "-Weffc++",
- "-Wformat=2",
- "-Wcast-qual",
- "-Wcast-align",
- "-Wwrite-strings",
- "-Wfloat-equal",
- "-Wpointer-arith",
- "-Winit-self",
- "-Wredundant-decls",
- "-Woverloaded-virtual",
- "-Wsign-promo",
- "-Wno-system-headers",
- "-Wno-format-nonliteral",
-
- // To suppress compiler warnings for unused variables/functions used for debug features etc.
- "-Wno-unused-parameter",
- "-Wno-unused-function",
- ],
- local_include_dirs: ["src"],
-
- srcs: [
- "com_android_inputmethod_keyboard_ProximityInfo.cpp",
- "com_android_inputmethod_latin_BinaryDictionary.cpp",
- "com_android_inputmethod_latin_BinaryDictionaryUtils.cpp",
- "com_android_inputmethod_latin_DicTraverseSession.cpp",
- "jni_common.cpp",
-
- ":LATIN_IME_CORE_SRC_FILES",
- ],
-
- target: {
- android_x86: {
- // HACK: -mstackrealign is required for x86 builds running on pre-KitKat devices to avoid crashes
- // with SSE instructions.
- cflags: ["-mstackrealign"],
- },
- android: {
- stl: "libc++_static",
- },
- host: {
- cflags: ["-DHOST_TOOL"],
- },
- },
-}
-
-cc_library_static {
- name: "liblatinime_static_for_unittests",
- host_supported: true,
-
- cflags: [
- "-Wno-unused-parameter",
- "-Wno-unused-function",
- "-Wall",
- "-Werror",
- ],
- local_include_dirs: ["src"],
- sdk_version: "14",
- stl: "libc++_static",
-
- srcs: [":LATIN_IME_CORE_SRC_FILES"],
-}
-
-cc_test {
- name: "liblatinime_unittests",
- host_supported: true,
-
- cflags: [
- "-Wno-unused-parameter",
- "-Wno-unused-function",
- "-Wall",
- "-Werror",
- ],
- local_include_dirs: ["src"],
- sdk_version: "14",
- stl: "libc++_static",
-
- srcs: [
- "tests/defines_test.cpp",
- "tests/dictionary/header/header_read_write_utils_test.cpp",
- "tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp",
- "tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp",
- "tests/dictionary/structure/v4/content/probability_entry_test.cpp",
- "tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp",
- "tests/dictionary/utils/bloom_filter_test.cpp",
- "tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp",
- "tests/dictionary/utils/byte_array_utils_test.cpp",
- "tests/dictionary/utils/format_utils_test.cpp",
- "tests/dictionary/utils/probability_utils_test.cpp",
- "tests/dictionary/utils/sparse_table_test.cpp",
- "tests/dictionary/utils/trie_map_test.cpp",
- "tests/suggest/core/dicnode/dic_node_pool_test.cpp",
- "tests/suggest/core/layout/geometry_utils_test.cpp",
- "tests/suggest/core/layout/normal_distribution_2d_test.cpp",
- "tests/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp",
- "tests/utils/autocorrection_threshold_utils_test.cpp",
- "tests/utils/char_utils_test.cpp",
- "tests/utils/int_array_view_test.cpp",
- "tests/utils/time_keeper_test.cpp",
- ],
- static_libs: ["liblatinime_static_for_unittests"],
-}
diff --git a/app/src/main/jni/Android.mk b/app/src/main/jni/Android.mk
deleted file mode 100755
index 0099cafb..00000000
--- a/app/src/main/jni/Android.mk
+++ /dev/null
@@ -1,106 +0,0 @@
-# Copyright (C) 2011 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.
-
-LOCAL_PATH := $(call my-dir)
-
-############ some local flags
-# If you change any of those flags, you need to rebuild both libjni_latinime_common_static
-# and the shared library that uses libjni_latinime_common_static.
-FLAG_DBG ?= false
-FLAG_DO_PROFILE ?= false
-
-######################################
-include $(CLEAR_VARS)
-
-LATIN_IME_SRC_DIR := src
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-
-LOCAL_CFLAGS += -Wall -Wextra -Weffc++ -Wformat=2 -Wcast-qual -Wcast-align \
- -Wwrite-strings -Wfloat-equal -Wpointer-arith -Winit-self -Wredundant-decls \
- -Woverloaded-virtual -Wsign-promo -Wno-system-headers
-
-# To suppress compiler warnings for unused variables/functions used for debug features etc.
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-
-# HACK: -mstackrealign is required for x86 builds running on pre-KitKat devices to avoid crashes
-# with SSE instructions.
-ifeq ($(TARGET_ARCH), x86)
- LOCAL_CFLAGS += -mstackrealign
-endif # x86
-
-include $(LOCAL_PATH)/NativeFileList.mk
-
-LOCAL_SRC_FILES := \
- $(LATIN_IME_JNI_SRC_FILES) \
- $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-
-ifeq ($(FLAG_DO_PROFILE), true)
- $(warning Making profiling version of native library)
- LOCAL_CFLAGS += -DFLAG_DO_PROFILE -funwind-tables
-else # FLAG_DO_PROFILE
-ifeq ($(FLAG_DBG), true)
- $(warning Making debug version of native library)
- LOCAL_CFLAGS += -DFLAG_DBG -funwind-tables -fno-inline
-ifeq ($(FLAG_FULL_DBG), true)
- $(warning Making full debug version of native library)
- LOCAL_CFLAGS += -DFLAG_FULL_DBG
-endif # FLAG_FULL_DBG
-endif # FLAG_DBG
-endif # FLAG_DO_PROFILE
-
-LOCAL_MODULE := libjni_latinime_common_static
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CLANG := true
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-
-include $(BUILD_STATIC_LIBRARY)
-######################################
-include $(CLEAR_VARS)
-
-# All code in LOCAL_WHOLE_STATIC_LIBRARIES will be built into this shared library.
-LOCAL_WHOLE_STATIC_LIBRARIES := libjni_latinime_common_static
-
-ifeq ($(FLAG_DO_PROFILE), true)
- $(warning Making profiling version of native library)
- LOCAL_LDFLAGS += -llog
-else # FLAG_DO_PROFILE
-ifeq ($(FLAG_DBG), true)
- $(warning Making debug version of native library)
- LOCAL_LDFLAGS += -llog
-endif # FLAG_DBG
-endif # FLAG_DO_PROFILE
-
-LOCAL_MODULE := libjni_latinime
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CLANG := true
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-LOCAL_LDFLAGS += -ldl
-
-# Avoid issues with reproducible builds, see https://gitlab.com/fdroid/rfp/-/issues/2662
-LOCAL_LDFLAGS += -Wl,--build-id=none -Wl,--hash-style=both -Wl,-z,max-page-size=16384
-
-include $(BUILD_SHARED_LIBRARY)
-#################### Clean up the tmp vars
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
-
-#################### Unit test on host environment
-#include $(LOCAL_PATH)/HostUnitTests.mk
-
-#################### Unit test on target environment
-#include $(LOCAL_PATH)/TargetUnitTests.mk
diff --git a/app/src/main/jni/Application.mk b/app/src/main/jni/Application.mk
deleted file mode 100755
index a169e740..00000000
--- a/app/src/main/jni/Application.mk
+++ /dev/null
@@ -1,2 +0,0 @@
-APP_STL := c++_static
-APP_ABI := all
diff --git a/app/src/main/jni/CleanupNativeFileList.mk b/app/src/main/jni/CleanupNativeFileList.mk
deleted file mode 100755
index eed6f1e6..00000000
--- a/app/src/main/jni/CleanupNativeFileList.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 2013 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.
-
-LATIN_IME_CORE_SRC_FILES :=
-LATIN_IME_CORE_SRC_FILES_BACKWARD_V401 :=
-LATIN_IME_CORE_TEST_FILES :=
-LATIN_IME_JNI_SRC_FILES :=
-LATIN_IME_SRC_DIR :=
diff --git a/app/src/main/jni/HostUnitTests.mk b/app/src/main/jni/HostUnitTests.mk
deleted file mode 100755
index 6a8bcec2..00000000
--- a/app/src/main/jni/HostUnitTests.mk
+++ /dev/null
@@ -1,64 +0,0 @@
-# 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.
-
-# Host build is never supported in unbundled (NDK/tapas) build
-ifeq (,$(TARGET_BUILD_APPS))
-
-# HACK: Temporarily disable host tool build on Mac until the build system is ready for C++11.
-LATINIME_HOST_OSNAME := $(shell uname -s)
-ifneq ($(LATINIME_HOST_OSNAME), Darwin) # TODO: Remove this
-
-LOCAL_PATH := $(call my-dir)
-
-######################################
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/NativeFileList.mk
-
-#################### Host library for unit test
-LATIN_IME_SRC_DIR := src
-LOCAL_ADDRESS_SANITIZER := true
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CLANG := true
-LOCAL_CXX_STL := libc++
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_host_static_for_unittests
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-#################### Host native tests
-include $(CLEAR_VARS)
-LATIN_IME_TEST_SRC_DIR := tests
-LOCAL_ADDRESS_SANITIZER := true
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CLANG := true
-LOCAL_CXX_STL := libc++
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_host_unittests
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_TEST_SRC_DIR)/, $(LATIN_IME_CORE_TEST_FILES))
-LOCAL_STATIC_LIBRARIES += liblatinime_host_static_for_unittests
-include $(BUILD_HOST_NATIVE_TEST)
-
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
-
-endif # Darwin - TODO: Remove this
-
-endif # TARGET_BUILD_APPS
-
-#################### Clean up the tmp vars
-LATINIME_HOST_OSNAME :=
-LATIN_IME_SRC_DIR :=
-LATIN_IME_TEST_SRC_DIR :=
diff --git a/app/src/main/jni/NativeFileList.mk b/app/src/main/jni/NativeFileList.mk
deleted file mode 100755
index d8b69bfd..00000000
--- a/app/src/main/jni/NativeFileList.mk
+++ /dev/null
@@ -1,146 +0,0 @@
-# Copyright (C) 2013 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.
-
-LATIN_IME_JNI_SRC_FILES := \
- com_android_inputmethod_keyboard_ProximityInfo.cpp \
- com_android_inputmethod_latin_BinaryDictionary.cpp \
- com_android_inputmethod_latin_BinaryDictionaryUtils.cpp \
- com_android_inputmethod_latin_DicTraverseSession.cpp \
- jni_common.cpp
-
-LATIN_IME_CORE_SRC_FILES := \
- $(addprefix dictionary/header/, \
- header_policy.cpp \
- header_read_write_utils.cpp) \
- dictionary/property/ngram_context.cpp \
- dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp \
- $(addprefix dictionary/structure/pt_common/, \
- bigram/bigram_list_read_write_utils.cpp \
- dynamic_pt_gc_event_listeners.cpp \
- dynamic_pt_reading_helper.cpp \
- dynamic_pt_reading_utils.cpp \
- dynamic_pt_updating_helper.cpp \
- dynamic_pt_writing_utils.cpp \
- patricia_trie_reading_utils.cpp \
- shortcut/shortcut_list_reading_utils.cpp) \
- $(addprefix dictionary/structure/v2/, \
- patricia_trie_policy.cpp \
- ver2_patricia_trie_node_reader.cpp \
- ver2_pt_node_array_reader.cpp) \
- $(addprefix dictionary/structure/v4/, \
- ver4_dict_buffers.cpp \
- ver4_dict_constants.cpp \
- ver4_patricia_trie_node_reader.cpp \
- ver4_patricia_trie_node_writer.cpp \
- ver4_patricia_trie_policy.cpp \
- ver4_patricia_trie_reading_utils.cpp \
- ver4_patricia_trie_writing_helper.cpp \
- ver4_pt_node_array_reader.cpp) \
- $(addprefix dictionary/structure/v4/content/, \
- dynamic_language_model_probability_utils.cpp \
- language_model_dict_content.cpp \
- language_model_dict_content_global_counters.cpp \
- shortcut_dict_content.cpp \
- sparse_table_dict_content.cpp \
- terminal_position_lookup_table.cpp) \
- $(addprefix dictionary/utils/, \
- buffer_with_extendable_buffer.cpp \
- byte_array_utils.cpp \
- dict_file_writing_utils.cpp \
- file_utils.cpp \
- forgetting_curve_utils.cpp \
- format_utils.cpp \
- mmapped_buffer.cpp \
- multi_bigram_map.cpp \
- probability_utils.cpp \
- sparse_table.cpp \
- trie_map.cpp ) \
- suggest/core/suggest.cpp \
- $(addprefix suggest/core/dicnode/, \
- dic_node.cpp \
- dic_node_utils.cpp \
- dic_nodes_cache.cpp) \
- $(addprefix suggest/core/dictionary/, \
- dictionary.cpp \
- dictionary_utils.cpp \
- digraph_utils.cpp \
- error_type_utils.cpp ) \
- $(addprefix suggest/core/layout/, \
- additional_proximity_chars.cpp \
- proximity_info.cpp \
- proximity_info_params.cpp \
- proximity_info_state.cpp \
- proximity_info_state_utils.cpp) \
- suggest/core/policy/weighting.cpp \
- suggest/core/session/dic_traverse_session.cpp \
- $(addprefix suggest/core/result/, \
- suggestion_results.cpp \
- suggestions_output_utils.cpp) \
- suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp \
- $(addprefix suggest/policyimpl/typing/, \
- scoring_params.cpp \
- typing_scoring.cpp \
- typing_suggest_policy.cpp \
- typing_traversal.cpp \
- typing_weighting.cpp) \
- $(addprefix utils/, \
- autocorrection_threshold_utils.cpp \
- char_utils.cpp \
- jni_data_utils.cpp \
- log_utils.cpp \
- time_keeper.cpp)
-
-LATIN_IME_CORE_SRC_FILES_BACKWARD_V402 := \
- $(addprefix dictionary/structure/backward/v402/, \
- ver4_dict_buffers.cpp \
- ver4_dict_constants.cpp \
- ver4_patricia_trie_node_reader.cpp \
- ver4_patricia_trie_node_writer.cpp \
- ver4_patricia_trie_policy.cpp \
- ver4_patricia_trie_reading_utils.cpp \
- ver4_patricia_trie_writing_helper.cpp \
- ver4_pt_node_array_reader.cpp) \
- $(addprefix dictionary/structure/backward/v402/content/, \
- bigram_dict_content.cpp \
- probability_dict_content.cpp \
- shortcut_dict_content.cpp \
- sparse_table_dict_content.cpp \
- terminal_position_lookup_table.cpp) \
- $(addprefix dictionary/structure/backward/v402/bigram/, \
- ver4_bigram_list_policy.cpp)
-
-LATIN_IME_CORE_SRC_FILES += $(LATIN_IME_CORE_SRC_FILES_BACKWARD_V402)
-
-LATIN_IME_CORE_TEST_FILES := \
- defines_test.cpp \
- dictionary/header/header_read_write_utils_test.cpp \
- dictionary/structure/v4/content/language_model_dict_content_test.cpp \
- dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp \
- dictionary/structure/v4/content/probability_entry_test.cpp \
- dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp \
- dictionary/utils/bloom_filter_test.cpp \
- dictionary/utils/buffer_with_extendable_buffer_test.cpp \
- dictionary/utils/byte_array_utils_test.cpp \
- dictionary/utils/format_utils_test.cpp \
- dictionary/utils/probability_utils_test.cpp \
- dictionary/utils/sparse_table_test.cpp \
- dictionary/utils/trie_map_test.cpp \
- suggest/core/dicnode/dic_node_pool_test.cpp \
- suggest/core/layout/geometry_utils_test.cpp \
- suggest/core/layout/normal_distribution_2d_test.cpp \
- suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp \
- utils/autocorrection_threshold_utils_test.cpp \
- utils/char_utils_test.cpp \
- utils/int_array_view_test.cpp \
- utils/time_keeper_test.cpp
diff --git a/app/src/main/jni/TargetUnitTests.mk b/app/src/main/jni/TargetUnitTests.mk
deleted file mode 100755
index 69a32edb..00000000
--- a/app/src/main/jni/TargetUnitTests.mk
+++ /dev/null
@@ -1,52 +0,0 @@
-# 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.
-
-LOCAL_PATH := $(call my-dir)
-
-######################################
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/NativeFileList.mk
-
-#################### Target library for unit test
-LATIN_IME_SRC_DIR := src
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_target_static_for_unittests
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := $(addprefix $(LATIN_IME_SRC_DIR)/, $(LATIN_IME_CORE_SRC_FILES))
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-include $(BUILD_STATIC_LIBRARY)
-
-#################### Target native tests
-include $(CLEAR_VARS)
-LATIN_IME_TEST_SRC_DIR := tests
-LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
-LOCAL_CLANG := true
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(LATIN_IME_SRC_DIR)
-LOCAL_MODULE := liblatinime_target_unittests
-LOCAL_MODULE_TAGS := tests
-LOCAL_SRC_FILES := \
- $(addprefix $(LATIN_IME_TEST_SRC_DIR)/, $(LATIN_IME_CORE_TEST_FILES))
-LOCAL_STATIC_LIBRARIES += liblatinime_target_static_for_unittests
-LOCAL_SDK_VERSION := 14
-LOCAL_NDK_STL_VARIANT := c++_static
-include $(BUILD_NATIVE_TEST)
-
-#################### Clean up the tmp vars
-LATIN_IME_SRC_DIR :=
-LATIN_IME_TEST_SRC_DIR :=
-include $(LOCAL_PATH)/CleanupNativeFileList.mk
diff --git a/app/src/main/jni/run-tests.sh b/app/src/main/jni/run-tests.sh
deleted file mode 100755
index a7fa82d9..00000000
--- a/app/src/main/jni/run-tests.sh
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/bin/bash
-# Copyright 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.
-
-function usage() {
- echo "usage: source run-tests.sh [--host] [--target] [-h] [--help]" 1>&2
- echo " --host: run test on the host environment" 1>&2
- echo " --no-host: skip host test" 1>&2
- echo " --target: run test on the target environment" 1>&2
- echo " --no-target: skip target device test" 1>&2
-}
-
-# check script arguments
-if [[ $(type -t mmm) != function ]]; then
-usage
-if [[ ${BASH_SOURCE[0]} != $0 ]]; then return; else exit 1; fi
-fi
-
-show_usage=no
-enable_host_test=yes
-enable_target_device_test=no
-while [ "$1" != "" ]
- do
- case "$1" in
- "-h") show_usage=yes;;
- "--help") show_usage=yes;;
- "--target") enable_target_device_test=yes;;
- "--no-target") enable_target_device_test=no;;
- "--host") enable_host_test=yes;;
- "--no-host") enable_host_test=no;;
- esac
- shift
-done
-
-if [[ $show_usage == yes ]]; then
- usage
- if [[ ${BASH_SOURCE[0]} != $0 ]]; then return; else exit 1; fi
-fi
-
-# Host build is never supported in unbundled (NDK/tapas) build
-if [[ $enable_host_test == yes && -n $TARGET_BUILD_APPS ]]; then
- echo "Host build is never supported in tapas build." 1>&2
- echo "Use lunch command instead." 1>&2
- if [[ ${BASH_SOURCE[0]} != $0 ]]; then return; else exit 1; fi
-fi
-
-target_test_name=liblatinime_target_unittests
-host_test_name=liblatinime_host_unittests
-
-pushd $PWD > /dev/null
-cd $(gettop)
-mmm -j16 packages/inputmethods/LatinIME/native/jni || \
- make -j16 adb $target_test_name $host_test_name
-if [[ $enable_host_test == yes ]]; then
- $ANDROID_HOST_OUT/bin/$host_test_name
-fi
-if [[ $enable_target_device_test == yes ]]; then
- target_test_local=$ANDROID_PRODUCT_OUT/data/nativetest/$target_test_name/$target_test_name
- target_test_device=/data/nativetest/$target_test_name/$target_test_name
- adb push $target_test_local $target_test_device
- adb shell $target_test_device
- adb shell rm -rf $target_test_device
-fi
-popd > /dev/null
diff --git a/app/src/main/jni/tests/defines_test.cpp b/app/src/main/jni/tests/defines_test.cpp
deleted file mode 100644
index f7b80b2b..00000000
--- a/app/src/main/jni/tests/defines_test.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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 "defines.h"
-
-#include
-
-namespace latinime {
-namespace {
-
-TEST(DefinesTest, NELEMSForFixedLengthArray) {
- const size_t SMALL_ARRAY_SIZE = 1;
- const size_t LARGE_ARRAY_SIZE = 100;
- int smallArray[SMALL_ARRAY_SIZE];
- int largeArray[LARGE_ARRAY_SIZE];
- EXPECT_EQ(SMALL_ARRAY_SIZE, NELEMS(smallArray));
- EXPECT_EQ(LARGE_ARRAY_SIZE, NELEMS(largeArray));
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/header/header_read_write_utils_test.cpp b/app/src/main/jni/tests/dictionary/header/header_read_write_utils_test.cpp
deleted file mode 100644
index eab5d657..00000000
--- a/app/src/main/jni/tests/dictionary/header/header_read_write_utils_test.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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 "dictionary/header/header_read_write_utils.h"
-
-#include
-
-#include
-#include
-
-#include "dictionary/interface/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 codePoints = { 0x0, 0x20, 0x1F, 0x100000 };
- HeaderReadWriteUtils::setCodePointVectorAttribute(&attributeMap, "abc", codePoints);
- EXPECT_EQ(codePoints, HeaderReadWriteUtils::readCodePointVectorAttributeValue(
- &attributeMap, "abc"));
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp
deleted file mode 100644
index 2e3047ed..00000000
--- a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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 "dictionary/structure/v4/content/language_model_dict_content_global_counters.h"
-
-#include
-
-#include "dictionary/structure/v4/ver4_dict_constants.h"
-
-namespace latinime {
-namespace {
-
-TEST(LanguageModelDictContentGlobalCountersTest, TestUpdateMaxValueOfCounters) {
- LanguageModelDictContentGlobalCounters globalCounters;
-
- EXPECT_FALSE(globalCounters.needsToHalveCounters());
- globalCounters.updateMaxValueOfCounters(10);
- EXPECT_FALSE(globalCounters.needsToHalveCounters());
- const int count = (1 << (Ver4DictConstants::WORD_COUNT_FIELD_SIZE * CHAR_BIT)) - 1;
- globalCounters.updateMaxValueOfCounters(count);
- EXPECT_TRUE(globalCounters.needsToHalveCounters());
- globalCounters.halveCounters();
- EXPECT_FALSE(globalCounters.needsToHalveCounters());
-}
-
-TEST(LanguageModelDictContentGlobalCountersTest, TestIncrementTotalCount) {
- LanguageModelDictContentGlobalCounters globalCounters;
-
- EXPECT_EQ(0, globalCounters.getTotalCount());
- globalCounters.incrementTotalCount();
- EXPECT_EQ(1, globalCounters.getTotalCount());
- for (int i = 1; i < 50; ++i) {
- globalCounters.incrementTotalCount();
- }
- EXPECT_EQ(50, globalCounters.getTotalCount());
- globalCounters.halveCounters();
- EXPECT_EQ(25, globalCounters.getTotalCount());
- globalCounters.halveCounters();
- EXPECT_EQ(12, globalCounters.getTotalCount());
- for (int i = 0; i < 4; ++i) {
- globalCounters.halveCounters();
- }
- EXPECT_EQ(0, globalCounters.getTotalCount());
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp
deleted file mode 100644
index ab11975c..00000000
--- a/app/src/main/jni/tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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 "dictionary/structure/v4/content/language_model_dict_content.h"
-
-#include
-
-#include
-#include
-
-#include "utils/int_array_view.h"
-
-namespace latinime {
-namespace {
-
-TEST(LanguageModelDictContentTest, TestUnigramProbability) {
- LanguageModelDictContent languageModelDictContent(false /* useHistoricalInfo */);
-
- const int flag = 0xF0;
- const int probability = 10;
- const int wordId = 100;
- const ProbabilityEntry probabilityEntry(flag, probability);
- languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry);
- const ProbabilityEntry entry =
- languageModelDictContent.getProbabilityEntry(wordId);
- EXPECT_EQ(flag, entry.getFlags());
- EXPECT_EQ(probability, entry.getProbability());
-
- // Remove
- EXPECT_TRUE(languageModelDictContent.removeProbabilityEntry(wordId));
- EXPECT_FALSE(languageModelDictContent.getProbabilityEntry(wordId).isValid());
- EXPECT_FALSE(languageModelDictContent.removeProbabilityEntry(wordId));
- EXPECT_TRUE(languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry));
- EXPECT_TRUE(languageModelDictContent.getProbabilityEntry(wordId).isValid());
-}
-
-TEST(LanguageModelDictContentTest, TestUnigramProbabilityWithHistoricalInfo) {
- LanguageModelDictContent languageModelDictContent(true /* useHistoricalInfo */);
-
- const int flag = 0xF0;
- const int timestamp = 0x3FFFFFFF;
- const int count = 10;
- const int wordId = 100;
- const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
- const ProbabilityEntry probabilityEntry(flag, &historicalInfo);
- languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry);
- const ProbabilityEntry entry = languageModelDictContent.getProbabilityEntry(wordId);
- EXPECT_EQ(flag, entry.getFlags());
- EXPECT_EQ(timestamp, entry.getHistoricalInfo()->getTimestamp());
- EXPECT_EQ(count, entry.getHistoricalInfo()->getCount());
-
- // Remove
- EXPECT_TRUE(languageModelDictContent.removeProbabilityEntry(wordId));
- EXPECT_FALSE(languageModelDictContent.getProbabilityEntry(wordId).isValid());
- EXPECT_FALSE(languageModelDictContent.removeProbabilityEntry(wordId));
- EXPECT_TRUE(languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry));
- EXPECT_TRUE(languageModelDictContent.removeProbabilityEntry(wordId));
-}
-
-TEST(LanguageModelDictContentTest, TestIterateProbabilityEntry) {
- LanguageModelDictContent languageModelDictContent(false /* useHistoricalInfo */);
-
- const ProbabilityEntry originalEntry(0xFC, 100);
-
- const int wordIds[] = { 1, 2, 3, 4, 5 };
- for (const int wordId : wordIds) {
- languageModelDictContent.setProbabilityEntry(wordId, &originalEntry);
- }
- std::unordered_set wordIdSet(std::begin(wordIds), std::end(wordIds));
- for (const auto& entry : languageModelDictContent.getProbabilityEntries(WordIdArrayView())) {
- EXPECT_EQ(originalEntry.getFlags(), entry.getProbabilityEntry().getFlags());
- EXPECT_EQ(originalEntry.getProbability(), entry.getProbabilityEntry().getProbability());
- wordIdSet.erase(entry.getWordId());
- }
- EXPECT_TRUE(wordIdSet.empty());
-}
-
-TEST(LanguageModelDictContentTest, TestGetWordProbability) {
- LanguageModelDictContent languageModelDictContent(false /* useHistoricalInfo */);
-
- const int flag = 0xFF;
- const int probability = 10;
- const int bigramProbability = 20;
- const int trigramProbability = 30;
- const int wordId = 100;
- const std::array prevWordIdArray = {{ 1, 2 }};
- const WordIdArrayView prevWordIds = WordIdArrayView::fromArray(prevWordIdArray);
-
- const ProbabilityEntry probabilityEntry(flag, probability);
- languageModelDictContent.setProbabilityEntry(wordId, &probabilityEntry);
- const ProbabilityEntry bigramProbabilityEntry(flag, bigramProbability);
- languageModelDictContent.setProbabilityEntry(prevWordIds[0], &probabilityEntry);
- languageModelDictContent.setNgramProbabilityEntry(prevWordIds.limit(1), wordId,
- &bigramProbabilityEntry);
- EXPECT_EQ(bigramProbability, languageModelDictContent.getWordAttributes(prevWordIds, wordId,
- false /* mustMatchAllPrevWords */, nullptr /* headerPolicy */).getProbability());
- const ProbabilityEntry trigramProbabilityEntry(flag, trigramProbability);
- languageModelDictContent.setNgramProbabilityEntry(prevWordIds.limit(1),
- prevWordIds[1], &probabilityEntry);
- languageModelDictContent.setNgramProbabilityEntry(prevWordIds.limit(2), wordId,
- &trigramProbabilityEntry);
- EXPECT_EQ(trigramProbability, languageModelDictContent.getWordAttributes(prevWordIds, wordId,
- false /* mustMatchAllPrevWords */, nullptr /* headerPolicy */).getProbability());
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/probability_entry_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/probability_entry_test.cpp
deleted file mode 100644
index ba81671b..00000000
--- a/app/src/main/jni/tests/dictionary/structure/v4/content/probability_entry_test.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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 "dictionary/structure/v4/content/probability_entry.h"
-
-#include
-
-#include "defines.h"
-
-namespace latinime {
-namespace {
-
-TEST(ProbabilityEntryTest, TestEncodeDecode) {
- const int flag = 0xFF;
- const int probability = 10;
-
- const ProbabilityEntry entry(flag, probability);
- const uint64_t encodedEntry = entry.encode(false /* hasHistoricalInfo */);
- const ProbabilityEntry decodedEntry =
- ProbabilityEntry::decode(encodedEntry, false /* hasHistoricalInfo */);
- EXPECT_EQ(0xFF0Aull, encodedEntry);
- EXPECT_EQ(flag, decodedEntry.getFlags());
- EXPECT_EQ(probability, decodedEntry.getProbability());
-}
-
-TEST(ProbabilityEntryTest, TestEncodeDecodeWithHistoricalInfo) {
- const int flag = 0xF0;
- const int timestamp = 0x3FFFFFFF;
- const int count = 0xABCD;
-
- const HistoricalInfo historicalInfo(timestamp, 0 /* level */, count);
- const ProbabilityEntry entry(flag, &historicalInfo);
-
- const uint64_t encodedEntry = entry.encode(true /* hasHistoricalInfo */);
- EXPECT_EQ(0xF03FFFFFFFABCDull, encodedEntry);
- const ProbabilityEntry decodedEntry =
- ProbabilityEntry::decode(encodedEntry, true /* hasHistoricalInfo */);
-
- EXPECT_EQ(flag, decodedEntry.getFlags());
- EXPECT_EQ(timestamp, decodedEntry.getHistoricalInfo()->getTimestamp());
- EXPECT_EQ(count, decodedEntry.getHistoricalInfo()->getCount());
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp b/app/src/main/jni/tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp
deleted file mode 100644
index 4f23889c..00000000
--- a/app/src/main/jni/tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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 "dictionary/structure/v4/content/terminal_position_lookup_table.h"
-
-#include
-
-#include
-
-#include "defines.h"
-#include "dictionary/structure/v4/ver4_dict_constants.h"
-
-namespace latinime {
-namespace {
-
-TEST(TerminalPositionLookupTableTest, TestGetFromEmptyTable) {
- TerminalPositionLookupTable lookupTable;
-
- EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(0));
- EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(-1));
- EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(
- Ver4DictConstants::NOT_A_TERMINAL_ID));
-}
-
-TEST(TerminalPositionLookupTableTest, TestSetAndGet) {
- TerminalPositionLookupTable lookupTable;
-
- EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(10, 100));
- EXPECT_EQ(100, lookupTable.getTerminalPtNodePosition(10));
- EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(9));
- EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(9, 200));
- EXPECT_EQ(200, lookupTable.getTerminalPtNodePosition(9));
- EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(10, 300));
- EXPECT_EQ(300, lookupTable.getTerminalPtNodePosition(10));
- EXPECT_FALSE(lookupTable.setTerminalPtNodePosition(-1, 400));
- EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(-1));
- EXPECT_FALSE(lookupTable.setTerminalPtNodePosition(Ver4DictConstants::NOT_A_TERMINAL_ID, 500));
- EXPECT_EQ(NOT_A_DICT_POS, lookupTable.getTerminalPtNodePosition(
- Ver4DictConstants::NOT_A_TERMINAL_ID));
-}
-
-TEST(TerminalPositionLookupTableTest, TestGC) {
- TerminalPositionLookupTable lookupTable;
-
- const std::vector terminalIds = { 10, 20, 30 };
- const std::vector terminalPositions = { 100, 200, 300 };
-
- for (size_t i = 0; i < terminalIds.size(); ++i) {
- EXPECT_TRUE(lookupTable.setTerminalPtNodePosition(terminalIds[i], terminalPositions[i]));
- }
-
- TerminalPositionLookupTable::TerminalIdMap terminalIdMap;
- EXPECT_TRUE(lookupTable.runGCTerminalIds(&terminalIdMap));
-
- for (size_t i = 0; i < terminalIds.size(); ++i) {
- EXPECT_EQ(static_cast(i), terminalIdMap[terminalIds[i]])
- << "Terminal id (" << terminalIds[i] << ") should be changed to " << i;
- EXPECT_EQ(terminalPositions[i], lookupTable.getTerminalPtNodePosition(i));
- }
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/utils/bloom_filter_test.cpp b/app/src/main/jni/tests/dictionary/utils/bloom_filter_test.cpp
deleted file mode 100644
index bcc88438..00000000
--- a/app/src/main/jni/tests/dictionary/utils/bloom_filter_test.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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 "dictionary/utils/bloom_filter.h"
-
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace latinime {
-namespace {
-
-TEST(BloomFilterTest, TestFilter) {
- static const int TEST_RANDOM_DATA_MAX = 65536;
- static const int ELEMENT_COUNT = 1000;
- std::vector elements;
-
- // Initialize data set with random integers.
- {
- // Use the uniform integer distribution [0, TEST_RANDOM_DATA_MAX].
- std::uniform_int_distribution distribution(0, TEST_RANDOM_DATA_MAX);
- auto randomNumberGenerator = std::bind(distribution, std::mt19937());
- for (int i = 0; i < ELEMENT_COUNT; ++i) {
- elements.push_back(randomNumberGenerator());
- }
- }
-
- // Make sure BloomFilter contains nothing by default.
- BloomFilter bloomFilter;
- for (const int elem : elements) {
- ASSERT_FALSE(bloomFilter.isInFilter(elem));
- }
-
- // Copy some of the test vector into bloom filter.
- std::unordered_set elementsThatHaveBeenSetInFilter;
- {
- // Use the uniform integer distribution [0, 1].
- std::uniform_int_distribution distribution(0, 1);
- auto randomBitGenerator = std::bind(distribution, std::mt19937());
- for (const int elem : elements) {
- if (randomBitGenerator() == 0) {
- bloomFilter.setInFilter(elem);
- elementsThatHaveBeenSetInFilter.insert(elem);
- }
- }
- }
-
- for (const int elem : elements) {
- const bool existsInFilter = bloomFilter.isInFilter(elem);
- const bool hasBeenSetInFilter =
- elementsThatHaveBeenSetInFilter.find(elem) != elementsThatHaveBeenSetInFilter.end();
- if (hasBeenSetInFilter) {
- EXPECT_TRUE(existsInFilter) << "elem: " << elem;
- }
- if (!existsInFilter) {
- EXPECT_FALSE(hasBeenSetInFilter) << "elem: " << elem;
- }
- }
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp b/app/src/main/jni/tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp
deleted file mode 100644
index 25878910..00000000
--- a/app/src/main/jni/tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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 "dictionary/utils/buffer_with_extendable_buffer.h"
-
-#include
-
-namespace latinime {
-namespace {
-
-const int DEFAULT_MAX_BUFFER_SIZE = 1024;
-
-TEST(BufferWithExtendablebufferTest, TestWriteAndRead) {
- BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
- int pos = 0;
- // 1 byte
- const uint32_t data_1 = 0xFF;
- EXPECT_TRUE(buffer.writeUint(data_1, 1 /* size */, pos));
- EXPECT_EQ(data_1, buffer.readUint(1, pos));
- pos += 1;
- // 2 byte
- const uint32_t data_2 = 0xFFFF;
- EXPECT_TRUE(buffer.writeUint(data_2, 2 /* size */, pos));
- EXPECT_EQ(data_2, buffer.readUint(2, pos));
- pos += 2;
- // 3 byte
- const uint32_t data_3 = 0xFFFFFF;
- EXPECT_TRUE(buffer.writeUint(data_3, 3 /* size */, pos));
- EXPECT_EQ(data_3, buffer.readUint(3, pos));
- pos += 3;
- // 4 byte
- const uint32_t data_4 = 0xFFFFFFFF;
- EXPECT_TRUE(buffer.writeUint(data_4, 4 /* size */, pos));
- EXPECT_EQ(data_4, buffer.readUint(4, pos));
-}
-
-TEST(BufferWithExtendablebufferTest, TestExtend) {
- BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
- EXPECT_EQ(0, buffer.getTailPosition());
- EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */));
- EXPECT_EQ(4, buffer.getTailPosition());
- EXPECT_TRUE(buffer.extend(8 /* size */));
- EXPECT_EQ(12, buffer.getTailPosition());
- EXPECT_TRUE(buffer.writeUint(0xFFFF /* data */, 4 /* size */, 8 /* pos */));
- EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */));
-}
-
-TEST(BufferWithExtendablebufferTest, TestCopy) {
- BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
- EXPECT_TRUE(buffer.writeUint(0xFF /* data */, 4 /* size */, 0 /* pos */));
- EXPECT_TRUE(buffer.writeUint(0xFFFF /* data */, 4 /* size */, 4 /* pos */));
- BufferWithExtendableBuffer targetBuffer(DEFAULT_MAX_BUFFER_SIZE);
- EXPECT_TRUE(targetBuffer.copy(&buffer));
- EXPECT_EQ(0xFFu, targetBuffer.readUint(4 /* size */, 0 /* pos */));
- EXPECT_EQ(0xFFFFu, targetBuffer.readUint(4 /* size */, 4 /* pos */));
-}
-
-TEST(BufferWithExtendablebufferTest, TestSizeLimit) {
- BufferWithExtendableBuffer emptyBuffer(0 /* maxAdditionalBufferSize */);
- EXPECT_FALSE(emptyBuffer.writeUint(0 /* data */, 1 /* size */, 0 /* pos */));
- EXPECT_FALSE(emptyBuffer.extend(1 /* size */));
-
- BufferWithExtendableBuffer smallBuffer(4 /* maxAdditionalBufferSize */);
- EXPECT_TRUE(smallBuffer.writeUint(0 /* data */, 4 /* size */, 0 /* pos */));
- EXPECT_FALSE(smallBuffer.writeUint(0 /* data */, 1 /* size */, 4 /* pos */));
-
- EXPECT_TRUE(smallBuffer.copy(&emptyBuffer));
- EXPECT_FALSE(emptyBuffer.copy(&smallBuffer));
-
- BufferWithExtendableBuffer buffer(DEFAULT_MAX_BUFFER_SIZE);
- EXPECT_FALSE(buffer.isNearSizeLimit());
- int pos = 0;
- while (!buffer.isNearSizeLimit()) {
- EXPECT_TRUE(buffer.writeUintAndAdvancePosition(0 /* data */, 4 /* size */, &pos));
- }
- EXPECT_GT(pos, 0);
- EXPECT_LE(pos, DEFAULT_MAX_BUFFER_SIZE);
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/utils/byte_array_utils_test.cpp b/app/src/main/jni/tests/dictionary/utils/byte_array_utils_test.cpp
deleted file mode 100644
index 07257530..00000000
--- a/app/src/main/jni/tests/dictionary/utils/byte_array_utils_test.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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 "dictionary/utils/byte_array_utils.h"
-
-#include
-
-#include
-
-namespace latinime {
-namespace {
-
-TEST(ByteArrayUtilsTest, TestReadCodePointTable) {
- const int codePointTable[] = { 0x6f, 0x6b };
- const uint8_t buffer[] = { 0x20u, 0x21u, 0x00u, 0x01u, 0x00u };
- int pos = 0;
- // Expect the first entry of codePointTable
- EXPECT_EQ(0x6f, ByteArrayUtils::readCodePointAndAdvancePosition(buffer, codePointTable, &pos));
- // Expect the second entry of codePointTable
- EXPECT_EQ(0x6b, ByteArrayUtils::readCodePointAndAdvancePosition(buffer, codePointTable, &pos));
- // Expect the original code point from buffer[2] to buffer[4], 0x100
- // It isn't picked from the codePointTable, since it exceeds the range of the codePointTable.
- EXPECT_EQ(0x100, ByteArrayUtils::readCodePointAndAdvancePosition(buffer, codePointTable, &pos));
-}
-
-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, nullptr,
- 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
diff --git a/app/src/main/jni/tests/dictionary/utils/format_utils_test.cpp b/app/src/main/jni/tests/dictionary/utils/format_utils_test.cpp
deleted file mode 100644
index 3561bda3..00000000
--- a/app/src/main/jni/tests/dictionary/utils/format_utils_test.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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 "dictionary/utils/format_utils.h"
-
-#include
-
-#include
-
-#include "utils/byte_array_view.h"
-
-namespace latinime {
-namespace {
-
-TEST(FormatUtilsTest, TestMagicNumber) {
- EXPECT_EQ(0x9BC13AFE, FormatUtils::MAGIC_NUMBER) << "Magic number must not be changed.";
-}
-
-const std::vector getBuffer(const int magicNumber, const int version, const uint16_t flags,
- const size_t headerSize) {
- std::vector buffer;
- buffer.push_back(magicNumber >> 24);
- buffer.push_back(magicNumber >> 16);
- buffer.push_back(magicNumber >> 8);
- buffer.push_back(magicNumber);
-
- buffer.push_back(version >> 8);
- buffer.push_back(version);
-
- buffer.push_back(flags >> 8);
- buffer.push_back(flags);
-
- buffer.push_back(headerSize >> 24);
- buffer.push_back(headerSize >> 16);
- buffer.push_back(headerSize >> 8);
- buffer.push_back(headerSize);
- return buffer;
-}
-
-TEST(FormatUtilsTest, TestDetectFormatVersion) {
- EXPECT_EQ(FormatUtils::UNKNOWN_VERSION,
- FormatUtils::detectFormatVersion(ReadOnlyByteArrayView()));
-
- {
- const std::vector buffer =
- getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_2, 0, 0);
- EXPECT_EQ(FormatUtils::VERSION_2, FormatUtils::detectFormatVersion(
- ReadOnlyByteArrayView(buffer.data(), buffer.size())));
- }
- {
- const std::vector buffer =
- getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_402, 0, 0);
- EXPECT_EQ(FormatUtils::VERSION_402, FormatUtils::detectFormatVersion(
- ReadOnlyByteArrayView(buffer.data(), buffer.size())));
- }
- {
- const std::vector buffer =
- getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_403, 0, 0);
- EXPECT_EQ(FormatUtils::VERSION_403, FormatUtils::detectFormatVersion(
- ReadOnlyByteArrayView(buffer.data(), buffer.size())));
- }
-
- {
- const std::vector buffer =
- getBuffer(FormatUtils::MAGIC_NUMBER - 1, FormatUtils::VERSION_2, 0, 0);
- EXPECT_EQ(FormatUtils::UNKNOWN_VERSION, FormatUtils::detectFormatVersion(
- ReadOnlyByteArrayView(buffer.data(), buffer.size())));
- }
- {
- const std::vector buffer =
- getBuffer(FormatUtils::MAGIC_NUMBER, 100, 0, 0);
- EXPECT_EQ(FormatUtils::UNKNOWN_VERSION, FormatUtils::detectFormatVersion(
- ReadOnlyByteArrayView(buffer.data(), buffer.size())));
- }
- {
- const std::vector buffer =
- getBuffer(FormatUtils::MAGIC_NUMBER, FormatUtils::VERSION_2, 0, 0);
- EXPECT_EQ(FormatUtils::UNKNOWN_VERSION, FormatUtils::detectFormatVersion(
- ReadOnlyByteArrayView(buffer.data(), buffer.size() - 1)));
- }
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/utils/probability_utils_test.cpp b/app/src/main/jni/tests/dictionary/utils/probability_utils_test.cpp
deleted file mode 100644
index 4020ea44..00000000
--- a/app/src/main/jni/tests/dictionary/utils/probability_utils_test.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 "dictionary/utils/probability_utils.h"
-
-#include
-
-#include "defines.h"
-
-namespace latinime {
-namespace {
-
-TEST(ProbabilityUtilsTest, TestEncodeRawProbability) {
- EXPECT_EQ(MAX_PROBABILITY, ProbabilityUtils::encodeRawProbability(1.0f));
- EXPECT_EQ(MAX_PROBABILITY - 9, ProbabilityUtils::encodeRawProbability(0.5f));
- EXPECT_EQ(0, ProbabilityUtils::encodeRawProbability(0.0f));
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/utils/sparse_table_test.cpp b/app/src/main/jni/tests/dictionary/utils/sparse_table_test.cpp
deleted file mode 100644
index 237c9631..00000000
--- a/app/src/main/jni/tests/dictionary/utils/sparse_table_test.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 "dictionary/utils/sparse_table.h"
-
-#include
-
-#include "dictionary/utils/buffer_with_extendable_buffer.h"
-
-namespace latinime {
-namespace {
-
-TEST(SparseTableTest, TestSetAndGet) {
- static const int BLOCK_SIZE = 64;
- static const int DATA_SIZE = 4;
- BufferWithExtendableBuffer indexTableBuffer(
- BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
- BufferWithExtendableBuffer contentTableBuffer(
- BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE);
- SparseTable sparseTable(&indexTableBuffer, &contentTableBuffer, BLOCK_SIZE, DATA_SIZE);
-
- EXPECT_FALSE(sparseTable.contains(10));
- EXPECT_TRUE(sparseTable.set(10, 100u));
- EXPECT_EQ(100u, sparseTable.get(10));
- EXPECT_TRUE(sparseTable.contains(10));
- EXPECT_TRUE(sparseTable.contains(BLOCK_SIZE - 1));
- EXPECT_FALSE(sparseTable.contains(BLOCK_SIZE));
- EXPECT_TRUE(sparseTable.set(11, 101u));
- EXPECT_EQ(100u, sparseTable.get(10));
- EXPECT_EQ(101u, sparseTable.get(11));
-}
-
-} // namespace
-} // namespace latinime
diff --git a/app/src/main/jni/tests/dictionary/utils/trie_map_test.cpp b/app/src/main/jni/tests/dictionary/utils/trie_map_test.cpp
deleted file mode 100644
index 8f3ec9d2..00000000
--- a/app/src/main/jni/tests/dictionary/utils/trie_map_test.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * 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 "dictionary/utils/trie_map.h"
-
-#include
-
-#include
-#include
-#include
-#include