summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-29 15:51:22 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-29 16:00:37 +0800
commit192b5d79a24c36f0c1247bf837e2e837098145f6 (patch)
tree60b95981a8cc787fe69a42e9406900422a653c3f
parent15cb3e9a981848bd1ad14a09067c102196c743db (diff)
downloadlibpinyin-192b5d79a24c36f0c1247bf837e2e837098145f6.tar.gz
libpinyin-192b5d79a24c36f0c1247bf837e2e837098145f6.tar.xz
libpinyin-192b5d79a24c36f0c1247bf837e2e837098145f6.zip
refactor test cases
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/lookup/Makefile.am1
-rw-r--r--tests/lookup/test_simple_lookup.cpp22
-rw-r--r--tests/storage/Makefile.am1
-rw-r--r--tests/storage/test_phrase_index.cpp21
-rw-r--r--tests/storage/test_phrase_table.cpp21
-rw-r--r--tests/storage/test_pinyin_index.cpp21
-rw-r--r--tests/timer.h48
8 files changed, 56 insertions, 81 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 94c831c..6cc9e51 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,6 +30,8 @@ INCLUDES = -I$(top_srcdir)/src \
-I$(top_srcdir)/src/lookup \
@GLIB2_CPPFLAGS@
+noinst_HEADERS = timer.h
+
noinst_PROGRAMS = test_pinyin \
test_phrase \
test_chewing
diff --git a/tests/lookup/Makefile.am b/tests/lookup/Makefile.am
index 68ef412..9c93dad 100644
--- a/tests/lookup/Makefile.am
+++ b/tests/lookup/Makefile.am
@@ -19,6 +19,7 @@ INCLUDES = -I$(top_srcdir)/src \
-I$(top_srcdir)/src/include \
-I$(top_srcdir)/src/storage \
-I$(top_srcdir)/src/lookup \
+ -I$(top_srcdir)/tests \
@GLIB2_CPPFLAGS@
noinst_PROGRAMS = test_simple_lookup test_phrase_lookup
diff --git a/tests/lookup/test_simple_lookup.cpp b/tests/lookup/test_simple_lookup.cpp
index 8114a12..7fefa99 100644
--- a/tests/lookup/test_simple_lookup.cpp
+++ b/tests/lookup/test_simple_lookup.cpp
@@ -1,29 +1,9 @@
+#include "timer.h"
#include <string.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <glib.h>
#include "pinyin_internal.h"
size_t bench_times = 1000;
-guint32 record_time ()
-{
- timeval tv;
- gettimeofday (&tv, NULL);
- return (guint32) tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
-void print_time (guint32 old_time, guint32 times)
-{
- timeval tv;
- gettimeofday (&tv, NULL);
-
- guint32 wasted = (guint32) tv.tv_sec * 1000000 + tv.tv_usec - old_time;
-
- printf("Spent %d us for %d operations, %f us/op, %f times/s.\n\n" , wasted , times , ((double) wasted)/times , times * 1000000.0/wasted );
-}
-
-
int main( int argc, char * argv[]){
PinyinCustomSettings custom;
diff --git a/tests/storage/Makefile.am b/tests/storage/Makefile.am
index 87f5504..54de6af 100644
--- a/tests/storage/Makefile.am
+++ b/tests/storage/Makefile.am
@@ -19,6 +19,7 @@ INCLUDES = -I$(top_srcdir)/src \
-I$(top_srcdir)/src/include \
-I$(top_srcdir)/src/storage \
-I$(top_srcdir)/src/lookup \
+ -I$(top_srcdir)/tests \
@GLIB2_CPPFLAGS@
noinst_PROGRAMS = test_parser \
diff --git a/tests/storage/test_phrase_index.cpp b/tests/storage/test_phrase_index.cpp
index 8f22a7d..066176c 100644
--- a/tests/storage/test_phrase_index.cpp
+++ b/tests/storage/test_phrase_index.cpp
@@ -1,29 +1,10 @@
+#include "timer.h"
#include <stdio.h>
-#include <sys/time.h>
#include <errno.h>
-#include <glib.h>
#include "pinyin_internal.h"
size_t bench_times = 100000;
-guint32 record_time ()
-{
- timeval tv;
- gettimeofday (&tv, NULL);
- return (guint32) tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
-void print_time (guint32 old_time, guint32 times)
-{
- timeval tv;
- gettimeofday (&tv, NULL);
-
- guint32 wasted = (guint32) tv.tv_sec * 1000000 + tv.tv_usec - old_time;
-
- printf("Spent %d us for %d operations, %f us/op, %f times/s.\n\n" , wasted , times , ((double) wasted)/times , times * 1000000.0/wasted );
-}
-
-
int main(int argc, char * argv[]){
PhraseItem phrase_item;
utf16_t string1 = 2;
diff --git a/tests/storage/test_phrase_table.cpp b/tests/storage/test_phrase_table.cpp
index 1bab4cf..a4e3a30 100644
--- a/tests/storage/test_phrase_table.cpp
+++ b/tests/storage/test_phrase_table.cpp
@@ -1,28 +1,9 @@
+#include "timer.h"
#include <string.h>
-#include <stdio.h>
-#include <sys/time.h>
#include "pinyin_internal.h"
size_t bench_times = 1000;
-guint32 record_time ()
-{
- timeval tv;
- gettimeofday(&tv, NULL);
- return (guint32) tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
-void print_time (guint32 old_time, guint32 times)
-{
- timeval tv;
- gettimeofday (&tv, NULL);
-
- guint32 wasted = (guint32) tv.tv_sec * 1000000 + tv.tv_usec - old_time;
-
- printf("Spent %d us for %d operations, %f us/op, %f times/s.\n\n", wasted, times, ((double)wasted)/times, times * 1000000.0/wasted);
-}
-
-
int main(int argc, char * argv[]){
PhraseLargeTable largetable;
diff --git a/tests/storage/test_pinyin_index.cpp b/tests/storage/test_pinyin_index.cpp
index 2a945f4..64e926d 100644
--- a/tests/storage/test_pinyin_index.cpp
+++ b/tests/storage/test_pinyin_index.cpp
@@ -1,28 +1,9 @@
+#include "timer.h"
#include <string.h>
-#include <stdio.h>
-#include <sys/time.h>
#include "pinyin_internal.h"
size_t bench_times = 1000;
-guint32 record_time ()
-{
- timeval tv;
- gettimeofday (&tv, NULL);
- return (guint32) tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
-void print_time (guint32 old_time, guint32 times)
-{
- timeval tv;
- gettimeofday (&tv, NULL);
-
- guint32 wasted = (guint32) tv.tv_sec * 1000000 + tv.tv_usec - old_time;
-
- printf("Spent %d us for %d operations, %f us/op, %f times/s.\n\n" , wasted , times , ((double) wasted)/times , times * 1000000.0/wasted );
-}
-
-
int main( int argc, char * argv[]){
PinyinCustomSettings custom;
diff --git a/tests/timer.h b/tests/timer.h
new file mode 100644
index 0000000..d3f0822
--- /dev/null
+++ b/tests/timer.h
@@ -0,0 +1,48 @@
+/*
+ * libpinyin
+ * Library to deal with pinyin.
+ *
+ * Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef TIMER_H
+#define TIMER_H
+
+#include <sys/time.h>
+#include <stdio.h>
+#include <glib.h>
+
+
+static guint32 record_time ()
+{
+ timeval tv;
+ gettimeofday (&tv, NULL);
+ return (guint32) tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
+static void print_time (guint32 old_time, guint32 times)
+{
+ timeval tv;
+ gettimeofday (&tv, NULL);
+
+ guint32 wasted = (guint32) tv.tv_sec * 1000000 + tv.tv_usec - old_time;
+
+ printf("Spent %d us for %d operations, %f us/op, %f times/s.\n\n" , wasted , times , ((double) wasted)/times , times * 1000000.0/wasted );
+}
+
+
+#endif