summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-05-24 16:09:40 +0800
committerPeng Wu <alexepico@gmail.com>2016-05-24 16:09:40 +0800
commitb92ec5fc578b73479861b7da9e4524fc8998df2d (patch)
tree2f354a84a0ad72716eb0fe371c05bc6457312118 /tests
parent0d2c765a160775f1b97be83c3bd8a045b7b5600a (diff)
downloadlibpinyin-b92ec5fc578b73479861b7da9e4524fc8998df2d.zip
libpinyin-b92ec5fc578b73479861b7da9e4524fc8998df2d.tar.gz
libpinyin-b92ec5fc578b73479861b7da9e4524fc8998df2d.tar.xz
write dump_ranges function
Diffstat (limited to 'tests')
-rw-r--r--tests/storage/test_chewing_table.cpp53
-rw-r--r--tests/tests_helper.h54
2 files changed, 57 insertions, 50 deletions
diff --git a/tests/storage/test_chewing_table.cpp b/tests/storage/test_chewing_table.cpp
index c0a1ae7..7a819b9 100644
--- a/tests/storage/test_chewing_table.cpp
+++ b/tests/storage/test_chewing_table.cpp
@@ -96,58 +96,11 @@ int main(int argc, char * argv[]) {
phrase_index.clear_ranges(ranges);
largetable.search(keys->len, (ChewingKey *)keys->data, ranges);
- for (i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
- GArray * & range = ranges[i];
- if (!range)
- continue;
-
- if (range->len)
- printf("range items number:%d\n", range->len);
-
- for (size_t k = 0; k < range->len; ++k) {
- PhraseIndexRange * onerange =
- &g_array_index(range, PhraseIndexRange, k);
- printf("start:%d\tend:%d\n", onerange->m_range_begin,
- onerange->m_range_end);
-
- PhraseItem item;
- for ( phrase_token_t token = onerange->m_range_begin;
- token != onerange->m_range_end; ++token){
-
- phrase_index.get_phrase_item( token, item);
-
- /* get phrase string */
- ucs4_t buffer[MAX_PHRASE_LENGTH + 1];
- item.get_phrase_string(buffer);
- char * string = g_ucs4_to_utf8
- ( buffer, item.get_phrase_length(),
- NULL, NULL, NULL);
- printf("%s\t", string);
- g_free(string);
-
- ChewingKey chewing_buffer[MAX_PHRASE_LENGTH];
- size_t npron = item.get_n_pronunciation();
- guint32 freq;
- for (size_t m = 0; m < npron; ++m){
- item.get_nth_pronunciation(m, chewing_buffer, freq);
- for (size_t n = 0; n < item.get_phrase_length();
- ++n){
- gchar * pinyins =
- chewing_buffer[n].get_pinyin_string();
- printf("%s'", pinyins);
- g_free(pinyins);
- }
- printf("\b\t%d\t", freq);
- }
- }
- printf("\n");
- }
- g_array_set_size(range, 0);
- }
+ dump_ranges(&phrase_index, ranges);
phrase_index.destroy_ranges(ranges);
- g_array_free(keys, TRUE);
- g_array_free(key_rests, TRUE);
+ g_array_free(keys, TRUE);
+ g_array_free(key_rests, TRUE);
}
if (linebuf)
diff --git a/tests/tests_helper.h b/tests/tests_helper.h
index aa43324..995d8c1 100644
--- a/tests/tests_helper.h
+++ b/tests/tests_helper.h
@@ -83,4 +83,58 @@ inline bool load_phrase_table(const pinyin_table_info_t * phrase_files,
return true;
}
+inline bool dump_ranges(FacadePhraseIndex * phrase_index,
+ PhraseIndexRanges ranges) {
+
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ GArray * & range = ranges[i];
+ if (!range)
+ continue;
+
+ if (range->len)
+ printf("range items number:%d\n", range->len);
+
+ for (size_t k = 0; k < range->len; ++k) {
+ PhraseIndexRange * onerange =
+ &g_array_index(range, PhraseIndexRange, k);
+ printf("start:%d\tend:%d\n", onerange->m_range_begin,
+ onerange->m_range_end);
+
+ PhraseItem item;
+ for ( phrase_token_t token = onerange->m_range_begin;
+ token != onerange->m_range_end; ++token){
+
+ phrase_index->get_phrase_item( token, item);
+
+ /* get phrase string */
+ ucs4_t buffer[MAX_PHRASE_LENGTH + 1];
+ item.get_phrase_string(buffer);
+ char * string = g_ucs4_to_utf8
+ ( buffer, item.get_phrase_length(),
+ NULL, NULL, NULL);
+ printf("%s\t", string);
+ g_free(string);
+
+ ChewingKey chewing_buffer[MAX_PHRASE_LENGTH];
+ size_t npron = item.get_n_pronunciation();
+ guint32 freq;
+ for (size_t m = 0; m < npron; ++m){
+ item.get_nth_pronunciation(m, chewing_buffer, freq);
+ for (size_t n = 0; n < item.get_phrase_length();
+ ++n){
+ gchar * pinyins =
+ chewing_buffer[n].get_pinyin_string();
+ printf("%s'", pinyins);
+ g_free(pinyins);
+ }
+ printf("\b\t%d\t", freq);
+ }
+ }
+ printf("\n");
+ }
+ }
+
+ return true;
+}
+
#endif