diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 10 | ||||
-rw-r--r-- | tests/include/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/include/Makefile.am | 2 | ||||
-rw-r--r-- | tests/include/test_memory_chunk.cpp | 8 | ||||
-rw-r--r-- | tests/lookup/Makefile.am | 9 | ||||
-rw-r--r-- | tests/lookup/test_pinyin_lookup.cpp | 2 | ||||
-rw-r--r-- | tests/storage/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tests/storage/Makefile.am | 9 | ||||
-rw-r--r-- | tests/storage/test_flexible_ngram.cpp | 20 | ||||
-rw-r--r-- | tests/storage/test_ngram.cpp | 20 | ||||
-rw-r--r-- | tests/storage/test_phrase_index.cpp | 6 | ||||
-rw-r--r-- | tests/storage/test_phrase_index_logger.cpp | 6 | ||||
-rw-r--r-- | tests/storage/test_table_info.cpp | 6 | ||||
-rw-r--r-- | tests/test_pinyin.cpp | 4 |
14 files changed, 64 insertions, 46 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 34da2d0..5cf6d32 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,7 +23,7 @@ CLEANFILES = *.bak ACLOCAL = aclocal -I $(ac_aux_dir) -INCLUDES = -I$(top_srcdir)/src \ +AM_CPPFLAGS = -I$(top_srcdir)/src \ -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/storage \ -I$(top_srcdir)/src/lookup \ @@ -40,20 +40,20 @@ noinst_PROGRAMS = test_pinyin \ test_pinyin_SOURCES = test_pinyin.cpp -test_pinyin_LDADD = ../src/libpinyin.la +test_pinyin_LDADD = ../src/libpinyin.la @GLIB2_LIBS@ test_phrase_SOURCES = test_phrase.cpp -test_phrase_LDADD = ../src/libpinyin.la +test_phrase_LDADD = ../src/libpinyin.la @GLIB2_LIBS@ test_chewing_SOURCES = test_chewing.cpp -test_chewing_LDADD = ../src/libpinyin.la +test_chewing_LDADD = ../src/libpinyin.la @GLIB2_LIBS@ if ENABLE_LIBZHUYIN noinst_PROGRAMS += test_zhuyin test_zhuyin_SOURCES = test_zhuyin.cpp -test_zhuyin_LDADD = ../src/libzhuyin.la +test_zhuyin_LDADD = ../src/libzhuyin.la @GLIB2_LIBS@ endif diff --git a/tests/include/CMakeLists.txt b/tests/include/CMakeLists.txt index 3ad956c..43c029f 100644 --- a/tests/include/CMakeLists.txt +++ b/tests/include/CMakeLists.txt @@ -7,3 +7,5 @@ target_link_libraries( test_memory_chunk pinyin ) + +add_test(NAME memory_chunk COMMAND test_memory_chunk) diff --git a/tests/include/Makefile.am b/tests/include/Makefile.am index 4a22aea..a140ff0 100644 --- a/tests/include/Makefile.am +++ b/tests/include/Makefile.am @@ -14,7 +14,7 @@ ## You should have received a copy of the GNU General Public License ## along with this program. If not, see <http://www.gnu.org/licenses/>. -INCLUDES = -I$(top_srcdir)/src \ +AM_CPPFLAGS = -I$(top_srcdir)/src \ -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/storage \ -I$(top_srcdir)/src/lookup \ diff --git a/tests/include/test_memory_chunk.cpp b/tests/include/test_memory_chunk.cpp index 5042882..f496e4d 100644 --- a/tests/include/test_memory_chunk.cpp +++ b/tests/include/test_memory_chunk.cpp @@ -55,13 +55,13 @@ int main(int argc, char * argv[]){ printf("%d\t%d\n", *p3, *(p3+1)); int tmp; - assert(chunk->get_content(sizeof(int), &tmp, sizeof(int))); + check_result(chunk->get_content(sizeof(int), &tmp, sizeof(int))); printf("%d\n", tmp); - assert(chunk->save("/tmp/test.bin")); - assert(chunk->load("/tmp/test.bin")); + check_result(chunk->save("/tmp/test.bin")); + check_result(chunk->load("/tmp/test.bin")); #ifdef LIBPINYIN_USE_MMAP - assert(chunk->mmap("/tmp/test.bin")); + check_result(chunk->mmap("/tmp/test.bin")); #endif delete chunk; diff --git a/tests/lookup/Makefile.am b/tests/lookup/Makefile.am index 10c5301..027298b 100644 --- a/tests/lookup/Makefile.am +++ b/tests/lookup/Makefile.am @@ -14,14 +14,19 @@ ## You should have received a copy of the GNU General Public License ## along with this program. If not, see <http://www.gnu.org/licenses/>. -INCLUDES = -I$(top_srcdir)/src \ +AM_CPPFLAGS = -I$(top_srcdir)/src \ -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/storage \ -I$(top_srcdir)/src/lookup \ -I$(top_srcdir)/tests \ @GLIB2_CFLAGS@ -LDADD = ../../src/libpinyin_internal.la @GLIB2_LIBS@ +LDADD = \ + ../../src/libpinyin_internal.a \ + ../../src/storage/libstorage.a \ + ../../src/lookup/liblookup.a \ + @GLIB2_LIBS@ \ + $(NULL) noinst_PROGRAMS = test_pinyin_lookup \ test_phrase_lookup diff --git a/tests/lookup/test_pinyin_lookup.cpp b/tests/lookup/test_pinyin_lookup.cpp index c1552b4..9cc9f86 100644 --- a/tests/lookup/test_pinyin_lookup.cpp +++ b/tests/lookup/test_pinyin_lookup.cpp @@ -115,7 +115,7 @@ int main( int argc, char * argv[]){ for (size_t i = 0; i < results.size(); ++i) { MatchResult result = NULL; - assert(results.get_result(i, result)); + check_result(results.get_result(i, result)); for (size_t j = 0; j < result->len; ++j){ phrase_token_t * token = &g_array_index(result, phrase_token_t, j); diff --git a/tests/storage/CMakeLists.txt b/tests/storage/CMakeLists.txt index 378e134..4b3a60f 100644 --- a/tests/storage/CMakeLists.txt +++ b/tests/storage/CMakeLists.txt @@ -40,6 +40,8 @@ target_link_libraries( pinyin ) +add_test(NAME phrase_index_logger COMMAND test_phrase_index_logger) + add_executable( test_phrase_table test_phrase_table.cpp @@ -60,6 +62,8 @@ target_link_libraries( pinyin ) +add_test(NAME ngram COMMAND test_ngram) + add_executable( test_flexible_ngram test_flexible_ngram.cpp @@ -69,3 +73,5 @@ target_link_libraries( test_flexible_ngram pinyin ) + +add_test(NAME flexible_ngram COMMAND test_flexible_ngram) diff --git a/tests/storage/Makefile.am b/tests/storage/Makefile.am index 6f75534..6b05918 100644 --- a/tests/storage/Makefile.am +++ b/tests/storage/Makefile.am @@ -14,14 +14,19 @@ ## You should have received a copy of the GNU General Public License ## along with this program. If not, see <http://www.gnu.org/licenses/>. -INCLUDES = -I$(top_srcdir)/src \ +AM_CPPFLAGS = -I$(top_srcdir)/src \ -I$(top_srcdir)/src/include \ -I$(top_srcdir)/src/storage \ -I$(top_srcdir)/src/lookup \ -I$(top_srcdir)/tests \ @GLIB2_CFLAGS@ -LDADD = ../../src/libpinyin_internal.la @GLIB2_LIBS@ +LDADD = \ + ../../src/libpinyin_internal.a \ + ../../src/storage/libstorage.a \ + ../../src/lookup/liblookup.a \ + @GLIB2_LIBS@ \ + $(NULL) TESTS = test_phrase_index_logger \ test_ngram \ diff --git a/tests/storage/test_flexible_ngram.cpp b/tests/storage/test_flexible_ngram.cpp index 0aaf15c..28b1d70 100644 --- a/tests/storage/test_flexible_ngram.cpp +++ b/tests/storage/test_flexible_ngram.cpp @@ -26,7 +26,7 @@ int main(int argc, char * argv[]) { typedef FlexibleSingleGram<guint32, guint32>::ArrayItemWithToken array_item_t; const guint32 total_freq = 16; - assert(single_gram.set_array_header(total_freq)); + check_result(single_gram.set_array_header(total_freq)); phrase_token_t tokens[6] = { 2, 6, 4, 3, 1, 3 }; guint32 freqs[6] = { 1, 2, 4, 8, 16, 32}; @@ -35,9 +35,9 @@ int main(int argc, char * argv[]) { for ( size_t i = 0; i < G_N_ELEMENTS(tokens); ++i ){ if ( single_gram.get_array_item(tokens[i], freq) ) - assert(single_gram.set_array_item(tokens[i], freqs[i])); + check_result(single_gram.set_array_item(tokens[i], freqs[i])); else - assert(single_gram.insert_array_item(tokens[i], freqs[i])); + check_result(single_gram.insert_array_item(tokens[i], freqs[i])); } single_gram.get_array_item(3, freq); @@ -53,16 +53,16 @@ int main(int argc, char * argv[]) { printf("item:%d:%d\n", item->m_token, item->m_item); } - assert(single_gram.get_array_header(freq)); + check_result(single_gram.get_array_header(freq)); assert(freq == total_freq); FlexibleBigram<guint32, guint32, guint32> bigram("TEST"); - assert(bigram.attach("/tmp/training.db", ATTACH_READWRITE|ATTACH_CREATE)); + check_result(bigram.attach("/tmp/training.db", ATTACH_READWRITE|ATTACH_CREATE)); bigram.store(1, &single_gram); - assert(single_gram.insert_array_item(5, 8)); - assert(single_gram.remove_array_item(1, freq)); - assert(single_gram.set_array_header(32)); - assert(single_gram.get_array_header(freq)); + check_result(single_gram.insert_array_item(5, 8)); + check_result(single_gram.remove_array_item(1, freq)); + check_result(single_gram.set_array_header(32)); + check_result(single_gram.get_array_header(freq)); printf("new array header:%d\n", freq); bigram.store(2, &single_gram); @@ -122,7 +122,7 @@ int main(int argc, char * argv[]) { delete train_gram; } - assert(bigram.remove(1)); + check_result(bigram.remove(1)); bigram.get_all_items(items); printf("-----------------------items----------------------------\n"); diff --git a/tests/storage/test_ngram.cpp b/tests/storage/test_ngram.cpp index 0313f1c..3070ee9 100644 --- a/tests/storage/test_ngram.cpp +++ b/tests/storage/test_ngram.cpp @@ -6,7 +6,7 @@ int main(int argc, char * argv[]){ SingleGram single_gram; const guint32 total_freq = 16; - assert(single_gram.set_total_freq(total_freq)); + check_result(single_gram.set_total_freq(total_freq)); phrase_token_t tokens[6] = { 2, 6, 4, 3, 1, 3}; guint32 freqs[6] = { 1, 2, 4, 8, 16, 32}; @@ -15,9 +15,9 @@ int main(int argc, char * argv[]){ for(size_t i = 0; i < 6 ;++i){ if ( single_gram.get_freq(tokens[i], freq)) - assert(single_gram.set_freq(tokens[i], freqs[i])); + check_result(single_gram.set_freq(tokens[i], freqs[i])); else - assert(single_gram.insert_freq(tokens[i], freqs[i])); + check_result(single_gram.insert_freq(tokens[i], freqs[i])); } single_gram.get_freq(3, freq); @@ -33,14 +33,14 @@ int main(int argc, char * argv[]){ printf("item:%d:%f\n", item->m_token, item->m_freq); } - assert(single_gram.get_total_freq(freq)); + check_result(single_gram.get_total_freq(freq)); assert(freq == total_freq); Bigram bigram; - assert(bigram.attach("/tmp/test.db", ATTACH_CREATE|ATTACH_READWRITE)); + check_result(bigram.attach("/tmp/test.db", ATTACH_CREATE|ATTACH_READWRITE)); bigram.store(1, &single_gram); - assert(single_gram.insert_freq(5, 8)); - assert(single_gram.remove_freq(1, freq)); + check_result(single_gram.insert_freq(5, 8)); + check_result(single_gram.remove_freq(1, freq)); single_gram.set_total_freq(32); bigram.store(2, &single_gram); @@ -61,7 +61,7 @@ int main(int argc, char * argv[]){ } printf("--------------------------------------------------------\n"); - assert(single_gram.get_total_freq(freq)); + check_result(single_gram.get_total_freq(freq)); printf("total_freq:%d\n", freq); g_array_free(array, TRUE); @@ -75,8 +75,8 @@ int main(int argc, char * argv[]){ printf("item:%d\n", *token); } - assert(bigram.load_db("/tmp/test.db")); - assert(bigram.save_db("/tmp/test.db")); + check_result(bigram.save_db("/tmp/snapshot.db")); + check_result(bigram.load_db("/tmp/snapshot.db")); g_array_free(items, TRUE); diff --git a/tests/storage/test_phrase_index.cpp b/tests/storage/test_phrase_index.cpp index fa0721a..0fa6a29 100644 --- a/tests/storage/test_phrase_index.cpp +++ b/tests/storage/test_phrase_index.cpp @@ -38,11 +38,11 @@ int main(int argc, char * argv[]){ assert(string1 == string2); FacadePhraseIndex phrase_index_test; - assert(!phrase_index_test.add_phrase_item(1, &phrase_item)); + check_result(!phrase_index_test.add_phrase_item(1, &phrase_item)); MemoryChunk* chunk = new MemoryChunk; - assert(phrase_index_test.store(0, chunk)); - assert(phrase_index_test.load(0, chunk)); + check_result(phrase_index_test.store(0, chunk)); + check_result(phrase_index_test.load(0, chunk)); PhraseItem item2; guint32 time = record_time(); diff --git a/tests/storage/test_phrase_index_logger.cpp b/tests/storage/test_phrase_index_logger.cpp index 4f77964..452b162 100644 --- a/tests/storage/test_phrase_index_logger.cpp +++ b/tests/storage/test_phrase_index_logger.cpp @@ -30,7 +30,7 @@ int main(int argc, char * argv[]){ phrase_index.load(1, chunk); PhraseIndexRange range; - assert(ERROR_OK == phrase_index.get_range(1, range)); + check_result(ERROR_OK == phrase_index.get_range(1, range)); for (size_t i = range.m_range_begin; i < range.m_range_end; ++i ) { phrase_index.add_unigram_frequency(i, 1); } @@ -45,7 +45,7 @@ int main(int argc, char * argv[]){ chunk = new MemoryChunk; chunk->load("../../data/gb_char.bin"); new_chunk = new MemoryChunk; - assert(phrase_index.diff(1, chunk, new_chunk)); + check_result(phrase_index.diff(1, chunk, new_chunk)); new_chunk->save("/tmp/gb_char.dbin"); delete new_chunk; @@ -54,7 +54,7 @@ int main(int argc, char * argv[]){ phrase_index.load(1, chunk); new_chunk = new MemoryChunk; new_chunk->load("/tmp/gb_char.dbin"); - assert(phrase_index.merge(1, new_chunk)); + check_result(phrase_index.merge(1, new_chunk)); chunk = new MemoryChunk; phrase_index.store(1, chunk); chunk->save("/tmp/gb_char2.bin"); diff --git a/tests/storage/test_table_info.cpp b/tests/storage/test_table_info.cpp index e2e4893..27933bc 100644 --- a/tests/storage/test_table_info.cpp +++ b/tests/storage/test_table_info.cpp @@ -44,7 +44,7 @@ void dump_table_info(const pinyin_table_info_t * table_info) { break; default: - assert(false); + abort(); } } @@ -90,8 +90,8 @@ int main(int argc, char * argv[]) { retval = user_table_info.is_conform(&system_table_info); assert(retval); - assert(user_table_info.save("/tmp/user.conf")); - assert(user_table_info.load("/tmp/user.conf")); + check_result(user_table_info.save("/tmp/user.conf")); + check_result(user_table_info.load("/tmp/user.conf")); retval = user_table_info.is_conform(&system_table_info); assert(retval); diff --git a/tests/test_pinyin.cpp b/tests/test_pinyin.cpp index 8eadf89..316cf1e 100644 --- a/tests/test_pinyin.cpp +++ b/tests/test_pinyin.cpp @@ -69,8 +69,8 @@ int main(int argc, char * argv[]){ size_t len = pinyin_parse_more_full_pinyins(instance, linebuf); pinyin_guess_sentence_with_prefix(instance, prefixbuf); - pinyin_guess_candidates(instance, 0, - SORT_BY_PHRASE_LENGTH_AND_FREQUENCY); + guint sort_option = SORT_BY_PHRASE_LENGTH | SORT_BY_FREQUENCY; + pinyin_guess_candidates(instance, 0, sort_option); size_t i = 0; for (i = 0; i <= len; ++i) { |