Permalink
Browse files

Add test-special-symbol

  • Loading branch information...
czchen committed Nov 10, 2012
1 parent 0f6d437 commit 9a297fe8ecac74a708d4ec6eea856faab58d832d
Showing with 176 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 test/Makefile.am
  3. +173 −0 test/test-special-symbol.c
View
@@ -65,6 +65,8 @@ test/test-reset
test/test-reset.exe
test/test-symbol
test/test-symbol.exe
+test/test-special-symbol
+test/test-special-symbol.exe
test/test-utf8
test/test-utf8.exe
View
@@ -33,6 +33,7 @@ NATIVE_TESTS = \
test-path \
test-reset \
test-symbol \
+ test-special-symbol \
test-utf8 \
$(NULL)
View
@@ -0,0 +1,173 @@
+/**
+ * test-special-symbol.c
+ *
+ * Copyright (c) 2012
+ * libchewing Core Team. See ChangeLog for details.
+ *
+ * See the file "COPYING" for information on usage and redistribution
+ * of this file.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "chewing.h"
+#include "test.h"
+
+static const TestData SPECIAL_SYMBOL_TABLE[] = {
+ { .token = "[<E>", .expected = "" },
+ { .token = "]<E>", .expected = "" },
+ { .token = "{<E>", .expected = "" },
+ { .token = "}<E>", .expected = ""},
+ { .token = "'<E>", .expected = "" },
+ { .token = "<<><E>", .expected = "" },
+ { .token = ":<E>", .expected = "" },
+ { .token = "\"<E>", .expected = "" },
+ { .token = "><E>", .expected = "" },
+ { .token = "~<E>", .expected = "" },
+ { .token = "!<E>", .expected = "" },
+ { .token = "@<E>", .expected = "" },
+ { .token = "#<E>", .expected = "" },
+ { .token = "$<E>", .expected = "" },
+ { .token = "%<E>", .expected = "" },
+ { .token = "^<E>", .expected = "︿" },
+ { .token = "&<E>", .expected = "" },
+ { .token = "*<E>", .expected = "" },
+ { .token = "(<E>", .expected = "" },
+ { .token = ")<E>", .expected = "" },
+ { .token = "_<E>", .expected = "" },
+ { .token = "+<E>", .expected = "" },
+ { .token = "=<E>", .expected = "" },
+ { .token = "\\<E>", .expected = "" },
+ { .token = "|<E>", .expected = "" },
+ { .token = "?<E>", .expected = "" },
+ { .token = ",<E>", .expected = "" },
+ { .token = ".<E>", .expected = "" },
+ { .token = ";<E>", .expected = "" },
+};
+
+int is_bopomofo_collision_key( const char *key )
+{
+ static const char *COLLISION_KEY[] = {
+ "<<><E>",
+ "><E>",
+ ";<E>",
+ ",<E>",
+ ".<E>",
+ };
+
+ for ( int i = 0; i < ARRAY_SIZE( COLLISION_KEY ); ++i ) {
+ if ( strcmp( key, COLLISION_KEY[i] ) == 0 ) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void test_in_chinese_mode()
+{
+ chewing_Init( NULL, NULL );
+
+ ChewingContext *ctx = chewing_new();
+ ok( ctx, "chewing_new shall not return NULL" );
+
+ chewing_set_maxChiSymbolLen( ctx, 16 );
+
+ for ( int i = 0; i < ARRAY_SIZE( SPECIAL_SYMBOL_TABLE ); ++i ) {
+ // If bopomofo symbol is collided with special symbol, use
+ // bopomofo symbol
+ if ( is_bopomofo_collision_key( SPECIAL_SYMBOL_TABLE[i].token ) )
+ continue;
+
+ ok_keystoke( ctx, SPECIAL_SYMBOL_TABLE[i].token,
+ SPECIAL_SYMBOL_TABLE[i].expected );
+ }
+
+ chewing_delete( ctx );
+ chewing_Terminate();
+}
+
+void test_in_easy_symbol_mode()
+{
+ chewing_Init( NULL, NULL );
+
+ ChewingContext *ctx = chewing_new();
+ ok( ctx, "chewing_new shall not return NULL" );
+
+ chewing_set_maxChiSymbolLen( ctx, 16 );
+ chewing_set_easySymbolInput( ctx, 1 );
+
+ for ( int i = 0; i < ARRAY_SIZE( SPECIAL_SYMBOL_TABLE ); ++i ) {
+ ok_keystoke( ctx, SPECIAL_SYMBOL_TABLE[i].token,
+ SPECIAL_SYMBOL_TABLE[i].expected );
+ }
+
+ chewing_delete( ctx );
+ chewing_Terminate();
+}
+
+int is_fullshape_collision_key( const char *key )
+{
+ static const char *COLLISION_KEY[] = {
+ "\"<E>",
+ "'<E>",
+ "/<E>",
+ "<<><E>",
+ "><E>",
+ "`<E>",
+ "[<E>",
+ "]<E>",
+ "{<E>",
+ "}<E>",
+ "+<E>",
+ "-<E>",
+ };
+
+ for ( int i = 0; i < ARRAY_SIZE( COLLISION_KEY ); ++i ) {
+ if ( strcmp( key, COLLISION_KEY[i] ) == 0 ) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+void test_in_fullshape_mode()
+{
+ chewing_Init( NULL, NULL );
+
+ ChewingContext *ctx = chewing_new();
+ ok( ctx, "chewing_new shall not return NULL" );
+
+ chewing_set_maxChiSymbolLen( ctx, 16 );
+ chewing_set_ChiEngMode( ctx, SYMBOL_MODE );
+ chewing_set_ShapeMode( ctx, FULLSHAPE_MODE );
+
+ for ( int i = 0; i < ARRAY_SIZE( SPECIAL_SYMBOL_TABLE ); ++i ) {
+ // If fullshape symbol is collided with special symbol, use
+ // fullshape symbol
+ if ( is_fullshape_collision_key( SPECIAL_SYMBOL_TABLE[i].token ) )
+ continue;
+
+ ok_keystoke( ctx, SPECIAL_SYMBOL_TABLE[i].token,
+ SPECIAL_SYMBOL_TABLE[i].expected );
+ }
+
+ chewing_delete( ctx );
+ chewing_Terminate();
+}
+
+int main()
+{
+ putenv( "CHEWING_PATH=" CHEWING_DATA_PREFIX );
+ putenv( "CHEWING_USER_PATH=" TEST_HASH_DIR );
+
+ test_in_chinese_mode();
+ test_in_easy_symbol_mode();
+ test_in_fullshape_mode();
+
+ return exit_status();
+}

0 comments on commit 9a297fe

Please sign in to comment.