Permalink
Browse files

Change default candidate per page to 10

  • Loading branch information...
1 parent 688c816 commit 785c046cd7b75e9f61f6e30e9db6f58250257367 @czchen czchen committed Oct 28, 2012
Showing with 43 additions and 15 deletions.
  1. +2 −2 .gitignore
  2. +7 −1 doc/libchewing.texi
  3. +1 −0 include/global.h
  4. +3 −1 src/chewingio.c
  5. +0 −7 src/chewingutil.c
  6. +0 −2 src/choice.c
  7. +1 −1 test/Makefile.am
  8. +29 −1 test/{test-default-config.c → test-config.c}
View
4 .gitignore
@@ -46,8 +46,8 @@ test/simulate
test/simulate.exe
test/testchewing
test/testchewing.exe
-test/test-default-config
-test/test-default-config.exe
+test/test-config
+test/test-config.exe
test/test-easy-symbol
test/test-easy-symbol.exe
test/test-key2pho
View
8 doc/libchewing.texi
@@ -525,7 +525,9 @@ This function checks if the candidates selection has finished.
@section Candidates Behavior
@deftypefun void chewing_set_candPerPage (ChewingContext *@var{ctx}, int @var{n})
-This function sets the candidates per page to @var{n}.
+This function sets the candidates per page to @var{n}. If MIN_SELKEY @leq{}
+@var{n} @leq{} MAX_SELKEY is not true, the @var{n} will be ignored. The default
+candidates per page is MAX_SELKEY.
@end deftypefun
@deftypefun int chewing_get_candPerPage (ChewingContext *@var{ctx})
@@ -536,6 +538,10 @@ This function returns the candidates per page.
The number of maximum candidates that are selectable via shortcut
keys.
@end deftypevr
+@deftypevr Marco int MIN_SELKEY
+The number of minimum candidates that are selectable via shortcut
+keys.
+@end deftypevr
@deftypefun void chewing_set_selKey (ChewingContext *@var{ctx}, int *@var{selkeys}, int @var{len})
This function sets the selection key to @var{selkeys}, an integer
View
1 include/global.h
@@ -55,6 +55,7 @@
#endif
#endif
+#define MIN_SELKEY 1
#define MAX_SELKEY 10
/**
View
4 src/chewingio.c
@@ -140,6 +140,7 @@ static void chooseCandidate( ChewingContext *ctx, int toSelect, int key_buf_curs
static ChewingData * allocate_ChewingData()
{
static const ChewingConfigData DEFAULT_CONFIG = {
+ .candPerPage = MAX_SELKEY,
.selKey = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' },
};
@@ -366,7 +367,8 @@ CHEWING_API int chewing_Configure( ChewingContext *ctx, ChewingConfigData *pcd )
CHEWING_API void chewing_set_candPerPage( ChewingContext *ctx, int n )
{
- ctx->data->config.candPerPage = n;
+ if ( MIN_SELKEY <= n && n <= MAX_SELKEY )
+ ctx->data->config.candPerPage = n;
}
CHEWING_API int chewing_get_candPerPage( ChewingContext *ctx )
View
7 src/chewingutil.c
@@ -153,9 +153,6 @@ int HaninSymbolInput( ChewingData *pgdata )
pai->nAvail = 1;
pai->currentAvail = 0;
pci->nChoicePerPage = candPerPage;
- if ( pci->nChoicePerPage > MAX_SELKEY ) {
- pci->nChoicePerPage = MAX_SELKEY;
- }
pci->nPage = CEIL_DIV( pci->nTotalChoice, pci->nChoicePerPage );
pci->pageNo = 0;
pci->isSymbol = 1;
@@ -387,8 +384,6 @@ int SymbolChoice( ChewingData *pgdata, int sel_i )
pai->nAvail = 1;
pai->currentAvail = 0;
pci->nChoicePerPage = pgdata->config.candPerPage;
- if ( pci->nChoicePerPage > MAX_SELKEY )
- pci->nChoicePerPage = MAX_SELKEY;
pci->nPage = CEIL_DIV( pci->nTotalChoice, pci->nChoicePerPage );
pci->pageNo = 0;
pci->isSymbol = 2;
@@ -1338,8 +1333,6 @@ int OpenSymbolChoice( ChewingData *pgdata )
}
pci->nChoicePerPage = pgdata->config.candPerPage;
- if ( pci->nChoicePerPage > MAX_SELKEY )
- pci->nChoicePerPage = MAX_SELKEY;
pci->nPage = CEIL_DIV( pci->nTotalChoice, pci->nChoicePerPage );
pci->pageNo = 0;
pci->isSymbol = 3;
View
2 src/choice.c
@@ -317,8 +317,6 @@ static void SetChoiceInfo( ChewingData *pgdata )
/* magic number */
pci->nChoicePerPage = candPerPage;
- if ( pci->nChoicePerPage > MAX_SELKEY )
- pci->nChoicePerPage = MAX_SELKEY;
pci->nPage = CEIL_DIV( pci->nTotalChoice, pci->nChoicePerPage );
pci->pageNo = 0;
}
View
2 test/Makefile.am
@@ -24,7 +24,7 @@ libtest_la_LIBADD = \
TESTS = $(NATIVE_TESTS)
NATIVE_TESTS = \
- test-default-config \
+ test-config \
test-easy-symbol \
test-key2pho \
test-mmap \
View
30 test/test-default-config.c → test/test-config.c
@@ -1,5 +1,5 @@
/**
- * test-default-config.c
+ * test-config.c
*
* Copyright (c) 2012
* libchewing Core Team. See ChangeLog for details.
@@ -12,11 +12,16 @@
#include <config.h>
#endif
+#include <stdlib.h>
#include <string.h>
#include "chewing.h"
#include "test.h"
+static const int MIN_CAND_PER_PAGE = 1;
+static const int MAX_CAND_PER_PAGE = 10;
+static const int DEFAULT_CAND_PER_PAGE = 10;
+
static const int DEFAULT_SELECT_KEY[] = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
@@ -38,12 +43,35 @@ void test_default_select_key()
chewing_Terminate();
}
+void test_cand_per_page()
+{
+ chewing_Init( 0, 0 );
+
+ ChewingContext *ctx = chewing_new();
+ ok( ctx, "chewing_new shall not return NULL" );
+
+ ok( chewing_get_candPerPage( ctx ) == DEFAULT_CAND_PER_PAGE,
+ "candPerPage shall be default value" );
+
+ chewing_set_candPerPage( ctx, MIN_CAND_PER_PAGE - 1 );
+ ok( chewing_get_candPerPage( ctx ) == DEFAULT_CAND_PER_PAGE,
+ "candPerPage shall not change" );
+
+ chewing_set_candPerPage( ctx, MAX_CAND_PER_PAGE + 1 );
+ ok( chewing_get_candPerPage( ctx ) == DEFAULT_CAND_PER_PAGE,
+ "candPerPage shall not change" );
+
+ chewing_delete( ctx );
+ chewing_Terminate();
+}
+
int main()
{
putenv( "CHEWING_PATH=" CHEWING_DATA_PREFIX );
putenv( "CHEWING_USER_PATH=" TEST_HASH_DIR );
test_default_select_key();
+ test_cand_per_page();
return exit_status();
}

0 comments on commit 785c046

Please sign in to comment.