From 2e94362059fe96a490ef7a8b320a08941b96ec81 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 28 Nov 2011 17:18:39 +0800 Subject: write test parser2 in progress --- tests/storage/test_parser2.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/storage/test_parser2.cpp b/tests/storage/test_parser2.cpp index be22351..a7e57e2 100644 --- a/tests/storage/test_parser2.cpp +++ b/tests/storage/test_parser2.cpp @@ -20,16 +20,26 @@ */ +#include #include +#include +#include +#include "pinyin_parser2.h" + + +using namespace pinyin; static const char * help_msg = "Usage:\n" " test-parser -p [-s ] [options].\n\n" " -p fullpinyin/doublepinyin/chewing.\n" +#if 0 " -s specify scheme for doublepinyin/chewing.\n" " schemes for doublepinyin: zrm, ms, ziguang, abc, pyjj, xhe.\n" " schemes for chewing: standard, ibm, ginyieh, eten.\n" +#endif " -i Use incomplete pinyin.\n" + " -h print this help msg.\n" ; @@ -38,5 +48,48 @@ void print_help(){ } int main(int argc, char * argv[]) { + PinyinParser2 * parser = NULL; + ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); + ChewingKeyRestVector key_rests = + g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); + guint32 options = PINYIN_CORRECT_ALL; + + int i = 1; + while(i < argc) { + if (strcmp("-h", argv[i]) == 0) { + print_help(); + exit(0); + } else if (strcmp("-i", argv[i]) == 0) { + options |= PINYIN_INCOMPLETE | CHEWING_INCOMPLETE; + } else if (strcmp("-p", argv[i]) == 0) { + if ( ++i >= argc ) { + print_help(); + exit(EINVAL); + } + const char * name = argv[i]; + if (strcmp("fullpinyin", name) == 0) { + parser = new FullPinyinParser2(); + } else if (strcmp("doublepinyin", name) == 0) { + parser = new DoublePinyinParser2(); + } else if (strcmp("chewing", name) == 0) { + parser = new ChewingParser2(); + } else { + print_help(); + exit(EINVAL); + } + } else { + print_help(); + exit(EINVAL); + } + ++i; + } + + if (NULL == parser) { + print_help(); + exit(EINVAL); + } + + + return 0; } -- cgit