From 5f3df104b5ac0c3497a48cfc476eb3eedf1e543b Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 6 Jun 2022 11:29:16 +0800 Subject: Use check_result macro in tests directory --- tests/include/test_memory_chunk.cpp | 8 ++++---- tests/lookup/test_pinyin_lookup.cpp | 2 +- tests/storage/test_flexible_ngram.cpp | 20 ++++++++++---------- tests/storage/test_ngram.cpp | 20 ++++++++++---------- tests/storage/test_phrase_index.cpp | 6 +++--- tests/storage/test_phrase_index_logger.cpp | 6 +++--- tests/storage/test_table_info.cpp | 6 +++--- 7 files changed, 34 insertions(+), 34 deletions(-) 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/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/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::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 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 c33df32..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.save_db("/tmp/snapshot.db")); - assert(bigram.load_db("/tmp/snapshot.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..4de1947 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); + assert(FALSE); } } @@ -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); -- cgit v1.2.1