summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-05-21 15:21:10 +0800
committerPeng Wu <alexepico@gmail.com>2012-05-21 15:21:10 +0800
commit48becacb2a3369491c869e78bcca88aa0db07518 (patch)
tree2951f7774048f1827bb317d12cdb33eab276ffc6
parent2380f39316da63d8c140fc920309e8ff149fec1f (diff)
downloadlibpinyin-48becacb2a3369491c869e78bcca88aa0db07518.zip
libpinyin-48becacb2a3369491c869e78bcca88aa0db07518.tar.gz
libpinyin-48becacb2a3369491c869e78bcca88aa0db07518.tar.xz
updates tests
-rw-r--r--tests/storage/test_chewing_table.cpp34
-rw-r--r--tests/storage/test_phrase_index.cpp33
-rw-r--r--tests/storage/test_phrase_table.cpp30
3 files changed, 47 insertions, 50 deletions
diff --git a/tests/storage/test_chewing_table.cpp b/tests/storage/test_chewing_table.cpp
index 1c705f1..028cda9 100644
--- a/tests/storage/test_chewing_table.cpp
+++ b/tests/storage/test_chewing_table.cpp
@@ -31,28 +31,26 @@ int main(int argc, char * argv[]) {
ChewingLargeTable largetable(options);
FacadePhraseIndex phrase_index;
- FILE * gbfile = fopen("../../data/gb_char.table", "r");
- if (NULL == gbfile) {
- fprintf(stderr, "open gb_char.table failed!\n");
- exit(ENOENT);
- }
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ const char * tablename = pinyin_table_files[i];
+ if ( NULL == tablename )
+ continue;
- largetable.load_text(gbfile);
- fseek(gbfile, 0L, SEEK_SET);
- phrase_index.load_text(1, gbfile);
- fclose(gbfile);
+ gchar * filename = g_build_filename("..", "..", "data",
+ tablename, NULL);
+ FILE * tablefile = fopen(filename, "r");
+ if (NULL == tablefile) {
+ fprintf(stderr, "open %s failed!\n", tablename);
+ exit(ENOENT);
+ }
- FILE * gbkfile = fopen("../../data/gbk_char.table", "r");
- if (NULL == gbkfile) {
- fprintf(stderr, "open gbk_char.table failed!\n");
- exit(ENOENT);
+ largetable.load_text(tablefile);
+ fseek(tablefile, 0L, SEEK_SET);
+ phrase_index.load_text(i, tablefile);
+ fclose(tablefile);
+ g_free(filename);
}
- largetable.load_text(gbkfile);
- fseek(gbkfile, 0L, SEEK_SET);
- phrase_index.load_text(2, gbkfile);
- fclose(gbkfile);
-
MemoryChunk * new_chunk = new MemoryChunk;
largetable.store(new_chunk);
largetable.load(new_chunk);
diff --git a/tests/storage/test_phrase_index.cpp b/tests/storage/test_phrase_index.cpp
index 22f5efc..4f1fe58 100644
--- a/tests/storage/test_phrase_index.cpp
+++ b/tests/storage/test_phrase_index.cpp
@@ -71,25 +71,24 @@ int main(int argc, char * argv[]){
}
FacadePhraseIndex phrase_index_load;
-
- FILE* infile = fopen("../../data/gb_char.table", "r");
- if ( NULL == infile ){
- fprintf(stderr, "open gb_char.table failed!\n");
- exit(ENOENT);
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ const char * tablename = pinyin_table_files[i];
+ if (NULL == tablename)
+ continue;
+
+ gchar * filename = g_build_filename("..", "..", "data",
+ tablename, NULL);
+ FILE* tablefile = fopen(filename, "r");
+ if ( NULL == tablefile ){
+ fprintf(stderr, "open %s failed!\n", tablename);
+ exit(ENOENT);
+ }
+
+ phrase_index_load.load_text(i, tablefile);
+ fclose(tablefile);
+ g_free(filename);
}
- phrase_index_load.load_text(1, infile);
- fclose(infile);
-
- infile = fopen("../../data/gbk_char.table", "r");
- if ( NULL == infile ){
- fprintf(stderr, "open gbk_char.table failed!\n");
- exit(ENOENT);
- }
-
- phrase_index_load.load_text(2, infile);
- fclose(infile);
-
phrase_index.compat();
MemoryChunk* store1 = new MemoryChunk;
diff --git a/tests/storage/test_phrase_table.cpp b/tests/storage/test_phrase_table.cpp
index 2907948..a7043a8 100644
--- a/tests/storage/test_phrase_table.cpp
+++ b/tests/storage/test_phrase_table.cpp
@@ -7,24 +7,24 @@ size_t bench_times = 1000;
int main(int argc, char * argv[]){
PhraseLargeTable largetable;
- FILE * gbfile = fopen("../../data/gb_char.table", "r");
- if ( gbfile == NULL ) {
- fprintf(stderr, "open gb_char.table failed!\n");
- return 1;
- }
-
- largetable.load_text(gbfile);
- fclose(gbfile);
+ for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
+ const char * tablename = pinyin_table_files[i];
+ if (NULL == tablename)
+ continue;
+
+ gchar * filename = g_build_filename("..", "..", "data",
+ tablename, NULL);
+ FILE * tablefile = fopen(filename, "r");
+ if ( tablefile == NULL ) {
+ fprintf(stderr, "open %s failed!\n", tablename);
+ return 1;
+ }
- FILE * gbkfile = fopen("../../data/gbk_char.table", "r");
- if (gbkfile == NULL ) {
- fprintf(stderr, "open gbk_char.table failed!\n");
- return 1;
+ largetable.load_text(tablefile);
+ fclose(tablefile);
+ g_free(filename);
}
- largetable.load_text(gbkfile);
- fclose(gbkfile);
-
MemoryChunk * chunk = new MemoryChunk;
largetable.store(chunk);
largetable.load(chunk);